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