fi.joensuu.cs.tra
Class Tree<E>

java.lang.Object
  extended by fi.joensuu.cs.tra.Tree<E>

public class Tree<E>
extends Object

Tree is a wrapper class for a root TreeNode.

See Also:
TreeNode

Constructor Summary
Tree()
          Creates an empty Tree.
Tree(TreeNode<E> node)
          Creates a Tree with the specified TreeNode as the root node.
 
Method Summary
 void destroyNode(TreeNode<E> node)
          Removes a single node.
 TreeNode<E> getRoot()
          Returns the root of this Tree.
 boolean isEmpty()
          Returns true if this Tree is empty.
 void killNode(TreeNode<E> node)
          Kills a node.
 TreeNode<E> setRoot(TreeNode<E> node)
          Sets the root of this Tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tree

public Tree()
Creates an empty Tree.


Tree

public Tree(TreeNode<E> node)
Creates a Tree with the specified TreeNode as the root node.

Parameters:
node - the root node for the Tree.
Throws:
IllegalArgumentException - if node has siblings.
Method Detail

setRoot

public TreeNode<E> setRoot(TreeNode<E> node)
Sets the root of this Tree.

Parameters:
node - the new root TreeNode.
Returns:
the old root TreeNode.
Throws:
IllegalArgumentException - if node has siblings.

getRoot

public TreeNode<E> getRoot()
Returns the root of this Tree.

Returns:
the root TreeNode or null if this Tree is empty.

isEmpty

public boolean isEmpty()
Returns true if this Tree is empty.

Returns:
true if the root TreeNode is null, false otherwise.

destroyNode

public void destroyNode(TreeNode<E> node)
Removes a single node. The node will be replaced with its right sibling if it has one.

Parameters:
node - the node to remove.
Throws:
NullPointerException - if node is null.

killNode

public void killNode(TreeNode<E> node)
Kills a node. Doesn't adjust any references so the children and right siblings of the node will be lost. If the specified node is the root node, its left child (in effect the whole tree) will be killed instead.

Parameters:
node - the node to kill.
Throws:
NullPointerException - if node is null.
TreeException - if node is not part of this Tree.