1 package org.djunits.value.vdouble.scalar;
2
3 import java.util.regex.Matcher;
4
5 import javax.annotation.Generated;
6
7 import org.djunits.Throw;
8 import org.djunits.unit.DurationUnit;
9 import org.djunits.unit.TimeUnit;
10 import org.djunits.value.util.ValueUtil;
11 import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarAbs;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2020-01-19T15:21:24.964166400Z")
30 public class Time extends AbstractDoubleScalarAbs<TimeUnit, Time, DurationUnit, Duration>
31 {
32
33 private static final long serialVersionUID = 20150901L;
34
35
36 public static final Timeuble/scalar/Time.html#Time">Time ZERO = new Time(0.0, TimeUnit.DEFAULT);
37
38
39
40
41
42
43 public Time(final double value, final TimeUnit unit)
44 {
45 super(value, unit);
46 }
47
48
49
50
51
52 public Timee/vdouble/scalar/Time.html#Time">Time(final Time value)
53 {
54 super(value);
55 }
56
57
58 @Override
59 public final Time instantiateAbs(final double value, final TimeUnit unit)
60 {
61 return new Time(value, unit);
62 }
63
64
65 @Override
66 public final Duration instantiateRel(final double value, final DurationUnit unit)
67 {
68 return new Duration(value, unit);
69 }
70
71
72
73
74
75
76 public static final Time instantiateSI(final double value)
77 {
78 return new Time(value, TimeUnit.DEFAULT);
79 }
80
81
82
83
84
85
86
87
88 public static Timeble/scalar/Time.html#Time">Timealar/Time.html#Time">Time interpolate(final Timeble/scalar/Time.html#Time">Time zero, final Time one, final double ratio)
89 {
90 return new Time(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio, zero.getDisplayUnit());
91 }
92
93
94
95
96
97
98
99 public static Timeouble/scalar/Time.html#Time">Timeouble/scalar/Time.html#Time">Time max(final Timeouble/scalar/Time.html#Time">Time a1, final Time a2)
100 {
101 return a1.gt(a2) ? a1 : a2;
102 }
103
104
105
106
107
108
109
110
111 public static Timeouble/scalar/Time.html#Time">Timeouble/scalar/Time.html#Time">Time max(final Timeouble/scalar/Time.html#Time">Time a1, final Time a2, final Time... an)
112 {
113 Time maxa = a1.gt(a2) ? a1 : a2;
114 for (Time a : an)
115 {
116 if (a.gt(maxa))
117 {
118 maxa = a;
119 }
120 }
121 return maxa;
122 }
123
124
125
126
127
128
129
130 public static Timeouble/scalar/Time.html#Time">Timeouble/scalar/Time.html#Time">Time min(final Timeouble/scalar/Time.html#Time">Time a1, final Time a2)
131 {
132 return a1.lt(a2) ? a1 : a2;
133 }
134
135
136
137
138
139
140
141
142 public static Timeouble/scalar/Time.html#Time">Timeouble/scalar/Time.html#Time">Time min(final Timeouble/scalar/Time.html#Time">Time a1, final Time a2, final Time... an)
143 {
144 Time mina = a1.lt(a2) ? a1 : a2;
145 for (Time a : an)
146 {
147 if (a.lt(mina))
148 {
149 mina = a;
150 }
151 }
152 return mina;
153 }
154
155
156
157
158
159
160
161
162
163
164 public static Time valueOf(final String text)
165 {
166 Throw.whenNull(text, "Error parsing Time: text to parse is null");
167 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Time: empty text to parse");
168 Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
169 if (matcher.find())
170 {
171 int index = matcher.end();
172 String unitString = text.substring(index).trim();
173 String valueString = text.substring(0, index).trim();
174 TimeUnit unit = TimeUnit.BASE.getUnitByAbbreviation(unitString);
175 if (unit != null)
176 {
177 double d = Double.parseDouble(valueString);
178 return new Time(d, unit);
179 }
180 }
181 throw new IllegalArgumentException("Error parsing Time from " + text);
182 }
183
184
185
186
187
188
189
190
191
192 public static Time of(final double value, final String unitString)
193 {
194 Throw.whenNull(unitString, "Error parsing Time: unitString is null");
195 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Time: empty unitString");
196 TimeUnit unit = TimeUnit.BASE.getUnitByAbbreviation(unitString);
197 if (unit != null)
198 {
199 return new Time(value, unit);
200 }
201 throw new IllegalArgumentException("Error parsing Time with unit " + unitString);
202 }
203
204 }