1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.datamodel; |
22 |
|
|
23 |
|
import java.awt.Color; |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
@author |
29 |
|
@version |
30 |
|
|
|
|
| 52.6% |
Uncovered Elements: 54 (114) |
Complexity: 45 |
Complexity Density: 0.7 |
|
31 |
|
public class BinaryNode<T> |
32 |
|
{ |
33 |
|
T element; |
34 |
|
|
35 |
|
String name; |
36 |
|
|
37 |
|
String label = null; |
38 |
|
|
39 |
|
BinaryNode<T> left; |
40 |
|
|
41 |
|
BinaryNode<T> right; |
42 |
|
|
43 |
|
BinaryNode<T> parent; |
44 |
|
|
45 |
|
|
46 |
|
public int bootstrap; |
47 |
|
|
48 |
|
|
49 |
|
public double dist; |
50 |
|
|
51 |
|
|
52 |
|
public int count; |
53 |
|
|
54 |
|
|
55 |
|
public double height; |
56 |
|
|
57 |
|
|
58 |
|
public float ycount; |
59 |
|
|
60 |
|
|
61 |
|
public Color color = Color.black; |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
public boolean dummy = false; |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
72 |
202 |
public BinaryNode()... |
73 |
|
{ |
74 |
202 |
left = right = parent = null; |
75 |
202 |
bootstrap = 0; |
76 |
202 |
dist = 0; |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
@param |
83 |
|
|
84 |
|
@param |
85 |
|
|
86 |
|
@param |
87 |
|
|
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
89 |
70 |
public BinaryNode(T element, BinaryNode<T> parent, String name,... |
90 |
|
double dist) |
91 |
|
{ |
92 |
70 |
this(); |
93 |
70 |
this.element = element; |
94 |
70 |
this.parent = parent; |
95 |
70 |
this.name = name; |
96 |
70 |
this.dist = dist; |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
99 |
70 |
public BinaryNode(T element, BinaryNode<T> parent, String name,... |
100 |
|
double dist, int bootstrap) |
101 |
|
{ |
102 |
70 |
this(element, parent, name, dist); |
103 |
70 |
this.bootstrap = bootstrap; |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
106 |
70 |
public BinaryNode(T val, BinaryNode<T> parent, String name, double dist,... |
107 |
|
int bootstrap, boolean dummy) |
108 |
|
{ |
109 |
70 |
this(val, parent, name, dist, bootstrap); |
110 |
70 |
this.dummy = dummy; |
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
@return |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
43 |
public T element()... |
119 |
|
{ |
120 |
43 |
return element; |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
@param |
127 |
|
|
128 |
|
|
129 |
|
@return |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
131 |
102 |
public T setElement(T v)... |
132 |
|
{ |
133 |
102 |
return element = v; |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
@return |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
141 |
1765 |
public BinaryNode<T> left()... |
142 |
|
{ |
143 |
1765 |
return left; |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
@param |
150 |
|
|
151 |
|
|
152 |
|
@return |
153 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
154 |
94 |
public BinaryNode<T> setLeft(BinaryNode<T> n)... |
155 |
|
{ |
156 |
94 |
return left = n; |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
@return |
163 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
164 |
1074 |
public BinaryNode<T> right()... |
165 |
|
{ |
166 |
1074 |
return right; |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
@param |
173 |
|
|
174 |
|
|
175 |
|
@return |
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
100 |
public BinaryNode<T> setRight(BinaryNode<T> n)... |
178 |
|
{ |
179 |
100 |
return right = n; |
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
@return |
186 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
187 |
500 |
public BinaryNode<T> parent()... |
188 |
|
{ |
189 |
500 |
return parent; |
190 |
|
} |
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
@param |
196 |
|
|
197 |
|
|
198 |
|
@return |
199 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
200 |
124 |
public BinaryNode<T> setParent(BinaryNode<T> n)... |
201 |
|
{ |
202 |
124 |
return parent = n; |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
@return |
209 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
210 |
161 |
public boolean isLeaf()... |
211 |
|
{ |
212 |
161 |
return (left == null) && (right == null); |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
222 |
0 |
public void SetChildren(BinaryNode<T> leftchild, BinaryNode<T> rightchild)... |
223 |
|
{ |
224 |
0 |
if (leftchild != null) |
225 |
|
{ |
226 |
0 |
this.setLeft(leftchild); |
227 |
0 |
leftchild.detach(); |
228 |
0 |
leftchild.setParent(this); |
229 |
|
} |
230 |
|
|
231 |
0 |
if (rightchild != null) |
232 |
|
{ |
233 |
0 |
this.setRight(rightchild); |
234 |
0 |
rightchild.detach(); |
235 |
0 |
rightchild.setParent(this); |
236 |
|
} |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
@return |
243 |
|
|
|
|
| 69.2% |
Uncovered Elements: 4 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
244 |
6 |
public BinaryNode<T> detach()... |
245 |
|
{ |
246 |
6 |
if (this.parent != null) |
247 |
|
{ |
248 |
6 |
if (this.parent.left == this) |
249 |
|
{ |
250 |
0 |
this.parent.left = null; |
251 |
|
} |
252 |
|
else |
253 |
|
{ |
254 |
6 |
if (this.parent.right == this) |
255 |
|
{ |
256 |
6 |
this.parent.right = null; |
257 |
|
} |
258 |
|
} |
259 |
|
} |
260 |
|
|
261 |
6 |
this.parent = null; |
262 |
|
|
263 |
6 |
return this; |
264 |
|
} |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
@return |
271 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 4 |
Complexity Density: 1 |
|
272 |
0 |
public BinaryNode<T> ascendLeft()... |
273 |
|
{ |
274 |
0 |
BinaryNode<T> c = this; |
275 |
|
|
276 |
0 |
do |
277 |
|
{ |
278 |
0 |
c = c.parent(); |
279 |
0 |
} while ((c != null) && (c.left() != null) && !c.left().isLeaf()); |
280 |
|
|
281 |
0 |
return c; |
282 |
|
} |
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
@return |
290 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 4 |
Complexity Density: 1 |
|
291 |
0 |
public BinaryNode<T> ascendRight()... |
292 |
|
{ |
293 |
0 |
BinaryNode<T> c = this; |
294 |
|
|
295 |
0 |
do |
296 |
|
{ |
297 |
0 |
c = c.parent(); |
298 |
0 |
} while ((c != null) && (c.right() != null) && !c.right().isLeaf()); |
299 |
|
|
300 |
0 |
return c; |
301 |
|
} |
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
@param |
308 |
|
|
309 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
310 |
96 |
public void setName(String name)... |
311 |
|
{ |
312 |
96 |
this.name = name; |
313 |
|
} |
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
@return |
319 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
320 |
458 |
public String getName()... |
321 |
|
{ |
322 |
458 |
return this.name; |
323 |
|
} |
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
@param |
329 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
330 |
32 |
public void setBootstrap(int boot)... |
331 |
|
{ |
332 |
32 |
this.bootstrap = boot; |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
@return |
339 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
340 |
234 |
public int getBootstrap()... |
341 |
|
{ |
342 |
234 |
return bootstrap; |
343 |
|
} |
344 |
|
|
345 |
|
|
346 |
|
@param |
347 |
|
|
348 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
349 |
78 |
public boolean isDummy()... |
350 |
|
{ |
351 |
78 |
return dummy; |
352 |
|
} |
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
@param |
358 |
|
|
359 |
|
|
360 |
|
@return |
361 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
362 |
0 |
public boolean setDummy(boolean newstate)... |
363 |
|
{ |
364 |
0 |
boolean oldstate = dummy; |
365 |
0 |
dummy = newstate; |
366 |
|
|
367 |
0 |
return oldstate; |
368 |
|
} |
369 |
|
|
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
@return |
374 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
375 |
0 |
public boolean hasLabel()... |
376 |
|
{ |
377 |
0 |
return label != null && !label.isEmpty(); |
378 |
|
} |
379 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
380 |
0 |
public String getLabel()... |
381 |
|
{ |
382 |
0 |
return label; |
383 |
|
} |
384 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
385 |
0 |
public void setLabel(String label)... |
386 |
|
{ |
387 |
0 |
this.label = label; |
388 |
|
} |
389 |
|
|
390 |
|
|
391 |
|
|
392 |
|
|
393 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
394 |
32 |
public BinaryNode<T> AscendTree()... |
395 |
|
{ |
396 |
32 |
BinaryNode<T> c = this; |
397 |
|
|
398 |
32 |
do |
399 |
|
{ |
400 |
32 |
c = c.parent(); |
401 |
32 |
} while ((c != null) && c.dummy); |
402 |
|
|
403 |
32 |
return c; |
404 |
|
} |
405 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 5 |
Complexity Density: 1 |
|
406 |
0 |
public String getDisplayName()... |
407 |
|
{ |
408 |
0 |
if (name != null && !name.isBlank()) |
409 |
|
{ |
410 |
|
|
411 |
0 |
if (hasLabel()) |
412 |
|
{ |
413 |
0 |
return getName() + "|" + label; |
414 |
|
} |
415 |
0 |
return name; |
416 |
|
} |
417 |
0 |
return hasLabel() ? label : ""; |
418 |
|
} |
419 |
|
} |