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