Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.datamodel

File BinaryNode.java

 

Coverage histogram

../../img/srcFileCovDistChart6.png
35% of files have more coverage

Code metrics

14
42
19
1
303
126
30
0.71
2.21
19
1.58

Classes

Class Line # Actions
BinaryNode 29 42 30 35
0.5333333653.3%
 

Contributing tests

This file is covered by 17 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.datamodel;
22   
23    /**
24    * DOCUMENT ME!
25    *
26    * @author $author$
27    * @version $Revision$
28    */
 
29    public class BinaryNode
30    {
31    Object element;
32   
33    String name;
34   
35    BinaryNode left;
36   
37    BinaryNode right;
38   
39    BinaryNode parent;
40   
41    /** DOCUMENT ME!! */
42    public int bootstrap;
43   
44    /**
45    * Creates a new BinaryNode object.
46    */
 
47  18 toggle public BinaryNode()
48    {
49  18 left = right = parent = null;
50  18 bootstrap = 0;
51    }
52   
53    /**
54    * Creates a new BinaryNode object.
55    *
56    * @param element
57    * DOCUMENT ME!
58    * @param parent
59    * DOCUMENT ME!
60    * @param name
61    * DOCUMENT ME!
62    */
 
63  298 toggle public BinaryNode(Object element, BinaryNode parent, String name)
64    {
65  298 this.element = element;
66  298 this.parent = parent;
67  298 this.name = name;
68   
69  298 left = right = null;
70    }
71   
72    /**
73    * DOCUMENT ME!
74    *
75    * @return DOCUMENT ME!
76    */
 
77  10922 toggle public Object element()
78    {
79  10922 return element;
80    }
81   
82    /**
83    * DOCUMENT ME!
84    *
85    * @param v
86    * DOCUMENT ME!
87    *
88    * @return DOCUMENT ME!
89    */
 
90  158 toggle public Object setElement(Object v)
91    {
92  158 return element = v;
93    }
94   
95    /**
96    * DOCUMENT ME!
97    *
98    * @return DOCUMENT ME!
99    */
 
100  19268 toggle public BinaryNode left()
101    {
102  19268 return left;
103    }
104   
105    /**
106    * DOCUMENT ME!
107    *
108    * @param n
109    * DOCUMENT ME!
110    *
111    * @return DOCUMENT ME!
112    */
 
113  140 toggle public BinaryNode setLeft(BinaryNode n)
114    {
115  140 return left = n;
116    }
117   
118    /**
119    * DOCUMENT ME!
120    *
121    * @return DOCUMENT ME!
122    */
 
123  15338 toggle public BinaryNode right()
124    {
125  15338 return right;
126    }
127   
128    /**
129    * DOCUMENT ME!
130    *
131    * @param n
132    * DOCUMENT ME!
133    *
134    * @return DOCUMENT ME!
135    */
 
136  158 toggle public BinaryNode setRight(BinaryNode n)
137    {
138  158 return right = n;
139    }
140   
141    /**
142    * DOCUMENT ME!
143    *
144    * @return DOCUMENT ME!
145    */
 
146  1208 toggle public BinaryNode parent()
147    {
148  1208 return parent;
149    }
150   
151    /**
152    * DOCUMENT ME!
153    *
154    * @param n
155    * DOCUMENT ME!
156    *
157    * @return DOCUMENT ME!
158    */
 
159  0 toggle public BinaryNode setParent(BinaryNode n)
160    {
161  0 return parent = n;
162    }
163   
164    /**
165    * DOCUMENT ME!
166    *
167    * @return DOCUMENT ME!
168    */
 
169  73 toggle public boolean isLeaf()
170    {
171  73 return (left == null) && (right == null);
172    }
173   
174    /**
175    * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of
176    * this node (removing any old references) a null parameter DOES NOT mean that
177    * the pointer to the corresponding child node is set to NULL - you should use
178    * setChild(null), or detach() for this.
179    *
180    */
 
181  0 toggle public void SetChildren(BinaryNode leftchild, BinaryNode rightchild)
182    {
183  0 if (leftchild != null)
184    {
185  0 this.setLeft(leftchild);
186  0 leftchild.detach();
187  0 leftchild.setParent(this);
188    }
189   
190  0 if (rightchild != null)
191    {
192  0 this.setRight(rightchild);
193  0 rightchild.detach();
194  0 rightchild.setParent(this);
195    }
196    }
197   
198    /**
199    * Detaches the node from the binary tree, along with all its child nodes.
200    *
201    * @return BinaryNode The detached node.
202    */
 
203  18 toggle public BinaryNode detach()
204    {
205  18 if (this.parent != null)
206    {
207  18 if (this.parent.left == this)
208    {
209  0 this.parent.left = null;
210    }
211    else
212    {
213  18 if (this.parent.right == this)
214    {
215  18 this.parent.right = null;
216    }
217    }
218    }
219   
220  18 this.parent = null;
221   
222  18 return this;
223    }
224   
225    /**
226    * Traverses up through the tree until a node with a free leftchild is
227    * discovered.
228    *
229    * @return BinaryNode
230    */
 
231  0 toggle public BinaryNode ascendLeft()
232    {
233  0 BinaryNode c = this;
234   
235  0 do
236    {
237  0 c = c.parent();
238  0 } while ((c != null) && (c.left() != null) && !c.left().isLeaf());
239   
240  0 return c;
241    }
242   
243    /**
244    * Traverses up through the tree until a node with a free rightchild is
245    * discovered. Jalview builds trees by descent on the left, so this may be
246    * unused.
247    *
248    * @return BinaryNode
249    */
 
250  0 toggle public BinaryNode ascendRight()
251    {
252  0 BinaryNode c = this;
253   
254  0 do
255    {
256  0 c = c.parent();
257  0 } while ((c != null) && (c.right() != null) && !c.right().isLeaf());
258   
259  0 return c;
260    }
261   
262    /**
263    *
264    * set the display name
265    *
266    * @param new
267    * name
268    */
 
269  140 toggle public void setName(String name)
270    {
271  140 this.name = name;
272    }
273   
274    /**
275    *
276    *
277    * @return the display name for this node
278    */
 
279  3848 toggle public String getName()
280    {
281  3848 return this.name;
282    }
283   
284    /**
285    * set integer bootstrap value
286    *
287    * @param boot
288    */
 
289  140 toggle public void setBootstrap(int boot)
290    {
291  140 this.bootstrap = boot;
292    }
293   
294    /**
295    * get bootstrap
296    *
297    * @return integer value
298    */
 
299  0 toggle public int getBootstrap()
300    {
301  0 return bootstrap;
302    }
303    }