|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objecttrees.Tree<V>
V - The type of value allowed in Tree nodes.public class Tree<V>
General tree API.
| Constructor Summary | |
|---|---|
Tree(V value)
Constructor for Tree objects. |
|
| Method Summary | |
|---|---|
void |
addChild(Tree<V> newChild)
Adds the given node as the new last child of this node. |
void |
addChildren(java.util.ArrayList<Tree<V>> newChildren)
Adds the given nodes as new children of this node. |
java.util.ArrayList<Tree<V>> |
children()
Returns a genericized list of the children of this node. |
int |
depth()
Returns the depth of this node in the tree; that is, it returns the distance to the root. |
boolean |
equals(java.lang.Object o)
|
Tree<V> |
firstChild()
Returns the first child of this node, or null
if this node has no children. |
V |
getValue()
Returns the value in this node of the tree. |
boolean |
hasAncestor(Tree<V> ancestor)
Tests if the given node is the same as this node, or is an ancestor of this node. |
boolean |
hasChildren()
Tests whether this node is a leaf. |
boolean |
hasNextSibling()
Tests whether there are nodes "to the right" of this node. |
boolean |
hasPreviousSibling()
Tests whether there are nodes "to the left" of this node. |
boolean |
isLeaf()
Tests whether this node is a leaf. |
boolean |
isRoot()
Tests whether this tree node is the root. |
java.util.Iterator<Tree<V>> |
iterator()
Returns an iterator that will step through this tree in preorder. |
Tree<V> |
lastChild()
Returns the last child of this node, or null
if this node has no children. |
static void |
main(java.lang.String[] args)
Tests parsing and printing of trees; this is only a test method, not to be used for other purposes. |
Tree<V> |
nextSibling()
Returns the next sibling of this node, or null
if this node is the rightmost node. |
Tree<V> |
parent()
Returns the parent of this node, or null if
this is a root node. |
static Tree<java.lang.String> |
parse(java.lang.String s)
Parses a string of the general form value(child, child, ..., child)
and returns the corresponding tree. |
Tree<V> |
previousSibling()
Returns the previous sibling of this node, or null
if this node is the leftmost node. |
void |
print()
Prints this tree as an indented structure. |
void |
remove()
Removes this node from whatever tree it may be in. |
void |
setValue(V value)
Sets the value in this node of the tree. |
java.lang.String |
toString()
Returns a string representing this tree. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Tree(V value)
value - The value to put in the new tree node.| Method Detail |
|---|
public V getValue()
public void setValue(V value)
value - The value to put in this node.public boolean equals(java.lang.Object o)
equals in class java.lang.ObjectObject.equals(java.lang.Object)public boolean isRoot()
true if this node has no parent.public boolean isLeaf()
true if this node has no children.public boolean hasChildren()
true if this node has children.public boolean hasNextSibling()
true if this node is not the last child.public boolean hasPreviousSibling()
true if this node is not the first child.public Tree<V> parent()
null if
this is a root node.
public Tree<V> firstChild()
null
if this node has no children.
public Tree<V> lastChild()
null
if this node has no children.
public java.util.ArrayList<Tree<V>> children()
public Tree<V> nextSibling()
null
if this node is the rightmost node.
public Tree<V> previousSibling()
null
if this node is the leftmost node.
public int depth()
public boolean hasAncestor(Tree<V> ancestor)
ancestor - The node that may be an ancestor of this node.
public void addChild(Tree<V> newChild)
newChild - The node to be added.public void addChildren(java.util.ArrayList<Tree<V>> newChildren)
newChildren - The nodes to be added.public void remove()
public java.util.Iterator<Tree<V>> iterator()
public java.lang.String toString()
value(child, child, ..., child).
toString in class java.lang.ObjectObject.toString()public void print()
public static Tree<java.lang.String> parse(java.lang.String s)
value(child, child, ..., child)
and returns the corresponding tree. Children may be separated
by commas and/or spaces. Node values are all Strings.
s - The String to be parsed.
public static void main(java.lang.String[] args)
args - Unused.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||