Class BinaryTree

java.lang.Object
edu.ksu.cis.viewer.BinaryTree
All Implemented Interfaces:
Serializable, Cloneable

public final class BinaryTree extends Object implements Cloneable, Serializable
An immutable binary tree that can draw itself.
Author:
Rod Howell (rhowell@ksu.edu)
See Also:
  • Constructor Details

    • 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 Details

    • isEmpty

      public boolean isEmpty()
      Returns true if this tree is empty.
      Returns:
      whether this tree is empty
    • getRoot

      public Node getRoot() throws EmptyTreeException
      Returns the root of this tree.
      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.
      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.
      Returns:
      a drawing of this tree
    • getDrawing

      public TreeComponent getDrawing(Font fnt) throws NullPointerException
      Returns a drawing of the tree using the given Font.
      Parameters:
      fnt - the font to use
      Returns:
      a drawing of this tree
      Throws:
      NullPointerException - if fnt is null
    • clone

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