uk.ed.inf.tree
Interface ITree<T extends ITreeNode<T>>

Type Parameters:
T -
All Known Implementing Classes:
GeneralTree

public interface ITree<T extends ITreeNode<T>>

A tree data structure. This class provides methods for manipulating the tree or querying the tree structure and characteristics.

Author:
smoodie

Method Summary
 boolean containsNode(int testIndex)
           
 boolean containsNode(T testNode)
           
 T get(int testIndex)
           
 T getLowestCommonAncestor(T thisNode, T thatNode)
           
 T getRootNode()
          Get the root node of this tree.
 boolean isAncestor(T startNode, T testNode)
          Tests if testNode is an anscestor of startNode.
 boolean isDescendant(T startNode, T testNode)
          Tests if testNode is a descendent of startNode.
 java.util.Iterator<T> levelOrderIterator()
           
 ITreeWalker<T> levelOrderTreeWalker(ITreeNodeAction<T> visitorAction)
          Obtain a visitor that will traverse the tree from the root node in level-order.
 int size()
           
 

Method Detail

getRootNode

T getRootNode()
Get the root node of this tree. A tree wil at the very least have a root.

Returns:
The root node, cannot be null.

containsNode

boolean containsNode(T testNode)

containsNode

boolean containsNode(int testIndex)

get

T get(int testIndex)

getLowestCommonAncestor

T getLowestCommonAncestor(T thisNode,
                          T thatNode)

isDescendant

boolean isDescendant(T startNode,
                     T testNode)
Tests if testNode is a descendent of startNode. This means traversing from the startNode until it finds the testNode.

Parameters:
startNode - the node to start from, can be null.
testNode - the node to be tested, can be null.
Returns:
true if testNode is an descendent of startNode, false otherwise.

isAncestor

boolean isAncestor(T startNode,
                   T testNode)
Tests if testNode is an anscestor of startNode. This means traversing from the startNode until it finds the testNode.

Parameters:
startNode - the node to start from, can be null.
testNode - the node to be tested, can be null.
Returns:
true if testNode is an ancestor of startNode, false otherwise.

levelOrderIterator

java.util.Iterator<T> levelOrderIterator()

levelOrderTreeWalker

ITreeWalker<T> levelOrderTreeWalker(ITreeNodeAction<T> visitorAction)
Obtain a visitor that will traverse the tree from the root node in level-order. At each node the actions specified by visitorAction will be performed.

Parameters:
visitorAction - the action to be executed at each node visited.
Returns:
a new instance of the tree visitor, which cannot be null.

size

int size()