edu.wlu.cs.levy.RAAM
Class Tree

java.lang.Object
  |
  +--edu.wlu.cs.levy.RAAM.Tree

public class Tree
extends java.lang.Object

Tree is a class supporting trees of arbitrary arity.

Since:
JDK1.2

Field Summary
 edu.wlu.cs.levy.RAAM.Tree[] branches
           
 java.lang.String value
           
 
Constructor Summary
Tree(java.lang.String s)
          Creates a tree by parsing a parenthesized expression.
Tree(edu.wlu.cs.levy.RAAM.Tree[] b)
          Creates tree from a shallow copy of multiple branches.
Tree(edu.wlu.cs.levy.RAAM.Tree l, edu.wlu.cs.levy.RAAM.Tree r)
          Creates a tree from two branches.
 
Method Summary
 int arity()
          Returns the arity (number of branches) of the tree.
 int depth()
          Returns the depth of the tree.
 boolean equals(java.lang.Object o)
          Overrides Object.equals() method.
 java.lang.String frontier()
          Returns the frontier of the tree.
 edu.wlu.cs.levy.RAAM.Tree getBranch(int n)
          Returns a branch of the tree.
 java.lang.String getValue()
          Returns the string in the value field of the tree.
 int hashCode()
          Overrides Object.hashCode() method.
 boolean isTerminal()
          Determines whether tree is terminal (has non-empty value).
 edu.wlu.cs.levy.RAAM.Tree[] subtrees()
          Returns all subtrees of the tree.
 java.lang.String toString()
          Overrides Object.toString() method.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

value

public java.lang.String value

branches

public edu.wlu.cs.levy.RAAM.Tree[] branches
Constructor Detail

Tree

public Tree(java.lang.String s)
Creates a tree by parsing a parenthesized expression. If expression is not a well-formed tree, behavior is undefined.

Parameters:
s - the parenthesized expression

Tree

public Tree(edu.wlu.cs.levy.RAAM.Tree[] b)
Creates tree from a shallow copy of multiple branches.

Parameters:
b - the branches

Tree

public Tree(edu.wlu.cs.levy.RAAM.Tree l,
            edu.wlu.cs.levy.RAAM.Tree r)
Creates a tree from two branches.

Parameters:
l - the left branch
r - the right branch
Method Detail

isTerminal

public boolean isTerminal()
Determines whether tree is terminal (has non-empty value).

Returns:
true if tree is terminal, false otherwise

toString

public java.lang.String toString()
Overrides Object.toString() method.

Overrides:
toString in class java.lang.Object
Returns:
a parenthesized expression representing the tree

equals

public boolean equals(java.lang.Object o)
Overrides Object.equals() method.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides Object.hashCode() method.

Overrides:
hashCode in class java.lang.Object

getValue

public java.lang.String getValue()
Returns the string in the value field of the tree.

Returns:
the string in the value field of the tree

getBranch

public edu.wlu.cs.levy.RAAM.Tree getBranch(int n)
Returns a branch of the tree.

Parameters:
n - branch index (first = 0)
Returns:
the nth branch of the tree

arity

public int arity()
Returns the arity (number of branches) of the tree.

Returns:
the arity of the tree

depth

public int depth()
Returns the depth of the tree.

Returns:
the depth of the tree

frontier

public java.lang.String frontier()
Returns the frontier of the tree.

Returns:
the frontier of the tree

subtrees

public edu.wlu.cs.levy.RAAM.Tree[] subtrees()
Returns all subtrees of the tree.

Returns:
the subtrees