edu.ksu.cis.viewer
Class BinaryTree

java.lang.Object
  extended byedu.ksu.cis.viewer.BinaryTree
All Implemented Interfaces:
Cloneable

public final class BinaryTree
extends Object
implements Cloneable

An immutable binary tree that can draw itself.

Author:
Rod Howell (howell@cis.ksu.edu)

Constructor Summary
BinaryTree()
          Constructs an empty BinaryTree.
BinaryTree(Node root, BinaryTree left, BinaryTree right)
          Constructs a BinaryTree with the given root and children.
 
Method Summary
 Object clone()
          Because this structure is immutable, this method simply returns this tree itself.
 TreeComponent getDrawing()
          Returns a drawing of this tree.
 TreeComponent getDrawing(Font fnt)
          Returns a drawing of the tree using the given Font.
 BinaryTree getLeftChild()
          Returns the left-hand child of this tree.
 BinaryTree getRightChild()
          Returns the right-hand child of this tree.
 Node getRoot()
          Returns the root of this tree.
 boolean isEmpty()
          Returns true if this tree is empty.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryTree

public BinaryTree()
Constructs an empty BinaryTree.


BinaryTree

public BinaryTree(Node root,
                  BinaryTree left,
                  BinaryTree right)
           throws NullPointerException
Constructs a BinaryTree with the given root and children. If either BinaryTree parameter is null, an empty BinaryTree will be used for that child.

Parameters:
root - the root of the tree
left - the left child
right - the right child
Throws:
NullPointerException - if root is null
Method Detail

isEmpty

public boolean isEmpty()
Returns true if this tree is empty.


getRoot

public Node getRoot()
             throws EmptyTreeException
Returns the root of this tree.

Throws:
EmptyTreeException - If this tree is empty.

getLeftChild

public BinaryTree getLeftChild()
                        throws EmptyTreeException
Returns the left-hand child of this tree.

Throws:
EmptyTreeException - If this tree is empty.

getRightChild

public BinaryTree getRightChild()
                         throws EmptyTreeException
Returns the right-hand child of this tree.

Returns:
The right child If this tree is empty.
Throws:
EmptyTreeException

getDrawing

public TreeComponent getDrawing()
Returns a drawing of this tree.


getDrawing

public TreeComponent getDrawing(Font fnt)
                         throws NullPointerException
Returns a drawing of the tree using the given Font.

Throws:
NullPointerException - if fnt is null

clone

public Object clone()
Because this structure is immutable, this method simply returns this tree itself.