2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.datamodel;
26 public class BinaryNode
42 * Creates a new BinaryNode object.
46 left = right = parent = null;
51 * Creates a new BinaryNode object.
60 public BinaryNode(Object element, BinaryNode parent, String name)
62 this.element = element;
72 * @return DOCUMENT ME!
74 public Object element()
85 * @return DOCUMENT ME!
87 public Object setElement(Object v)
95 * @return DOCUMENT ME!
97 public BinaryNode left()
108 * @return DOCUMENT ME!
110 public BinaryNode setLeft(BinaryNode n)
118 * @return DOCUMENT ME!
120 public BinaryNode right()
131 * @return DOCUMENT ME!
133 public BinaryNode setRight(BinaryNode n)
141 * @return DOCUMENT ME!
143 public BinaryNode parent()
154 * @return DOCUMENT ME!
156 public BinaryNode setParent(BinaryNode n)
164 * @return DOCUMENT ME!
166 public boolean isLeaf()
168 return (left == null) && (right == null);
172 * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of
173 * this node (removing any old references) a null parameter DOES NOT mean that
174 * the pointer to the corresponding child node is set to NULL - you should use
175 * setChild(null), or detach() for this.
178 public void SetChildren(BinaryNode leftchild, BinaryNode rightchild)
180 if (leftchild != null)
182 this.setLeft(leftchild);
184 leftchild.setParent(this);
187 if (rightchild != null)
189 this.setRight(rightchild);
191 rightchild.setParent(this);
196 * Detaches the node from the binary tree, along with all its child nodes.
198 * @return BinaryNode The detached node.
200 public BinaryNode detach()
202 if (this.parent != null)
204 if (this.parent.left == this)
206 this.parent.left = null;
210 if (this.parent.right == this)
212 this.parent.right = null;
223 * Traverses up through the tree until a node with a free leftchild is
228 public BinaryNode ascendLeft()
235 } while ((c != null) && (c.left() != null) && !c.left().isLeaf());
241 * Traverses up through the tree until a node with a free rightchild is
242 * discovered. Jalview builds trees by descent on the left, so this may be
247 public BinaryNode ascendRight()
254 } while ((c != null) && (c.right() != null) && !c.right().isLeaf());
261 * set the display name
265 public void setName(String name)
273 * @return the display name for this node
275 public String getName()
281 * set integer bootstrap value
285 public void setBootstrap(int boot)
287 this.bootstrap = boot;
293 * @return integer value
295 public int getBootstrap()