2 * This file is part of the Vamsas Client version 0.1.
\r
3 * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite,
\r
4 * Andrew Waterhouse and Dominik Lindner.
\r
6 * Earlier versions have also been incorporated into Jalview version 2.4
\r
7 * since 2008, and TOPALi version 2 since 2007.
\r
9 * The Vamsas Client is free software: you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation, either version 3 of the License, or
\r
12 * (at your option) any later version.
\r
14 * The Vamsas Client is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public License
\r
20 * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.
\r
22 package uk.ac.vamsas.objects.utils.trees;
\r
24 import uk.ac.vamsas.client.Vobject;
\r
25 import uk.ac.vamsas.client.VorbaId;
\r
27 public class BinaryNode {
\r
38 /** bootstrap is non-negative integer */
\r
39 public int bootstrap = -1;
\r
42 * Creates a new BinaryNode object.
\r
44 public BinaryNode() {
\r
45 left = right = parent = null;
\r
50 * Creates a new BinaryNode object.
\r
59 public BinaryNode(Vobject val, BinaryNode parent, String name) {
\r
61 this.parent = parent;
\r
64 left = right = null;
\r
70 * @return DOCUMENT ME!
\r
72 public Vobject element() {
\r
82 * @return DOCUMENT ME!
\r
84 public Vobject setElement(Vobject v) {
\r
91 * @return DOCUMENT ME!
\r
93 public BinaryNode left() {
\r
103 * @return DOCUMENT ME!
\r
105 public BinaryNode setLeft(BinaryNode n) {
\r
112 * @return DOCUMENT ME!
\r
114 public BinaryNode right() {
\r
124 * @return DOCUMENT ME!
\r
126 public BinaryNode setRight(BinaryNode n) {
\r
133 * @return DOCUMENT ME!
\r
135 public BinaryNode parent() {
\r
145 * @return DOCUMENT ME!
\r
147 public BinaryNode setParent(BinaryNode n) {
\r
154 * @return DOCUMENT ME!
\r
156 public boolean isLeaf() {
\r
157 return (left == null) && (right == null);
\r
161 * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of
\r
162 * this node (removing any old references) a null parameter DOES NOT mean that
\r
163 * 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
168 if (leftchild != null) {
\r
169 this.setLeft(leftchild);
\r
170 leftchild.detach();
\r
171 leftchild.setParent(this);
\r
174 if (rightchild != null) {
\r
175 this.setRight(rightchild);
\r
176 rightchild.detach();
\r
177 rightchild.setParent(this);
\r
182 * Detaches the node from the binary tree, along with all its child nodes.
\r
184 * @return BinaryNode The detached node.
\r
186 public BinaryNode detach() {
\r
187 if (this.parent != null) {
\r
188 if (this.parent.left == this) {
\r
189 this.parent.left = null;
\r
191 if (this.parent.right == this) {
\r
192 this.parent.right = null;
\r
197 this.parent = null;
\r
203 * Traverses up through the tree until a node with a free leftchild is
\r
206 * @return BinaryNode
\r
208 public BinaryNode ascendLeft() {
\r
209 BinaryNode c = this;
\r
213 } while ((c != null) && (c.left() != null) && !c.left().isLeaf());
\r
219 * Traverses up through the tree until a node with a free rightchild is
\r
220 * discovered. Jalview builds trees by descent on the left, so this may be
\r
223 * @return BinaryNode
\r
225 public BinaryNode ascendRight() {
\r
226 BinaryNode c = this;
\r
230 } while ((c != null) && (c.right() != null) && !c.right().isLeaf());
\r
241 public void setName(String name) {
\r
248 * @return DOCUMENT ME!
\r
250 public String getName() {
\r
260 public void setBootstrap(int boot) {
\r
261 this.bootstrap = boot;
\r
267 * @return DOCUMENT ME!
\r
269 public int getBootstrap() {
\r
274 * @return unquoted string of form VorbaId|v|node name string public String
\r
275 * getNewickNodeName() { if (element!=null || name!=null) { return
\r
276 * ((element!=null) ? element.getVorbaId().getId()+"|v|" : "") +
\r
277 * ((name == null) ? "" : name); } return ""; }
\r
279 * note we probably don't need this now
\r
282 * parseNodeNameString(uk.ac.vamsas.client.ClientDocument binder) {
\r
284 * if (element==null && name!=null && name.indexOf("|v|")>-1) {
\r
285 * element = binder.getObject(null).getVorbaId(); // TODO: fix THIS !
\r
286 * name.substring(0, name.indexOf("|v")));
\r
288 * } return false; }
\r