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