|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.util.Tree
This class a represents the tree abstraction. This implementation takes a recursive definition where a tree is a root node connected to other (sub)trees.
This implementation allows the same node to be used in more than position in the tree. For example, you can do something like this:
Tree aa = new Tree("a"); Tree bb = aa.addChild("b"); bb.addChild("a"); aa.addChild("c");
This can be visualized as follows:
a / \ / \ b c \ \ a
The only ways to add node to the tree is through the constructor
and the addChild(Object)
addChild(Object,
Object)
methods.
Nested Class Summary | |
static class |
Tree.EdgeTreePair
Nodes in a tree are connected with edges. |
Constructor Summary | |
Tree(Object root)
|
Method Summary | |
Tree |
addChild(Object child)
A shortcut for addChild(child, null) . |
Tree |
addChild(Object child,
Object edge)
Adds a child element to the root of this tree. |
void |
addSubtree(Tree subtree)
A shortcut for addSubtree(subtree,null) . |
void |
addSubtree(Tree subtree,
Object edge)
Adds subtree to the root node of this tree. |
Tree |
copy()
Returns a copy of this tree. |
int |
depth()
Returns the maximum depth of the tree. |
List |
getAncestors()
Returns the list of trees such that each of the returned trees is rooted at the ancestor nodes of this tree or an empty list, if the root of this tree has no ancestors. |
String |
getLabel()
|
Tree |
getParent()
Returns the tree rooted at the parent node of the root of this tree or null , if the root of this tree has no parent node. |
Object |
getRoot()
Returns the root of this tree. |
List |
getSubtrees()
Returns the list of edge-tree pairs parented to
the root node of this tree in the order in which they were initially
added. |
int |
nodeCount()
|
void |
setLabel(String label)
|
static List |
treesToNodes(List trees)
Takes a list of trees and returns a new list where each tree from the passed in list is replaced with its root node. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Tree(Object root)
root
- the root node of the treeMethod Detail |
public void setLabel(String label)
public String getLabel()
public Object getRoot()
public Tree addChild(Object child, Object edge)
public Tree addChild(Object child)
addChild(child, null)
.
addChild(Object, Object)
public void addSubtree(Tree subtree, Object edge)
subtree
to the root node of this tree.
Note: This doesn't check for cycles. If you do something like,
tree.addSubtree(tree);
you're on your own. I'll add a check for cycles like this when I have the time. (This probably means never.)
public void addSubtree(Tree subtree)
addSubtree(subtree,null)
.
addSubtree(Tree, Object)
public Tree getParent()
null
, if the root of this tree has no parent node.
public List getSubtrees()
edge-tree pairs
parented to
the root node of this tree in the order in which they were initially
added. Manipulating the returned list does not affect this tree. For
example, if you remove an element from the list, no changes are made to
this tree.
public Tree copy()
public int nodeCount()
public int depth()
public List getAncestors()
public static List treesToNodes(List trees)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |