1 package org.djunits.value.vfloat.scalar;
2
3 import java.util.Locale;
4
5 import org.djunits.unit.AccelerationUnit;
6 import org.djunits.unit.DimensionlessUnit;
7 import org.djunits.unit.DurationUnit;
8 import org.djunits.unit.EnergyUnit;
9 import org.djunits.unit.FlowVolumeUnit;
10 import org.djunits.unit.ForceUnit;
11 import org.djunits.unit.FrequencyUnit;
12 import org.djunits.unit.LengthUnit;
13 import org.djunits.unit.MomentumUnit;
14 import org.djunits.unit.PowerUnit;
15 import org.djunits.unit.SpeedUnit;
16 import org.djunits.value.vfloat.scalar.base.FloatScalarRel;
17 import org.djutils.base.NumberParser;
18 import org.djutils.exceptions.Throw;
19
20 import jakarta.annotation.Generated;
21
22
23
24
25
26
27
28
29
30
31 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2025-09-06T15:16:28.380798Z")
32 public class FloatSpeed extends FloatScalarRel<SpeedUnit, FloatSpeed>
33 {
34
35 private static final long serialVersionUID = 20150901L;
36
37
38 public static final FloatSpeed ZERO = new FloatSpeed(0.0f, SpeedUnit.SI);
39
40
41 public static final FloatSpeed ONE = new FloatSpeed(1.0f, SpeedUnit.SI);
42
43
44 @SuppressWarnings("checkstyle:constantname")
45 public static final FloatSpeed NaN = new FloatSpeed(Float.NaN, SpeedUnit.SI);
46
47
48 public static final FloatSpeed POSITIVE_INFINITY = new FloatSpeed(Float.POSITIVE_INFINITY, SpeedUnit.SI);
49
50
51 public static final FloatSpeed NEGATIVE_INFINITY = new FloatSpeed(Float.NEGATIVE_INFINITY, SpeedUnit.SI);
52
53
54 public static final FloatSpeed POS_MAXVALUE = new FloatSpeed(Float.MAX_VALUE, SpeedUnit.SI);
55
56
57 public static final FloatSpeed NEG_MAXVALUE = new FloatSpeed(-Float.MAX_VALUE, SpeedUnit.SI);
58
59
60
61
62
63
64 public FloatSpeed(final float value, final SpeedUnit unit)
65 {
66 super(value, unit);
67 }
68
69
70
71
72
73 public FloatSpeed(final FloatSpeed value)
74 {
75 super(value);
76 }
77
78
79
80
81
82
83 public FloatSpeed(final double value, final SpeedUnit unit)
84 {
85 super((float) value, unit);
86 }
87
88 @Override
89 public final FloatSpeed instantiateRel(final float value, final SpeedUnit unit)
90 {
91 return new FloatSpeed(value, unit);
92 }
93
94
95
96
97
98
99 public static final FloatSpeed ofSI(final float value)
100 {
101 return new FloatSpeed(value, SpeedUnit.SI);
102 }
103
104
105
106
107
108
109
110
111 public static FloatSpeed interpolate(final FloatSpeed zero, final FloatSpeed one, final float ratio)
112 {
113 Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
114 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
115 return new FloatSpeed(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
116 zero.getDisplayUnit());
117 }
118
119
120
121
122
123
124
125 public static FloatSpeed max(final FloatSpeed r1, final FloatSpeed r2)
126 {
127 return r1.gt(r2) ? r1 : r2;
128 }
129
130
131
132
133
134
135
136
137 public static FloatSpeed max(final FloatSpeed r1, final FloatSpeed r2, final FloatSpeed... rn)
138 {
139 FloatSpeed maxr = r1.gt(r2) ? r1 : r2;
140 for (FloatSpeed 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 FloatSpeed min(final FloatSpeed r1, final FloatSpeed r2)
157 {
158 return r1.lt(r2) ? r1 : r2;
159 }
160
161
162
163
164
165
166
167
168 public static FloatSpeed min(final FloatSpeed r1, final FloatSpeed r2, final FloatSpeed... rn)
169 {
170 FloatSpeed minr = r1.lt(r2) ? r1 : r2;
171 for (FloatSpeed 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 FloatSpeed valueOf(final String text)
191 {
192 Throw.whenNull(text, "Error parsing FloatSpeed: text to parse is null");
193 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatSpeed: empty text to parse");
194 try
195 {
196 NumberParser numberParser = new NumberParser().lenient().trailing();
197 float f = numberParser.parseFloat(text);
198 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
199 SpeedUnit unit = SpeedUnit.BASE.getUnitByAbbreviation(unitString);
200 Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity Speed", unitString);
201 return new FloatSpeed(f, unit);
202 }
203 catch (Exception exception)
204 {
205 throw new IllegalArgumentException(
206 "Error parsing FloatSpeed from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
207 exception);
208 }
209 }
210
211
212
213
214
215
216
217
218
219 public static FloatSpeed of(final float value, final String unitString)
220 {
221 Throw.whenNull(unitString, "Error parsing FloatSpeed: unitString is null");
222 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatSpeed: empty unitString");
223 SpeedUnit unit = SpeedUnit.BASE.getUnitByAbbreviation(unitString);
224 Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FloatSpeed with unit %s", unitString);
225 return new FloatSpeed(value, unit);
226 }
227
228
229
230
231
232
233 public final FloatDimensionless divide(final FloatSpeed v)
234 {
235 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
236 }
237
238
239
240
241
242
243 public final FloatFlowVolume times(final FloatArea v)
244 {
245 return new FloatFlowVolume(this.si * v.si, FlowVolumeUnit.SI);
246 }
247
248
249
250
251
252
253 public final FloatPower times(final FloatForce v)
254 {
255 return new FloatPower(this.si * v.si, PowerUnit.SI);
256 }
257
258
259
260
261
262
263 public final FloatAcceleration times(final FloatFrequency v)
264 {
265 return new FloatAcceleration(this.si * v.si, AccelerationUnit.SI);
266 }
267
268
269
270
271
272
273 public final FloatFrequency divide(final FloatLength v)
274 {
275 return new FloatFrequency(this.si / v.si, FrequencyUnit.SI);
276 }
277
278
279
280
281
282
283 public final FloatLength divide(final FloatFrequency v)
284 {
285 return new FloatLength(this.si / v.si, LengthUnit.SI);
286 }
287
288
289
290
291
292
293 public final FloatFrequency times(final FloatLinearDensity v)
294 {
295 return new FloatFrequency(this.si * v.si, FrequencyUnit.SI);
296 }
297
298
299
300
301
302
303 public final FloatLength times(final FloatDuration v)
304 {
305 return new FloatLength(this.si * v.si, LengthUnit.SI);
306 }
307
308
309
310
311
312
313 public final FloatAcceleration divide(final FloatDuration v)
314 {
315 return new FloatAcceleration(this.si / v.si, AccelerationUnit.SI);
316 }
317
318
319
320
321
322
323 public final FloatDuration divide(final FloatAcceleration v)
324 {
325 return new FloatDuration(this.si / v.si, DurationUnit.SI);
326 }
327
328
329
330
331
332
333 public final FloatForce times(final FloatFlowMass v)
334 {
335 return new FloatForce(this.si * v.si, ForceUnit.SI);
336 }
337
338
339
340
341
342
343 public final FloatMomentum times(final FloatMass v)
344 {
345 return new FloatMomentum(this.si * v.si, MomentumUnit.SI);
346 }
347
348
349
350
351
352
353 public final FloatEnergy times(final FloatMomentum v)
354 {
355 return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
356 }
357
358 @Override
359 public FloatSIScalar reciprocal()
360 {
361 return FloatSIScalar.divide(FloatDimensionless.ONE, this);
362 }
363
364
365
366
367
368
369
370 public static FloatSpeed multiply(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
371 {
372 Throw.whenNull(scalar1, "scalar1 cannot be null");
373 Throw.whenNull(scalar2, "scalar2 cannot be null");
374 Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
375 .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(SpeedUnit.BASE.getSiDimensions()),
376 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type FloatSpeed",
377 scalar1.toDisplayString(), scalar2.toDisplayString());
378 return new FloatSpeed(scalar1.si * scalar2.si, SpeedUnit.SI);
379 }
380
381
382
383
384
385
386
387 public static FloatSpeed divide(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
388 {
389 Throw.whenNull(scalar1, "scalar1 cannot be null");
390 Throw.whenNull(scalar2, "scalar2 cannot be null");
391 Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
392 .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(SpeedUnit.BASE.getSiDimensions()),
393 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type FloatSpeed",
394 scalar1.toDisplayString(), scalar2.toDisplayString());
395 return new FloatSpeed(scalar1.si / scalar2.si, SpeedUnit.SI);
396 }
397
398 }