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;
23 import java.awt.Color;
31 public class BinaryNode
43 /** Bootstrap value */
59 public Color color = Color.black;
62 public boolean dummy = false;
65 * Creates a new BinaryNode object.
69 left = right = parent = null;
75 * Creates a new BinaryNode object.
84 public BinaryNode(Object element, BinaryNode parent, String name,
88 this.element = element;
94 public BinaryNode(Object element, BinaryNode parent, String name,
95 double dist, int bootstrap)
97 this(element, parent, name, dist);
98 this.bootstrap = bootstrap;
101 public BinaryNode(Object val, BinaryNode parent, String name, double dist,
102 int bootstrap, boolean dummy)
104 this(val, parent, name, dist, bootstrap);
111 * @return DOCUMENT ME!
113 public Object element()
124 * @return DOCUMENT ME!
126 public Object setElement(Object v)
134 * @return DOCUMENT ME!
136 public BinaryNode left()
147 * @return DOCUMENT ME!
149 public BinaryNode setLeft(BinaryNode n)
157 * @return DOCUMENT ME!
159 public BinaryNode right()
170 * @return DOCUMENT ME!
172 public BinaryNode setRight(BinaryNode n)
180 * @return DOCUMENT ME!
182 public BinaryNode parent()
193 * @return DOCUMENT ME!
195 public BinaryNode setParent(BinaryNode n)
203 * @return DOCUMENT ME!
205 public boolean isLeaf()
207 return (left == null) && (right == null);
211 * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of
212 * this node (removing any old references) a null parameter DOES NOT mean that
213 * the pointer to the corresponding child node is set to NULL - you should use
214 * setChild(null), or detach() for this.
217 public void SetChildren(BinaryNode leftchild, BinaryNode rightchild)
219 if (leftchild != null)
221 this.setLeft(leftchild);
223 leftchild.setParent(this);
226 if (rightchild != null)
228 this.setRight(rightchild);
230 rightchild.setParent(this);
235 * Detaches the node from the binary tree, along with all its child nodes.
237 * @return BinaryNode The detached node.
239 public BinaryNode detach()
241 if (this.parent != null)
243 if (this.parent.left == this)
245 this.parent.left = null;
249 if (this.parent.right == this)
251 this.parent.right = null;
262 * Traverses up through the tree until a node with a free leftchild is
267 public BinaryNode ascendLeft()
274 } while ((c != null) && (c.left() != null) && !c.left().isLeaf());
280 * Traverses up through the tree until a node with a free rightchild is
281 * discovered. Jalview builds trees by descent on the left, so this may be
286 public BinaryNode ascendRight()
293 } while ((c != null) && (c.right() != null) && !c.right().isLeaf());
300 * set the display name
305 public void setName(String name)
313 * @return the display name for this node
315 public String getName()
321 * set integer bootstrap value
325 public void setBootstrap(int boot)
327 this.bootstrap = boot;
333 * @return integer value
335 public int getBootstrap()
342 * true if node is created for the representation of polytomous trees
344 public boolean isDummy()
355 * @return DOCUMENT ME!
357 public boolean setDummy(boolean newstate)
359 boolean oldstate = dummy;
366 * ascends the tree but doesn't stop until a non-dummy node is discovered.
369 public BinaryNode AscendTree()
376 } while ((c != null) && c.dummy);