Class binaryTree.DatNode


class DatNode
extends binaryTree.ANode
Stores data and represents a non-empty state.

Author:
Dung X. Nguyen - Copyright 1999 - All rights reserved.

Variable Index

 o _dat
the stored data element
 o _leftTree
Data Invariant: != null
 o _rightTree
Data Invariant: != null

Constructor Index

 o DatNode (Object)
Initialize the data element to a given object

Method Index

 o execute (IVisitor, Object, BiTree)
Calls the visitor's nonNullCase () method to execute the visiting algorithm
 o getLeftSubTree (BiTree)
Gets the left subtree of the parent tree
 o getRightSubTree (BiTree)
Gets the right subtree of the parent tree
 o getRootDat (BiTree)
Gets the root data of the parent Tree
 o insertRoot (Object, BiTree)
Throws an IllegalStateException because the parent tree is not empty
 o remOurParent (BiTree, BiTree)
Throws an IllegalStateException because the parent tree is not empty
 o remParent (BiTree, BiTree, BiTree)
Throws an IllegalStateException because the parent tree is not empty
 o remRoot (BiTree)
Removes and returns the root element from the parent tree by handing the right
 o setLeftSubTree (BiTree, BiTree)
Sets the left subtree of this node to a given tree
 o setRightSubTree (BiTree, BiTree)
Sets the right subtree of this node to a given tree
 o setRootDat (Object, BiTree)
Sets the data element of this node to a given data object

Variables

 o _leftTree
private BiTree _leftTree
Data Invariant: != null.

 o _dat
private Object _dat
the stored data element.

 o _rightTree
private BiTree _rightTree
Data Invariant: != null.

Constructors

 o DatNode
 DatNode(Object dat)
Initialize the data element to a given object.

Parameters:
dat -

Methods

 o getRootDat
Object getRootDat(BiTree parent)
Gets the root data of the parent Tree.

Parameters:
parent - the context of the state.
Returns:
the data element of this node.
 o setRootDat
void setRootDat(Object dat, BiTree parent)
Sets the data element of this node to a given data object.

Parameters:
dat -
parent - the context of this state.
 o getLeftSubTree
BiTree getLeftSubTree(BiTree parent)
Gets the left subtree of the parent tree.

Parameters:
parent - the context of this state.
Returns:
the left subtree of this node.
 o getRightSubTree
BiTree getRightSubTree(BiTree parent)
Gets the right subtree of the parent tree.

Parameters:
parent - the context of this state.
Returns:
the right subtree of this node.
 o setLeftSubTree
void setLeftSubTree(BiTree biTree, BiTree parent)
Sets the left subtree of this node to a given tree. Allows for growing the parent tree.

Parameters:
biTree - != null.
parent - the context of this state.
 o setRightSubTree
void setRightSubTree(BiTree biTree, BiTree parent)
Sets the right subtree of this node to a given tree. Allows for growing the parent tree.

Parameters:
biTree - != null.
parent - the context of this state.
 o insertRoot
void insertRoot(Object dat, BiTree parent)
Throws an IllegalStateException because the parent tree is not empty.

Throws: IllegaStateException.
 o remRoot
Object remRoot(BiTree parent)
Removes and returns the root element from the parent tree by handing the right subtree to the left subtree to do the job.

Parameters:
dat -
parent - the context of this state.
Throws: IllegaStateException
if the parent has more than one element.
 o remParent
Object remParent(BiTree sis, BiTree grandPo, BiTree mom)
Throws an IllegalStateException because the parent tree is not empty.

 o remOurParent
Object remOurParent(BiTree grandParent, BiTree parent)
Throws an IllegalStateException because the parent tree is not empty.

 o execute
Object execute(IVisitor algo, Object input, BiTree parent)
Calls the visitor's nonNullCase () method to execute the visiting algorithm.

Parameters:
algo - the visiting algorithm
input - the input the algorithm needs.
parent - the context of this node.
Returns:
the output for the nonNullCase() of the algorithm.