exe
Class TreeNode

java.lang.Object
  extended by exe.VisNode
      extended by exe.TreeNode
All Implemented Interfaces:
java.lang.Comparable

public class TreeNode
extends VisNode

This class maintains the information for a single node in the Tree data structure. A TreeNode object inherits from the VisNode class and adds additional data members and methods to allow these nodes to be used in binary and general trees.

In order to use any of these tree classes in a script-producing program, the script-producing program must import the package exe.

Author:
Sven Moen (original author), Ethan Dereszynski (adaptations), Ben Tidman (GAIGS adaptations), Andrew Jungwirth (more GAIGS adaptations and Javadoc comments)

Field Summary
 
Fields inherited from class exe.VisNode
activated, cindex, closed, cost, heuristic, hexColor, pred, x, y
 
Constructor Summary
TreeNode()
          Constructs a TreeNode with default values.
TreeNode(java.lang.String v)
          Constructs a TreeNode by specifying its value.
TreeNode(java.lang.String v, int i)
          Constructs a TreeNode by giving its value and id.
TreeNode(java.lang.String v, TreeNode p, TreeNode c, TreeNode s, int i)
          Constructs a TreeNode by passing in the values for value, parent, child, sibling, and id.
TreeNode(VisNode copy)
          Constructs a TreeNode that matches the information contained within the VisNode copy.
 
Method Summary
 TreeNode getChild()
          Returns a reference to the child of this TreeNode in the Tree structure.
 int getID()
          Gives the id assigned to this TreeNode.
 TreeNode getLeftChild()
          Returns a reference to this TreeNode's left child in a binary Tree.
 Edge getLineToParent()
          Returns a reference to the Edge that connects this TreeNode to its parent in the Tree.
 TreeNode getParent()
          Returns a reference to the parent of this TreeNode in the Tree structure.
 TreeNode getRightChild()
          Returns a reference to this TreeNode's right child in a binary Tree.
 TreeNode getSibling()
          Returns a reference to the sibling of this TreeNode in the Tree structure.
 java.lang.String getValue()
          Retrieves the value stored within this TreeNode.
 void insertLeftChild(TreeNode lc)
          Adds a left child to this TreeNode in a binary Tree.
 void insertRightChild(TreeNode rc)
          Adds a right child to this TreeNode in a binary Tree.
 boolean isLeftChild()
          Indicates if this TreeNode is a left child in a binary Tree.
 boolean isPlaceHolder()
          Indicates if this TreeNode is a placeholder in a binary Tree.
 boolean isRightChild()
          Indicates if this TreeNode is a right child in a binary Tree.
 void setChild(TreeNode c)
          Assigns a reference to this TreeNode's child.
 void setChildWithEdge(TreeNode c)
          Adds a child to this TreeNode and properly sets its lineToParent with one method call.
 void setID(int i)
          Sets the id for this TreeNode.
 void setLeftChild(boolean t)
          Assigns the left child status of this TreeNode in a binary Tree.
 void setLineToParent(Edge e)
          Assigns a reference to this TreeNode's lineToParent, the Edge that connects this TreeNode with its parent in the Tree.
 void setParent(TreeNode p)
          Assigns a reference to this TreeNode's parent.
 void setPlaceHolder(boolean t)
          Assigns the placeholder status of this TreeNode in a binary Tree.
 void setRightChild(boolean t)
          Assigns the right child status of this TreeNode in a binary Tree.
 void setSibling(TreeNode s)
          Assigns a reference to this TreeNode's sibling.
 void setSiblingWithEdge(TreeNode s)
          Adds a sibling to this TreeNode and properly sets its lineToParent with one method call.
 void setValue(java.lang.String v)
          Sets this TreeNode's value that appears inside the circular node when it is drawn on the screen.
 
Methods inherited from class exe.VisNode
activate, clearNode, compareTo, compareToNoCost, deactivate, getChar, getCost, getHeuristic, getHexColor, getPred, getX, getY, isActivated, isClosed, setChar, setClosed, setCost, setHeuristic, setHexColor, setLimitedX, setLimitedY, setPred, setX, setY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeNode

public TreeNode()
Constructs a TreeNode with default values.


TreeNode

public TreeNode(java.lang.String v)
Constructs a TreeNode by specifying its value.

Parameters:
v - Specifies the label that appears within the circular node when this TreeNode is output to the animation file. If v contains multiple lines, this TreeNode's label will have multiple lines.

TreeNode

public TreeNode(java.lang.String v,
                int i)
Constructs a TreeNode by giving its value and id.

Parameters:
v - Indicates the value that appears within the circular node when this TreeNode is output to the animation file. If v contains multiple lines, this TreeNode's label will have multiple lines.
i - Sets the id for this TreeNode. Giving each TreeNode in a Tree a unique id makes it possible to find a specific TreeNode in a Tree structure.

TreeNode

public TreeNode(java.lang.String v,
                TreeNode p,
                TreeNode c,
                TreeNode s,
                int i)
Constructs a TreeNode by passing in the values for value, parent, child, sibling, and id.

Parameters:
v - Specifies the value that appears within the circular node when this TreeNode is output to the animation file. If v contains multiple lines, this TreeNode's label will have multiple lines.
p - Indicates the parent value for this TreeNode. This is a reference to this TreeNode's parent node in a Tree structure.
c - Sets the child value for this TreeNode. This is a reference to this TreeNode's left-most child in a Tree structure.
s - Gives the sibling value for this TreeNode. This is a reference to the child to the right of this TreeNode in a Tree structure.
i - Sets the id for this TreeNode. Giving each TreeNode in a Tree a unique id makes it possible to find a specific TreeNode in a Tree structure.

TreeNode

public TreeNode(VisNode copy)
Constructs a TreeNode that matches the information contained within the VisNode copy. This method is useful for making TreeNodes that represent the VisNodes in a VisualGraph, such as in the visualization of graph-searching algorithms. After this method is used create a TreeNode copy of the given VisNode, the rest of this TreeNode's data can be set via method calls to properly link the copied VisNode into a Tree structure.

Parameters:
copy - Gives the VisNode that contains the information that should be used to initialize the data that this TreeNode inherits from the VisNode class. The new TreeNode is constructed to be a copy of copy.
Method Detail

getValue

public java.lang.String getValue()
Retrieves the value stored within this TreeNode.

Returns:
Gives the String that appears inside this TreeNode when it is displayed on the screen.

getParent

public TreeNode getParent()
Returns a reference to the parent of this TreeNode in the Tree structure.

Returns:
Gives a reference to the TreeNode that is this TreeNode's parent in the Tree. This value is null if this TreeNode has no parent.

getChild

public TreeNode getChild()
Returns a reference to the child of this TreeNode in the Tree structure.

Returns:
Yields a reference to the TreeNode that is this TreeNode's left-most child in the Tree. This value is null if this TreeNode has no child.

getSibling

public TreeNode getSibling()
Returns a reference to the sibling of this TreeNode in the Tree structure.

Returns:
Gives a reference to the TreeNode that is the child to this right of this TreeNode in the Tree. This value is null if this TreeNode has no sibling.

getID

public int getID()
Gives the id assigned to this TreeNode.

Returns:
Yields the value stored in id, used to uniquely identify TreeNodes in a Tree.

getLineToParent

public Edge getLineToParent()
Returns a reference to the Edge that connects this TreeNode to its parent in the Tree.

Returns:
Gives a reference to the Edge that connects this TreeNode to its parent in the Tree. If this TreeNode has no parent or if no lineToParent has been set for this TreeNode, the value returned will be null.

isLeftChild

public boolean isLeftChild()
Indicates if this TreeNode is a left child in a binary Tree.

Returns:
Gives a value of true if this TreeNode is a left child in a binary Tree. A value of false is returned if this TreeNode is a right child or a placeholder or if it is a node in a general Tree.

isRightChild

public boolean isRightChild()
Indicates if this TreeNode is a right child in a binary Tree.

Returns:
Gives a value of true if this TreeNode is a right child in a binary Tree. Returns false if this TreeNode is a left child or a placeholder or if it is a node in a general Tree.

isPlaceHolder

public boolean isPlaceHolder()
Indicates if this TreeNode is a placeholder in a binary Tree.

Returns:
Yields true if this TreeNode is a placeholder in a binary Tree. Returns false if this TreeNode is a left child or a right child or if it is a node in a general Tree.

getRightChild

public TreeNode getRightChild()
Returns a reference to this TreeNode's right child in a binary Tree.

Returns:
Gives a reference to this TreeNode's right child in a binary tree. Returns null if this TreeNode has no right child or if the Tree is not a binary Tree.

getLeftChild

public TreeNode getLeftChild()
Returns a reference to this TreeNode's left child in a binary Tree.

Returns:
Gives a reference to this TreeNode's left child in a binary tree. Returns null if this TreeNode has no left child or if the Tree is not a binary Tree.

setValue

public void setValue(java.lang.String v)
Sets this TreeNode's value that appears inside the circular node when it is drawn on the screen.

Parameters:
v - Specifies the value that should be displayed within this TreeNode when it is displayed on the screen. If v contains multiple lines, this TreeNode's label will have multiple lines.

setParent

public void setParent(TreeNode p)
Assigns a reference to this TreeNode's parent.

Parameters:
p - Indicates the parent of this TreeNode in the Tree. A reference to this parent is stored in this TreeNode's parent variable.

setChild

public void setChild(TreeNode c)
Assigns a reference to this TreeNode's child.

Parameters:
c - Indicates the left-most child of this TreeNode in the Tree. A reference to this child is stored in this TreeNode's child variable.

setSibling

public void setSibling(TreeNode s)
Assigns a reference to this TreeNode's sibling.

Parameters:
s - Indicates the sibling of this TreeNode in the Tree. A reference to this sibling is stored in this TreeNode's sibling variable.

setID

public void setID(int i)
Sets the id for this TreeNode.

Parameters:
i - Specifies the unique int value that is used to identify this TreeNode.

setLineToParent

public void setLineToParent(Edge e)
Assigns a reference to this TreeNode's lineToParent, the Edge that connects this TreeNode with its parent in the Tree.

Parameters:
e - Indicates the Edge that connects this TreeNode to its parent in the Tree. A reference to this Edge is stored in this TreeNode's lineToParent variable.

setLeftChild

public void setLeftChild(boolean t)
Assigns the left child status of this TreeNode in a binary Tree.

Parameters:
t - Specifies the left child status of this TreeNode. The value of t is assigned to leftChild; a value of true means that it is a left child, and a value of false means that it is not a left child.

setRightChild

public void setRightChild(boolean t)
Assigns the right child status of this TreeNode in a binary Tree.

Parameters:
t - Specifies the right child status of this TreeNode. The value of t is assigned to rightChild; a value of true means that it is a right child, and a value of false means that it is not a right child.

setPlaceHolder

public void setPlaceHolder(boolean t)
Assigns the placeholder status of this TreeNode in a binary Tree.

Parameters:
t - Specifies the placeholder status of this TreeNode. The value of t is assigned to placeHolder; a value of true means that it is a placeholder, and a value of false means that it is not a placeholder.

insertRightChild

public void insertRightChild(TreeNode rc)
Adds a right child to this TreeNode in a binary Tree.

Parameters:
rc - Indicates the TreeNode that is to be inserted as the right child of this TreeNode. A reference to rc is assigned to the sibling variable of the TreeNode referenced by this TreeNode's child variable. If this TreeNode has no child, a placeholder left child will be assigned to child so that rc can be added as its sibling.

insertLeftChild

public void insertLeftChild(TreeNode lc)
Adds a left child to this TreeNode in a binary Tree.

Parameters:
lc - Indicates the TreeNode that is to be inserted as the left child of this TreeNode. A reference to lc is assigned to this TreeNode's child variable. If child already contains a reference to a left child or placeholder, its sibling link is copied to the new left child.

setChildWithEdge

public void setChildWithEdge(TreeNode c)
Adds a child to this TreeNode and properly sets its lineToParent with one method call. If this TreeNode already has a child or children, the new child is added as the right-most child of this TreeNode. Therefore, this method is useful for building general trees as a program executes.

Parameters:
c - Indicates the TreeNode that should be inserted as this TreeNode's right-most child.

setSiblingWithEdge

public void setSiblingWithEdge(TreeNode s)
Adds a sibling to this TreeNode and properly sets its lineToParent with one method call. If this TreeNode already has a sibling, the new sibling is inserted at the end of the sibling chain to become the right-most child of the parent node. Therefore, this method is useful for building general trees as a program executes.

Parameters:
s - Indicates the TreeNode that should be inserted as this TreeNode's parent's right-most child.