|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.util.TreeIterator
public abstract class TreeIterator
Defines an abstract base class for different tree traversal algorithms, for example preorder traversal, inorder traversal, and postorder traversal.
Each node in the tree is identified by a zero-based integer index, thus the first node, as defined by the traversal algorithm, is assigned index zero and the last node is assigned an index equal to one less than the total number of nodes in the tree.
Nodes can be visited in succession using the standard
enumeration methods
hasMoreElements()
and nextElement()
, or
by jumping to a specific index via setNodeIndex()
.
In either case, the current node is always accessible via
getNode()
.
Note that TreeIterator will not be aware of any changes made to the tree it's traversing, such as new or deleted nodes. Therefore it is the user of TreeIterator's responsibility to reset or reposition the iterator when traversing a dynamic tree.
PreorderTreeIterator
Constructor Summary | |
---|---|
TreeIterator(com.sas.models.TreeInterface tree)
Constructor. |
Method Summary | |
---|---|
boolean |
equals(java.lang.Object obj)
Compares this and a given object for equality. |
boolean |
equals(TreeIterator other)
Compares this and a given TreeIterator for equality. |
com.sas.models.TreeInterface |
getTree()
Returns the tree being traversed. |
boolean |
hasNext()
Implementation of java.util.Iterator . |
java.lang.Object |
next()
Implementation of java.util.Iterator . |
void |
remove()
Implementation of java.util.Iterator . |
void |
setNode(com.sas.models.SimpleNodeInterface node)
Sets the current node. |
void |
setNodeIndex(int newIndex)
Sets the current node via index. |
Methods inherited from interface com.sas.util.TreeIteratorInterface |
---|
getNode, getNodeIndex, getNodeParents, hasMoreNodes, nextNode, reset |
Constructor Detail |
---|
public TreeIterator(com.sas.models.TreeInterface tree)
tree
- The tree to traverse.getTree()
Method Detail |
---|
public com.sas.models.TreeInterface getTree()
getTree
in interface TreeIteratorInterface
public void setNode(com.sas.models.SimpleNodeInterface node)
Implementation note: the algorithm used is to sequentially search for
the node from the current node to the end of the tree continuing as
necessary from the beginning of the tree. If the node isn't found,
an java.util.NoSuchElementException
is thrown.
Subclasses that have additional
knowledge about the node and/or the tree may be able to implement this
more efficiently and should do so.
setNode
in interface TreeIteratorInterface
node
- the node to position on.TreeIteratorInterface.getNode()
public void setNodeIndex(int newIndex)
Implementation note: the algorithm used is to sequentially advance the
node via nextNode()
until getNodeIndex()
returns newIndex. If getNodeIndex()
is
initially greater than newIndex, then a reset()
is done first. If after searching the whole tree a match wasn't found,
then an IndexOutOfBoundsException
is thrown.
Subclasses that have additional
knowledge about the node and/or the tree may be able to implement this
more efficiently and should do so.
setNodeIndex
in interface TreeIteratorInterface
newIndex
- the zero-based index of the node to position on.TreeIteratorInterface.getNodeIndex()
public final boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
true
if obj is a TreeIterator and
equals((TreeIterator)obj)
returns true
,
and false
otherwise.public boolean equals(TreeIterator other)
true
if this has the same nodeIndex
and equivalent tree as other,
and false
otherwise.public boolean hasNext()
java.util.Iterator
. Alias for
hasMoreElements()
.
hasNext
in interface java.util.Iterator
public java.lang.Object next()
java.util.Iterator
. Alias for
next()
.
next
in interface java.util.Iterator
public void remove()
java.util.Iterator
. This method is
is not supported and an UnsupportedOperationException
will result if called.
remove
in interface java.util.Iterator
java.lang.UnsupportedOperationException
- remove()
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |