Package com.yahoo.document.annotation
Class SpanNode
java.lang.Object
com.yahoo.document.annotation.SpanNode
- All Implemented Interfaces:
SpanNodeParent
,Comparable<SpanNode>
Base class of nodes in a Span tree.
- Author:
- Einar M R Rosenvinge
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionannotate
(Annotation annotation) Convenience method for adding an annotation to this span, same asgetSpanTree().
spanTree.annotate(this,annotation)
annotate
(AnnotationType type) Convenience method for adding an annotation with no value to this span, same asgetSpanTree().
spanTree.annotate(this,type)
annotate
(AnnotationType type, FieldValue value) Convenience method for adding an annotation to this span, same asgetSpanTree().
spanTree.annotate(this,type,value)
annotate
(AnnotationType type, Integer value) Convenience method for adding an annotation to this span, same asgetSpanTree().
spanTree.annotate(this,type,new IntegerFieldValue(value))
annotate
(AnnotationType type, String value) Convenience method for adding an annotation to this span, same asgetSpanTree().
spanTree.annotate(this,type,new StringFieldValue(value))
abstract ListIterator<SpanNode>
Traverses all immediate children of this SpanNode.abstract ListIterator<SpanNode>
Recursively traverses all possible children (not only leaf nodes) of this SpanNode, in a depth-first fashion.int
Compares two SpanNodes. Note: this class has a natural ordering that might be inconsistent with equals.boolean
Checks if the text covered by another span is within the text covered by this span.boolean
abstract int
getFrom()
Returns the character index where this SpanNode starts (inclusive).abstract int
Returns the length of this span, i.e. getFrom() - getTo().Returns the parent node of this SpanNode, if any.int
Returns the SpanTree that this node belongs to, if any.Returns the StringFieldValue that this node belongs to, if any.abstract CharSequence
getText
(CharSequence text) Returns the text that is covered by this SpanNode.abstract int
getTo()
Returns the character index where this SpanNode ends (exclusive).int
hashCode()
abstract boolean
Returns true if this node is a leaf node in the tree.boolean
isValid()
Returns whether this node is valid or not. When a child node from a SpanList, the child is marked as invalid, and the reference to it is removed from the parent SpanList.boolean
Checks if the text covered by this span overlaps with the text covered by another span.void
setScratchId
(int id)
-
Constructor Details
-
SpanNode
protected SpanNode()
-
-
Method Details
-
isValid
public boolean isValid()Returns whether this node is valid or not. When a child node from a SpanList, the child is marked as invalid, and the reference to it is removed from the parent SpanList. However, Annotations in the global list kept in SpanTree may still have references to the removed SpanNode. Removing these references is costly, and is only done when callingSpanTree.cleanup()
.- Returns:
- true if this node is valid, false otherwise.
-
setScratchId
public void setScratchId(int id) -
getScratchId
public int getScratchId() -
getParent
Returns the parent node of this SpanNode, if any.- Returns:
- the parent node, or null if this is not yet added to a parent SpanList
-
getSpanTree
Returns the SpanTree that this node belongs to, if any.- Specified by:
getSpanTree
in interfaceSpanNodeParent
- Returns:
- the SpanTree that this node belongs to, or null if it is not yet added to a SpanTree.
-
annotate
Convenience method for adding an annotation to this span, same asgetSpanTree().
spanTree.annotate(this,annotation)
- Parameters:
annotation
- the annotation to add- Returns:
- this for chaining
- Throws:
NullPointerException
- if this span is not attached to a tree
-
annotate
Convenience method for adding an annotation to this span, same asgetSpanTree().
spanTree.annotate(this,type,value)
- Parameters:
type
- the type of the annotation to addvalue
- the value of the annotation to add- Returns:
- this for chaining
- Throws:
NullPointerException
- if this span is not attached to a tree
-
annotate
Convenience method for adding an annotation to this span, same asgetSpanTree().
spanTree.annotate(this,type,new StringFieldValue(value))
- Parameters:
type
- the type of the annotation to addvalue
- the string value of the annotation to add- Returns:
- this for chaining
- Throws:
NullPointerException
- if this span is not attached to a tree
-
annotate
Convenience method for adding an annotation to this span, same asgetSpanTree().
spanTree.annotate(this,type,new IntegerFieldValue(value))
- Parameters:
type
- the type of the annotation to addvalue
- the integer value of the annotation to add- Returns:
- this for chaining
- Throws:
NullPointerException
- if this span is not attached to a tree
-
annotate
Convenience method for adding an annotation with no value to this span, same asgetSpanTree().
spanTree.annotate(this,type)
- Parameters:
type
- the type of the annotation to add- Returns:
- this for chaining
- Throws:
NullPointerException
- if this span is not attached to a tree
-
getStringFieldValue
Returns the StringFieldValue that this node belongs to, if any.- Specified by:
getStringFieldValue
in interfaceSpanNodeParent
- Returns:
- the StringFieldValue that this node belongs to, if any, otherwise null.
-
isLeafNode
public abstract boolean isLeafNode()Returns true if this node is a leaf node in the tree.- Returns:
- true if this node is a leaf node in the tree.
-
childIterator
Traverses all immediate children of this SpanNode.- Returns:
- a ListIterator which traverses all immediate children of this SpanNode
-
childIteratorRecursive
Recursively traverses all possible children (not only leaf nodes) of this SpanNode, in a depth-first fashion.- Returns:
- a ListIterator which recursively traverses all children and their children etc. of this SpanNode.
-
getFrom
public abstract int getFrom()Returns the character index where this SpanNode starts (inclusive).- Returns:
- the character index where this SpanNode starts (inclusive).
-
getTo
public abstract int getTo()Returns the character index where this SpanNode ends (exclusive).- Returns:
- the character index where this SpanNode ends (exclusive).
-
getLength
public abstract int getLength()Returns the length of this span, i.e. getFrom() - getTo().- Returns:
- the length of this span
-
getText
Returns the text that is covered by this SpanNode.- Parameters:
text
- the input text- Returns:
- the text that is covered by this SpanNode.
-
overlaps
Checks if the text covered by this span overlaps with the text covered by another span.- Parameters:
o
- the other SpanNode to check- Returns:
- true if spans are overlapping, false otherwise
-
contains
Checks if the text covered by another span is within the text covered by this span.- Parameters:
o
- the other SpanNode to check.- Returns:
- true if the text covered by another span is within the text covered by this span, false otherwise.
-
equals
-
hashCode
public int hashCode() -
compareTo
Compares two SpanNodes. Note: this class has a natural ordering that might be inconsistent with equals.First, getFrom() is compared, and -1 or 1 is return if our getFrom() is smaller or greater that o.getFrom(), respectively. If and only if getFrom() is equal, getTo() is compared, and -1 or 1 is return if our getTo() is smaller or greater that o.getTo(), respectively. In all other cases, the two SpanNodes are equal both for getFrom() and getTo(), and 0 is returned.
Note that if a subclass has overridden equals(), which is very likely, but has not overridden compareTo(), then that subclass will have a natural ordering that is inconsistent with equals.
- Specified by:
compareTo
in interfaceComparable<SpanNode>
- Parameters:
o
- the SpanNode to compare to- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
-