1 package jalview.datamodel;
3 public class BinaryNode
15 left = right = parent = null;
19 public BinaryNode(Object element, BinaryNode parent, String name)
21 this.element = element;
28 public Object element()
33 public Object setElement(Object v)
38 public BinaryNode left()
43 public BinaryNode setLeft(BinaryNode n)
48 public BinaryNode right()
53 public BinaryNode setRight(BinaryNode n)
58 public BinaryNode parent()
63 public BinaryNode setParent(BinaryNode n)
68 public boolean isLeaf()
70 return (left == null) && (right == null);
74 * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of this node (removing any old references)
75 * a null parameter DOES NOT mean that the pointer to the corresponding child node is set to NULL - you should use
76 * setChild(null), or detach() for this.
79 public void SetChildren(BinaryNode leftchild, BinaryNode rightchild)
81 if (leftchild != null)
83 this.setLeft(leftchild);
85 leftchild.setParent(this);
88 if (rightchild != null)
90 this.setRight(rightchild);
92 rightchild.setParent(this);
97 * Detaches the node from the binary tree, along with all its child nodes.
98 * @return BinaryNode The detached node.
100 public BinaryNode detach()
102 if (this.parent!=null) {
103 if (this.parent.left == this)
105 this.parent.left = null;
109 if (this.parent.right == this)
111 this.parent.right = null;
119 * Traverses up through the tree until a node with a free leftchild is discovered.
122 public BinaryNode ascendLeft() {
126 } while (c!=null && c.left()!=null && !c.left().isLeaf());
130 * Traverses up through the tree until a node with a free rightchild is discovered.
131 * Jalview builds trees by descent on the left, so this may be unused.
134 public BinaryNode ascendRight() {
138 } while (c!=null && c.right()!=null && !c.right().isLeaf());
143 public void setName(String name)
148 public String getName()
153 public void setBootstrap(int boot)
155 this.bootstrap = boot;
158 public int getBootstrap()