2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
29 public class BinaryNode
45 * Creates a new BinaryNode object.
49 left = right = parent = null;
54 * Creates a new BinaryNode object.
63 public BinaryNode(Object element, BinaryNode parent, String name)
65 this.element = element;
75 * @return DOCUMENT ME!
77 public Object element()
88 * @return DOCUMENT ME!
90 public Object setElement(Object v)
98 * @return DOCUMENT ME!
100 public BinaryNode left()
111 * @return DOCUMENT ME!
113 public BinaryNode setLeft(BinaryNode n)
121 * @return DOCUMENT ME!
123 public BinaryNode right()
134 * @return DOCUMENT ME!
136 public BinaryNode setRight(BinaryNode n)
144 * @return DOCUMENT ME!
146 public BinaryNode parent()
157 * @return DOCUMENT ME!
159 public BinaryNode setParent(BinaryNode n)
167 * @return DOCUMENT ME!
169 public boolean isLeaf()
171 return (left == null) && (right == null);
175 * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of
176 * this node (removing any old references) a null parameter DOES NOT mean that
177 * the pointer to the corresponding child node is set to NULL - you should use
178 * setChild(null), or detach() for this.
181 public void SetChildren(BinaryNode leftchild, BinaryNode rightchild)
183 if (leftchild != null)
185 this.setLeft(leftchild);
187 leftchild.setParent(this);
190 if (rightchild != null)
192 this.setRight(rightchild);
194 rightchild.setParent(this);
199 * Detaches the node from the binary tree, along with all its child nodes.
201 * @return BinaryNode The detached node.
203 public BinaryNode detach()
205 if (this.parent != null)
207 if (this.parent.left == this)
209 this.parent.left = null;
213 if (this.parent.right == this)
215 this.parent.right = null;
226 * Traverses up through the tree until a node with a free leftchild is
231 public BinaryNode ascendLeft()
238 } while ((c != null) && (c.left() != null) && !c.left().isLeaf());
244 * Traverses up through the tree until a node with a free rightchild is
245 * discovered. Jalview builds trees by descent on the left, so this may be
250 public BinaryNode ascendRight()
257 } while ((c != null) && (c.right() != null) && !c.right().isLeaf());
264 * set the display name
269 public void setName(String name)
277 * @return the display name for this node
279 public String getName()
285 * set integer bootstrap value
289 public void setBootstrap(int boot)
291 this.bootstrap = boot;
297 * @return integer value
299 public int getBootstrap()