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