Package com.yahoo.document.annotation
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 Summary
Fields Modifier and Type Field Description static byte
ID
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SpanList
add(SpanNode node)
Adds a child node to this SpanList.ListIterator<SpanNode>
childIterator()
Traverses all immediate children of this SpanList.ListIterator<SpanNode>
childIteratorRecursive()
Recursively traverses all children (not only leaf nodes) of this SpanList, in a depth-first fashion.protected List<SpanNode>
children()
Returns a modifiable list of the immediate children of this SpanList.void
clearChildren()
Removes and invalidates all references to child nodes.boolean
equals(Object o)
int
getFrom()
Returns the character index where thisSpanNode
starts (inclusive), i.e. the smallestSpanNode.getFrom()
of all children.int
getLength()
Returns the length of this span, i.e. getFrom() - getTo().CharSequence
getText(CharSequence text)
Returns the text that is covered by this SpanNode.int
getTo()
Returns the character index where thisSpanNode
ends (exclusive), i.e. the greatestSpanNode.getTo()
of all children.int
hashCode()
boolean
isLeafNode()
Always returns false, even if this node has no children.void
move(int nodeNum, AlternateSpanList target, int targetSubTree)
Moves a child of this SpanList to another SpanList.void
move(int nodeNum, SpanList target)
Moves a child of this SpanList to another SpanList.void
move(SpanNode node, AlternateSpanList target, int targetSubTree)
Moves a child of this SpanList to another SpanList.void
move(SpanNode node, SpanList target)
Moves a child of this SpanList to another SpanList.int
numChildren()
Returns the number of children this SpanList holds.SpanList
remove(int i)
Removes and invalidates the SpanNode at the given index from this.SpanList
remove(SpanNode node)
Removes and invalidates the given SpanNode from this.void
sortChildren()
Sorts children by occurrence in the text covered.void
sortChildrenRecursive()
Recursively sorts all children by occurrence in the text covered.Span
span(int from, int length)
Create a span, add it to this list and return itString
toString()
-
Methods inherited from class com.yahoo.document.annotation.SpanNode
annotate, annotate, annotate, annotate, annotate, compareTo, contains, getParent, getScratchId, getSpanTree, getStringFieldValue, isValid, overlaps, setScratchId
-
-
-
-
Field Detail
-
ID
public static final byte ID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SpanList
public SpanList()
Creates a new SpanList.
-
SpanList
public SpanList(SpanNodeReader reader)
-
SpanList
public SpanList(SpanList other)
Deep-copies a SpanList.- Parameters:
other
- the SpanList to copy.
-
-
Method Detail
-
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 movetarget
- 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 movetarget
- 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 movetarget
- the SpanList to add the node totargetSubTree
- 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 SpanListIndexOutOfBoundsException
- 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 movetarget
- the SpanList to add the node totargetSubTree
- 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 classSpanNode
- Returns:
- a ListIterator which traverses all immediate children of this SpanNode
- See Also:
ListIterator
-
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 classSpanNode
- Returns:
- a ListIterator which recursively traverses all children and their children etc. of this SpanList.
- See Also:
ListIterator
-
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:
SpanNode.compareTo(SpanNode)
-
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 classSpanNode
- Returns:
- always false, even if this node has no children
-
getFrom
public int getFrom()
Returns the character index where thisSpanNode
starts (inclusive), i.e. the smallestSpanNode.getFrom()
of all children.
-
getTo
public int getTo()
Returns the character index where thisSpanNode
ends (exclusive), i.e. the greatestSpanNode.getTo()
of all children.
-
getLength
public int getLength()
Returns the length of this span, i.e. getFrom() - getTo().
-
getText
public CharSequence getText(CharSequence text)
Returns the text that is covered by this SpanNode.
-
-