Package com.vladsch.flexmark.util.ast
Class NodeIterator
- java.lang.Object
-
- com.vladsch.flexmark.util.ast.NodeIterator
-
- All Implemented Interfaces:
ReversibleIterator<Node>
,ReversiblePeekingIterator<Node>
,java.util.Iterator<Node>
public class NodeIterator extends java.lang.Object implements ReversiblePeekingIterator<Node>
-
-
Field Summary
Fields Modifier and Type Field Description static ReversiblePeekingIterator<Node>
EMPTY
-
Constructor Summary
Constructors Constructor Description NodeIterator(Node firstNode)
NodeIterator(Node firstNode, boolean reversed)
NodeIterator(Node firstNode, Node lastNode)
NodeIterator(Node firstNode, Node lastNode, boolean reversed)
iterate nodes until null or last node is iterated over
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
forEachRemaining(java.util.function.Consumer<? super Node> consumer)
boolean
hasNext()
boolean
isReversed()
Node
next()
Node
peek()
void
remove()
Remove the last node returned bynext()
-
-
-
Field Detail
-
EMPTY
public static final 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 traversedreversed
- 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 traversedlastNode
- 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 traversedlastNode
- the last node to be traversedreversed
- 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 interfaceReversibleIterator<Node>
- Returns:
- true if the iterator is a reversed iterator
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfacejava.util.Iterator<Node>
- Returns:
- true if there is a next node
-
next
public Node next()
- Specified by:
next
in interfacejava.util.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 Node peek()
- Specified by:
peek
in interfaceReversiblePeekingIterator<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 bynext()
- Specified by:
remove
in interfacejava.util.Iterator<Node>
-
-