Algernon Software

org.algernon.util
Class SimpleTree

java.lang.Object
  extended byjava.util.AbstractMap
      extended byjava.util.HashMap
          extended byorg.algernon.util.SimpleTree
All Implemented Interfaces:
Cloneable, Map, Serializable

public class SimpleTree
extends HashMap

SimpleTree stores a tree whose nodes can contain multiple children. The tree is not kept balanced or sorted. The tree can have multiple roots.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.HashMap
 
Nested classes inherited from class java.util.AbstractMap
 
Field Summary
(package private)  Map f_parentMap
           
 
Fields inherited from class java.util.HashMap
 
Fields inherited from class java.util.AbstractMap
 
Constructor Summary
SimpleTree()
           
SimpleTree(int i)
          Pass in the approximate number of nodes in the tree.
 
Method Summary
 void addChild(Object parent, Object child)
          Adds a child to a node.
 Collection getChildren(Object node)
          Returns a collection of the children in the tree.
 Collection getNodes()
          Returns a collection of all of the nodes in the tree.
 Object getParent(Object o)
          Returns the parent of a node.
 Collection getRoots()
          Returns a collection of the roots of the tree - those that have no parents.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

f_parentMap

Map f_parentMap
Constructor Detail

SimpleTree

public SimpleTree()

SimpleTree

public SimpleTree(int i)
Pass in the approximate number of nodes in the tree.

Parameters:
i -
Method Detail

addChild

public void addChild(Object parent,
                     Object child)
Adds a child to a node. Only adds it if it is not in the child collection already. Send in null for the child if you want to store a leaf node.

Parameters:
parent -
child -

getChildren

public Collection getChildren(Object node)
Returns a collection of the children in the tree. Returns null if there are none.


getParent

public Object getParent(Object o)
Returns the parent of a node. Returns null for a root.


getRoots

public Collection getRoots()
Returns a collection of the roots of the tree - those that have no parents.


getNodes

public Collection getNodes()
Returns a collection of all of the nodes in the tree.


Algernon Software