Package com.yahoo.document.annotation
Class SpanTree
java.lang.Object
com.yahoo.document.annotation.SpanTree
- All Implemented Interfaces:
SpanNodeParent
,Comparable<SpanTree>
,Iterable<Annotation>
public class SpanTree
extends Object
implements Iterable<Annotation>, SpanNodeParent, Comparable<SpanTree>
A SpanTree holds a root node of a tree of SpanNodes, and a List of Annotations pointing to these nodes
or each other. It also has a name.
- Author:
- Einar M R Rosenvinge
- See Also:
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionSpanTree()
WARNING! Only to be used by deserializers! Creates an empty SpanTree instance.Creates a new SpanTree with the given name and an empty SpanList as its root node.Creates a new SpanTree with a given root node. -
Method Summary
Modifier and TypeMethodDescriptionAdds an Annotation to the internal list of annotations for this SpanTree. Use this when adding an Annotation that uses an AnnotationReference, and does not annotate a SpanNode.annotate
(SpanNode node, Annotation annotation) Adds an Annotation to the internal list of annotations for this SpanTree.annotate
(SpanNode node, AnnotationType type) Creates an Annotation based on the given AnnotationType, and adds it to the internal list of annotations for this SpanTree (convenience method). Use this when adding an Annotation (that does not have a FieldValue) that shall annotate a SpanNode.annotate
(SpanNode node, AnnotationType type, FieldValue value) Adds an Annotation.final SpanTree
annotateFast
(SpanNode node, Annotation annotation) Adds an Annotation to the internal list of annotations for this SpanTree.void
cleanup()
Ensures consistency of the tree in case SpanNodes have been removed, and there are still Annotations pointing to them.void
clearAnnotations
(SpanNode node) Clears all Annotations for a given SpanNode.void
Clears all Annotations for a given SpanNode and its child nodes.void
void
int
void
boolean
getName()
Returns the name of this span tree.getRoot()
Returns the root node of this span tree.Returns itself. Needed for this class to be able to be a parent of SpanNodes.Returns the StringFieldValue that this SpanTree belongs to.int
hashCode()
iterator()
Returns an Iterator over all annotations in this tree.Returns an Iterator over all annotations that annotate the given node.iteratorRecursive
(SpanNode node) Returns a recursive Iterator over all annotations that annotate the given node and its subnodes.int
Returns the total number of annotations in the tree.boolean
remove
(Annotation a) Removes an Annotation from the internal list of annotations.void
WARNING! Only to be used by deserializers! Sets the name of this SpanTree instance.void
WARNING! Only to be used by deserializers! Sets the root of this SpanTree instance.void
setStringFieldValue
(StringFieldValue stringFieldValue) Sets the StringFieldValue that this SpanTree belongs to. This is called byStringFieldValue.setSpanTree(SpanTree)
and there is no need for the user to call this except in unit tests.spanList()
Convenience shorthand for(SpanList)getRoot()
.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
SpanTree
public SpanTree()WARNING! Only to be used by deserializers! Creates an empty SpanTree instance. -
SpanTree
Creates a new SpanTree with a given root node.- Parameters:
name
- the name of the span treeroot
- the root node of the span tree- Throws:
IllegalStateException
- if the root node is invalid
-
SpanTree
Creates a new SpanTree with the given name and an empty SpanList as its root node.- Parameters:
name
- the name of the span tree
-
SpanTree
-
-
Method Details
-
setName
WARNING! Only to be used by deserializers! Sets the name of this SpanTree instance.- Parameters:
name
- the name to set for this SpanTree instance.
-
setRoot
WARNING! Only to be used by deserializers! Sets the root of this SpanTree instance.- Parameters:
root
- the root to set for this SpanTree instance.
-
getName
Returns the name of this span tree. -
getRoot
Returns the root node of this span tree. -
spanList
Convenience shorthand for(SpanList)getRoot()
. This must of course only be used when it is known that the root in this tree actually is a SpanList. -
cleanup
public void cleanup()Ensures consistency of the tree in case SpanNodes have been removed, and there are still Annotations pointing to them. This method has a maximum upper bound of O(3nm), where n is the total number of Annotations, and m is the number of SpanNodes that had been removed from the tree. The lower bound is Omega(n), if no SpanNodes had been removed from the tree. -
annotate
Adds an Annotation to the internal list of annotations for this SpanTree. Use this when adding an Annotation that uses an AnnotationReference, and does not annotate a SpanNode.- Parameters:
a
- the Annotation to add- Returns:
- this, for chaining
- See Also:
-
annotate
Adds an Annotation to the internal list of annotations for this SpanTree. Use this when adding an Annotation that shall annotate a SpanNode. Upon return, Annotation.getSpanNode() returns the given node.- Parameters:
node
- the node to annotateannotation
- the Annotation to add- Returns:
- this, for chaining
- See Also:
-
annotateFast
Adds an Annotation to the internal list of annotations for this SpanTree. Use this when adding an Annotation that shall annotate a SpanNode. Upon return, Annotation.getSpanNode() returns the given node. This one is unchecked and assumes that the SpanNode is valid and has already been attached to the Annotation.- Parameters:
node
- the node to annotateannotation
- the Annotation to add- Returns:
- this, for chaining
- See Also:
-
annotate
Adds an Annotation. Convenience shorthand forannotate(node,new Annotation(type,value)
- Parameters:
node
- the node to annotatetype
- the type of the Annotation to addvalue
- the value of the Annotation to add- Returns:
- this, for chaining
- See Also:
-
annotate
Creates an Annotation based on the given AnnotationType, and adds it to the internal list of annotations for this SpanTree (convenience method). Use this when adding an Annotation (that does not have a FieldValue) that shall annotate a SpanNode. Upon return, Annotation.getSpanNode() returns the given node.- Parameters:
node
- the node to annotatetype
- the AnnotationType to create an Annotation from- Returns:
- this, for chaining
- See Also:
-
remove
Removes an Annotation from the internal list of annotations.- Parameters:
a
- the annotation to remove- Returns:
- true if the Annotation was successfully removed, false otherwise
-
numAnnotations
public int numAnnotations()Returns the total number of annotations in the tree.- Returns:
- the total number of annotations in the tree.
-
clearAnnotations
Clears all Annotations for a given SpanNode.- Parameters:
node
- the SpanNode to clear all Annotations for.
-
clearAnnotationsRecursive
Clears all Annotations for a given SpanNode and its child nodes.- Parameters:
node
- the SpanNode to clear all Annotations for.
-
iterator
Returns an Iterator over all annotations in this tree. Note that the iteration order is non-deterministic.- Specified by:
iterator
in interfaceIterable<Annotation>
-
iterator
Returns an Iterator over all annotations that annotate the given node.- Parameters:
node
- the node to return annotations for.- Returns:
- an Iterator over all annotations that annotate the given node.
-
iteratorRecursive
Returns a recursive Iterator over all annotations that annotate the given node and its subnodes.- Parameters:
node
- the node to recursively return annotations for.- Returns:
- a recursive Iterator over all annotations that annotate the given node and its subnodes.
-
getSpanTree
Returns itself. Needed for this class to be able to be a parent of SpanNodes.- Specified by:
getSpanTree
in interfaceSpanNodeParent
- Returns:
- this SpanTree instance.
-
setStringFieldValue
Sets the StringFieldValue that this SpanTree belongs to. This is called byStringFieldValue.setSpanTree(SpanTree)
and there is no need for the user to call this except in unit tests.- Parameters:
stringFieldValue
- the StringFieldValue that this SpanTree should belong to (might be null to clear the current value)
-
getStringFieldValue
Returns the StringFieldValue that this SpanTree belongs to.- Specified by:
getStringFieldValue
in interfaceSpanNodeParent
- Returns:
- the StringFieldValue that this SpanTree belongs to, if any, otherwise null.
-
createIndex
-
clearIndex
-
clearIndexes
public void clearIndexes() -
getCurrentIndexes
-
toString
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareTo
in interfaceComparable<SpanTree>
-