2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2005 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
20 package jalview.datamodel;
22 public class BinaryNode
34 left = right = parent = null;
38 public BinaryNode(Object element, BinaryNode parent, String name)
40 this.element = element;
47 public Object element()
52 public Object setElement(Object v)
57 public BinaryNode left()
62 public BinaryNode setLeft(BinaryNode n)
67 public BinaryNode right()
72 public BinaryNode setRight(BinaryNode n)
77 public BinaryNode parent()
82 public BinaryNode setParent(BinaryNode n)
87 public boolean isLeaf()
89 return (left == null) && (right == null);
93 * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of this node (removing any old references)
94 * a null parameter DOES NOT mean that the pointer to the corresponding child node is set to NULL - you should use
95 * setChild(null), or detach() for this.
98 public void SetChildren(BinaryNode leftchild, BinaryNode rightchild)
100 if (leftchild != null)
102 this.setLeft(leftchild);
104 leftchild.setParent(this);
107 if (rightchild != null)
109 this.setRight(rightchild);
111 rightchild.setParent(this);
116 * Detaches the node from the binary tree, along with all its child nodes.
117 * @return BinaryNode The detached node.
119 public BinaryNode detach()
121 if (this.parent!=null) {
122 if (this.parent.left == this)
124 this.parent.left = null;
128 if (this.parent.right == this)
130 this.parent.right = null;
138 * Traverses up through the tree until a node with a free leftchild is discovered.
141 public BinaryNode ascendLeft() {
145 } while (c!=null && c.left()!=null && !c.left().isLeaf());
149 * Traverses up through the tree until a node with a free rightchild is discovered.
150 * Jalview builds trees by descent on the left, so this may be unused.
153 public BinaryNode ascendRight() {
157 } while (c!=null && c.right()!=null && !c.right().isLeaf());
162 public void setName(String name)
167 public String getName()
172 public void setBootstrap(int boot)
174 this.bootstrap = boot;
177 public int getBootstrap()