Class SpanList

java.lang.Object
com.yahoo.document.annotation.SpanNode
com.yahoo.document.annotation.SpanList
All Implemented Interfaces:
SpanNodeParent, Comparable<SpanNode>
Direct Known Subclasses:
AlternateSpanList

public class SpanList extends SpanNode
A node in a Span tree that can have child nodes.
Author:
Einar M R Rosenvinge
  • Field Details

  • Constructor Details

    • SpanList

      public SpanList()
      Creates a new SpanList.
    • SpanList

      public SpanList(SpanNodeReader reader)
    • SpanList

      protected SpanList(List<SpanNode> children)
    • SpanList

      public SpanList(SpanList other)
      Deep-copies a SpanList.
      Parameters:
      other - the SpanList to copy.
  • Method Details

    • add

      public SpanList add(SpanNode node)
      Adds a child node to this SpanList.
      Parameters:
      node - the node to add.
      Returns:
      this, for call chaining
      Throws:
      IllegalStateException - if SpanNode.isValid() returns false.
    • span

      public Span span(int from, int length)
      Create a span, add it to this list and return it
    • move

      public void move(SpanNode node, SpanList target)
      Moves a child of this SpanList to another SpanList.
      Parameters:
      node - the node to move
      target - the SpanList to add the node to
      Throws:
      IllegalArgumentException - if the given node is not a child of this SpanList
    • move

      public void move(int nodeNum, SpanList target)
      Moves a child of this SpanList to another SpanList.
      Parameters:
      nodeNum - the index of the node to move
      target - the SpanList to add the node to
      Throws:
      IndexOutOfBoundsException - if the given index is out of range
    • move

      public void move(SpanNode node, AlternateSpanList target, int targetSubTree)
      Moves a child of this SpanList to another SpanList.
      Parameters:
      node - the node to move
      target - the SpanList to add the node to
      targetSubTree - the index of the subtree of the given AlternateSpanList to add the node to
      Throws:
      IllegalArgumentException - if the given node is not a child of this SpanList
      IndexOutOfBoundsException - if the target subtree index is out of range
    • move

      public void move(int nodeNum, AlternateSpanList target, int targetSubTree)
      Moves a child of this SpanList to another SpanList.
      Parameters:
      nodeNum - the index of the node to move
      target - the SpanList to add the node to
      targetSubTree - the index of the subtree of the given AlternateSpanList to add the node to
      Throws:
      IndexOutOfBoundsException - if the given index is out of range, or the target subtree index is out of range
    • remove

      public SpanList remove(SpanNode node)
      Removes and invalidates the given SpanNode from this.
      Parameters:
      node - the node to remove.
      Returns:
      this, for chaining.
    • remove

      public SpanList remove(int i)
      Removes and invalidates the SpanNode at the given index from this.
      Parameters:
      i - the index of the node to remove.
      Returns:
      this, for chaining.
    • children

      protected List<SpanNode> children()
      Returns a modifiable list of the immediate children of this SpanList.
      Returns:
      a modifiable list of the immediate children of this SpanList.
    • numChildren

      public int numChildren()
      Returns the number of children this SpanList holds.
      Returns:
      the number of children this SpanList holds.
    • childIterator

      public ListIterator<SpanNode> childIterator()
      Traverses all immediate children of this SpanList. The ListIterator returned support all optional operations specified in the ListIterator interface.
      Specified by:
      childIterator in class SpanNode
      Returns:
      a ListIterator which traverses all immediate children of this SpanNode
      See Also:
    • childIteratorRecursive

      public ListIterator<SpanNode> childIteratorRecursive()
      Recursively traverses all children (not only leaf nodes) of this SpanList, in a depth-first fashion. The ListIterator only supports iteration forwards, and the optional operations that are implemented are remove() and set(). add() is not supported.
      Specified by:
      childIteratorRecursive in class SpanNode
      Returns:
      a ListIterator which recursively traverses all children and their children etc. of this SpanList.
      See Also:
    • clearChildren

      public void clearChildren()
      Removes and invalidates all references to child nodes.
    • sortChildren

      public void sortChildren()
      Sorts children by occurrence in the text covered.
      See Also:
    • sortChildrenRecursive

      public void sortChildrenRecursive()
      Recursively sorts all children by occurrence in the text covered.
    • isLeafNode

      public boolean isLeafNode()
      Always returns false, even if this node has no children.
      Specified by:
      isLeafNode in class SpanNode
      Returns:
      always false, even if this node has no children
    • getFrom

      public int getFrom()
      Returns the character index where this SpanNode starts (inclusive), i.e. the smallest SpanNode.getFrom() of all children.
      Specified by:
      getFrom in class SpanNode
      Returns:
      the lowest getFrom() of all children, or -1 if this SpanList has no children.
    • getTo

      public int getTo()
      Returns the character index where this SpanNode ends (exclusive), i.e. the greatest SpanNode.getTo() of all children.
      Specified by:
      getTo in class SpanNode
      Returns:
      the greatest getTo() of all children, or -1 if this SpanList has no children.
    • getLength

      public int getLength()
      Returns the length of this span, i.e. getFrom() - getTo().
      Specified by:
      getLength in class SpanNode
      Returns:
      the length of this span
    • getText

      public CharSequence getText(CharSequence text)
      Returns the text that is covered by this SpanNode.
      Specified by:
      getText in class SpanNode
      Parameters:
      text - the input text
      Returns:
      the text that is covered by this SpanNode.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class SpanNode
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class SpanNode
    • toString

      public String toString()
      Overrides:
      toString in class Object