com.sas.util
Class PreorderTreeIterator

com.sas.util.PreorderTreeIterator
All Implemented Interfaces:
TreeIteratorInterface, java.util.Enumeration, java.util.Iterator

public class PreorderTreeIterator

Provides a mechanism for visiting each node in a tree using preorder traversal. Preorder traversal is a common tree traversal algorithm where a node is visited before any of its children are; thus the tree's root is the first node, the root's first child is the second node, the first child's first child would be the third node, etc.


Constructor Summary
PreorderTreeIterator(com.sas.models.TreeInterface tree)
          Constructor.
 
Method Summary
 com.sas.models.SimpleNodeInterface getNode()
          Returns the current node.
 int getNodeIndex()
          Returns the zero-based index associated with the current node.
 com.sas.models.SimpleNodeInterface[] getNodeParents()
          Returns the parents of the current node.
 boolean hasMoreElements()
          Alias for hasMoreNodes() to satisfy java.util.Enumeration.
 boolean hasMoreNodes()
          Tests if nextNode() has another node to return.
 java.lang.Object nextElement()
          Alias for nextNode() to satisfy java.util.Enumeration.
 com.sas.models.SimpleNodeInterface nextNode()
          Returns the current node and advances to the next one.
 void reset()
          Resets the iterator to the beginning of the tree.
 
Methods inherited from class com.sas.util.TreeIterator
equals, equals, getTree, hasNext, next, remove, setNode, setNodeIndex
 

Constructor Detail

PreorderTreeIterator

public PreorderTreeIterator(com.sas.models.TreeInterface tree)
Constructor.

Parameters:
tree - The tree to traverse.
Method Detail

hasMoreNodes

public boolean hasMoreNodes()
Tests if nextNode() has another node to return.

Returns:
true if there is another node, and false otherwise.
See Also:
nextNode()

nextNode

public com.sas.models.SimpleNodeInterface nextNode()
Returns the current node and advances to the next one. Throws a java.util.NoSuchElementException if there isn't a current node; to avoid check hasMoreNodes() before calling this.

Returns:
A SimpleNodeInterface instance; will never be null.
See Also:
hasMoreNodes()

hasMoreElements

public final boolean hasMoreElements()
Alias for hasMoreNodes() to satisfy java.util.Enumeration.

Returns:
true if there is another node, and false otherwise.
See Also:
hasMoreNodes()

nextElement

public final java.lang.Object nextElement()
Alias for nextNode() to satisfy java.util.Enumeration.

Returns:
A non-null object that can be cast to SimpleNodeInterface.
See Also:
nextNode()

reset

public void reset()
Resets the iterator to the beginning of the tree.


getNode

public com.sas.models.SimpleNodeInterface getNode()
Returns the current node.

Returns:
the node the iterator is stopped on.
See Also:
TreeIterator.setNode(com.sas.models.SimpleNodeInterface), getNodeIndex(), getNodeParents()

getNodeParents

public com.sas.models.SimpleNodeInterface[] getNodeParents()
Returns the parents of the current node. A zero-length array will be returned if the node is the tree's root node and therefore has no parents.

Returns:
A SimpleNodeInterface array.
See Also:
getNode()

getNodeIndex

public int getNodeIndex()
Returns the zero-based index associated with the current node.

Returns:
the current node's zero-based index.
See Also:
getNode(), TreeIterator.setNodeIndex(int)



Copyright © 2009 SAS Institute Inc. All Rights Reserved.