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

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

public class BTreeNode<E>
extends Object

BTreeNode is a building block for basic BTrees.

See Also:
BTree

Constructor Summary
BTreeNode(E element)
          Creates a new BTreeNode with the specified element.
 
Method Summary
 int getBalance()
          Returns this node's balance.
 E getElement()
          Returns this node's element.
 BTreeNode<E> getLeftChild()
          Returns this node's leftmost child.
 BTreeNode<E> getParent()
          Returns this node's parent node.
 BTreeNode<E> getRightChild()
          Returns this node's right child.
 void removeLeftChild()
          Removes this node's left child.
 void removeRightChild()
          Removes this node's right child.
 void setBalance(int balance)
          Sets this node's balance.
 E setElement(E element)
          Sets this node's element.
 void setLeftChild(BTree<E> tree)
          Sets this node's left child to be the root node of the specified BTree.
 void setLeftChild(BTreeNode<E> node)
          Sets this node's left child.
 void setRightChild(BTree<E> tree)
          Sets this node's right child to be the root node of the specified BTree.
 void setRightChild(BTreeNode<E> node)
          Sets this node's right child.
 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

BTreeNode

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

Parameters:
element - the element for the BTreeNode.
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 BTreeNode<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 BTree.

getLeftChild

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

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

setLeftChild

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

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

setLeftChild

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

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

removeLeftChild

public void removeLeftChild()
Removes this node's left child.


getRightChild

public BTreeNode<E> getRightChild()
Returns this node's right child.

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

setRightChild

public void setRightChild(BTreeNode<E> node)
Sets this node's right child.

Parameters:
node - the new right child.
Throws:
NullPointerException - if node is null.
BTreeException - if this node is the root node.

setRightChild

public void setRightChild(BTree<E> tree)
Sets this node's right child to be the root node of the specified BTree.

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

removeRightChild

public void removeRightChild()
Removes this node's right child.


toString

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

Overrides:
toString in class Object