Package Torello.HTML

Class SubSection

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.CharSequence, java.lang.Cloneable, java.lang.Comparable<Replaceable>, Replaceable

    public class SubSection
    extends java.lang.Object
    implements java.lang.CharSequence, java.io.Serializable, java.lang.Cloneable, Replaceable
    Allows the NodeSearch Package to simultaneously return both an HTML-Vector sublist, and the location where that sub-list was located (as an instance of DotPair) where that sublist was located.

    This class is is a simple data-structure-class which is used to represent vectorized-html web-page "sub-sections." This class keeps a copy of both the html (as a page-Vector), and the location of this sub-page from whence this html was copied from the original page. The location is saved as an instance of DotPair.

    If the above sounds like technical-jargon, please review class DotPair and notice that the start and end are merely pointers into a vectorized-html web-page. They 'point' to the starting and ending places on the main html web-page that stored this "sub-section" or "sub-list" html-contents.

    This class implements the Replaceable interface which can encapsulate both the location of a portion of html, and its location inside of a main page - from which it was copied, as public fields in this data-structure.

    STALE-DATA NOTE: The burden of ensuring that stale-data is not contained inside an instance of class 'SubSection' is left as an exercise for the programmer using this class. If the original page vector is modified, even the portion of the original page being modified does not overlap this sub-section the values inside the location field could become stale - with respect to the original page. This will happen if any nodes are added or removed from the original page. The location pointers would no longer have indices that represent the original sub-section intended by the original instantiation of this class.
    See Also:
    HTMLNode, DotPair, NodeIndex, TagNodePeekInclusive, InnerTagPeekInclusive, Serialized Form


    • Field Detail

      • serialVersionUID

        🡇    
        public static final long serialVersionUID
        This fulfils the SerialVersion UID requirement for all classes that implement Java's interface java.io.Serializable. Using the Serializable Implementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
        public static final long serialVersionUID = 1;
        
      • location

        🡅  🡇    
        public final DotPair location
        This public field identifies the sub-section location of a particular sub-section from a vectorized-html webpage. The location of the sub-page is specified by the class DotPair public-fields: public final int 'start' and public final int 'end'
        See Also:
        DotPair
        Code:
        Exact Field Declaration Expression:
        public final DotPair location;
        
      • html

        🡅  🡇    
        public java.util.Vector<HTMLNode> html
        This public field identifies the actual nodes - the vectorized-html sub-list - that are included in this sub-section of an html web-page.
        See Also:
        HTMLNode
        Code:
        Exact Field Declaration Expression:
        public Vector<HTMLNode> html;
        
      • comp2

        🡅  🡇    
        public static java.util.Comparator<SubSection> comp2
        This is an "alternative Comparitor" that can be used for sorting instances of this class. It should work with the Collections.sort(List, Comparator) method in the standard JDK package java.util.*;

        NOTE: This simply compares the fields public DotPair location to each-other using the secondary instance of Comparator that is available as a lambda in class DotPair.
        See Also:
        DotPair.comp2
        Code:
        Exact Field Declaration Expression:
        public static Comparator<SubSection> comp2 =
                (SubSection ss1, SubSection ss2) -> DotPair.comp2.compare(ss1.location, ss2.location);
        
    • Constructor Detail

      • SubSection

        🡅  🡇    
        public SubSection​(DotPair location,
                          java.util.Vector<HTMLNode> html)
        This just builds a new instance of this class. It represents a 'sub-section' of the html-page that needs to encapsulated into an object-instance. The contents of this data-structure are merely these two parameters that are passed to this constructor.
        Parameters:
        location - This parameter value will be assigned immediately to the internal-field public DotPair location. It is a two-integer Vector-index class that points to the starting index-position, inside the main html-Vector, of the html class 'SubSection' being constructed here.
        html - This parameter may be any vectorized-html web-page, but the intention is that this Vector is an exact "cloned range" (a copy of a portion of the web-page) whose starting and ending integer index Vector-positions are demarcated by the contents of the parameter 'location'
        Throws:
        java.lang.IllegalArgumentException - This exception will throw if either of these two scenarios occur:

        • If the input Vector<HTMLNode> 'html' has html.size() == 0.
        • If html.size() != location.size()
        See Also:
        location, html, DotPair, NodeIndex, HTMLNode
        Code:
        Exact Constructor Body:
         if (location == null) throw new NullPointerException
             ("Parameter 'DotPair location' to SubSection constructor was null.");
        
         if (html == null) throw new NullPointerException
             ("Parameter 'Vector<HTMLNode> html' to SubSection constructor was null.");
        
         if (html.size() == 0) throw new IllegalArgumentException(
             "Parameter 'Vector<HTMLNode> html' to SubSection constructor has size zero, but " +
             "this is not allowed here."
         );
        
         if (location.size() != html.size()) throw new IllegalArgumentException(
             "Field 'public final int end' [value=" + location.end + "] of passed-parameter " +
             "'DotPair location' to SubSection constructor is different than the length of the " +
             "html-vector [" + html.size() + "]."
         );
        
         this.location   = location;
         this.html       = html;
        
    • Method Detail

      • clone

        🡅  🡇    
        public SubSection clone()
        Java's interface Cloneable requirements. This instantiates a new SubSection with identical Vector<HTMLNode> html and DotPair location fields.
        Overrides:
        clone in class java.lang.Object
        Returns:
        A new SubSection whose internal fields are identical to this one.
        Code:
        Exact Method Body:
         return new SubSection(location, html);
        
      • hashCode

        🡅  🡇    
        public int hashCode()
        Java's hash-code requirement.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hash-code that may be used when storing this node in a java hashed-collection. The starting location of this SubSection ought to be be a unique hash
        Code:
        Exact Method Body:
         return location.start;
        
      • toString

        🡅  🡇    
        public final java.lang.String toString()
        Java's toString() requirement.

        FINAL METHOD: This method is final, and cannot be modified by sub-classes.
        Specified by:
        toString in interface java.lang.CharSequence
        Overrides:
        toString in class java.lang.Object
        Returns:
        A String-representation of this HTMLNode.
        See Also:
        toString()
        Code:
        Exact Method Body:
         return Util.pageToString(html);
        
      • charAt

        🡅  🡇    
        public final char charAt​(int index)
        Returns the char value at the specified index of the String defined-by an invokation of the method: Util.pageToString(html). An index ranges from '0' (zero) to length() - 1. The first char value of the sequence is at index , the next at index one, and so on, as for array indexing.

        NOTE: If the char value specified by the index is a surrogate, the surrogate value is returned.

        FINAL METHOD: This method is final, and cannot be modified by sub-classes.
        Specified by:
        charAt in interface java.lang.CharSequence
        Parameters:
        index - The index of the char value to be returned
        Returns:
        The specified char value
        See Also:
        toString()
        Code:
        Exact Method Body:
         return toString().charAt(index);
        
      • length

        🡅  🡇    
        public final int length()
        Returns the length of the String defined-by an invokation of the method: Util.pageToString(html). The length is the number of 16-bit char's in the sequence.

        FINAL METHOD: This method is final, and cannot be modified by sub-classes.
        Specified by:
        length in interface java.lang.CharSequence
        Returns:
        the number of chars in this.n.str
        See Also:
        toString()
        Code:
        Exact Method Body:
         return toString().length();
        
      • subSequence

        🡅  🡇    
        public final java.lang.CharSequence subSequence​(int start,
                                                        int end)
        Returns a java.lang.CharSequence that is a subsequence of the String defined-by an invokation of the method: Util.pageToString(html). The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in char's) of the returned sequence is end - start, so if start == end then an empty sequence is returned.

        FINAL METHOD: This method is final, and cannot be modified by sub-classes.
        Specified by:
        subSequence in interface java.lang.CharSequence
        Parameters:
        start - The start index, inclusive
        end - The end index, exclusive
        Returns:
        The specified subsequence
        See Also:
        toString()
        Code:
        Exact Method Body:
         return toString().substring(start, end);
        
      • originalSize

        🡅  🡇    
        public int originalSize()
        Description copied from interface: Replaceable
        Reports how many nodes were copied into this instance. For implementing classes that inherit NodeIndex, this value will always be one. For others, it should report exactly how many HTMLNode's were copied.
        Specified by:
        originalSize in interface Replaceable
        Returns:
        Number of nodes originally contained by this instance.

        The purpose of Replaceable's is to allow a user to modify HTML using a smaller sub-list, without having to operate on the entire HTML-Vector since adding & removing nodes is one variant of Vector-modification, the original-size may often differ from the current-size.

        When modifying HTML, if a web-page is broken into smaller-pieces, and changes are restricted to those smaller sub-lists (and the original page is rebuilt, all at once, after all changes have been made) then those modifications should require far-fewer time-consuming list-shift operations, tremendously improving the performance of the code.
        Code:
        Exact Method Body:
         return location.size();
        
      • currentSize

        🡅  🡇    
        public int currentSize()
        Description copied from interface: Replaceable
        Returns how many nodes are currently in this instance.
        Specified by:
        currentSize in interface Replaceable
        Returns:
        Number of nodes. See explanation of the original size, versus the current size here
        Code:
        Exact Method Body:
         return html.size();
        
      • originalLocationStart

        🡅  🡇    
        public int originalLocationStart()
        Description copied from interface: Replaceable
        Returns the start-location within the original page-Vector from whence the HTML contents of this instance were retrieved.

        NOTE: The returned value is inclusive of the actual, original-range of this instance. This means the first HTMLNode copied into this instance' internal data-structure was at originalLocationStart().

        ALSO: The two concrete implementatons of this interface (NodeIndex and SubSection) - both enforce the 'final' modifier on their location-fields. (See: NodeIndex.index and location).
        Specified by:
        originalLocationStart in interface Replaceable
        Returns:
        The Vector start-index from whence this HTML was copied.
        Code:
        Exact Method Body:
         return location.start;
        
      • originalLocationEnd

        🡅  🡇    
        public int originalLocationEnd()
        Description copied from interface: Replaceable
        Returns the end-location within the original page-Vector from whence the HTML contents of this instance were retrieved.

        NOTE: The returned value is exclusive of the actual, original-range of this instance. This means the last HTMLNode to actually be copied into this instance' internal data-structure was located at originalLocationEnd() - 1

        ALSO: The two concrete implementatons of this interface (NodeIndex and SubSection) - both enforce the 'final' modifier on their location-fields. (See: NodeIndex.index and location).
        Specified by:
        originalLocationEnd in interface Replaceable
        Returns:
        The Vector end-index from whence this HTML was copied.
        Code:
        Exact Method Body:
         return location.end + 1;
        
      • currentNodes

        🡅  🡇    
        public java.util.Vector<HTMLNodecurrentNodes()
        Description copied from interface: Replaceable
        All nodes currently contained by this Replaceable. The concrete-classes which implement Replaceable (SubSection & TagNodeIndex) allow for the html they hold to be modified. The modification to a Replaceable happens independently from the original HTML Page out of which it was copied.

        NOTE: Replaceable's are, sort-of, the exact opposite of Java's List method 'subList'. According to the Sun / Oracle Documentation for java.util.List.subList(int fromIndex, int toIndex), any changes made to an instance of a 'subList' are immediately reflected back into the original List from where they were created.

        The List.subList operation has the advantage of being extremely easy to work with - however, an HTML-Page Vector has the potential to be hundreds of nodes long. Any operations that involve insertion or deletion will likely be terribly inefficient. Again - see ReplaceNodes.r(Vector, Iterable, boolean) to understand how quick updates on HTML-Pages is done using the Replaceable interface.
        Specified by:
        currentNodes in interface Replaceable
        Returns:
        An HTML-Vector of the nodes.
        Code:
        Exact Method Body:
         return html;
        
      • addAllInto

        🡅  🡇    
        public boolean addAllInto​(java.util.Vector<HTMLNode> fileVec)
        Description copied from interface: Replaceable
        Add all nodes currently retained in this instance into the HTML-Vector parameter html. The nodes are appended to the end of 'html'. Implementing classes NodeIndex and SubSection simply use the Java Vector method's add (for NodeIndex) and addAll (for SubSection).
        Specified by:
        addAllInto in interface Replaceable
        Parameters:
        fileVec - The HTML-Vector into which the nodes will be appended (to the end of this Vector, using Vector methods add or addAll dependent upon whether one or more-than-one nodes are being inserted).
        Returns:
        The result of Vector method add, or method allAll
        Code:
        Exact Method Body:
         return fileVec.addAll(html);
        
      • addAllInto

        🡅  🡇    
        public boolean addAllInto​(int index,
                                  java.util.Vector<HTMLNode> fileVec)
        Description copied from interface: Replaceable
        Add all nodes currently retained in this instance into the HTML-Vector parameter html.
        Specified by:
        addAllInto in interface Replaceable
        Parameters:
        index - The 'html' parameter's Vector-index where these nodes are to be inserted
        fileVec - The HTML-Vector into which the nodes will be appended (to the end of this Vector, using Vector methods add or addAll dependent upon whether one or more-than-one nodes are being inserted).
        Returns:
        The result of Vector method add, or method allAll
        Code:
        Exact Method Body:
         return fileVec.addAll(index, html);