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