org.algernon.util
Class SimpleTree
java.lang.Object
java.util.AbstractMap
java.util.HashMap
org.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 classes inherited from class java.util.HashMap |
|
Nested classes inherited from class java.util.AbstractMap |
|
Fields inherited from class java.util.HashMap |
|
Constructor Summary |
SimpleTree()
|
SimpleTree(int i)
Pass in the approximate number of nodes in the tree. |
Methods inherited from class java.util.HashMap |
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values |
f_parentMap
Map f_parentMap
SimpleTree
public SimpleTree()
SimpleTree
public SimpleTree(int i)
- Pass in the approximate number of nodes in the tree.
- Parameters:
i
-
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.