org.melati.util
Class Tree

Package class diagram package Tree
java.lang.Object
  extended by org.melati.util.Tree
Direct Known Subclasses:
JSDynamicTree, JSStaticTree

public class Tree
extends Object

A whole tree.


Constructor Summary
Tree(Treeable node)
          Constructor from root node.
Tree(Treeable[] nodes)
          Constructor for a multi-rooted tree.
Tree(Treeable[] nodes, int depth)
          Constructor for a multi-rooted tree with anticipated depth.
Tree(Treeable node, int depth)
          Constructor from root node with anticipated depth.
 
Method Summary
 Vector<TreeNode> apply(Function func, int depthP, boolean depthFirst)
          Apply the Function to each node in the tree.
 Vector<TreeNode> applyBreadthFirst(Function func)
          Apply a function to all nodes, breadth first.
 Vector<TreeNode> applyBreadthFirst(Function func, int depthP)
          Apply a function to all nodes to a given depth, breadth first.
 Vector<TreeNode> applyDepthFirst(Function func)
          Apply a function to all nodes, depth first.
 Vector<TreeNode> applyDepthFirst(Function func, int depthP)
          Apply a function to all nodes to a given depth, depth first.
 Vector<TreeNode> flattened()
           
 Vector<TreeNode> flattened(int depthP)
          Retrieve all the nodes down to a given depth, depth-first.
 Vector<TreeNode> flattened(int depthP, boolean depthFirst)
          Retrieve all the nodes down to a given depth.
 int getDepth()
           
 Treeable[] getTreeableRoots()
           
 Vector<TreeNode> sorted(Order cmp, int depthP)
          Retrieve a sorted Vector of the tree's contents, down to the given depth.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tree

public Tree(Treeable node)
Constructor from root node.

Parameters:
node - root node

Tree

public Tree(Treeable node,
            int depth)
Constructor from root node with anticipated depth.

Parameters:
node - root node
depth - the anticipated depth

Tree

public Tree(Treeable[] nodes)
Constructor for a multi-rooted tree.

Parameters:
nodes - the root nodes

Tree

public Tree(Treeable[] nodes,
            int depth)
Constructor for a multi-rooted tree with anticipated depth.

Parameters:
nodes - the root nodes
depth - anticipated depth
Method Detail

getTreeableRoots

public Treeable[] getTreeableRoots()
Returns:
the roots

getDepth

public int getDepth()
Returns:
the depth, possibly anticipated

flattened

public Vector<TreeNode> flattened(int depthP,
                                  boolean depthFirst)
Retrieve all the nodes down to a given depth.

Parameters:
depthP - Only apply the function to nodes at or above this depth. A negative depth means apply this to all nodes in the tree
depthFirst - If true, traverse the tree depth-first, otherwise traverse it breadth-first
Returns:
all the nodes down to the given depth

flattened

public Vector<TreeNode> flattened(int depthP)
Retrieve all the nodes down to a given depth, depth-first.

Parameters:
depthP - Only apply the function to nodes at or above this depth. A negative depth means apply this to all nodes in the tree
Returns:
all the nodes down to the given depth

flattened

public Vector<TreeNode> flattened()
Returns:
all the nodes, depth-first

apply

public Vector<TreeNode> apply(Function func,
                              int depthP,
                              boolean depthFirst)
Apply the Function to each node in the tree.

Parameters:
func - the Function to apply
depthP - Only apply the function to nodes at or above this depth. A negative depth means apply this to all nodes in the tree
depthFirst - If true, traverse the tree depth-first, otherwise traverse it breadth-first
Returns:
a Vector nodes that have had func applied to them

applyDepthFirst

public Vector<TreeNode> applyDepthFirst(Function func)
Apply a function to all nodes, depth first.

Parameters:
func - the function to apply
Returns:
a vector of nodes to which the function has been applied

applyDepthFirst

public Vector<TreeNode> applyDepthFirst(Function func,
                                        int depthP)
Apply a function to all nodes to a given depth, depth first.

Parameters:
func - the function to apply
depthP - Only apply the function to nodes at or above this depth. A negative depth means apply this to all nodes in the tree
Returns:
a vector of nodes to which the function has been applied

applyBreadthFirst

public Vector<TreeNode> applyBreadthFirst(Function func)
Apply a function to all nodes, breadth first.

Parameters:
func - the function to apply
Returns:
a vector of nodes to which the function has been applied

applyBreadthFirst

public Vector<TreeNode> applyBreadthFirst(Function func,
                                          int depthP)
Apply a function to all nodes to a given depth, breadth first.

Parameters:
func - the function to apply
depthP - Only apply the function to nodes at or above this depth. A negative depth means apply this to all nodes in the tree
Returns:
a vector of nodes to which the function has been applied

sorted

public Vector<TreeNode> sorted(Order cmp,
                               int depthP)
Retrieve a sorted Vector of the tree's contents, down to the given depth.

Parameters:
cmp - an Ordering
depthP - Only return nodes at or above this depth. A negative depth means return all nodes in the tree
Returns:
a sorted Vector of the tree's contents, down to the given depth


Copyright © 2000-2010 PanEris. All Rights Reserved.