Package Torello.HTML

Class TextNodeIndex

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

    public class TextNodeIndex
    extends NodeIndex
    implements java.lang.CharSequence, java.io.Serializable, java.lang.Cloneable
    TextNodeIndex - Documentation.

    TextNodeIndex: TextNode 'plus' the vector-index

    * This class has two member fields, listed below:

    • TextNodeIndex.n is an instance of TextNode
    • TextNodeIndex.index is int integer, and contains the Vector-index where this TextNode resides.


    This class is just an extremely simple data-structure-class used, generally, for returning both the index of an instance-node of class 'TextNode' inside a vectorized-html web-page, and also the TextNode itself -simultaneously. The constructor of this class accepts an index, and a TextNode, and saves both of these datum as public, final fields of this class. The 'Peek' suite of search methods in package NodeSearch return instances 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:



    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. This is because the 'index' is just a pointer into the Vector! For data-retrieval operations, these classes can prove highly useful. For page-modification operations, it is better to use the HTML Iterator / HNLI classes.
    See Also:
    TextNode, NodeIndex, TextNodePeek, 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;
        
      • n

        public final TextNode n
        A TextNode node 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.

        IMPORTANT: This field over-rides the parent-class field public final HTMLNode n - and it is an instance of TextNode, rather than HTMLNode
        Code:
        Exact Field Declaration Expression:
        1
        public final TextNode n;
        
      • comp2

        public static final java.util.Comparator<TextNodeIndex> 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 version utilizes the standard JDK String.compareTo(String) method.
        See Also:
        HTMLNode.str
        Code:
        Exact Field Declaration Expression:
        1
        2
        public static final Comparator<TextNodeIndex> comp2 =
                (TextNodeIndex txni1, TextNodeIndex txni2) -> txni1.n.str.compareTo(txni2.n.str);
        
      • comp3

        public static final java.util.Comparator<TextNodeIndex> comp3
        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 version utilizes the standard JDK String.compareToIgnoreCase(String) method.
        See Also:
        HTMLNode.str
        Code:
        Exact Field Declaration Expression:
        1
        2
        public static final Comparator<TextNodeIndex> comp3 =
                (TextNodeIndex txni1, TextNodeIndex txni2) -> txni1.n.str.compareToIgnoreCase(txni2.n.str);
        
    • Constructor Detail

      • TextNodeIndex

        public TextNodeIndex​(int index,
                             TextNode textNode)
        Constructor for this class. Some brief/minor error checking is performed before this class is instantiated.
        Parameters:
        index - This is the index of vectorized-page that contains HTMLNode 'n'
        textNode - This is the TextNode being stored in this light-simple data-structure.
        Throws:
        java.lang.IndexOutOfBoundsException - if index is negative, this exception is thrown.
    • Method Detail

      • clone

        public TextNodeIndex clone()
        Java's interface Cloneable requirements. This instantiates a new TextNodeIndex with identical TextNode n and int index fields.
        Overrides:
        clone in class java.lang.Object
        Returns:
        A new TextNodeIndex whose internal fields are identical to this one.
        Code:
        Exact Method Body:
        1
         return new TextNodeIndex(this.index, this.n);