Class brs.DatNode


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

Author:
Dung X. Nguyen - Copyright 2001 - 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 (BiTree, IVisitor, Object[])
Calls algo's nonEmptyCase() method to execute the algorithm algo
 o getLeftSubTree (BiTree)
Gets the left subtree of the owner tree
 o getRightSubTree (BiTree)
Gets the right subtree of the owner tree
 o getRootDat (BiTree)
Gets the root data of the owner Tree
 o insertRoot (Object, BiTree)
Throws an IllegalStateException because the owner tree is not empty
 o remRoot (final BiTree)
Removes and returns the root element from the owner tree by asking the
 o setLeftSubTree (BiTree, BiTree)
Sets the left subtree of this Datnode 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 = new BiTree ()
Data Invariant: != null.

 o _dat
private Object _dat
the stored data element.

 o _rightTree
private BiTree _rightTree = new BiTree ()
Data Invariant: != null.

Constructors

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

Parameters:
dat - a given data object.

Methods

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

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

Parameters:
dat - a given data object.
owner - the BiTree holding this DatNode.
 o getLeftSubTree
BiTree getLeftSubTree(BiTree owner)
Gets the left subtree of the owner tree.

Parameters:
owner - the BiTree holding this DatNode.
Returns:
the left subtree of this DatNode.
 o getRightSubTree
BiTree getRightSubTree(BiTree owner)
Gets the right subtree of the owner tree.

Parameters:
owner - the BiTree holding this DatNode.
Returns:
the right subtree of this DatNode.
 o setLeftSubTree
void setLeftSubTree(BiTree biTree, BiTree owner)
Sets the left subtree of this Datnode to a given tree. Allows for growing the owner tree.

Parameters:
biTree - != null. Does not check for null!
owner - the BiTree holding this DatNode.
 o setRightSubTree
void setRightSubTree(BiTree biTree, BiTree owner)
Sets the right subtree of this node to a given tree. Allows for growing the owner tree.

Parameters:
biTree - != null. Does not check for null!
owner - the BiTree holding this DatNode.
 o insertRoot
void insertRoot(Object dat, BiTree owner)
Throws an IllegalStateException because the owner tree is not empty.

Throws: IllegaStateException.
 o remRoot
Object remRoot(final BiTree 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.

Parameters:
owner - the BiTree holding this DatNode. Why is it final?
Throws: IllegaStateException
if both subtrees of owner are non-empty.
 o execute
Object execute(BiTree owner, IVisitor algo, Object[] inp)
Calls algo's nonEmptyCase() method to execute the algorithm algo.

Parameters:
algo - an algorithm on owner.
inp - the input algo needs.
owner - the BiTree holding this DatNode.
Returns:
the output for the nonEmptyCase() of algo.