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
39 * Creates a new BinaryNode object.
43 left = right = parent = null;
48 * Creates a new BinaryNode object.
50 * @param element DOCUMENT ME!
51 * @param parent DOCUMENT ME!
52 * @param name DOCUMENT ME!
54 public BinaryNode(Object element, BinaryNode parent, String name)
56 this.element = element;
66 * @return DOCUMENT ME!
68 public Object element()
76 * @param v DOCUMENT ME!
78 * @return DOCUMENT ME!
80 public Object setElement(Object v)
88 * @return DOCUMENT ME!
90 public BinaryNode left()
98 * @param n DOCUMENT ME!
100 * @return DOCUMENT ME!
102 public BinaryNode setLeft(BinaryNode n)
110 * @return DOCUMENT ME!
112 public BinaryNode right()
120 * @param n DOCUMENT ME!
122 * @return DOCUMENT ME!
124 public BinaryNode setRight(BinaryNode n)
132 * @return DOCUMENT ME!
134 public BinaryNode parent()
142 * @param n DOCUMENT ME!
144 * @return DOCUMENT ME!
146 public BinaryNode setParent(BinaryNode n)
154 * @return DOCUMENT ME!
156 public boolean isLeaf()
158 return (left == null) && (right == null);
162 * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of this node (removing any old references)
163 * a null parameter DOES NOT mean that the pointer to the corresponding child node is set to NULL - you should use
164 * setChild(null), or detach() for this.
167 public void SetChildren(BinaryNode leftchild, BinaryNode rightchild)
169 if (leftchild != null)
171 this.setLeft(leftchild);
173 leftchild.setParent(this);
176 if (rightchild != null)
178 this.setRight(rightchild);
180 rightchild.setParent(this);
185 * Detaches the node from the binary tree, along with all its child nodes.
186 * @return BinaryNode The detached node.
188 public BinaryNode detach()
190 if (this.parent != null)
192 if (this.parent.left == this)
194 this.parent.left = null;
198 if (this.parent.right == this)
200 this.parent.right = null;
211 * Traverses up through the tree until a node with a free leftchild is discovered.
214 public BinaryNode ascendLeft()
222 while ( (c != null) && (c.left() != null) && !c.left().isLeaf());
228 * Traverses up through the tree until a node with a free rightchild is discovered.
229 * Jalview builds trees by descent on the left, so this may be unused.
232 public BinaryNode ascendRight()
240 while ( (c != null) && (c.right() != null) && !c.right().isLeaf());
248 * @param name DOCUMENT ME!
250 public void setName(String name)
258 * @return DOCUMENT ME!
260 public String getName()
268 * @param boot DOCUMENT ME!
270 public void setBootstrap(int boot)
272 this.bootstrap = boot;
278 * @return DOCUMENT ME!
280 public int getBootstrap()