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
59 public Color color = Color.black;
62 public boolean dummy = false;
65 * Creates a new BinaryNode object.
69 left = right = parent = null;
74 * Creates a new BinaryNode object.
83 public BinaryNode(Object element, BinaryNode parent, String name)
85 this.element = element;
95 * @return DOCUMENT ME!
97 public Object element()
108 * @return DOCUMENT ME!
110 public Object setElement(Object v)
118 * @return DOCUMENT ME!
120 public BinaryNode left()
131 * @return DOCUMENT ME!
133 public BinaryNode setLeft(BinaryNode n)
141 * @return DOCUMENT ME!
143 public BinaryNode right()
154 * @return DOCUMENT ME!
156 public BinaryNode setRight(BinaryNode n)
164 * @return DOCUMENT ME!
166 public BinaryNode parent()
177 * @return DOCUMENT ME!
179 public BinaryNode setParent(BinaryNode n)
187 * @return DOCUMENT ME!
189 public boolean isLeaf()
191 return (left == null) && (right == null);
195 * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of
196 * this node (removing any old references) a null parameter DOES NOT mean that
197 * the pointer to the corresponding child node is set to NULL - you should use
198 * setChild(null), or detach() for this.
201 public void SetChildren(BinaryNode leftchild, BinaryNode rightchild)
203 if (leftchild != null)
205 this.setLeft(leftchild);
207 leftchild.setParent(this);
210 if (rightchild != null)
212 this.setRight(rightchild);
214 rightchild.setParent(this);
219 * Detaches the node from the binary tree, along with all its child nodes.
221 * @return BinaryNode The detached node.
223 public BinaryNode detach()
225 if (this.parent != null)
227 if (this.parent.left == this)
229 this.parent.left = null;
233 if (this.parent.right == this)
235 this.parent.right = null;
246 * Traverses up through the tree until a node with a free leftchild is
251 public BinaryNode ascendLeft()
258 } while ((c != null) && (c.left() != null) && !c.left().isLeaf());
264 * Traverses up through the tree until a node with a free rightchild is
265 * discovered. Jalview builds trees by descent on the left, so this may be
270 public BinaryNode ascendRight()
277 } while ((c != null) && (c.right() != null) && !c.right().isLeaf());
284 * set the display name
289 public void setName(String name)
297 * @return the display name for this node
299 public String getName()
305 * set integer bootstrap value
309 public void setBootstrap(int boot)
311 this.bootstrap = boot;
317 * @return integer value
319 public int getBootstrap()
325 * ascends the tree but doesn't stop until a non-dummy node is discovered.
328 public BinaryNode AscendTree()
335 } while ((c != null) && c.dummy);