Class NodeIterator

  • All Implemented Interfaces:
    com.vladsch.flexmark.util.collection.iteration.ReversibleIterator<Node>, com.vladsch.flexmark.util.collection.iteration.ReversiblePeekingIterator<Node>, Iterator<Node>

    public class NodeIterator
    extends Object
    implements com.vladsch.flexmark.util.collection.iteration.ReversiblePeekingIterator<Node>
    • Field Detail

      • EMPTY

        public static final com.vladsch.flexmark.util.collection.iteration.ReversiblePeekingIterator<Node> EMPTY
    • Constructor Detail

      • NodeIterator

        public NodeIterator​(Node firstNode)
        Parameters:
        firstNode - node from which to start the iteration and continue until all sibling nodes have been traversed
      • NodeIterator

        public NodeIterator​(Node firstNode,
                            boolean reversed)
        Parameters:
        firstNode - node from which to start the iteration and continue until all sibling nodes have been traversed
        reversed - true/false if the nodes are to be traversed in reverse order. If true the nodes previous sibling will be used instead of next sibling
      • NodeIterator

        public NodeIterator​(Node firstNode,
                            Node lastNode)
        Parameters:
        firstNode - node from which to start the iteration and continue until all sibling nodes have been traversed or lastNode has been traversed
        lastNode - the last node to be traversed
      • NodeIterator

        public NodeIterator​(Node firstNode,
                            Node lastNode,
                            boolean reversed)
        iterate nodes until null or last node is iterated over
        Parameters:
        firstNode - node from which to start the iteration and continue until all sibling nodes have been traversed or lastNode has been traversed
        lastNode - the last node to be traversed
        reversed - true/false if the nodes are to be traversed in reverse order. If true the nodes previous sibling will be used instead of next sibling
    • Method Detail

      • isReversed

        public boolean isReversed()
        Specified by:
        isReversed in interface com.vladsch.flexmark.util.collection.iteration.ReversibleIterator<Node>
        Returns:
        true if the iterator is a reversed iterator
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface Iterator<Node>
        Returns:
        true if there is a next node
      • next

        public Node next()
        Specified by:
        next in interface Iterator<Node>
        Returns:
        the next node for the iterator. If the iterator is not reversed then the previous node's next sibling is returned. If it is reversed the the previous node's previous sibling is returned.
      • peek

        @Nullable
        public @Nullable Node peek()
        Specified by:
        peek in interface com.vladsch.flexmark.util.collection.iteration.ReversiblePeekingIterator<Node>
        Returns:
        the node which would be returned by a call to next() or null if there is no next node.
      • remove

        public void remove()
        Remove the last node returned by next()
        Specified by:
        remove in interface Iterator<Node>