uk.ed.inf.tree
Class GeneralTree<T extends ITreeNode<T>>

java.lang.Object
  extended by uk.ed.inf.tree.GeneralTree<T>
All Implemented Interfaces:
ITree<T>

public final class GeneralTree<T extends ITreeNode<T>>
extends java.lang.Object
implements ITree<T>


Constructor Summary
GeneralTree(T rootNode)
           
 
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 descendant 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()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeneralTree

public GeneralTree(T rootNode)
Method Detail

getRootNode

public T getRootNode()
Description copied from interface: ITree
Get the root node of this tree. A tree wil at the very least have a root.

Specified by:
getRootNode in interface ITree<T extends ITreeNode<T>>
Returns:
The root node, cannot be null.

containsNode

public boolean containsNode(T testNode)
Specified by:
containsNode in interface ITree<T extends ITreeNode<T>>

containsNode

public boolean containsNode(int testIndex)
Specified by:
containsNode in interface ITree<T extends ITreeNode<T>>

get

public T get(int testIndex)
Specified by:
get in interface ITree<T extends ITreeNode<T>>

getLowestCommonAncestor

public T getLowestCommonAncestor(T thisNode,
                                 T thatNode)
Specified by:
getLowestCommonAncestor in interface ITree<T extends ITreeNode<T>>

levelOrderIterator

public java.util.Iterator<T> levelOrderIterator()
Specified by:
levelOrderIterator in interface ITree<T extends ITreeNode<T>>

isDescendant

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

Specified by:
isDescendant in interface ITree<T extends ITreeNode<T>>
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 descendant of startNode, false otherwise.

size

public int size()
Specified by:
size in interface ITree<T extends ITreeNode<T>>

isAncestor

public boolean isAncestor(T startNode,
                          T testNode)
Description copied from interface: ITree
Tests if testNode is an anscestor of startNode. This means traversing from the startNode until it finds the testNode.

Specified by:
isAncestor in interface ITree<T extends ITreeNode<T>>
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.

levelOrderTreeWalker

public ITreeWalker<T> levelOrderTreeWalker(ITreeNodeAction<T> visitorAction)
Description copied from interface: ITree
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.

Specified by:
levelOrderTreeWalker in interface ITree<T extends ITreeNode<T>>
Parameters:
visitorAction - the action to be executed at each node visited.
Returns:
a new instance of the tree visitor, which cannot be null.