com.sas.util
Interface TreeIteratorInterface

All Superinterfaces:
java.util.Enumeration
All Known Implementing Classes:
PreorderTreeIterator, TreeIterator

public interface TreeIteratorInterface
extends java.util.Enumeration

Defines an interface 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().

See Also:
TreeIterator

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.
 com.sas.models.TreeInterface getTree()
          Returns the tree being traversed.
 boolean hasMoreNodes()
          Tests if nextNode() has another node to return.
 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.
 void setNode(com.sas.models.SimpleNodeInterface node)
          Sets the current node.
 void setNodeIndex(int newIndex)
          Sets the current node via index.
 

Method Detail

hasMoreNodes

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

Implementation note: hasMoreElements() should be implemented as a final method that calls this one.

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

nextNode

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.

Implementation note: nextNode() should be implemented as a final method that calls this one.

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

reset

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


getTree

com.sas.models.TreeInterface getTree()
Returns the tree being traversed.

Returns:
the tree that was passed to the constructor.

getNode

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

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

setNode

void setNode(com.sas.models.SimpleNodeInterface node)
Sets the current node.

Parameters:
node - the node to position on.
See Also:
getNode()

getNodeParents

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

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

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

setNodeIndex

void setNodeIndex(int newIndex)
Sets the current node via index.

Parameters:
newIndex - the zero-based index of the node to position on.
See Also:
getNodeIndex()



Copyright © 2009 SAS Institute Inc. All Rights Reserved.