brs
Class DatNode<T>

java.lang.Object
  extended by brs.ANode<T>
      extended by brs.DatNode<T>

 class DatNode<T>
extends ANode<T>

Stores data and represents a non-empty state.


Field Summary
private  T _dat
          the stored data element.
private  BiTree<T> _leftTree
          Data Invariant: != null.
private  BiTree<T> _rightTree
          Data Invariant: != null.
 
Constructor Summary
DatNode(T dat)
          Initialize the data element to a given object.
 
Method Summary
(package private)
<R,P> R
execute(BiTree<T> owner, IVisitor<T,R,P> algo, P... inp)
          Calls algo's nonEmptyCase() method to execute the algorithm algo.
(package private)  BiTree<T> getLeftSubTree(BiTree<T> owner)
          Gets the left subtree of the owner tree.
(package private)  BiTree<T> getRightSubTree(BiTree<T> owner)
          Gets the right subtree of the owner tree.
(package private)  T getRootDat(BiTree<T> owner)
          Gets the root data of the owner Tree.
(package private)  void insertRoot(BiTree<T> owner, T dat)
          Throws an IllegalStateException because the owner tree is not empty.
(package private)  T remRoot(BiTree<T> owner)
          Removes and returns the root element from the owner tree by asking the left subtree and, if necessary, the right subtree to help do the job.
(package private)  void setLeftSubTree(BiTree<T> owner, BiTree<T> biTree)
          Sets the left subtree of this Datnode to a given tree.
(package private)  void setRightSubTree(BiTree<T> owner, BiTree<T> biTree)
          Sets the right subtree of this node to a given tree.
(package private)  void setRootDat(BiTree<T> owner, T dat)
          Sets the data element of this node to a given data object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_leftTree

private BiTree<T> _leftTree
Data Invariant: != null.


_dat

private T _dat
the stored data element.


_rightTree

private BiTree<T> _rightTree
Data Invariant: != null.

Constructor Detail

DatNode

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

Parameters:
dat - a given data object.
Method Detail

getRootDat

T getRootDat(BiTree<T> owner)
Gets the root data of the owner Tree.

Specified by:
getRootDat in class ANode<T>
Parameters:
owner - the BiTree holding this DatNode.
Returns:
the data element of this DatNode.

setRootDat

void setRootDat(BiTree<T> owner,
                T dat)
Sets the data element of this node to a given data object.

Specified by:
setRootDat in class ANode<T>
Parameters:
dat - a given data object.
owner - the BiTree holding this DatNode.

getLeftSubTree

BiTree<T> getLeftSubTree(BiTree<T> owner)
Gets the left subtree of the owner tree.

Specified by:
getLeftSubTree in class ANode<T>
Parameters:
owner - the BiTree holding this DatNode.
Returns:
the left subtree of this DatNode.

getRightSubTree

BiTree<T> getRightSubTree(BiTree<T> owner)
Gets the right subtree of the owner tree.

Specified by:
getRightSubTree in class ANode<T>
Parameters:
owner - the BiTree holding this DatNode.
Returns:
the right subtree of this DatNode.

setLeftSubTree

void setLeftSubTree(BiTree<T> owner,
                    BiTree<T> biTree)
Sets the left subtree of this Datnode to a given tree. Allows for growing the owner tree.

Specified by:
setLeftSubTree in class ANode<T>
Parameters:
biTree - != null. Does not check for null!
owner - the BiTree holding this DatNode.

setRightSubTree

void setRightSubTree(BiTree<T> owner,
                     BiTree<T> biTree)
Sets the right subtree of this node to a given tree. Allows for growing the owner tree.

Specified by:
setRightSubTree in class ANode<T>
Parameters:
biTree - != null. Does not check for null!
owner - the BiTree holding this DatNode.

insertRoot

void insertRoot(BiTree<T> owner,
                T dat)
Throws an IllegalStateException because the owner tree is not empty.

Specified by:
insertRoot in class ANode<T>
Parameters:
owner - the BiTree that holds this node.
Throws:
IllegaStateException.

remRoot

T remRoot(BiTree<T> owner)
Removes and returns the root element from the owner tree by asking the left subtree and, if necessary, the right subtree to help do the job. The subtrees help determine whether or not the root element can be removed by executing appropriate anonymous visitors.

Specified by:
remRoot in class ANode<T>
Parameters:
owner - the BiTree holding this DatNode. Why is it final?
Throws:
IllegaStateException - if both subtrees of owner are non-empty.

execute

<R,P> R execute(BiTree<T> owner,
                IVisitor<T,R,P> algo,
                P... inp)
Calls algo's nonEmptyCase() method to execute the algorithm algo.

Specified by:
execute in class ANode<T>
Parameters:
owner - the BiTree holding this DatNode.
algo - an algorithm on owner.
inp - the vararg input algo needs.
Returns:
the output for the nonEmptyCase() of algo.