1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
@version |
25 |
|
@author |
26 |
|
|
27 |
|
package jalview.util; |
28 |
|
|
29 |
|
import java.util.Arrays; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
@author |
35 |
|
@version |
36 |
|
|
|
|
| 44.1% |
Uncovered Elements: 270 (483) |
Complexity: 149 |
Complexity Density: 0.52 |
|
37 |
|
public class Format |
38 |
|
{ |
39 |
|
private int width; |
40 |
|
|
41 |
|
private int precision; |
42 |
|
|
43 |
|
private String pre; |
44 |
|
|
45 |
|
private String post; |
46 |
|
|
47 |
|
private boolean leading_zeroes; |
48 |
|
|
49 |
|
private boolean show_plus; |
50 |
|
|
51 |
|
private boolean alternate; |
52 |
|
|
53 |
|
private boolean show_space; |
54 |
|
|
55 |
|
private boolean left_align; |
56 |
|
|
57 |
|
private char fmt; |
58 |
|
|
59 |
|
private final String formatString; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@param |
65 |
|
|
66 |
|
|
|
|
| 78.4% |
Uncovered Elements: 24 (111) |
Complexity: 25 |
Complexity Density: 0.37 |
|
67 |
20147 |
public Format(String s)... |
68 |
|
{ |
69 |
20147 |
formatString = s; |
70 |
20147 |
width = 0; |
71 |
20147 |
precision = -1; |
72 |
20147 |
pre = ""; |
73 |
20147 |
post = ""; |
74 |
20147 |
leading_zeroes = false; |
75 |
20147 |
show_plus = false; |
76 |
20147 |
alternate = false; |
77 |
20147 |
show_space = false; |
78 |
20147 |
left_align = false; |
79 |
20147 |
fmt = ' '; |
80 |
|
|
81 |
20147 |
int length = s.length(); |
82 |
20147 |
int parse_state = 0; |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
20147 |
int i = 0; |
87 |
|
|
88 |
40838 |
while (parse_state == 0) |
89 |
|
{ |
90 |
20691 |
if (i >= length) |
91 |
|
{ |
92 |
0 |
parse_state = 5; |
93 |
|
} |
94 |
20691 |
else if (s.charAt(i) == '%') |
95 |
|
{ |
96 |
20147 |
if (i < (length - 1)) |
97 |
|
{ |
98 |
20147 |
if (s.charAt(i + 1) == '%') |
99 |
|
{ |
100 |
0 |
pre = pre + '%'; |
101 |
0 |
i++; |
102 |
|
} |
103 |
|
else |
104 |
|
{ |
105 |
20147 |
parse_state = 1; |
106 |
|
} |
107 |
|
} |
108 |
|
else |
109 |
|
{ |
110 |
0 |
throw new java.lang.IllegalArgumentException(); |
111 |
|
} |
112 |
|
} |
113 |
|
else |
114 |
|
{ |
115 |
544 |
pre = pre + s.charAt(i); |
116 |
|
} |
117 |
|
|
118 |
20691 |
i++; |
119 |
|
} |
120 |
|
|
121 |
41328 |
while (parse_state == 1) |
122 |
|
{ |
123 |
21181 |
if (i >= length) |
124 |
|
{ |
125 |
0 |
parse_state = 5; |
126 |
|
} |
127 |
21181 |
else if (s.charAt(i) == ' ') |
128 |
|
{ |
129 |
0 |
show_space = true; |
130 |
|
} |
131 |
21181 |
else if (s.charAt(i) == '-') |
132 |
|
{ |
133 |
1034 |
left_align = true; |
134 |
|
} |
135 |
20147 |
else if (s.charAt(i) == '+') |
136 |
|
{ |
137 |
0 |
show_plus = true; |
138 |
|
} |
139 |
20147 |
else if (s.charAt(i) == '0') |
140 |
|
{ |
141 |
0 |
leading_zeroes = true; |
142 |
|
} |
143 |
20147 |
else if (s.charAt(i) == '#') |
144 |
|
{ |
145 |
0 |
alternate = true; |
146 |
|
} |
147 |
|
else |
148 |
|
{ |
149 |
20147 |
parse_state = 2; |
150 |
20147 |
i--; |
151 |
|
} |
152 |
|
|
153 |
21181 |
i++; |
154 |
|
} |
155 |
|
|
156 |
61509 |
while (parse_state == 2) |
157 |
|
{ |
158 |
41362 |
if (i >= length) |
159 |
|
{ |
160 |
0 |
parse_state = 5; |
161 |
|
} |
162 |
41362 |
else if (('0' <= s.charAt(i)) && (s.charAt(i) <= '9')) |
163 |
|
{ |
164 |
21215 |
width = ((width * 10) + s.charAt(i)) - '0'; |
165 |
21215 |
i++; |
166 |
|
} |
167 |
20147 |
else if (s.charAt(i) == '.') |
168 |
|
{ |
169 |
35 |
parse_state = 3; |
170 |
35 |
precision = 0; |
171 |
35 |
i++; |
172 |
|
} |
173 |
|
else |
174 |
|
{ |
175 |
20112 |
parse_state = 4; |
176 |
|
} |
177 |
|
} |
178 |
|
|
179 |
20217 |
while (parse_state == 3) |
180 |
|
{ |
181 |
70 |
if (i >= length) |
182 |
|
{ |
183 |
0 |
parse_state = 5; |
184 |
|
} |
185 |
70 |
else if (('0' <= s.charAt(i)) && (s.charAt(i) <= '9')) |
186 |
|
{ |
187 |
35 |
precision = ((precision * 10) + s.charAt(i)) - '0'; |
188 |
35 |
i++; |
189 |
|
} |
190 |
|
else |
191 |
|
{ |
192 |
35 |
parse_state = 4; |
193 |
|
} |
194 |
|
} |
195 |
|
|
196 |
20147 |
if (parse_state == 4) |
197 |
|
{ |
198 |
20147 |
if (i >= length) |
199 |
|
{ |
200 |
0 |
parse_state = 5; |
201 |
|
} |
202 |
|
else |
203 |
|
{ |
204 |
20147 |
fmt = s.charAt(i); |
205 |
|
} |
206 |
|
|
207 |
20147 |
i++; |
208 |
|
} |
209 |
|
|
210 |
20147 |
if (i < length) |
211 |
|
{ |
212 |
34 |
post = s.substring(i, length); |
213 |
|
} |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
@param |
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
@exception |
272 |
|
|
273 |
|
|
274 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 4 |
Complexity Density: 0.31 |
|
275 |
41 |
public static String getHexString(java.awt.Color color)... |
276 |
|
{ |
277 |
41 |
String r; |
278 |
41 |
String g; |
279 |
41 |
String b; |
280 |
41 |
r = Integer.toHexString(color.getRed()); |
281 |
|
|
282 |
41 |
if (r.length() < 2) |
283 |
|
{ |
284 |
15 |
r = "0" + r; |
285 |
|
} |
286 |
|
|
287 |
41 |
g = Integer.toHexString(color.getGreen()); |
288 |
|
|
289 |
41 |
if (g.length() < 2) |
290 |
|
{ |
291 |
18 |
g = "0" + g; |
292 |
|
} |
293 |
|
|
294 |
41 |
b = Integer.toHexString(color.getBlue()); |
295 |
|
|
296 |
41 |
if (b.length() < 2) |
297 |
|
{ |
298 |
25 |
b = "0" + b; |
299 |
|
} |
300 |
|
|
301 |
41 |
return r + g + b; |
302 |
|
} |
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
@param |
308 |
|
|
309 |
|
@param |
310 |
|
|
311 |
|
@param |
312 |
|
|
313 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
314 |
0 |
public static void print(java.io.PrintStream s, String fmt, double x)... |
315 |
|
{ |
316 |
0 |
s.print(new Format(fmt).form(x)); |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
@param |
323 |
|
|
324 |
|
@param |
325 |
|
|
326 |
|
@param |
327 |
|
|
328 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
329 |
0 |
public static void print(java.io.PrintStream s, String fmt, long x)... |
330 |
|
{ |
331 |
0 |
s.print(new Format(fmt).form(x)); |
332 |
|
} |
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
@param |
338 |
|
|
339 |
|
@param |
340 |
|
|
341 |
|
@param |
342 |
|
|
343 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
344 |
0 |
public static void print(java.io.PrintStream s, String fmt, char x)... |
345 |
|
{ |
346 |
0 |
s.print(new Format(fmt).form(x)); |
347 |
|
} |
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
|
352 |
|
@param |
353 |
|
|
354 |
|
@param |
355 |
|
|
356 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
357 |
0 |
public static void print(java.io.PrintStream s, String fmt, String x)... |
358 |
|
{ |
359 |
0 |
s.print(new Format(fmt).form(x)); |
360 |
|
} |
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
@param |
366 |
|
|
367 |
|
@return |
368 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
369 |
0 |
public static int atoi(String s)... |
370 |
|
{ |
371 |
0 |
return (int) atol(s); |
372 |
|
} |
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
|
377 |
|
@param |
378 |
|
|
379 |
|
@return |
380 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 8 |
Complexity Density: 1 |
|
381 |
0 |
public static long atol(String s)... |
382 |
|
{ |
383 |
0 |
int i = 0; |
384 |
|
|
385 |
0 |
while ((i < s.length()) && Character.isWhitespace(s.charAt(i))) |
386 |
|
{ |
387 |
0 |
i++; |
388 |
|
} |
389 |
|
|
390 |
0 |
if ((i < s.length()) && (s.charAt(i) == '0')) |
391 |
|
{ |
392 |
0 |
if (((i + 1) < s.length()) |
393 |
|
&& ((s.charAt(i + 1) == 'x') || (s.charAt(i + 1) == 'X'))) |
394 |
|
{ |
395 |
0 |
return parseLong(s.substring(i + 2), 16); |
396 |
|
} |
397 |
|
else |
398 |
|
{ |
399 |
0 |
return parseLong(s, 8); |
400 |
|
} |
401 |
|
} |
402 |
|
else |
403 |
|
{ |
404 |
0 |
return parseLong(s, 10); |
405 |
|
} |
406 |
|
} |
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
@param |
412 |
|
|
413 |
|
@param |
414 |
|
|
415 |
|
|
416 |
|
@return |
417 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 14 |
Complexity Density: 0.67 |
|
418 |
0 |
private static long parseLong(String s, int base)... |
419 |
|
{ |
420 |
0 |
int i = 0; |
421 |
0 |
int sign = 1; |
422 |
0 |
long r = 0; |
423 |
|
|
424 |
0 |
while ((i < s.length()) && Character.isWhitespace(s.charAt(i))) |
425 |
|
{ |
426 |
0 |
i++; |
427 |
|
} |
428 |
|
|
429 |
0 |
if ((i < s.length()) && (s.charAt(i) == '-')) |
430 |
|
{ |
431 |
0 |
sign = -1; |
432 |
0 |
i++; |
433 |
|
} |
434 |
0 |
else if ((i < s.length()) && (s.charAt(i) == '+')) |
435 |
|
{ |
436 |
0 |
i++; |
437 |
|
} |
438 |
|
|
439 |
0 |
while (i < s.length()) |
440 |
|
{ |
441 |
0 |
char ch = s.charAt(i); |
442 |
|
|
443 |
0 |
if (('0' <= ch) && (ch < ('0' + base))) |
444 |
|
{ |
445 |
0 |
r = ((r * base) + ch) - '0'; |
446 |
|
} |
447 |
0 |
else if (('A' <= ch) && (ch < (('A' + base) - 10))) |
448 |
|
{ |
449 |
0 |
r = ((r * base) + ch) - 'A' + 10; |
450 |
|
} |
451 |
0 |
else if (('a' <= ch) && (ch < (('a' + base) - 10))) |
452 |
|
{ |
453 |
0 |
r = ((r * base) + ch) - 'a' + 10; |
454 |
|
} |
455 |
|
else |
456 |
|
{ |
457 |
0 |
return r * sign; |
458 |
|
} |
459 |
|
|
460 |
0 |
i++; |
461 |
|
} |
462 |
|
|
463 |
0 |
return r * sign; |
464 |
|
} |
465 |
|
|
466 |
|
|
467 |
|
|
468 |
|
|
469 |
|
@param |
470 |
|
|
471 |
|
|
|
|
| 0% |
Uncovered Elements: 50 (50) |
Complexity: 16 |
Complexity Density: 0.53 |
|
472 |
0 |
public static double atof(String s)... |
473 |
|
{ |
474 |
0 |
int i = 0; |
475 |
0 |
int sign = 1; |
476 |
0 |
double r = 0; |
477 |
|
|
478 |
0 |
double p = 1; |
479 |
0 |
int state = 0; |
480 |
|
|
481 |
0 |
while ((i < s.length()) && Character.isWhitespace(s.charAt(i))) |
482 |
|
{ |
483 |
0 |
i++; |
484 |
|
} |
485 |
|
|
486 |
0 |
if ((i < s.length()) && (s.charAt(i) == '-')) |
487 |
|
{ |
488 |
0 |
sign = -1; |
489 |
0 |
i++; |
490 |
|
} |
491 |
0 |
else if ((i < s.length()) && (s.charAt(i) == '+')) |
492 |
|
{ |
493 |
0 |
i++; |
494 |
|
} |
495 |
|
|
496 |
0 |
while (i < s.length()) |
497 |
|
{ |
498 |
0 |
char ch = s.charAt(i); |
499 |
|
|
500 |
0 |
if (('0' <= ch) && (ch <= '9')) |
501 |
|
{ |
502 |
0 |
if (state == 0) |
503 |
|
{ |
504 |
0 |
r = ((r * 10) + ch) - '0'; |
505 |
|
} |
506 |
0 |
else if (state == 1) |
507 |
|
{ |
508 |
0 |
p = p / 10; |
509 |
0 |
r = r + (p * (ch - '0')); |
510 |
|
} |
511 |
|
} |
512 |
0 |
else if (ch == '.') |
513 |
|
{ |
514 |
0 |
if (state == 0) |
515 |
|
{ |
516 |
0 |
state = 1; |
517 |
|
} |
518 |
|
else |
519 |
|
{ |
520 |
0 |
return sign * r; |
521 |
|
} |
522 |
|
} |
523 |
0 |
else if ((ch == 'e') || (ch == 'E')) |
524 |
|
{ |
525 |
0 |
long e = (int) parseLong(s.substring(i + 1), 10); |
526 |
|
|
527 |
0 |
return sign * r * Math.pow(10, e); |
528 |
|
} |
529 |
|
else |
530 |
|
{ |
531 |
0 |
return sign * r; |
532 |
|
} |
533 |
|
|
534 |
0 |
i++; |
535 |
|
} |
536 |
|
|
537 |
0 |
return sign * r; |
538 |
|
} |
539 |
|
|
540 |
|
|
541 |
|
|
542 |
|
|
543 |
|
@param |
544 |
|
|
545 |
|
@return |
546 |
|
@exception |
547 |
|
|
548 |
|
|
|
|
| 47.6% |
Uncovered Elements: 11 (21) |
Complexity: 8 |
Complexity Density: 0.62 |
|
549 |
17379 |
public String form(double x)... |
550 |
|
{ |
551 |
17379 |
String r; |
552 |
|
|
553 |
17379 |
if (precision < 0) |
554 |
|
{ |
555 |
0 |
precision = 6; |
556 |
|
} |
557 |
|
|
558 |
17379 |
int s = 1; |
559 |
|
|
560 |
17379 |
if (x < 0) |
561 |
|
{ |
562 |
0 |
x = -x; |
563 |
0 |
s = -1; |
564 |
|
} |
565 |
|
|
566 |
17379 |
if (fmt == 'f') |
567 |
|
{ |
568 |
17379 |
r = fixed_format(x); |
569 |
|
} |
570 |
0 |
else if ((fmt == 'e') || (fmt == 'E') || (fmt == 'g') || (fmt == 'G')) |
571 |
|
{ |
572 |
0 |
r = exp_format(x); |
573 |
|
} |
574 |
|
else |
575 |
|
{ |
576 |
0 |
throw new java.lang.IllegalArgumentException(); |
577 |
|
} |
578 |
|
|
579 |
17379 |
return pad(sign(s, r)); |
580 |
|
} |
581 |
|
|
582 |
|
|
583 |
|
|
584 |
|
|
585 |
|
@param |
586 |
|
|
587 |
|
@return |
588 |
|
|
|
|
| 34.6% |
Uncovered Elements: 17 (26) |
Complexity: 7 |
Complexity Density: 0.44 |
|
589 |
19072 |
public String form(long x)... |
590 |
|
{ |
591 |
19072 |
String r; |
592 |
19072 |
int s = 0; |
593 |
|
|
594 |
19072 |
if ((fmt == 'd') || (fmt == 'i')) |
595 |
|
{ |
596 |
19072 |
if (x < 0) |
597 |
|
{ |
598 |
0 |
r = ("" + x).substring(1); |
599 |
0 |
s = -1; |
600 |
|
} |
601 |
|
else |
602 |
|
{ |
603 |
19072 |
r = "" + x; |
604 |
19072 |
s = 1; |
605 |
|
} |
606 |
|
} |
607 |
0 |
else if (fmt == 'o') |
608 |
|
{ |
609 |
0 |
r = convert(x, 3, 7, "01234567"); |
610 |
|
} |
611 |
0 |
else if (fmt == 'x') |
612 |
|
{ |
613 |
0 |
r = convert(x, 4, 15, "0123456789abcdef"); |
614 |
|
} |
615 |
0 |
else if (fmt == 'X') |
616 |
|
{ |
617 |
0 |
r = convert(x, 4, 15, "0123456789ABCDEF"); |
618 |
|
} |
619 |
|
else |
620 |
|
{ |
621 |
0 |
throw new java.lang.IllegalArgumentException(); |
622 |
|
} |
623 |
|
|
624 |
19072 |
return pad(sign(s, r)); |
625 |
|
} |
626 |
|
|
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
@param |
631 |
|
|
632 |
|
@return |
633 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
634 |
0 |
public String form(char c)... |
635 |
|
{ |
636 |
0 |
if (fmt != 'c') |
637 |
|
{ |
638 |
0 |
throw new java.lang.IllegalArgumentException(); |
639 |
|
} |
640 |
|
|
641 |
0 |
String r = "" + c; |
642 |
|
|
643 |
0 |
return pad(r); |
644 |
|
} |
645 |
|
|
646 |
|
|
647 |
|
|
648 |
|
|
649 |
|
@param |
650 |
|
|
651 |
|
@return |
652 |
|
|
|
|
| 55.6% |
Uncovered Elements: 4 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
653 |
1377 |
public String form(String s)... |
654 |
|
{ |
655 |
1377 |
if (fmt != 's') |
656 |
|
{ |
657 |
0 |
throw new java.lang.IllegalArgumentException(); |
658 |
|
} |
659 |
|
|
660 |
1377 |
if (precision >= 0) |
661 |
|
{ |
662 |
0 |
s = s.substring(0, precision); |
663 |
|
} |
664 |
|
|
665 |
1377 |
return pad(s); |
666 |
|
} |
667 |
|
|
668 |
|
|
669 |
|
|
670 |
|
|
671 |
|
@param |
672 |
|
@param |
673 |
|
|
674 |
|
@return |
675 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
676 |
74279 |
static String repeat(char c, int n)... |
677 |
|
{ |
678 |
74279 |
if (n <= 0) |
679 |
|
{ |
680 |
54089 |
return ""; |
681 |
|
} |
682 |
20190 |
char[] chars = new char[n]; |
683 |
20190 |
Arrays.fill(chars, c); |
684 |
20190 |
return new String(chars); |
685 |
|
} |
686 |
|
|
687 |
|
|
688 |
|
|
689 |
|
|
690 |
|
@param |
691 |
|
|
692 |
|
@param |
693 |
|
|
694 |
|
@param |
695 |
|
|
696 |
|
@param |
697 |
|
|
698 |
|
|
699 |
|
@return |
700 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
701 |
0 |
private static String convert(long x, int n, int m, String d)... |
702 |
|
{ |
703 |
0 |
if (x == 0) |
704 |
|
{ |
705 |
0 |
return "0"; |
706 |
|
} |
707 |
|
|
708 |
0 |
String r = ""; |
709 |
|
|
710 |
0 |
while (x != 0) |
711 |
|
{ |
712 |
0 |
r = d.charAt((int) (x & m)) + r; |
713 |
0 |
x = x >>> n; |
714 |
|
} |
715 |
|
|
716 |
0 |
return r; |
717 |
|
} |
718 |
|
|
719 |
|
|
720 |
|
|
721 |
|
|
722 |
|
@param |
723 |
|
|
724 |
|
|
725 |
|
@return |
726 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
727 |
37828 |
private String pad(String r)... |
728 |
|
{ |
729 |
37828 |
String p = repeat(' ', width - r.length()); |
730 |
|
|
731 |
37828 |
if (left_align) |
732 |
|
{ |
733 |
1048 |
return pre + r + p + post; |
734 |
|
} |
735 |
|
else |
736 |
|
{ |
737 |
36780 |
return pre + p + r + post; |
738 |
|
} |
739 |
|
} |
740 |
|
|
741 |
|
|
742 |
|
|
743 |
|
|
744 |
|
@param |
745 |
|
|
746 |
|
@param |
747 |
|
|
748 |
|
|
749 |
|
@return |
750 |
|
|
|
|
| 39.5% |
Uncovered Elements: 23 (38) |
Complexity: 20 |
Complexity Density: 1 |
|
751 |
36451 |
private String sign(int s, String r)... |
752 |
|
{ |
753 |
36451 |
String p = ""; |
754 |
|
|
755 |
36451 |
if (s < 0) |
756 |
|
{ |
757 |
0 |
p = "-"; |
758 |
|
} |
759 |
36451 |
else if (s > 0) |
760 |
|
{ |
761 |
36451 |
if (show_plus) |
762 |
|
{ |
763 |
0 |
p = "+"; |
764 |
|
} |
765 |
36451 |
else if (show_space) |
766 |
|
{ |
767 |
0 |
p = " "; |
768 |
|
} |
769 |
|
} |
770 |
|
else |
771 |
|
{ |
772 |
0 |
if ((fmt == 'o') && alternate && (r.length() > 0) |
773 |
|
&& (r.charAt(0) != '0')) |
774 |
|
{ |
775 |
0 |
p = "0"; |
776 |
|
} |
777 |
0 |
else if ((fmt == 'x') && alternate) |
778 |
|
{ |
779 |
0 |
p = "0x"; |
780 |
|
} |
781 |
0 |
else if ((fmt == 'X') && alternate) |
782 |
|
{ |
783 |
0 |
p = "0X"; |
784 |
|
} |
785 |
|
} |
786 |
|
|
787 |
36451 |
int w = 0; |
788 |
|
|
789 |
36451 |
if (leading_zeroes) |
790 |
|
{ |
791 |
0 |
w = width; |
792 |
|
} |
793 |
36451 |
else if (((fmt == 'd') || (fmt == 'i') || (fmt == 'x') || (fmt == 'X') |
794 |
|
|| (fmt == 'o')) && (precision > 0)) |
795 |
|
{ |
796 |
0 |
w = precision; |
797 |
|
} |
798 |
|
|
799 |
36451 |
return p + repeat('0', w - p.length() - r.length()) + r; |
800 |
|
} |
801 |
|
|
802 |
|
|
803 |
|
|
804 |
|
|
805 |
|
@param |
806 |
|
|
807 |
|
|
808 |
|
@return |
809 |
|
|
|
|
| 52.2% |
Uncovered Elements: 22 (46) |
Complexity: 14 |
Complexity Density: 0.5 |
|
810 |
17379 |
private String fixed_format(double d)... |
811 |
|
{ |
812 |
17379 |
boolean removeTrailing = ((fmt == 'G') || (fmt == 'g')) && !alternate; |
813 |
|
|
814 |
|
|
815 |
17379 |
if (d > 0x7FFFFFFFFFFFFFFFL) |
816 |
|
{ |
817 |
0 |
return exp_format(d); |
818 |
|
} |
819 |
|
|
820 |
17379 |
if (precision == 0) |
821 |
|
{ |
822 |
0 |
return (long) (d + 0.5) + (removeTrailing ? "" : "."); |
823 |
|
} |
824 |
|
|
825 |
17379 |
long whole = (long) d; |
826 |
17379 |
double fr = d - whole; |
827 |
|
|
828 |
17379 |
if ((fr >= 1) || (fr < 0)) |
829 |
|
{ |
830 |
0 |
return exp_format(d); |
831 |
|
} |
832 |
|
|
833 |
17379 |
double factor = 1; |
834 |
17379 |
String leading_zeroes = ""; |
835 |
|
|
836 |
104172 |
for (int i = 1; (i <= precision) |
837 |
|
&& (factor <= 0x7FFFFFFFFFFFFFFFL); i++) |
838 |
|
{ |
839 |
86793 |
factor *= 10; |
840 |
86793 |
leading_zeroes = leading_zeroes + "0"; |
841 |
|
} |
842 |
|
|
843 |
17379 |
long l = (long) ((factor * fr) + 0.5); |
844 |
|
|
845 |
17379 |
if (l >= factor) |
846 |
|
{ |
847 |
0 |
l = 0; |
848 |
0 |
whole++; |
849 |
|
} |
850 |
|
|
851 |
|
|
852 |
17379 |
String z = leading_zeroes + l; |
853 |
17379 |
z = "." + z.substring(z.length() - precision, z.length()); |
854 |
|
|
855 |
17379 |
if (removeTrailing) |
856 |
|
{ |
857 |
0 |
int t = z.length() - 1; |
858 |
|
|
859 |
0 |
while ((t >= 0) && (z.charAt(t) == '0')) |
860 |
|
{ |
861 |
0 |
t--; |
862 |
|
} |
863 |
|
|
864 |
0 |
if ((t >= 0) && (z.charAt(t) == '.')) |
865 |
|
{ |
866 |
0 |
t--; |
867 |
|
} |
868 |
|
|
869 |
0 |
z = z.substring(0, t + 1); |
870 |
|
} |
871 |
|
|
872 |
17379 |
return whole + z; |
873 |
|
} |
874 |
|
|
875 |
|
|
876 |
|
|
877 |
|
|
878 |
|
@param |
879 |
|
|
880 |
|
|
881 |
|
@return |
882 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 11 |
Complexity Density: 0.48 |
|
883 |
0 |
private String exp_format(double d)... |
884 |
|
{ |
885 |
0 |
String f = ""; |
886 |
0 |
int e = 0; |
887 |
0 |
double dd = d; |
888 |
|
|
889 |
0 |
if (d != 0) |
890 |
|
{ |
891 |
0 |
while (dd > 10) |
892 |
|
{ |
893 |
0 |
e++; |
894 |
0 |
dd = dd / 10; |
895 |
|
} |
896 |
|
|
897 |
0 |
while (dd < 1) |
898 |
|
{ |
899 |
0 |
e--; |
900 |
0 |
dd = dd * 10; |
901 |
|
} |
902 |
|
} |
903 |
|
|
904 |
0 |
if (((fmt == 'g') || (fmt == 'G')) && (e >= -4) && (e < precision)) |
905 |
|
{ |
906 |
0 |
return fixed_format(d); |
907 |
|
} |
908 |
|
|
909 |
0 |
f = f + fixed_format(dd); |
910 |
|
|
911 |
0 |
if ((fmt == 'e') || (fmt == 'g')) |
912 |
|
{ |
913 |
0 |
f = f + "e"; |
914 |
|
} |
915 |
|
else |
916 |
|
{ |
917 |
0 |
f = f + "E"; |
918 |
|
} |
919 |
|
|
920 |
0 |
String p = "000"; |
921 |
|
|
922 |
0 |
if (e >= 0) |
923 |
|
{ |
924 |
0 |
f = f + "+"; |
925 |
0 |
p = p + e; |
926 |
|
} |
927 |
|
else |
928 |
|
{ |
929 |
0 |
f = f + "-"; |
930 |
0 |
p = p + (-e); |
931 |
|
} |
932 |
|
|
933 |
0 |
return f + p.substring(p.length() - 3, p.length()); |
934 |
|
} |
935 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
936 |
0 |
@Override... |
937 |
|
public String toString() |
938 |
|
{ |
939 |
0 |
return formatString; |
940 |
|
} |
941 |
|
|
942 |
|
|
943 |
|
|
944 |
|
|
945 |
|
|
946 |
|
|
947 |
|
@param |
948 |
|
@param |
949 |
|
@param |
950 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 4 |
Complexity Density: 0.27 |
|
951 |
80252 |
public static void appendPercentage(StringBuilder sb, float value, int dp)... |
952 |
|
{ |
953 |
|
|
954 |
|
|
955 |
|
|
956 |
80252 |
double d = value; |
957 |
80252 |
long factor = 1L; |
958 |
80258 |
for (int i = 0; i < dp; i++) |
959 |
|
{ |
960 |
6 |
factor *= 10; |
961 |
|
} |
962 |
80252 |
d *= factor; |
963 |
80252 |
d += 0.5; |
964 |
|
|
965 |
|
|
966 |
|
|
967 |
|
|
968 |
80252 |
value = (float) (d / factor); |
969 |
80252 |
sb.append((long) value); |
970 |
|
|
971 |
|
|
972 |
|
|
973 |
|
|
974 |
80252 |
if (dp > 0) |
975 |
|
{ |
976 |
6 |
sb.append("."); |
977 |
12 |
while (dp > 0) |
978 |
|
{ |
979 |
6 |
value = value - (int) value; |
980 |
6 |
value *= 10; |
981 |
6 |
sb.append((int) value); |
982 |
6 |
dp--; |
983 |
|
} |
984 |
|
} |
985 |
|
} |
986 |
|
} |