Class NodeIterator

java.lang.Object
com.vladsch.flexmark.util.ast.NodeIterator
All Implemented Interfaces:
ReversibleIterator<Node>, ReversiblePeekingIterator<Node>, Iterator<Node>

public class NodeIterator extends Object implements ReversiblePeekingIterator<Node>
  • Field Details

  • Constructor Details

    • 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 Details

    • isReversed

      public boolean isReversed()
      Specified by:
      isReversed in interface 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 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>
    • forEachRemaining

      public void forEachRemaining(Consumer<? super Node> consumer)
      Specified by:
      forEachRemaining in interface Iterator<Node>