org.vizzini.util.tree
Interface ITreeNode

All Superinterfaces:
Cloneable, IVisitable
All Known Subinterfaces:
IFunction, INode, ITerminal
All Known Implementing Classes:
AbsoluteValue, AbstractAntTerminal, AbstractArithmeticFunction, AbstractBooleanFunction, AbstractComparisonFunction, AbstractFunction, AbstractMathematicFunction, AbstractNode, AbstractSequenceFunction, AbstractTerminal, AbstractTreeNode, Add, And, ConstantDoubleTerminal, ConstantIntTerminal, DefaultTerminal, DefaultTreeNode, Divide, GreaterThan, GreaterThanDouble, GridBoardEvaluatorTerminal, If, IfFoodAheadFunction, InputTerminal, LeftTerminal, MoveTerminal, Multiply, Not, Or, RightTerminal, Sequence1Function, Sequence2Function, Sequence3Function, StateVariableTerminal, Subtract

public interface ITreeNode
extends Cloneable, IVisitable

Defines methods required by a tree node.

Since:
v0.3
Version:
v0.3
Author:
Jeffrey M. Thompson

Method Summary
 void add(ITreeNode treeNode)
          Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array.
 Iterator breadthFirstIterator()
          Creates and returns an enumeration that traverses the subtree rooted at this node in breadth-first order.
 Iterator children()
          Creates and returns a forward-order iterator of this node's children.
 Object clone()
          Return a clone of this instance.
 Iterator depthFirstIterator()
          Creates and returns an enumeration that traverses the subtree rooted at this node in depth-first order.
 ITreeNodeCollection getBreadthFirstList()
          Creates and returns a list containing the subtree rooted at this node in breadth-first order.
 ITreeNode getChildAt(int index)
          Returns the child at the specified index in this node's child array.
 int getChildCount()
          Returns the number of children of this node.
 int getDepth()
          Returns the depth of the tree rooted at this node -- the longest distance from this node to a leaf.
 ITreeNodeCollection getDepthFirstList()
          Creates and returns a list containing the subtree rooted at this node in depth-first order.
 ITreeNode getFirstChild()
          Returns this node's first child.
 ITreeNode getFirstLeaf()
          Finds and returns the first leaf that is a descendant of this node -- either this node or its first child's first leaf.
 int getIndex(ITreeNode treeNode)
          Returns the index of the specified child in this node's child array.
 ITreeNode getLastChild()
          Returns this node's last child.
 ITreeNode getLastLeaf()
          Finds and returns the last leaf that is a descendant of this node -- either this node or its last child's last leaf.
 int getLevel()
          Returns the number of levels above this node -- the distance from the root to this node.
 ITreeNode getNextSibling()
          Return the sibling after this.
 int getNodeCount()
          Return the count of all nodes in the subtree rooted at this node.
 ITreeNode getParent()
          Returns this node's parent or null if this node has no parent.
 ITreeNode[] getPath()
          Returns the path from the root, to get to this node.
 ITreeNode getRoot()
          Returns the root of the tree that contains this node.
 Object getUserObject()
          Returns this node's user object.
 void insert(ITreeNode treeNode, int index)
          Removes treeNode from its present parent (if it has a parent), sets the child's parent to this node, and then adds the child to this node's child array at index childIndex.
 boolean isChildAllowed()
          Returns true if this node is allowed to have children.
 boolean isLeaf()
          Returns true if this node has no children.
 boolean isRoot()
          Returns true if this node is the root of the tree.
 void remove(int index)
          Removes the child at the specified index from this node's children and sets that node's parent to null.
 void remove(ITreeNode treeNode)
          Removes treeNode from this node's child array, giving it a null parent.
 void removeAllChildren()
          Removes all of this node's children, setting their parents to null.
 void removeFromParent()
          Removes the subtree rooted at this node from the tree, giving this node a null parent.
 void setChildAllowed(boolean isChildAllowed)
          Determines whether or not this node is allowed to have children.
 void setParent(ITreeNode parent)
          Sets this node's parent to parent but does not change the parent's child array.
 void setUserObject(Object userObject)
          Sets the user object for this node to userObject.
 String toString()
          Return a string representation of this object.
 
Methods inherited from interface org.vizzini.util.tree.IVisitable
acceptBreadthFirst, acceptDepthFirst
 

Method Detail

add

void add(ITreeNode treeNode)
Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array.

Since:
v0.3

breadthFirstIterator

Iterator breadthFirstIterator()
Creates and returns an enumeration that traverses the subtree rooted at this node in breadth-first order.

Since:
v0.3

children

Iterator children()
Creates and returns a forward-order iterator of this node's children.

Since:
v0.3

clone

Object clone()
Return a clone of this instance.

Since:
v0.3

depthFirstIterator

Iterator depthFirstIterator()
Creates and returns an enumeration that traverses the subtree rooted at this node in depth-first order.

Since:
v0.3

getBreadthFirstList

ITreeNodeCollection getBreadthFirstList()
Creates and returns a list containing the subtree rooted at this node in breadth-first order.

Since:
v0.3

getChildAt

ITreeNode getChildAt(int index)
Returns the child at the specified index in this node's child array.

Since:
v0.3

getChildCount

int getChildCount()
Returns the number of children of this node.

Since:
v0.3

getDepth

int getDepth()
Returns the depth of the tree rooted at this node -- the longest distance from this node to a leaf.

Since:
v0.3

getDepthFirstList

ITreeNodeCollection getDepthFirstList()
Creates and returns a list containing the subtree rooted at this node in depth-first order.

Since:
v0.3

getFirstChild

ITreeNode getFirstChild()
Returns this node's first child.

Since:
v0.3

getFirstLeaf

ITreeNode getFirstLeaf()
Finds and returns the first leaf that is a descendant of this node -- either this node or its first child's first leaf.

Since:
v0.3

getIndex

int getIndex(ITreeNode treeNode)
Returns the index of the specified child in this node's child array.

Since:
v0.3

getLastChild

ITreeNode getLastChild()
Returns this node's last child.

Since:
v0.3

getLastLeaf

ITreeNode getLastLeaf()
Finds and returns the last leaf that is a descendant of this node -- either this node or its last child's last leaf.

Since:
v0.3

getLevel

int getLevel()
Returns the number of levels above this node -- the distance from the root to this node.

Since:
v0.3

getNextSibling

ITreeNode getNextSibling()
Return the sibling after this.

Since:
v0.3

getNodeCount

int getNodeCount()
Return the count of all nodes in the subtree rooted at this node.

Since:
v0.3

getParent

ITreeNode getParent()
Returns this node's parent or null if this node has no parent.

Since:
v0.3

getPath

ITreeNode[] getPath()
Returns the path from the root, to get to this node.

Since:
v0.3

getRoot

ITreeNode getRoot()
Returns the root of the tree that contains this node.

Since:
v0.3

getUserObject

Object getUserObject()
Returns this node's user object.

Since:
v0.3

insert

void insert(ITreeNode treeNode,
            int index)
Removes treeNode from its present parent (if it has a parent), sets the child's parent to this node, and then adds the child to this node's child array at index childIndex.

Since:
v0.3

isChildAllowed

boolean isChildAllowed()
Returns true if this node is allowed to have children.

Since:
v0.3

isLeaf

boolean isLeaf()
Returns true if this node has no children.

Since:
v0.3

isRoot

boolean isRoot()
Returns true if this node is the root of the tree.

Since:
v0.3

remove

void remove(int index)
Removes the child at the specified index from this node's children and sets that node's parent to null.

Since:
v0.3

remove

void remove(ITreeNode treeNode)
Removes treeNode from this node's child array, giving it a null parent.

Since:
v0.3

removeAllChildren

void removeAllChildren()
Removes all of this node's children, setting their parents to null.

Since:
v0.3

removeFromParent

void removeFromParent()
Removes the subtree rooted at this node from the tree, giving this node a null parent.

Since:
v0.3

setChildAllowed

void setChildAllowed(boolean isChildAllowed)
Determines whether or not this node is allowed to have children.

Since:
v0.3

setParent

void setParent(ITreeNode parent)
Sets this node's parent to parent but does not change the parent's child array.

Since:
v0.3

setUserObject

void setUserObject(Object userObject)
Sets the user object for this node to userObject.

Since:
v0.3

toString

String toString()
Return a string representation of this object.

Overrides:
toString in class Object
Since:
v0.3


Copyright 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02