Class SpanList

    • Constructor Detail

      • SpanList

        public SpanList()
        Creates a new SpanList.
      • SpanList

        protected SpanList​(java.util.List<SpanNode> children)
      • 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:
        java.lang.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 move
        target - the SpanList to add the node to
        Throws:
        java.lang.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 move
        target - the SpanList to add the node to
        Throws:
        java.lang.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 move
        target - the SpanList to add the node to
        targetSubTree - the index of the subtree of the given AlternateSpanList to add the node to
        Throws:
        java.lang.IllegalArgumentException - if the given node is not a child of this SpanList
        java.lang.IndexOutOfBoundsException - 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 move
        target - the SpanList to add the node to
        targetSubTree - the index of the subtree of the given AlternateSpanList to add the node to
        Throws:
        java.lang.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 java.util.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 java.util.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 class SpanNode
        Returns:
        a ListIterator which traverses all immediate children of this SpanNode
        See Also:
        ListIterator
      • childIteratorRecursive

        public java.util.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 class SpanNode
        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.
      • 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 class SpanNode
        Returns:
        always false, even if this node has no children
      • getFrom

        public int getFrom()
        Returns the character index where this SpanNode starts (inclusive), i.e. the smallest SpanNode.getFrom() of all children.
        Specified by:
        getFrom in class SpanNode
        Returns:
        the lowest getFrom() of all children, or -1 if this SpanList has no children.
      • getTo

        public int getTo()
        Returns the character index where this SpanNode ends (exclusive), i.e. the greatest SpanNode.getTo() of all children.
        Specified by:
        getTo in class SpanNode
        Returns:
        the greatest getTo() of all children, or -1 if this SpanList has no children.
      • getLength

        public int getLength()
        Returns the length of this span, i.e. getFrom() - getTo().
        Specified by:
        getLength in class SpanNode
        Returns:
        the length of this span
      • getText

        public java.lang.CharSequence getText​(java.lang.CharSequence text)
        Returns the text that is covered by this SpanNode.
        Specified by:
        getText in class SpanNode
        Parameters:
        text - the input text
        Returns:
        the text that is covered by this SpanNode.
      • equals

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

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