2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.datamodel;
27 public class BinaryNode
43 * Creates a new BinaryNode object.
47 left = right = parent = null;
52 * Creates a new BinaryNode object.
61 public BinaryNode(Object element, BinaryNode parent, String name)
63 this.element = element;
73 * @return DOCUMENT ME!
75 public Object element()
86 * @return DOCUMENT ME!
88 public Object setElement(Object v)
96 * @return DOCUMENT ME!
98 public BinaryNode left()
109 * @return DOCUMENT ME!
111 public BinaryNode setLeft(BinaryNode n)
119 * @return DOCUMENT ME!
121 public BinaryNode right()
132 * @return DOCUMENT ME!
134 public BinaryNode setRight(BinaryNode n)
142 * @return DOCUMENT ME!
144 public BinaryNode parent()
155 * @return DOCUMENT ME!
157 public BinaryNode setParent(BinaryNode n)
165 * @return DOCUMENT ME!
167 public boolean isLeaf()
169 return (left == null) && (right == null);
173 * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of
174 * this node (removing any old references) a null parameter DOES NOT mean that
175 * the pointer to the corresponding child node is set to NULL - you should use
176 * setChild(null), or detach() for this.
179 public void SetChildren(BinaryNode leftchild, BinaryNode rightchild)
181 if (leftchild != null)
183 this.setLeft(leftchild);
185 leftchild.setParent(this);
188 if (rightchild != null)
190 this.setRight(rightchild);
192 rightchild.setParent(this);
197 * Detaches the node from the binary tree, along with all its child nodes.
199 * @return BinaryNode The detached node.
201 public BinaryNode detach()
203 if (this.parent != null)
205 if (this.parent.left == this)
207 this.parent.left = null;
211 if (this.parent.right == this)
213 this.parent.right = null;
224 * Traverses up through the tree until a node with a free leftchild is
229 public BinaryNode ascendLeft()
236 } while ((c != null) && (c.left() != null) && !c.left().isLeaf());
242 * Traverses up through the tree until a node with a free rightchild is
243 * discovered. Jalview builds trees by descent on the left, so this may be
248 public BinaryNode ascendRight()
255 } while ((c != null) && (c.right() != null) && !c.right().isLeaf());
266 public void setName(String name)
274 * @return DOCUMENT ME!
276 public String getName()
287 public void setBootstrap(int boot)
289 this.bootstrap = boot;
295 * @return DOCUMENT ME!
297 public int getBootstrap()