TreeNode.java
Simplification tree node
Size 2.3 kB - File type text/plainFile contents
// Name: TreeNode.java
// Intent: simplification tree node
// Programmer: John P. Kavanagh #2748 2405
// Date Modified: 9 May 2002
// Audit: Clifford Meyers (cmeyers@buffalo.edu)
public class TreeNode {
private Point nodePoint; // this is a point on the simplified line
private double bandwidth; // this stores the point distance from the given line segment
private TreeNode left, right;
// Initialize a null node
public TreeNode() {
nodePoint = null;
bandwidth = 0;
}
// Initialize a node with a simplified line point
public TreeNode(Point pt, double distance) {
nodePoint = pt;
bandwidth = distance;
}
// accessor method for private point data
public Point getPoint(){
//System.out.println("Get node point: (" + nodePoint.getXvalue() + "," + nodePoint.getYvalue() + ")");
return nodePoint;
}
// modifier method for private point data
public void setPoint(Point newPoint){
nodePoint = newPoint;
//System.out.println("Set node point: (" + nodePoint.getXvalue() + "," + nodePoint.getYvalue() + ")");
}
// accessor method for private bandwidth data
public double getBandwidth(){
//System.out.println("Get node bandwidth: " + bandwidth);
return bandwidth;
}
// modifier method for private bandwidth data
public void setBandwidth(double newDistance){
bandwidth = newDistance;
//System.out.println("Set node bandwidth: " + bandwidth);
}
// accessor method for private left node data
public TreeNode getLeftNode(){
return left;
}
// modifier method for private left node data
public void setLeftNode(TreeNode newLeftNode){
left = newLeftNode;
}
// accessor method for private right node data
public TreeNode getRightNode(){
return right;
}
// modifier method for private right node data
public void setRightNode(TreeNode newRightNode){
right = newRightNode;
}
// if node has no leaves then it is a leaf
public boolean isLeaf(){
return (left == null) && (right == null);
}
// destroy node and branches
public void Destroy(){
nodePoint = null;
bandwidth = 0;
if (left != null) { // destroy existing left node
left.Destroy();
}
if (right != null) { // destroy existing right node
right.Destroy();
}
}
}
Click here to get the file