Package com.yahoo.document.annotation
Class SpanNode
- java.lang.Object
-
- com.yahoo.document.annotation.SpanNode
-
- All Implemented Interfaces:
SpanNodeParent
,java.lang.Comparable<SpanNode>
public abstract class SpanNode extends java.lang.Object implements java.lang.Comparable<SpanNode>, SpanNodeParent
Base class of nodes in a Span tree.- Author:
- Einar M R Rosenvinge
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SpanNode()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description SpanNode
annotate(Annotation annotation)
Convenience method for adding an annotation to this span, same asgetSpanTree().
spanTree.annotate(this,annotation)
SpanNode
annotate(AnnotationType type)
Convenience method for adding an annotation with no value to this span, same asgetSpanTree().
spanTree.annotate(this,type)
SpanNode
annotate(AnnotationType type, FieldValue value)
Convenience method for adding an annotation to this span, same asgetSpanTree().
spanTree.annotate(this,type,value)
SpanNode
annotate(AnnotationType type, java.lang.Integer value)
Convenience method for adding an annotation to this span, same asgetSpanTree().
spanTree.annotate(this,type,new IntegerFieldValue(value))
SpanNode
annotate(AnnotationType type, java.lang.String value)
Convenience method for adding an annotation to this span, same asgetSpanTree().
spanTree.annotate(this,type,new StringFieldValue(value))
abstract java.util.ListIterator<SpanNode>
childIterator()
Traverses all immediate children of this SpanNode.abstract java.util.ListIterator<SpanNode>
childIteratorRecursive()
Recursively traverses all possible children (not only leaf nodes) of this SpanNode, in a depth-first fashion.int
compareTo(SpanNode o)
Compares two SpanNodes. Note: this class has a natural ordering that might be inconsistent with equals.boolean
contains(SpanNode o)
Checks if the text covered by another span is within the text covered by this span.boolean
equals(java.lang.Object o)
abstract int
getFrom()
Returns the character index where this SpanNode starts (inclusive).abstract int
getLength()
Returns the length of this span, i.e. getFrom() - getTo().SpanNodeParent
getParent()
Returns the parent node of this SpanNode, if any.int
getScratchId()
SpanTree
getSpanTree()
Returns the SpanTree that this node belongs to, if any.StringFieldValue
getStringFieldValue()
Returns the StringFieldValue that this node belongs to, if any.abstract java.lang.CharSequence
getText(java.lang.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
isLeafNode()
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
overlaps(SpanNode o)
Checks if the text covered by this span overlaps with the text covered by another span.void
setScratchId(int id)
-
-
-
Method Detail
-
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
public SpanNodeParent 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
public SpanTree 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
public SpanNode annotate(Annotation annotation)
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:
java.lang.NullPointerException
- if this span is not attached to a tree
-
annotate
public SpanNode annotate(AnnotationType type, FieldValue value)
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:
java.lang.NullPointerException
- if this span is not attached to a tree
-
annotate
public SpanNode annotate(AnnotationType type, java.lang.String value)
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:
java.lang.NullPointerException
- if this span is not attached to a tree
-
annotate
public SpanNode annotate(AnnotationType type, java.lang.Integer value)
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:
java.lang.NullPointerException
- if this span is not attached to a tree
-
annotate
public SpanNode annotate(AnnotationType type)
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:
java.lang.NullPointerException
- if this span is not attached to a tree
-
getStringFieldValue
public StringFieldValue 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
public abstract java.util.ListIterator<SpanNode> childIterator()
Traverses all immediate children of this SpanNode.- Returns:
- a ListIterator which traverses all immediate children of this SpanNode
-
childIteratorRecursive
public abstract java.util.ListIterator<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
public abstract java.lang.CharSequence getText(java.lang.CharSequence text)
Returns the text that is covered by this SpanNode.- Parameters:
text
- the input text- Returns:
- the text that is covered by this SpanNode.
-
overlaps
public boolean overlaps(SpanNode o)
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
public boolean contains(SpanNode o)
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
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
compareTo
public int compareTo(SpanNode o)
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 interfacejava.lang.Comparable<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
-
-