org.objectweb.fractal.julia.loader
Class Tree

java.lang.Object
  extended by org.objectweb.fractal.julia.loader.Tree

public class Tree
extends Object

An immutable string tree.


Constructor Summary
Tree(String leaf)
          Constructs a new Tree instance.
Tree(Tree[] subTrees)
          Constructs a new Tree instance.
 
Method Summary
 boolean equals(Object o)
          Tests if this tree is equal to the given object.
 int equals(String str, int off, int len)
          Test if the String representation of this tree is equal to the given String.
 int getSize()
          Returns the number of sub trees of this tree.
 Tree getSubTree(int index)
          Returns the sub tree of this tree whose index is given.
 Tree[] getSubTrees()
          Returns the sub trees of this tree.
 Tree getValue(String key)
          Return the value associated to the given key.
 int hashCode()
          Returns the hashcode of this tree.
 String toString()
          Returns a string representation of this tree.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Tree

public Tree(String leaf)
Constructs a new Tree instance.

Parameters:
leaf - the value of the node to be created.

Tree

public Tree(Tree[] subTrees)
Constructs a new Tree instance.

Parameters:
subTrees - the subtrees of the node to be created, or null for a leaf node.
Method Detail

getSize

public int getSize()
Returns the number of sub trees of this tree.

Returns:
the number of sub trees of this tree.

getSubTree

public Tree getSubTree(int index)
Returns the sub tree of this tree whose index is given.

Parameters:
index - the index of the sub tree to be returned.
Returns:
the sub tree of this tree whose index is given.
Throws:
ArrayIndexOutOfBoundsException - if index is negative or strictly greater than getSize.

getSubTrees

public Tree[] getSubTrees()
Returns the sub trees of this tree.

Returns:
the sub trees of this tree.

getValue

public Tree getValue(String key)
Return the value associated to the given key. This method supposes that this tree is of the form "((key1 value1) ... (keyN valueN))".

Parameters:
key - a key
Returns:
the value returned to this key, or null.

equals

public boolean equals(Object o)
Tests if this tree is equal to the given object.

Overrides:
equals in class Object
Parameters:
o - the object to be compared to this tree.
Returns:
true if o is a tree that is equal to this tree, or if o is a String that is equal to the String representation of this tree.

hashCode

public int hashCode()
Returns the hashcode of this tree.

Overrides:
hashCode in class Object
Returns:
the hashcode of this tree.

toString

public String toString()
Returns a string representation of this tree.

Overrides:
toString in class Object
Returns:
a string representation of this tree, with a LISP like syntax, as in the following example: "(foo (bar foo))".

equals

public int equals(String str,
                  int off,
                  int len)
Test if the String representation of this tree is equal to the given String.

Parameters:
str - a String.
off - the start index of the String to be compared to this tree in str;
len - the length of the String to be compared to this tree.
Returns:
the number of remaining characters in str, once the prefix corresponding to the String representation of this tree is removed, or -1 if the given String does not starts with the String representation of this tree.