net.ultrametrics.util
Class Node

java.lang.Object
  |
  +--net.ultrametrics.util.Node

public class Node
extends java.lang.Object

A class representing a node or collection of nodes which can paint themselves onto a canvas

Since:
$Date: 1998/06/11 21:58:45 $

Constructor Summary
Node()
          Constructs an unnamed node.
Node(java.lang.String name)
          Constructs a node with the specified name.
 
Method Summary
 void addChild(Node child)
          Adds a child to this node.
 void dump(int depth)
          Deprecated. Provided for testing. Dumps the contents of this node on stdout. Recursively invokes dump() on the children of this node, causing the complete tree to be displayed.
 void generate(int depth)
          recursively populates this tree.
 void generateChildren(int maxBranches, int maxDepth)
          Randomly and recursively populates this tree.
 void generateChildren(int minBranches, int maxBranches, int maxDepth)
           
 java.util.Enumeration getChildren()
          Returns an enumeration of this node's children.
 int getMaxBranches()
          Deprecated. Provided for testing. Returns the maximum branching-factor of this tree if generateChildren was used to randomly populate this tree.
 int getMaxDepth()
          Deprecated. Provided for testing. Returns the maximum depth of this tree if generateChildren was used to randomly populate this tree.
 int getMinBranches()
          Deprecated. Provided for testing. Returns the maximum branching-factor of this tree if generateChildren was used to randomly populate this tree.
 java.lang.String getName()
          Returns the name of this node.
 Node getParent()
          Returns the parent node of this node.
 int getSize()
          Returns the number of children of this node.
 void setName(java.lang.String name)
          Sets the name of this node.
 void setParent(Node parent)
          Sets the parent of this node.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

public Node()
Constructs an unnamed node.

Node

public Node(java.lang.String name)
Constructs a node with the specified name.
Parameters:
name - the name of the node
Method Detail

setParent

public void setParent(Node parent)
Sets the parent of this node.
Parameters:
parent - the parent node of this node.

addChild

public void addChild(Node child)
Adds a child to this node.

getChildren

public java.util.Enumeration getChildren()
Returns an enumeration of this node's children.

getParent

public Node getParent()
Returns the parent node of this node.

getName

public java.lang.String getName()
Returns the name of this node.

getSize

public int getSize()
Returns the number of children of this node.

setName

public void setName(java.lang.String name)
Sets the name of this node.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

generateChildren

public void generateChildren(int maxBranches,
                             int maxDepth)
Randomly and recursively populates this tree.

 For example: 
   Node tree = new Node("top");
   tree.generateChildren(4, 4);
 

Random node generation is constrained by the branching-factor and depth specified. Each node of the tree can have between 0 and maxBranches children. The resulting tree will have a depth between 0 and maxDepth measured from the top to leaf node. Each child node is named "x, y" where x is the depth and y the child's index (position relative to its siblings.)

Parameters:
maxBranches - the maximum allowed branching-factor
maxDepth - the maximum allowed depth

generateChildren

public void generateChildren(int minBranches,
                             int maxBranches,
                             int maxDepth)

generate

public void generate(int depth)
recursively populates this tree.
Parameters:
depth - initial depth; usually 0.

getMaxDepth

public int getMaxDepth()
Deprecated. Provided for testing. Returns the maximum depth of this tree if generateChildren was used to randomly populate this tree.

getMaxBranches

public int getMaxBranches()
Deprecated. Provided for testing. Returns the maximum branching-factor of this tree if generateChildren was used to randomly populate this tree.

getMinBranches

public int getMinBranches()
Deprecated. Provided for testing. Returns the maximum branching-factor of this tree if generateChildren was used to randomly populate this tree.

dump

public void dump(int depth)
Deprecated. Provided for testing. Dumps the contents of this node on stdout. Recursively invokes dump() on the children of this node, causing the complete tree to be displayed.