Package Torello.HTML

Class SubSection

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

    public final class SubSection
    extends java.lang.Object
    implements java.lang.CharSequence, java.io.Serializable, java.lang.Comparable<SubSection>, java.lang.Cloneable
    SubSection - Documentation.

    This class is is a simple data-structure-class which is used to represent vectorized-html web-page "sub-sections." It is used almost identically with the class public class 'DotPair' but this class also keeps a copy of the actual HTMLNode content of the vector sub-section that is identified by the fields in this class. While class 'DotPair' only keeps a pointer to the starting and ending index-positions of the html-vector, this class - in addition to keeping an instance of class 'DotPair' as a public member field - also keeps a clone/copy of the sub-list itself as a public field of this class.

    NOTE: If the above sounds like technical-jargon, please review public class DotPair, and notice that the public final int 'start' and 'end' fields are merely pointers into a vectorized-html web-page. They 'point' to the starting and ending places on the main html web-page where this "sub-section" or "sub-list" being and end. This class 'SubSection' is intended to have the same meaning as class class 'DotPair' - except that actual HTML, itself, not just start and end pointers is stored 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 public DotPair location and the values inside public final Vector<HTMLNode> html could become stale. If any nodes are removed or added, the index pointers contained in this class would no longer point to indexes inside the html-page-vector that represent the original sub-section intended by the original instantiation of this class.

    POINT: Make sure that when modifying a vectorized-html web-page that you update, renew, re-look-for, or discard stale vector-index data, and / or stale vector HTMLNode's. If nodes are shifted in the vector due to an insertion or removal, then every instance of "SubSection" created for the vector will be "stale" or "invalid." Keep in mind, and instance of "SubSection" could easily be "shifted" left or right by as many nodes as were inserted or deleted, however, these simple Data Structures in Java-HTML are all immutable. "Shifting" the start and end index positions of a subsection by so many nodes would require building a new public class 'DotPair', and new public class 'SubSection' instance. Luckily, these 'ultra-light' Data-Structures are very easily instantiated.
    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:
        1
        public static final long serialVersionUID = 1;
        
      • location

        public 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:
        1
        public DotPair location;
        
      • html

        public final 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:
        1
        public final 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:
        1
        2
        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 range-clone ... or "cloned range" of a web-page whose starting and ending integer index Vector-positions are 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
    • 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:
        1
         return new SubSection(location, html);
        
      • compareTo

        public final int compareTo​(SubSection other)
        Java's interface Comparable<T> requirements. This does a very simple comparison using the field public DotPair location.

        FINAL METHOD: This method is declared final, and cannot be modified by sub-classes.
        Specified by:
        compareTo in interface java.lang.Comparable<SubSection>
        Parameters:
        other - Any other SubSection to be compared to 'this' NodeISubSectionndex
        Returns:
        An integer that fulfils Java's interface Comparable<T> public boolean compareTo(T t) method requirements.
        See Also:
        DotPair.compareTo(DotPair)
        Code:
        Exact Method Body:
        1
         return this.location.compareTo(other.location);
        
      • 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:
        1
         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:
        1
         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:
        1
         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:
        1
         return toString().substring(start, end);