Class SpanTree

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  SpanTree.IndexKey  
    • Constructor Summary

      Constructors 
      Constructor Description
      SpanTree()
      WARNING! Only to be used by deserializers! Creates an empty SpanTree instance.
      SpanTree​(SpanTree otherToCopy)  
      SpanTree​(java.lang.String name)
      Creates a new SpanTree with the given name and an empty SpanList as its root node.
      SpanTree​(java.lang.String name, SpanNode root)
      Creates a new SpanTree with a given root node.
    • Constructor Detail

      • SpanTree

        public SpanTree()
        WARNING! Only to be used by deserializers! Creates an empty SpanTree instance.
      • SpanTree

        public SpanTree​(java.lang.String name,
                        SpanNode root)
        Creates a new SpanTree with a given root node.
        Parameters:
        name - the name of the span tree
        root - the root node of the span tree
        Throws:
        java.lang.IllegalStateException - if the root node is invalid
      • SpanTree

        public SpanTree​(java.lang.String name)
        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

        public SpanTree​(SpanTree otherToCopy)
    • Method Detail

      • setName

        public void setName​(java.lang.String name)
        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

        public void setRoot​(SpanNode root)
        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

        public java.lang.String getName()
        Returns the name of this span tree.
        Returns:
        the name of this span tree.
      • getRoot

        public SpanNode getRoot()
        Returns the root node of this span tree.
        Returns:
        the root node of this span tree.
      • spanList

        public SpanList 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

        public SpanTree annotate​(Annotation a)
        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:
        Annotation, AnnotationReference, AnnotationReferenceDataType
      • annotate

        public SpanTree annotate​(SpanNode node,
                                 Annotation annotation)
        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 annotate
        annotation - the Annotation to add
        Returns:
        this, for chaining
        See Also:
        Annotation
      • annotateFast

        public final SpanTree annotateFast​(SpanNode node,
                                           Annotation annotation)
        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 annotate
        annotation - the Annotation to add
        Returns:
        this, for chaining
        See Also:
        Annotation
      • annotate

        public SpanTree annotate​(SpanNode node,
                                 AnnotationType type,
                                 FieldValue value)
        Adds an Annotation. Convenience shorthand for annotate(node,new Annotation(type,value)
        Parameters:
        node - the node to annotate
        type - the type of the Annotation to add
        value - the value of the Annotation to add
        Returns:
        this, for chaining
        See Also:
        Annotation
      • annotate

        public 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. Upon return, Annotation.getSpanNode() returns the given node.
        Parameters:
        node - the node to annotate
        type - the AnnotationType to create an Annotation from
        Returns:
        this, for chaining
        See Also:
        Annotation, AnnotationType
      • remove

        public boolean remove​(Annotation a)
        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

        public void clearAnnotations​(SpanNode node)
        Clears all Annotations for a given SpanNode.
        Parameters:
        node - the SpanNode to clear all Annotations for.
      • clearAnnotationsRecursive

        public void clearAnnotationsRecursive​(SpanNode node)
        Clears all Annotations for a given SpanNode and its child nodes.
        Parameters:
        node - the SpanNode to clear all Annotations for.
      • iterator

        public java.util.Iterator<Annotation> iterator()
        Returns an Iterator over all annotations in this tree. Note that the iteration order is non-deterministic.
        Specified by:
        iterator in interface java.lang.Iterable<Annotation>
        Returns:
        an Iterator over all annotations in this tree.
      • iterator

        public java.util.Iterator<Annotation> iterator​(SpanNode node)
        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

        public java.util.Iterator<Annotation> iteratorRecursive​(SpanNode node)
        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

        public SpanTree getSpanTree()
        Returns itself. Needed for this class to be able to be a parent of SpanNodes.
        Specified by:
        getSpanTree in interface SpanNodeParent
        Returns:
        this SpanTree instance.
      • setStringFieldValue

        public void setStringFieldValue​(StringFieldValue stringFieldValue)
        Sets the StringFieldValue that this SpanTree belongs to. This is called by StringFieldValue.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

        public StringFieldValue getStringFieldValue()
        Returns the StringFieldValue that this SpanTree belongs to.
        Specified by:
        getStringFieldValue in interface SpanNodeParent
        Returns:
        the StringFieldValue that this SpanTree belongs to, if any, otherwise null.
      • clearIndexes

        public void clearIndexes()
      • getCurrentIndexes

        public java.util.Collection<SpanTree.IndexKey> getCurrentIndexes()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • compareTo

        public int compareTo​(SpanTree spanTree)
        Specified by:
        compareTo in interface java.lang.Comparable<SpanTree>