Package Torello.HTML

Class NodeIndex

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.CharSequence, java.lang.Cloneable, java.lang.Comparable<NodeIndex>
    Direct Known Subclasses:
    CommentNodeIndex, TagNodeIndex, TextNodeIndex

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

    NodeIndex: HTMLNode 'plus' the vector-index

    * This class is just an extremely simple data-structure-class used, generally, for returning both the index of an instance-node of class 'HTMLNode' inside a vectorized-html web-page, and also the node itself. This class is the "parent class" of the extending classes: TextNodeIndex and TagNodeIndex. It is very light-weight, and generally just used by the PEEK operations in the "complex" node-search package. The constructor of this class accepts an index, and a HTMLNode, and saves both of these datum as public, final fields of this class.

    STALE DATA NOTE: If a vectorized-html webpage is modified after any of these Node + Index classes are created / instantiated, and nodes are added or removed from the webpage, then the (integer) index data inside these classes would have become stale when they are next accessed.

    The following public class definitions incorporate vector-index and vector-node-content into a single "combined unit" class:

    • TagNodeIndex
    • TextNodeIndex
    • CommentNodeIndex
    • NodeIndex - is abstract, and the parent of the three above.
    • SubSection - a sublist of nodes


    It is important to remember that vector-position (a.k.a. "vector-index") information that is stored inside object instances of these (extremely-simple) classes will become stale, immediately if nodes are ever added or removed to the underlying vector from which these Node + Index object-classes are created.
    See Also:
    HTMLNode, CommentNodeIndex, TagNodeIndex, TextNodeIndex, 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;
        
      • index

        public int index
        An index to a node from a web-page. This index must point to a the exact same node inside of a vectorized-html page as the node stored in member-field HTMLNode 'n'
        Code:
        Exact Field Declaration Expression:
        1
        public int index;
        
      • n

        public final HTMLNode n
        A HTMLNode from a web-page. This node is supposed to be the same node stored at the index specified by member-field int 'index' of some vectorized-html web-page in memory or on disk.
        Code:
        Exact Field Declaration Expression:
        1
        public final HTMLNode n;
        
    • Constructor Detail

      • NodeIndex

        protected NodeIndex​(int index,
                            HTMLNode n)
        a default constructor. This assigns a value to the index field.
        Parameters:
        index - This is the vector-index location of HTMLNode 'n' inside of a vectorized-HTML web-page.

        STALE DATA NOTE: This class is a minor-use class, not one of the primary data classes. This instance shall become 'useless' the moment the vector that was used to instantiate this class is modified, and the node 'n' is no longer at vector-index 'index.' These "NodeIndex" classes are retained, not deprecated due to the fundamental nature of using the classes of the NodeSearch Package. Data is easily made stale. Generally, when modifying HTML Vectors, the easiest thing to do is to remember to modify a vector at specific locations by iterating from the end of the vector, back to the beginning. This will generally prevent "state-data vector-indexes" from rearing their ugly head.
        n - An HTMLNode that needs to be the node found in the underlying vector at vector-index 'index.'
    • Method Detail

      • check

        protected static final void check​(int index,
                                          HTMLNode n)
        Helps to check data before creating an instance of this class. Exceptions shall contain consistent error messages.

        FINAL METHOD: This method is final, and cannot be modified by sub-classes.
        Parameters:
        index - This is the index of vectorized-page that contains HTMLNode 'n'
        n - This is the HTMLNode being stored in this light-simple data-structure.
        Throws:
        java.lang.IndexOutOfBoundsException - if index is negative, this exception is thrown.
        java.lang.NullPointerException - If the parameter 'n' is null.
        Code:
        Exact Method Body:
        1
        2
        3
        4
        5
        6
        7
         if (n == null)  throw new NullPointerException(
             "HTMLNode parameter 'n' to this constructor was passed a null value, but this " +
             "is not allowed here."
         );
        
         if (index < 0)  throw new IndexOutOfBoundsException
             ("Integer parameter 'index' to this constructor was passed a negative value: " + index);
        
      • equals

        public final boolean equals​(java.lang.Object o)
        Java's public boolean equals(Object o) requirements.

        FINAL METHOD: This method is final, and cannot be modified by sub-classes.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - This may be any Java Object, but only ones of 'this' type whose internal-values are identical will bring this method to return true.
        Returns:
        TRUE If 'this' equals another object HTMLNode.
        Code:
        Exact Method Body:
        1
        2
        3
        4
        5
        6
        7
         NodeIndex other;
         return (this == o) || (
                 (o != null)
             &&  (this.getClass().equals(o.getClass()))
             &&  ((other = (NodeIndex) o).n.str.equals(this.n.str))
             &&  (other.index == this.index)
         );
        
      • hashCode

        public final int hashCode()
        Java's hash-code requirement.

        FINAL METHOD: This method is final, and cannot be modified by sub-classes.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hash-code that may be used when storing this node in a java sorted-collection.
        Code:
        Exact Method Body:
        1
         return index + this.n.str.hashCode();
        
      • compareTo

        public final int compareTo​(NodeIndex ni)
        Java's interface Comparable<T> requirements. This does a very simple comparison using the vector-index position.

        FINAL METHOD: This method is final, and cannot be modified by sub-classes.
        Specified by:
        compareTo in interface java.lang.Comparable<NodeIndex>
        Parameters:
        ni - Any other NodeIndex to be compared to 'this' NodeIndex
        Returns:
        An integer that fulfils Java's interface Comparable<T> public boolean compareTo(T t) method requirements.
        See Also:
        index
        Code:
        Exact Method Body:
        1
         return this.index - ni.index;
        
      • charAt

        public final char charAt​(int index)
        Returns the char value at the specified index of the public final String str field of 'this' field public final HTMLNode n. An index ranges from zero to length() - 1. The first char value of the sequence is at index zero, 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
        Code:
        Exact Method Body:
        1
         return n.str.charAt(index);
        
      • length

        public final int length()
        Returns the length of the public final String str field of 'this' field public final HTMLNode n. The length is the number of 16-bit chars 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
        Code:
        Exact Method Body:
        1
         return n.str.length();
        
      • subSequence

        public final java.lang.CharSequence subSequence​(int start,
                                                        int end)
        Returns a CharSequence that is a subsequence of the public final String str field of 'this' field public final HTMLNode n. The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in chars) 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
        Code:
        Exact Method Body:
        1
         return n.str.substring(start, end);
        
      • toString

        public final java.lang.String toString()
        Returns the public final String str field of 'this' field public final HTMLNode n.

        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 consisting of exactly this sequence of characters.
        See Also:
        HTMLNode.str
        Code:
        Exact Method Body:
        1
         return n.str;