org.melati.util
Class TreeNode

Package class diagram package TreeNode
java.lang.Object
  extended by org.melati.util.TreeNode

public class TreeNode
extends Object

A Tree node.

Author:
MylesC At paneris.org

Field Summary
protected  TreeNode parent
           
 
Constructor Summary
TreeNode(Treeable n, int d)
          Constructor.
 
Method Summary
static TreeNode[] augment(Treeable[] nodes, int depth)
          Create a new Array of TreeNodes specifying a new depth.
 TreeNode[] getChildren()
           
 Treeable getData()
           
 int getDepth()
           
 TreeNode[] getNodeToRootPath(boolean includeNode, boolean reverse)
          Retrieve an Array of TreeNodes which is the shortest path from this node to its root.
 TreeNode getParent()
           
 TreeNode[] getPathFromRoot()
           
 TreeNode[] getPathToRoot()
           
 String getUniqueName()
           
 boolean isLeaf()
           
 boolean isRoot()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

protected TreeNode parent
Constructor Detail

TreeNode

public TreeNode(Treeable n,
                int d)
Constructor.

Parameters:
n - the Treeable object
d - the depth of this node
Method Detail

isRoot

public boolean isRoot()
Returns:
whether this is a root node

isLeaf

public boolean isLeaf()
Returns:
whether this is a terminal node

getDepth

public int getDepth()
Returns:
the depth in the tree

getData

public Treeable getData()
Returns:
the Treeable data object this wraps

getParent

public TreeNode getParent()
Returns:
theis nodes parent, null if this is a root node

getUniqueName

public String getUniqueName()
Returns:
the name unique within the Tree

getChildren

public TreeNode[] getChildren()
Returns:
the descendants of this node, maybe an empty Array

getNodeToRootPath

public TreeNode[] getNodeToRootPath(boolean includeNode,
                                    boolean reverse)
Retrieve an Array of TreeNodes which is the shortest path from this node to its root.

Parameters:
includeNode - whether to include this node in the path
reverse - if true returns a path from root to this
Returns:
an Array of TreeNodes

getPathToRoot

public TreeNode[] getPathToRoot()
Returns:
the path to this node's root excluding this node

getPathFromRoot

public TreeNode[] getPathFromRoot()
Returns:
the path from this node's root excluding this node

augment

public static TreeNode[] augment(Treeable[] nodes,
                                 int depth)
Create a new Array of TreeNodes specifying a new depth.

Parameters:
nodes - the nodes to copy
depth - the new depth
Returns:
a new Array of TreeNodes with the new depth


Copyright © 2000-2010 PanEris. All Rights Reserved.