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

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

public class TreeNode<E>
extends java.lang.Object

TreeNode is a building block for basic Trees.

See Also:
Tree

Constructor Summary
TreeNode(E element)
          Creates a new TreeNode with the specified element.
 
Method Summary
 int getBalance()
          Returns this node's balance.
 E getElement()
          Returns this node's element.
 TreeNode<E> getLeftChild()
          Returns this node's leftmost child.
 TreeNode<E> getParent()
          Returns this node's parent node.
 TreeNode<E> getRightSibling()
          Returns this node's right sibling.
 TreeNode<E> removeLeftChild()
          Removes this node's left child.
 TreeNode<E> removeRightSibling()
          Removes this node's right sibling.
 void setBalance(int balance)
          Sets this node's balance.
 E setElement(E element)
          Sets this node's element.
 void setLeftChild(Tree<E> tree)
          Sets this node's left child to be the root node of the specified Tree.
 void setLeftChild(TreeNode<E> node)
          Sets this node's left child.
 void setRightSibling(Tree<E> tree)
          Sets this node's right sibling to be the root node of the specified Tree.
 void setRightSibling(TreeNode<E> node)
          Sets this node's right sibling.
 java.lang.String toString()
          Returns (element) as String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TreeNode

public TreeNode(E element)
Creates a new TreeNode with the specified element.

Parameters:
element - the element for the TreeNode.
Method Detail

setBalance

public void setBalance(int balance)
Sets this node's balance.

Parameters:
balance - the new balance for this node.

getBalance

public int getBalance()
Returns this node's balance.

Returns:
this node's balance.

getElement

public E getElement()
Returns this node's element.

Returns:
this node's element or null if none.

setElement

public E setElement(E element)
Sets this node's element.

Parameters:
element - new element for this node.
Returns:
the old element or null if none.
Throws:
ElementTypeMismatchException - if the type of element does not match that of this node.

getParent

public TreeNode<E> getParent()
Returns this node's parent node.

Returns:
this node's parent node or null if this node is the root node or not part of a Tree.

getLeftChild

public TreeNode<E> getLeftChild()
Returns this node's leftmost child.

Returns:
this node's leftmost child or null if none exists.

setLeftChild

public void setLeftChild(TreeNode<E> node)
Sets this node's left child.

Parameters:
node - the new left child.
Throws:
java.lang.NullPointerException - if node is null.
ElementTypeMismatchException - if node's element type does not match that of this node.

setLeftChild

public void setLeftChild(Tree<E> tree)
Sets this node's left child to be the root node of the specified Tree.

Parameters:
tree - the Tree the root node of which is to be this node's left child.
Throws:
java.lang.NullPointerException - if tree or its root node is null.
ElementTypeMismatchException - if tree's element type does not match that of this node.

removeLeftChild

public TreeNode<E> removeLeftChild()
Removes this node's left child. The old left child's right sibling (if any) will become this node's new left child.

Returns:
the node that used to be this node's left child or null if this node had no left child.

getRightSibling

public TreeNode<E> getRightSibling()
Returns this node's right sibling.

Returns:
this node's right sibling or null if none exists.

setRightSibling

public void setRightSibling(TreeNode<E> node)
Sets this node's right sibling.

Parameters:
node - the new right sibling.
Throws:
java.lang.NullPointerException - if node is null.
TreeException - if this node is the root node.

setRightSibling

public void setRightSibling(Tree<E> tree)
Sets this node's right sibling to be the root node of the specified Tree.

Parameters:
tree - the Tree the root node of which is to become this node's right sibling.
Throws:
java.lang.NullPointerException - if tree or its root node is null.
ElementTypeMismatchException - if tree's element type does not match that of this node.

removeRightSibling

public TreeNode<E> removeRightSibling()
Removes this node's right sibling. The old right sibling's right sibling (if any) will become this node's new right sibling.

Returns:
the node that used to be the right sibling or null if this node had no right sibling.

toString

public java.lang.String toString()
Returns (element) as String.

Overrides:
toString in class java.lang.Object