Skip to content

Commit 8169f19

Browse files
convert SmartTime to Java, removing Xtend dependencies
1 parent ab6b036 commit 8169f19

File tree

1 file changed

+47
-63
lines changed

1 file changed

+47
-63
lines changed
Lines changed: 47 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,71 +17,55 @@
1717

1818
import java.text.DecimalFormat;
1919

20-
@SuppressWarnings("all")
2120
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";
7261
} 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";
7764
}
78-
}
65+
} else {
66+
final DecimalFormat formatter = new DecimalFormat("##,##0.000");
67+
ret = formatter.format(seconds);
7968
}
80-
} else {
81-
final DecimalFormat formatter_4 = new DecimalFormat("##,##0.000");
82-
ret = formatter_4.format(this.seconds);
83-
}
69+
return ret;
8470
}
85-
return ret;
86-
}
8771
}

0 commit comments

Comments
 (0)