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