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.AbstractFloatScalarRel;
17 import org.djunits.value.vfloat.scalar.base.FloatScalar;
18 import org.djutils.base.NumberParser;
19 import org.djutils.exceptions.Throw;
20
21 import jakarta.annotation.Generated;
22
23
24
25
26
27
28
29
30
31
32 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-04-30T13:59:27.633664900Z")
33 public class FloatSpeed extends AbstractFloatScalarRel<SpeedUnit, FloatSpeed>
34 {
35
36 private static final long serialVersionUID = 20150901L;
37
38
39 public static final FloatSpeed ZERO = new FloatSpeed(0.0f, SpeedUnit.SI);
40
41
42 public static final FloatSpeed ONE = new FloatSpeed(1.0f, SpeedUnit.SI);
43
44
45 @SuppressWarnings("checkstyle:constantname")
46 public static final FloatSpeed NaN = new FloatSpeed(Float.NaN, SpeedUnit.SI);
47
48
49 public static final FloatSpeed POSITIVE_INFINITY = new FloatSpeed(Float.POSITIVE_INFINITY, SpeedUnit.SI);
50
51
52 public static final FloatSpeed NEGATIVE_INFINITY = new FloatSpeed(Float.NEGATIVE_INFINITY, SpeedUnit.SI);
53
54
55 public static final FloatSpeed POS_MAXVALUE = new FloatSpeed(Float.MAX_VALUE, SpeedUnit.SI);
56
57
58 public static final FloatSpeed NEG_MAXVALUE = new FloatSpeed(-Float.MAX_VALUE, SpeedUnit.SI);
59
60
61
62
63
64
65 public FloatSpeed(final float value, final SpeedUnit unit)
66 {
67 super(value, unit);
68 }
69
70
71
72
73
74 public FloatSpeed(final FloatSpeed value)
75 {
76 super(value);
77 }
78
79
80
81
82
83
84 public FloatSpeed(final double value, final SpeedUnit unit)
85 {
86 super((float) value, unit);
87 }
88
89
90 @Override
91 public final FloatSpeed instantiateRel(final float value, final SpeedUnit unit)
92 {
93 return new FloatSpeed(value, unit);
94 }
95
96
97
98
99
100
101 public static final FloatSpeed instantiateSI(final float value)
102 {
103 return new FloatSpeed(value, SpeedUnit.SI);
104 }
105
106
107
108
109
110
111
112
113 public static FloatSpeed interpolate(final FloatSpeed zero, final FloatSpeed one, final float ratio)
114 {
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 if (unit == null)
201 throw new IllegalArgumentException("Unit " + unitString + " not found");
202 return new FloatSpeed(f, unit);
203 }
204 catch (Exception exception)
205 {
206 throw new IllegalArgumentException(
207 "Error parsing FloatSpeed from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
208 exception);
209 }
210 }
211
212
213
214
215
216
217
218
219
220 public static FloatSpeed of(final float value, final String unitString)
221 {
222 Throw.whenNull(unitString, "Error parsing FloatSpeed: unitString is null");
223 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatSpeed: empty unitString");
224 SpeedUnit unit = SpeedUnit.BASE.getUnitByAbbreviation(unitString);
225 if (unit != null)
226 {
227 return new FloatSpeed(value, unit);
228 }
229 throw new IllegalArgumentException("Error parsing FloatSpeed with unit " + unitString);
230 }
231
232
233
234
235
236
237 public final FloatDimensionless divide(final FloatSpeed v)
238 {
239 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
240 }
241
242
243
244
245
246
247 public final FloatFlowVolume times(final FloatArea v)
248 {
249 return new FloatFlowVolume(this.si * v.si, FlowVolumeUnit.SI);
250 }
251
252
253
254
255
256
257 public final FloatPower times(final FloatForce v)
258 {
259 return new FloatPower(this.si * v.si, PowerUnit.SI);
260 }
261
262
263
264
265
266
267 public final FloatAcceleration times(final FloatFrequency v)
268 {
269 return new FloatAcceleration(this.si * v.si, AccelerationUnit.SI);
270 }
271
272
273
274
275
276
277 public final FloatFrequency divide(final FloatLength v)
278 {
279 return new FloatFrequency(this.si / v.si, FrequencyUnit.SI);
280 }
281
282
283
284
285
286
287 public final FloatLength divide(final FloatFrequency v)
288 {
289 return new FloatLength(this.si / v.si, LengthUnit.SI);
290 }
291
292
293
294
295
296
297 public final FloatFrequency times(final FloatLinearDensity v)
298 {
299 return new FloatFrequency(this.si * v.si, FrequencyUnit.SI);
300 }
301
302
303
304
305
306
307 public final FloatLength times(final FloatDuration v)
308 {
309 return new FloatLength(this.si * v.si, LengthUnit.SI);
310 }
311
312
313
314
315
316
317 public final FloatAcceleration divide(final FloatDuration v)
318 {
319 return new FloatAcceleration(this.si / v.si, AccelerationUnit.SI);
320 }
321
322
323
324
325
326
327 public final FloatDuration divide(final FloatAcceleration v)
328 {
329 return new FloatDuration(this.si / v.si, DurationUnit.SI);
330 }
331
332
333
334
335
336
337 public final FloatForce times(final FloatFlowMass v)
338 {
339 return new FloatForce(this.si * v.si, ForceUnit.SI);
340 }
341
342
343
344
345
346
347 public final FloatMomentum times(final FloatMass v)
348 {
349 return new FloatMomentum(this.si * v.si, MomentumUnit.SI);
350 }
351
352
353
354
355
356
357 public final FloatEnergy times(final FloatMomentum v)
358 {
359 return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
360 }
361
362
363 @Override
364 public FloatSIScalar reciprocal()
365 {
366 return FloatScalar.divide(FloatDimensionless.ONE, this);
367 }
368
369 }