public class NodePreorderIterator
extends java.lang.Object
Iterates preorder over the whole sub tree of a given Node
.
Instances of this class should always be used instead of recursive method
calls because they cause StackOverflowError
s even in small programs.
Attention: The iteration process does not take care of changes in the model. If the containment hierarchy changes during iteration it is possible that elements are left or visited multiple times. For this reason it is forbidden to change the model during iteration. But the developer has to take care about it.
Modifier and Type | Field and Description |
---|---|
private int |
childIndexOnParent
The child index of
next on its parent. |
private Node |
next
The next element or
null if no more elements exists. |
private int |
returnedParents
The number of previously returned parents.
|
private Node |
start
The element at that the iteration has started used as end condition
to make sure that only over the subtree of the element is iterated.
|
Constructor and Description |
---|
NodePreorderIterator(Node start)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
getChildIndexOnParent()
Returns the child index of
next() on its parent. |
protected Node |
getNextOnParent(Node node)
Returns the next element to select if all children of the given
Node are visited. |
int |
getReturnedParents()
|
boolean |
hasNext()
Checks if more elements are available.
|
Node |
next()
Returns the next
Node in the containment hierarchy. |
protected void |
updateNext()
Computes the next element and updates
next() . |
private final Node start
private Node next
null
if no more elements exists.private int childIndexOnParent
next
on its parent.private int returnedParents
public boolean hasNext()
true
has more elements, false
has not more elements.public int getChildIndexOnParent()
next()
on its parent.
Attention: Needs to be called before next()
is called.
next()
on its parent or -1
if no parent is available.public int getReturnedParents()
next()
call which where required in order to find the next Node
which
will be returned by the next call of next()
.protected void updateNext()
next()
.