beowulf.model.tree
Class DefaultBinaryTree

java.lang.Object
  extended bybeowulf.model.tree.AbstractBinaryTreeModel
      extended bybeowulf.model.tree.DefaultBinaryTree
All Implemented Interfaces:
BinaryTreeModel, TreeModel
Direct Known Subclasses:
DefaultBST

public class DefaultBinaryTree
extends AbstractBinaryTreeModel

Version:
1.0, 11/17/2003
Author:
Andy Scukanec (ags at cs dot cornell dot edu)

Field Summary
protected  int count
           
protected  int maxDepth
           
protected  boolean recalcMaxDepth
           
protected  BinaryTreeNode root
           
 
Fields inherited from class beowulf.model.tree.AbstractBinaryTreeModel
listenerList
 
Constructor Summary
DefaultBinaryTree()
           
 
Method Summary
 void add(Object value)
          This method will create a new node with the given value, and add it to the tree.
 Enumeration elements()
          This will return an enumeration of all values in the tree.
 Object getChild(Object parent, int index)
           
 int getChildCount(Object parent)
           
 int getIndexOfChild(Object parent, Object child)
           
 int getMaxDepth()
          Returns the maximum depth of the tree.
 int getNodeCount()
          Returns the number of nodes in the tree.
 BinaryTreeNode[] getPathToNode(BinaryTreeNode node)
           
 Object getRoot()
           
 boolean isLeaf(Object node)
           
protected  void recalcMaxDepth(BinaryTreeNode root, int depth)
           
 void remove(Object value)
          Given a node's value, this method will find and remove that node from the tree.
 String toString(boolean verbose)
          Returns a verbose description if passed in true.
 void valueForPathChanged(TreePath path, Object newValue)
           
 
Methods inherited from class beowulf.model.tree.AbstractBinaryTreeModel
addTreeModelListener, fireNodesChanged, fireNodesInserted, fireNodesRemoved, fireStructureChanged, getListeners, getTreeListeners, removeTreeModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

protected BinaryTreeNode root

count

protected int count

maxDepth

protected int maxDepth

recalcMaxDepth

protected boolean recalcMaxDepth
Constructor Detail

DefaultBinaryTree

public DefaultBinaryTree()
Method Detail

add

public void add(Object value)
Description copied from class: AbstractBinaryTreeModel
This method will create a new node with the given value, and add it to the tree.

Specified by:
add in class AbstractBinaryTreeModel
Parameters:
value - The value of the new node.

remove

public void remove(Object value)
Description copied from class: AbstractBinaryTreeModel
Given a node's value, this method will find and remove that node from the tree. If the value does not occur in the tree

Specified by:
remove in class AbstractBinaryTreeModel
Parameters:
value - The value of the node to be removed.

getPathToNode

public BinaryTreeNode[] getPathToNode(BinaryTreeNode node)

elements

public Enumeration elements()
Description copied from interface: BinaryTreeModel
This will return an enumeration of all values in the tree.

Returns:
An enumeration of all the elements in the tree.

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                Object newValue)

getChild

public Object getChild(Object parent,
                       int index)

getChildCount

public int getChildCount(Object parent)

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)

getRoot

public Object getRoot()

isLeaf

public boolean isLeaf(Object node)

getNodeCount

public int getNodeCount()
Description copied from interface: BinaryTreeModel
Returns the number of nodes in the tree.

Returns:
The number of nodes in the tree.

getMaxDepth

public int getMaxDepth()
Description copied from interface: BinaryTreeModel
Returns the maximum depth of the tree.

Returns:
The maximum depth of the tree.

recalcMaxDepth

protected void recalcMaxDepth(BinaryTreeNode root,
                              int depth)

toString

public String toString(boolean verbose)
Description copied from interface: BinaryTreeModel
Returns a verbose description if passed in true. Returns a shorter description otherwise.

Parameters:
verbose - Whether or not to return a verbose description.
Returns:
A description like toString(), but possibly more verbose.