2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.datamodel;
\r
25 * @version $Revision$
\r
27 public class BinaryNode
\r
35 /** DOCUMENT ME!! */
\r
36 public int bootstrap;
\r
39 * Creates a new BinaryNode object.
\r
43 left = right = parent = null;
\r
48 * Creates a new BinaryNode object.
\r
50 * @param element DOCUMENT ME!
\r
51 * @param parent DOCUMENT ME!
\r
52 * @param name DOCUMENT ME!
\r
54 public BinaryNode(Object element, BinaryNode parent, String name)
\r
56 this.element = element;
\r
57 this.parent = parent;
\r
60 left = right = null;
\r
66 * @return DOCUMENT ME!
\r
68 public Object element()
\r
76 * @param v DOCUMENT ME!
\r
78 * @return DOCUMENT ME!
\r
80 public Object setElement(Object v)
\r
88 * @return DOCUMENT ME!
\r
90 public BinaryNode left()
\r
98 * @param n DOCUMENT ME!
\r
100 * @return DOCUMENT ME!
\r
102 public BinaryNode setLeft(BinaryNode n)
\r
110 * @return DOCUMENT ME!
\r
112 public BinaryNode right()
\r
120 * @param n DOCUMENT ME!
\r
122 * @return DOCUMENT ME!
\r
124 public BinaryNode setRight(BinaryNode n)
\r
132 * @return DOCUMENT ME!
\r
134 public BinaryNode parent()
\r
142 * @param n DOCUMENT ME!
\r
144 * @return DOCUMENT ME!
\r
146 public BinaryNode setParent(BinaryNode n)
\r
154 * @return DOCUMENT ME!
\r
156 public boolean isLeaf()
\r
158 return (left == null) && (right == null);
\r
162 * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of this node (removing any old references)
\r
163 * a null parameter DOES NOT mean that the pointer to the corresponding child node is set to NULL - you should use
\r
164 * setChild(null), or detach() for this.
\r
167 public void SetChildren(BinaryNode leftchild, BinaryNode rightchild)
\r
169 if (leftchild != null)
\r
171 this.setLeft(leftchild);
\r
172 leftchild.detach();
\r
173 leftchild.setParent(this);
\r
176 if (rightchild != null)
\r
178 this.setRight(rightchild);
\r
179 rightchild.detach();
\r
180 rightchild.setParent(this);
\r
185 * Detaches the node from the binary tree, along with all its child nodes.
\r
186 * @return BinaryNode The detached node.
\r
188 public BinaryNode detach()
\r
190 if (this.parent != null)
\r
192 if (this.parent.left == this)
\r
194 this.parent.left = null;
\r
198 if (this.parent.right == this)
\r
200 this.parent.right = null;
\r
205 this.parent = null;
\r
211 * Traverses up through the tree until a node with a free leftchild is discovered.
\r
212 * @return BinaryNode
\r
214 public BinaryNode ascendLeft()
\r
216 BinaryNode c = this;
\r
222 while ( (c != null) && (c.left() != null) && !c.left().isLeaf());
\r
228 * Traverses up through the tree until a node with a free rightchild is discovered.
\r
229 * Jalview builds trees by descent on the left, so this may be unused.
\r
230 * @return BinaryNode
\r
232 public BinaryNode ascendRight()
\r
234 BinaryNode c = this;
\r
240 while ( (c != null) && (c.right() != null) && !c.right().isLeaf());
\r
248 * @param name DOCUMENT ME!
\r
250 public void setName(String name)
\r
258 * @return DOCUMENT ME!
\r
260 public String getName()
\r
268 * @param boot DOCUMENT ME!
\r
270 public void setBootstrap(int boot)
\r
272 this.bootstrap = boot;
\r
278 * @return DOCUMENT ME!
\r
280 public int getBootstrap()
\r