org.locomotive.util.data
Class DataTree

java.lang.Object
  |
  +--org.locomotive.util.data.DataTree
Direct Known Subclasses:
Heap

public class DataTree
extends java.lang.Object

this class is an abstract implementation of a data tree, and can be extended to for heaps or binary search trees. it proivides implementations for two kinds of data structures: 1. where there is a key and a data type 2. where the key is the data type All keys must implement the comparisonKey class

See Also:
ComparisonKey

Inner Class Summary
protected  class DataTree.TreeNode
          a node for a binary search tree
 
Field Summary
protected  int count
           
protected  DataTree.TreeNode root
           
 
Constructor Summary
DataTree()
          construct an empty tree sets number of items in the tree to zero
DataTree(ComparisonKey newObject)
          constructs a tree with the comparisonKey as the key and the data for the root node.
DataTree(ComparisonKey newKey, java.lang.Object newData)
          constructs a new tree with a key and it's data as the root
DataTree(DataTree.TreeNode node)
          create a tree with the node as it's root
 
Method Summary
 DataTree.TreeNode find(ComparisonKey key)
          finds the object node containing the object with the specified key and returns it.
 void insert(ComparisonKey newKey)
          inserts a node whose comparisonKey is its data
 void insert(ComparisonKey newKey, java.lang.Object newData)
          inserts a new object into tree
 boolean isEmpty()
          returns true if the tree is empty, false if otherwise
 DataTree.TreeNode root()
          returns the root node of the tree.
 int size()
          this method returns the number of elements in the tree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

protected DataTree.TreeNode root

count

protected int count
Constructor Detail

DataTree

public DataTree()
construct an empty tree sets number of items in the tree to zero

DataTree

public DataTree(DataTree.TreeNode node)
create a tree with the node as it's root
Parameters:
node - the TreeNode to set the root as

DataTree

public DataTree(ComparisonKey newKey,
                java.lang.Object newData)
constructs a new tree with a key and it's data as the root
Parameters:
newKey - the ComparisonKey to place at the root
newData - the data to place in the root node

DataTree

public DataTree(ComparisonKey newObject)
constructs a tree with the comparisonKey as the key and the data for the root node.
Parameters:
newObject - the ComparisonKey to place at the root
Method Detail

insert

public void insert(ComparisonKey newKey,
                   java.lang.Object newData)
inserts a new object into tree
Parameters:
newKey - the key to use for the object
newData - the ComparisonKey to enter

insert

public void insert(ComparisonKey newKey)
inserts a node whose comparisonKey is its data

isEmpty

public boolean isEmpty()
returns true if the tree is empty, false if otherwise

find

public DataTree.TreeNode find(ComparisonKey key)
finds the object node containing the object with the specified key and returns it. Returns null if key is not in the tree

root

public DataTree.TreeNode root()
returns the root node of the tree. Returns null if tree is empty

size

public int size()
this method returns the number of elements in the tree