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.AngleUnit;
9 import org.djunits.unit.AngularVelocityUnit;
10 import org.djunits.unit.DimensionlessUnit;
11 import org.djunits.unit.DurationUnit;
12 import org.djunits.unit.ElectricalCapacitanceUnit;
13 import org.djunits.unit.ElectricalChargeUnit;
14 import org.djunits.unit.ElectricalInductanceUnit;
15 import org.djunits.unit.EnergyUnit;
16 import org.djunits.unit.LengthUnit;
17 import org.djunits.unit.MagneticFluxUnit;
18 import org.djunits.unit.MassUnit;
19 import org.djunits.unit.SpeedUnit;
20 import org.djunits.unit.TimeUnit;
21 import org.djunits.unit.VolumeUnit;
22 import org.djunits.value.util.ValueUtil;
23 import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRelWithAbs;
24
25
26
27
28
29
30
31
32
33
34
35 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2020-01-19T15:21:24.964166400Z")
36 public class Duration extends AbstractDoubleScalarRelWithAbs<TimeUnit, Time, DurationUnit, Duration>
37 {
38
39 private static final long serialVersionUID = 20150901L;
40
41
42 public static final Duration/scalar/Duration.html#Duration">Duration ZERO = new Duration(0.0, DurationUnit.SI);
43
44
45 public static final Duratione/scalar/Duration.html#Duration">Duration ONE = new Duration(1.0, DurationUnit.SI);
46
47
48 @SuppressWarnings("checkstyle:constantname")
49 public static final Duratione/scalar/Duration.html#Duration">Duration NaN = new Duration(Double.NaN, DurationUnit.SI);
50
51
52 public static final Durationion.html#Duration">Duration POSITIVE_INFINITY = new Duration(Double.POSITIVE_INFINITY, DurationUnit.SI);
53
54
55 public static final Durationion.html#Duration">Duration NEGATIVE_INFINITY = new Duration(Double.NEGATIVE_INFINITY, DurationUnit.SI);
56
57
58 public static final DurationDuration.html#Duration">Duration POS_MAXVALUE = new Duration(Double.MAX_VALUE, DurationUnit.SI);
59
60
61 public static final DurationDuration.html#Duration">Duration NEG_MAXVALUE = new Duration(-Double.MAX_VALUE, DurationUnit.SI);
62
63
64
65
66
67
68 public Duration(final double value, final DurationUnit unit)
69 {
70 super(value, unit);
71 }
72
73
74
75
76
77 public Durationouble/scalar/Duration.html#Duration">Duration(final Duration value)
78 {
79 super(value);
80 }
81
82
83 @Override
84 public final Duration instantiateRel(final double value, final DurationUnit unit)
85 {
86 return new Duration(value, unit);
87 }
88
89
90 @Override
91 public final Time instantiateAbs(final double value, final TimeUnit unit)
92 {
93 return new Time(value, unit);
94 }
95
96
97
98
99
100
101 public static final Duration instantiateSI(final double value)
102 {
103 return new Duration(value, DurationUnit.SI);
104 }
105
106
107
108
109
110
111
112
113 public static Durationscalar/Duration.html#Duration">Duration/Duration.html#Duration">Duration interpolate(final Durationscalar/Duration.html#Duration">Duration zero, final Duration one, final double ratio)
114 {
115 return new Duration(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
116 zero.getDisplayUnit());
117 }
118
119
120
121
122
123
124
125 public static Duratione/scalar/Duration.html#Duration">Duratione/scalar/Duration.html#Duration">Duration max(final Duratione/scalar/Duration.html#Duration">Duration r1, final Duration r2)
126 {
127 return r1.gt(r2) ? r1 : r2;
128 }
129
130
131
132
133
134
135
136
137 public static Duratione/scalar/Duration.html#Duration">Duratione/scalar/Duration.html#Duration">Duration max(final Duratione/scalar/Duration.html#Duration">Duration r1, final Duration r2, final Duration... rn)
138 {
139 Duration maxr = r1.gt(r2) ? r1 : r2;
140 for (Duration r : rn)
141 {
142 if (r.gt(maxr))
143 {
144 maxr = r;
145 }
146 }
147 return maxr;
148 }
149
150
151
152
153
154
155
156 public static Duratione/scalar/Duration.html#Duration">Duratione/scalar/Duration.html#Duration">Duration min(final Duratione/scalar/Duration.html#Duration">Duration r1, final Duration r2)
157 {
158 return r1.lt(r2) ? r1 : r2;
159 }
160
161
162
163
164
165
166
167
168 public static Duratione/scalar/Duration.html#Duration">Duratione/scalar/Duration.html#Duration">Duration min(final Duratione/scalar/Duration.html#Duration">Duration r1, final Duration r2, final Duration... rn)
169 {
170 Duration minr = r1.lt(r2) ? r1 : r2;
171 for (Duration r : rn)
172 {
173 if (r.lt(minr))
174 {
175 minr = r;
176 }
177 }
178 return minr;
179 }
180
181
182
183
184
185
186
187
188
189
190 public static Duration valueOf(final String text)
191 {
192 Throw.whenNull(text, "Error parsing Duration: text to parse is null");
193 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Duration: empty text to parse");
194 Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
195 if (matcher.find())
196 {
197 int index = matcher.end();
198 String unitString = text.substring(index).trim();
199 String valueString = text.substring(0, index).trim();
200 DurationUnit unit = DurationUnit.BASE.getUnitByAbbreviation(unitString);
201 if (unit != null)
202 {
203 double d = Double.parseDouble(valueString);
204 return new Duration(d, unit);
205 }
206 }
207 throw new IllegalArgumentException("Error parsing Duration from " + text);
208 }
209
210
211
212
213
214
215
216
217
218 public static Duration of(final double value, final String unitString)
219 {
220 Throw.whenNull(unitString, "Error parsing Duration: unitString is null");
221 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Duration: empty unitString");
222 DurationUnit unit = DurationUnit.BASE.getUnitByAbbreviation(unitString);
223 if (unit != null)
224 {
225 return new Duration(value, unit);
226 }
227 throw new IllegalArgumentException("Error parsing Duration with unit " + unitString);
228 }
229
230
231
232
233
234
235 public final Dimensionless divide(final Duration v)
236 {
237 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
238 }
239
240
241
242
243
244
245 public final Dimensionless times(final Frequency v)
246 {
247 return new Dimensionless(this.si * v.si, DimensionlessUnit.SI);
248 }
249
250
251
252
253
254
255 public final ElectricalCharge times(final ElectricalCurrent v)
256 {
257 return new ElectricalCharge(this.si * v.si, ElectricalChargeUnit.SI);
258 }
259
260
261
262
263
264
265 public final Mass times(final FlowMass v)
266 {
267 return new Mass(this.si * v.si, MassUnit.SI);
268 }
269
270
271
272
273
274
275 public final Volume times(final FlowVolume v)
276 {
277 return new Volume(this.si * v.si, VolumeUnit.SI);
278 }
279
280
281
282
283
284
285 public final Speed times(final Acceleration v)
286 {
287 return new Speed(this.si * v.si, SpeedUnit.SI);
288 }
289
290
291
292
293
294
295 public final Energy times(final Power v)
296 {
297 return new Energy(this.si * v.si, EnergyUnit.SI);
298 }
299
300
301
302
303
304
305 public final Length times(final Speed v)
306 {
307 return new Length(this.si * v.si, LengthUnit.SI);
308 }
309
310
311
312
313
314
315 public final MagneticFlux times(final ElectricalPotential v)
316 {
317 return new MagneticFlux(this.si * v.si, MagneticFluxUnit.SI);
318 }
319
320
321
322
323
324
325 public final ElectricalInductance times(final ElectricalResistance v)
326 {
327 return new ElectricalInductance(this.si * v.si, ElectricalInductanceUnit.SI);
328 }
329
330
331
332
333
334
335 public final ElectricalCapacitance times(final ElectricalConductance v)
336 {
337 return new ElectricalCapacitance(this.si * v.si, ElectricalCapacitanceUnit.SI);
338 }
339
340
341
342
343
344
345 public final Angle times(final AngularVelocity v)
346 {
347 return new Angle(this.si * v.si, AngleUnit.SI);
348 }
349
350
351
352
353
354
355 public final AngularVelocity times(final AngularAcceleration v)
356 {
357 return new AngularVelocity(this.si * v.si, AngularVelocityUnit.SI);
358 }
359
360 }