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
19 package jalview.datamodel;
\r
21 public class BinaryNode {
\r
27 public int bootstrap;
\r
29 public BinaryNode() {
\r
30 left = right = parent = null;
\r
34 public BinaryNode(Object element, BinaryNode parent, String name) {
\r
35 this.element = element;
\r
36 this.parent = parent;
\r
39 left = right = null;
\r
42 public Object element() {
\r
46 public Object setElement(Object v) {
\r
50 public BinaryNode left() {
\r
54 public BinaryNode setLeft(BinaryNode n) {
\r
58 public BinaryNode right() {
\r
62 public BinaryNode setRight(BinaryNode n) {
\r
66 public BinaryNode parent() {
\r
70 public BinaryNode setParent(BinaryNode n) {
\r
74 public boolean isLeaf() {
\r
75 return (left == null) && (right == null);
\r
79 * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of this node (removing any old references)
80 * a null parameter DOES NOT mean that the pointer to the corresponding child node is set to NULL - you should use
81 * setChild(null), or detach() for this.
84 public void SetChildren(BinaryNode leftchild, BinaryNode rightchild) {
\r
85 if (leftchild != null) {
\r
86 this.setLeft(leftchild);
\r
88 leftchild.setParent(this);
\r
91 if (rightchild != null) {
\r
92 this.setRight(rightchild);
\r
93 rightchild.detach();
\r
94 rightchild.setParent(this);
\r
99 * Detaches the node from the binary tree, along with all its child nodes.
100 * @return BinaryNode The detached node.
102 public BinaryNode detach() {
\r
103 if (this.parent != null) {
\r
104 if (this.parent.left == this) {
\r
105 this.parent.left = null;
\r
107 if (this.parent.right == this) {
\r
108 this.parent.right = null;
\r
113 this.parent = null;
\r
119 * Traverses up through the tree until a node with a free leftchild is discovered.
122 public BinaryNode ascendLeft() {
\r
123 BinaryNode c = this;
\r
127 } while ((c != null) && (c.left() != null) && !c.left().isLeaf());
\r
133 * Traverses up through the tree until a node with a free rightchild is discovered.
134 * Jalview builds trees by descent on the left, so this may be unused.
137 public BinaryNode ascendRight() {
\r
138 BinaryNode c = this;
\r
142 } while ((c != null) && (c.right() != null) && !c.right().isLeaf());
\r
147 public void setName(String name) {
\r
151 public String getName() {
\r
155 public void setBootstrap(int boot) {
\r
156 this.bootstrap = boot;
\r
159 public int getBootstrap() {
\r