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 |
|
|
|
|
| 59.6% |
Uncovered Elements: 46 (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 |
563 |
public BinaryNode()... |
73 |
|
{ |
74 |
563 |
left = right = parent = null; |
75 |
563 |
bootstrap = 0; |
76 |
563 |
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 |
396 |
public BinaryNode(T element, BinaryNode<T> parent, String name,... |
90 |
|
double dist) |
91 |
|
{ |
92 |
396 |
this(); |
93 |
396 |
this.element = element; |
94 |
396 |
this.parent = parent; |
95 |
396 |
this.name = name; |
96 |
396 |
this.dist = dist; |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
99 |
396 |
public BinaryNode(T element, BinaryNode<T> parent, String name,... |
100 |
|
double dist, int bootstrap) |
101 |
|
{ |
102 |
396 |
this(element, parent, name, dist); |
103 |
396 |
this.bootstrap = bootstrap; |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
106 |
396 |
public BinaryNode(T val, BinaryNode<T> parent, String name, double dist,... |
107 |
|
int bootstrap, boolean dummy) |
108 |
|
{ |
109 |
396 |
this(val, parent, name, dist, bootstrap); |
110 |
396 |
this.dummy = dummy; |
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
@return |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
114 |
public T element()... |
119 |
|
{ |
120 |
114 |
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 |
283 |
public T setElement(T v)... |
132 |
|
{ |
133 |
283 |
return element = v; |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
@return |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
141 |
5487 |
public BinaryNode<T> left()... |
142 |
|
{ |
143 |
5487 |
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 |
260 |
public BinaryNode<T> setLeft(BinaryNode<T> n)... |
155 |
|
{ |
156 |
260 |
return left = n; |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
@return |
163 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
164 |
3785 |
public BinaryNode<T> right()... |
165 |
|
{ |
166 |
3785 |
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 |
280 |
public BinaryNode<T> setRight(BinaryNode<T> n)... |
178 |
|
{ |
179 |
280 |
return right = n; |
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
@return |
186 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
187 |
2120 |
public BinaryNode<T> parent()... |
188 |
|
{ |
189 |
2120 |
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 |
144 |
public BinaryNode<T> setParent(BinaryNode<T> n)... |
201 |
|
{ |
202 |
144 |
return parent = n; |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
@return |
209 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
210 |
278 |
public boolean isLeaf()... |
211 |
|
{ |
212 |
278 |
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 |
20 |
public BinaryNode<T> detach()... |
245 |
|
{ |
246 |
20 |
if (this.parent != null) |
247 |
|
{ |
248 |
20 |
if (this.parent.left == this) |
249 |
|
{ |
250 |
0 |
this.parent.left = null; |
251 |
|
} |
252 |
|
else |
253 |
|
{ |
254 |
20 |
if (this.parent.right == this) |
255 |
|
{ |
256 |
20 |
this.parent.right = null; |
257 |
|
} |
258 |
|
} |
259 |
|
} |
260 |
|
|
261 |
20 |
this.parent = null; |
262 |
|
|
263 |
20 |
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 |
263 |
public void setName(String name)... |
311 |
|
{ |
312 |
263 |
this.name = name; |
313 |
|
} |
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
@return |
319 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
320 |
802 |
public String getName()... |
321 |
|
{ |
322 |
802 |
return this.name; |
323 |
|
} |
324 |
|
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
@param |
329 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
330 |
188 |
public void setBootstrap(int boot)... |
331 |
|
{ |
332 |
188 |
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 |
134 |
public boolean isDummy()... |
350 |
|
{ |
351 |
134 |
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
375 |
192 |
public boolean hasLabel()... |
376 |
|
{ |
377 |
192 |
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 |
188 |
public BinaryNode<T> AscendTree()... |
395 |
|
{ |
396 |
188 |
BinaryNode<T> c = this; |
397 |
|
|
398 |
188 |
do |
399 |
|
{ |
400 |
188 |
c = c.parent(); |
401 |
188 |
} while ((c != null) && c.dummy); |
402 |
|
|
403 |
188 |
return c; |
404 |
|
} |
405 |
|
|
|
|
| 45.5% |
Uncovered Elements: 6 (11) |
Complexity: 5 |
Complexity Density: 1 |
|
406 |
192 |
public String getDisplayName()... |
407 |
|
{ |
408 |
192 |
if (name != null && !name.isBlank()) |
409 |
|
{ |
410 |
|
|
411 |
192 |
if (hasLabel()) |
412 |
|
{ |
413 |
0 |
return getName() + "|" + label; |
414 |
|
} |
415 |
192 |
return name; |
416 |
|
} |
417 |
0 |
return hasLabel() ? label : ""; |
418 |
|
} |
419 |
|
} |