1 package org.djunits.value.vfloat.scalar;
2
3 import java.util.Locale;
4
5 import org.djunits.unit.AngleUnit;
6 import org.djunits.unit.AngularVelocityUnit;
7 import org.djunits.unit.DimensionlessUnit;
8 import org.djunits.unit.DurationUnit;
9 import org.djunits.unit.ElectricalCapacitanceUnit;
10 import org.djunits.unit.ElectricalChargeUnit;
11 import org.djunits.unit.ElectricalInductanceUnit;
12 import org.djunits.unit.EnergyUnit;
13 import org.djunits.unit.LengthUnit;
14 import org.djunits.unit.MagneticFluxUnit;
15 import org.djunits.unit.MassUnit;
16 import org.djunits.unit.SpeedUnit;
17 import org.djunits.unit.TimeUnit;
18 import org.djunits.unit.VolumeUnit;
19 import org.djunits.value.vfloat.scalar.base.FloatScalarRelWithAbs;
20 import org.djutils.base.NumberParser;
21 import org.djutils.exceptions.Throw;
22
23 import jakarta.annotation.Generated;
24
25
26
27
28
29
30
31
32
33
34
35 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
36 public class FloatDuration extends FloatScalarRelWithAbs<TimeUnit, FloatTime, DurationUnit, FloatDuration>
37 {
38
39 private static final long serialVersionUID = 20150901L;
40
41
42 public static final FloatDuration ZERO = new FloatDuration(0.0f, DurationUnit.SI);
43
44
45 public static final FloatDuration ONE = new FloatDuration(1.0f, DurationUnit.SI);
46
47
48 @SuppressWarnings("checkstyle:constantname")
49 public static final FloatDuration NaN = new FloatDuration(Float.NaN, DurationUnit.SI);
50
51
52 public static final FloatDuration POSITIVE_INFINITY = new FloatDuration(Float.POSITIVE_INFINITY, DurationUnit.SI);
53
54
55 public static final FloatDuration NEGATIVE_INFINITY = new FloatDuration(Float.NEGATIVE_INFINITY, DurationUnit.SI);
56
57
58 public static final FloatDuration POS_MAXVALUE = new FloatDuration(Float.MAX_VALUE, DurationUnit.SI);
59
60
61 public static final FloatDuration NEG_MAXVALUE = new FloatDuration(-Float.MAX_VALUE, DurationUnit.SI);
62
63
64
65
66
67
68 public FloatDuration(final float value, final DurationUnit unit)
69 {
70 super(value, unit);
71 }
72
73
74
75
76
77 public FloatDuration(final FloatDuration value)
78 {
79 super(value);
80 }
81
82
83
84
85
86
87 public FloatDuration(final double value, final DurationUnit unit)
88 {
89 super((float) value, unit);
90 }
91
92 @Override
93 public final FloatDuration instantiateRel(final float value, final DurationUnit unit)
94 {
95 return new FloatDuration(value, unit);
96 }
97
98
99
100
101
102
103 public static final FloatDuration instantiateSI(final float value)
104 {
105 return new FloatDuration(value, DurationUnit.SI);
106 }
107
108 @Override
109 public final FloatTime instantiateAbs(final float value, final TimeUnit unit)
110 {
111 return new FloatTime(value, unit);
112 }
113
114
115
116
117
118
119
120
121 public static FloatDuration interpolate(final FloatDuration zero, final FloatDuration one, final float ratio)
122 {
123 return new FloatDuration(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
124 zero.getDisplayUnit());
125 }
126
127
128
129
130
131
132
133 public static FloatDuration max(final FloatDuration r1, final FloatDuration r2)
134 {
135 return r1.gt(r2) ? r1 : r2;
136 }
137
138
139
140
141
142
143
144
145 public static FloatDuration max(final FloatDuration r1, final FloatDuration r2, final FloatDuration... rn)
146 {
147 FloatDuration maxr = r1.gt(r2) ? r1 : r2;
148 for (FloatDuration r : rn)
149 {
150 if (r.gt(maxr))
151 {
152 maxr = r;
153 }
154 }
155 return maxr;
156 }
157
158
159
160
161
162
163
164 public static FloatDuration min(final FloatDuration r1, final FloatDuration r2)
165 {
166 return r1.lt(r2) ? r1 : r2;
167 }
168
169
170
171
172
173
174
175
176 public static FloatDuration min(final FloatDuration r1, final FloatDuration r2, final FloatDuration... rn)
177 {
178 FloatDuration minr = r1.lt(r2) ? r1 : r2;
179 for (FloatDuration r : rn)
180 {
181 if (r.lt(minr))
182 {
183 minr = r;
184 }
185 }
186 return minr;
187 }
188
189
190
191
192
193
194
195
196
197
198 public static FloatDuration valueOf(final String text)
199 {
200 Throw.whenNull(text, "Error parsing FloatDuration: text to parse is null");
201 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatDuration: empty text to parse");
202 try
203 {
204 NumberParser numberParser = new NumberParser().lenient().trailing();
205 float f = numberParser.parseFloat(text);
206 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
207 DurationUnit unit = DurationUnit.BASE.getUnitByAbbreviation(unitString);
208 if (unit == null)
209 throw new IllegalArgumentException("Unit " + unitString + " not found");
210 return new FloatDuration(f, unit);
211 }
212 catch (Exception exception)
213 {
214 throw new IllegalArgumentException(
215 "Error parsing FloatDuration from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
216 exception);
217 }
218 }
219
220
221
222
223
224
225
226
227
228 public static FloatDuration of(final float value, final String unitString)
229 {
230 Throw.whenNull(unitString, "Error parsing FloatDuration: unitString is null");
231 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatDuration: empty unitString");
232 DurationUnit unit = DurationUnit.BASE.getUnitByAbbreviation(unitString);
233 if (unit != null)
234 {
235 return new FloatDuration(value, unit);
236 }
237 throw new IllegalArgumentException("Error parsing FloatDuration with unit " + unitString);
238 }
239
240
241
242
243
244
245 public final FloatDimensionless divide(final FloatDuration v)
246 {
247 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
248 }
249
250
251
252
253
254
255 public final FloatDimensionless times(final FloatFrequency v)
256 {
257 return new FloatDimensionless(this.si * v.si, DimensionlessUnit.SI);
258 }
259
260
261
262
263
264
265
266 public final FloatElectricalCharge times(final FloatElectricalCurrent v)
267 {
268 return new FloatElectricalCharge(this.si * v.si, ElectricalChargeUnit.SI);
269 }
270
271
272
273
274
275
276 public final FloatMass times(final FloatFlowMass v)
277 {
278 return new FloatMass(this.si * v.si, MassUnit.SI);
279 }
280
281
282
283
284
285
286 public final FloatVolume times(final FloatFlowVolume v)
287 {
288 return new FloatVolume(this.si * v.si, VolumeUnit.SI);
289 }
290
291
292
293
294
295
296 public final FloatSpeed times(final FloatAcceleration v)
297 {
298 return new FloatSpeed(this.si * v.si, SpeedUnit.SI);
299 }
300
301
302
303
304
305
306 public final FloatEnergy times(final FloatPower v)
307 {
308 return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
309 }
310
311
312
313
314
315
316 public final FloatLength times(final FloatSpeed v)
317 {
318 return new FloatLength(this.si * v.si, LengthUnit.SI);
319 }
320
321
322
323
324
325
326 public final FloatMagneticFlux times(final FloatElectricalPotential v)
327 {
328 return new FloatMagneticFlux(this.si * v.si, MagneticFluxUnit.SI);
329 }
330
331
332
333
334
335
336
337 public final FloatElectricalInductance times(final FloatElectricalResistance v)
338 {
339 return new FloatElectricalInductance(this.si * v.si, ElectricalInductanceUnit.SI);
340 }
341
342
343
344
345
346
347
348 public final FloatElectricalCapacitance times(final FloatElectricalConductance v)
349 {
350 return new FloatElectricalCapacitance(this.si * v.si, ElectricalCapacitanceUnit.SI);
351 }
352
353
354
355
356
357
358 public final FloatAngle times(final FloatAngularVelocity v)
359 {
360 return new FloatAngle(this.si * v.si, AngleUnit.SI);
361 }
362
363
364
365
366
367
368
369 public final FloatAngularVelocity times(final FloatAngularAcceleration v)
370 {
371 return new FloatAngularVelocity(this.si * v.si, AngularVelocityUnit.SI);
372 }
373
374 @Override
375 public FloatFrequency reciprocal()
376 {
377 return FloatFrequency.instantiateSI(1.0f / this.si);
378 }
379
380 }