|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectbrs.BiTree<T>
public class BiTree<T>
Models the binary tree structure using the state pattern and the visitor pattern. Provides only structural behaviors and a hook to execute any visitor algorithm. Exercise: Override the toString() method anonymous inner visitor classes.
| Field Summary | |
|---|---|
private ANode<T> |
_rootNode
the state of this BiTree. |
private ToString<T> |
_toString
Visitor to generate string representation. |
| Constructor Summary | |
|---|---|
BiTree()
Initializes this BiTree to the empty state. |
|
| Method Summary | ||
|---|---|---|
|
execute(IVisitor<T,R,P> algo,
P... inp)
Hook to execute any algorithm that presents itself as a visitor to this BiTree. |
|
BiTree<T> |
getLeftSubTree()
Gets the left subtree of this BiTree if it exists. |
|
BiTree<T> |
getRightSubTree()
Gets the right subtree of this BiTree if it exsists. |
|
T |
getRootDat()
Gets the root data of this BiTree if it exists. |
|
(package private) ANode<T> |
getRootNode()
Returns the current node (i.e. |
|
void |
insertRoot(T dat)
Inserts a root element to this BiTree. |
|
T |
remRoot()
Removes and returns the root data element of this BiTree. |
|
void |
setLeftSubTree(BiTree<T> biTree)
Attaches a new left subtree to the left of this BiTree, allowing this BiTree to grow to the left. |
|
void |
setRightSubTree(BiTree<T> biTree)
Attaches a new right subtree to the left of this BiTree, allowing this BiTree to grow to the right. |
|
void |
setRootDat(T dat)
Sets the root data element to a given object. |
|
(package private) void |
setRootNode(ANode<T> node)
Changes this BiTree to a given new node (i.e. |
|
java.lang.String |
toString()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private ANode<T> _rootNode
private ToString<T> _toString
| Constructor Detail |
|---|
public BiTree()
| Method Detail |
|---|
public T getRootDat()
NoSuchElementException - if this BiTree is empty.public void setRootDat(T dat)
dat - the new root data.
NoSuchElementException - if this BiTree is empty.public BiTree<T> getLeftSubTree()
NoSuchElementException - if this BiTree is empty.public BiTree<T> getRightSubTree()
NoSuchElementException - if this BiTree is empty.public void setLeftSubTree(BiTree<T> biTree)
biTree - to replace the current left subtree.
NoSuchElementException - if this BiTree is empty.public void setRightSubTree(BiTree<T> biTree)
biTree - to replace the current right subtree.
NoSuchElementException - if this BiTree is empty.public void insertRoot(T dat)
dat - the new root data.
java.lang.IllegalStateException - if this BiTree has more than one element.public T remRoot()
NoSuchElementException - if this BiTree is empty.
java.lang.IllegalStateException - if one of the subtrees is not empty.
public <R,P> R execute(IVisitor<T,R,P> algo,
P... inp)
algo - a visitor to a BiTree.inp - the vararg input for the algo visitor.
public java.lang.String toString()
toString in class java.lang.Objectfinal void setRootNode(ANode<T> node)
node - a new root node (i.e.state) for this BiTree.final ANode<T> getRootNode()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||