|
1 | | -/** |
| 1 | +/* |
2 | 2 | * Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com> |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
17 | 17 |
|
18 | 18 | import java.text.DecimalFormat; |
19 | 19 |
|
20 | | -@SuppressWarnings("all") |
21 | 20 | public class SmartTime { |
22 | | - private Double seconds; |
23 | | - |
24 | | - private boolean smart = false; |
25 | | - |
26 | | - public SmartTime() { |
27 | | - super(); |
28 | | - } |
29 | | - |
30 | | - public SmartTime(final Double seconds, final boolean smart) { |
31 | | - super(); |
32 | | - this.seconds = seconds; |
33 | | - this.smart = smart; |
34 | | - } |
35 | | - |
36 | | - public Double setSeconds(final Double seconds) { |
37 | | - return this.seconds = seconds; |
38 | | - } |
39 | | - |
40 | | - public boolean setSmart(final boolean smart) { |
41 | | - return this.smart = smart; |
42 | | - } |
43 | | - |
44 | | - public Double getSeconds() { |
45 | | - return this.seconds; |
46 | | - } |
47 | | - |
48 | | - @Override |
49 | | - public String toString() { |
50 | | - String ret = null; |
51 | | - if ((this.seconds == null)) { |
52 | | - ret = null; |
53 | | - } else { |
54 | | - if (this.smart) { |
55 | | - if (((this.seconds).doubleValue() >= (60 * 60))) { |
56 | | - final DecimalFormat formatter = new DecimalFormat("#0.00"); |
57 | | - String _format = formatter.format((((this.seconds).doubleValue() / 60) / 60)); |
58 | | - String _plus = (_format + " h"); |
59 | | - ret = _plus; |
60 | | - } else { |
61 | | - if (((this.seconds).doubleValue() >= 60)) { |
62 | | - final DecimalFormat formatter_1 = new DecimalFormat("#0.00"); |
63 | | - String _format_1 = formatter_1.format(((this.seconds).doubleValue() / 60)); |
64 | | - String _plus_1 = (_format_1 + " min"); |
65 | | - ret = _plus_1; |
66 | | - } else { |
67 | | - if (((this.seconds).doubleValue() >= 1)) { |
68 | | - final DecimalFormat formatter_2 = new DecimalFormat("#0.000"); |
69 | | - String _format_2 = formatter_2.format(this.seconds); |
70 | | - String _plus_2 = (_format_2 + " s"); |
71 | | - ret = _plus_2; |
| 21 | + private Double seconds; |
| 22 | + private boolean smart = false; |
| 23 | + |
| 24 | + public SmartTime() { |
| 25 | + super(); |
| 26 | + } |
| 27 | + |
| 28 | + public SmartTime(final Double seconds, final boolean smart) { |
| 29 | + super(); |
| 30 | + this.seconds = seconds; |
| 31 | + this.smart = smart; |
| 32 | + } |
| 33 | + |
| 34 | + public void setSeconds(final Double seconds) { |
| 35 | + this.seconds = seconds; |
| 36 | + } |
| 37 | + |
| 38 | + public void setSmart(final boolean smart) { |
| 39 | + this.smart = smart; |
| 40 | + } |
| 41 | + |
| 42 | + public Double getSeconds() { |
| 43 | + return seconds; |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public String toString() { |
| 48 | + String ret = null; |
| 49 | + if (seconds == null) { |
| 50 | + ret = null; |
| 51 | + } else if (smart) { |
| 52 | + if (seconds >= 60 * 60) { |
| 53 | + final DecimalFormat formatter = new DecimalFormat("#0.00"); |
| 54 | + ret = formatter.format(seconds / 60 / 60) + " h"; |
| 55 | + } else if (seconds >= 60) { |
| 56 | + final DecimalFormat formatter = new DecimalFormat("#0.00"); |
| 57 | + ret = formatter.format(seconds / 60) + " min"; |
| 58 | + } else if (seconds >= 1) { |
| 59 | + final DecimalFormat formatter = new DecimalFormat("#0.000"); |
| 60 | + ret = formatter.format(seconds) + " s"; |
72 | 61 | } else { |
73 | | - final DecimalFormat formatter_3 = new DecimalFormat("##0"); |
74 | | - String _format_3 = formatter_3.format(((this.seconds).doubleValue() * 1000)); |
75 | | - String _plus_3 = (_format_3 + " ms"); |
76 | | - ret = _plus_3; |
| 62 | + final DecimalFormat formatter = new DecimalFormat("##0"); |
| 63 | + ret = formatter.format(seconds * 1000) + " ms"; |
77 | 64 | } |
78 | | - } |
| 65 | + } else { |
| 66 | + final DecimalFormat formatter = new DecimalFormat("##,##0.000"); |
| 67 | + ret = formatter.format(seconds); |
79 | 68 | } |
80 | | - } else { |
81 | | - final DecimalFormat formatter_4 = new DecimalFormat("##,##0.000"); |
82 | | - ret = formatter_4.format(this.seconds); |
83 | | - } |
| 69 | + return ret; |
84 | 70 | } |
85 | | - return ret; |
86 | | - } |
87 | 71 | } |
0 commit comments