1 package org.djunits.value.vdouble.scalar;
2
3 import java.util.regex.Matcher;
4
5 import javax.annotation.Generated;
6
7 import org.djunits.Throw;
8 import org.djunits.unit.AccelerationUnit;
9 import org.djunits.unit.DimensionlessUnit;
10 import org.djunits.unit.ElectricalCurrentUnit;
11 import org.djunits.unit.ElectricalPotentialUnit;
12 import org.djunits.unit.EnergyUnit;
13 import org.djunits.unit.ForceUnit;
14 import org.djunits.unit.FrequencyUnit;
15 import org.djunits.unit.MomentumUnit;
16 import org.djunits.unit.PowerUnit;
17 import org.djunits.unit.SpeedUnit;
18 import org.djunits.value.util.ValueUtil;
19 import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRel;
20
21
22
23
24
25
26
27
28
29
30 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2020-01-19T15:21:24.964166400Z")
31 public class Power extends AbstractDoubleScalarRel<PowerUnit, Power>
32 {
33
34 private static final long serialVersionUID = 20150905L;
35
36
37 public static final Powerble/scalar/Power.html#Power">Power ZERO = new Power(0.0, PowerUnit.SI);
38
39
40 public static final Poweruble/scalar/Power.html#Power">Power ONE = new Power(1.0, PowerUnit.SI);
41
42
43 @SuppressWarnings("checkstyle:constantname")
44 public static final Poweruble/scalar/Power.html#Power">Power NaN = new Power(Double.NaN, PowerUnit.SI);
45
46
47 public static final Powerwer.html#Power">Power POSITIVE_INFINITY = new Power(Double.POSITIVE_INFINITY, PowerUnit.SI);
48
49
50 public static final Powerwer.html#Power">Power NEGATIVE_INFINITY = new Power(Double.NEGATIVE_INFINITY, PowerUnit.SI);
51
52
53 public static final Powerar/Power.html#Power">Power POS_MAXVALUE = new Power(Double.MAX_VALUE, PowerUnit.SI);
54
55
56 public static final Powerar/Power.html#Power">Power NEG_MAXVALUE = new Power(-Double.MAX_VALUE, PowerUnit.SI);
57
58
59
60
61
62
63 public Power(final double value, final PowerUnit unit)
64 {
65 super(value, unit);
66 }
67
68
69
70
71
72 public Power/vdouble/scalar/Power.html#Power">Power(final Power value)
73 {
74 super(value);
75 }
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 Powerle/scalar/Power.html#Power">Powerlar/Power.html#Power">Power interpolate(final Powerle/scalar/Power.html#Power">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 Poweruble/scalar/Power.html#Power">Poweruble/scalar/Power.html#Power">Power max(final Poweruble/scalar/Power.html#Power">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 Poweruble/scalar/Power.html#Power">Poweruble/scalar/Power.html#Power">Power max(final Poweruble/scalar/Power.html#Power">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 Poweruble/scalar/Power.html#Power">Poweruble/scalar/Power.html#Power">Power min(final Poweruble/scalar/Power.html#Power">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 Poweruble/scalar/Power.html#Power">Poweruble/scalar/Power.html#Power">Power min(final Poweruble/scalar/Power.html#Power">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 Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
182 if (matcher.find())
183 {
184 int index = matcher.end();
185 String unitString = text.substring(index).trim();
186 String valueString = text.substring(0, index).trim();
187 PowerUnit unit = PowerUnit.BASE.getUnitByAbbreviation(unitString);
188 if (unit != null)
189 {
190 double d = Double.parseDouble(valueString);
191 return new Power(d, unit);
192 }
193 }
194 throw new IllegalArgumentException("Error parsing Power from " + text);
195 }
196
197
198
199
200
201
202
203
204
205 public static Power of(final double value, final String unitString)
206 {
207 Throw.whenNull(unitString, "Error parsing Power: unitString is null");
208 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Power: empty unitString");
209 PowerUnit unit = PowerUnit.BASE.getUnitByAbbreviation(unitString);
210 if (unit != null)
211 {
212 return new Power(value, unit);
213 }
214 throw new IllegalArgumentException("Error parsing Power with unit " + unitString);
215 }
216
217
218
219
220
221
222 public final Dimensionless divide(final Power v)
223 {
224 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
225 }
226
227
228
229
230
231
232 public final Energy times(final Duration v)
233 {
234 return new Energy(this.si * v.si, EnergyUnit.SI);
235 }
236
237
238
239
240
241
242 public final Energy divide(final Frequency v)
243 {
244 return new Energy(this.si / v.si, EnergyUnit.SI);
245 }
246
247
248
249
250
251
252 public final Frequency divide(final Energy v)
253 {
254 return new Frequency(this.si / v.si, FrequencyUnit.SI);
255 }
256
257
258
259
260
261
262 public final Force divide(final Speed v)
263 {
264 return new Force(this.si / v.si, ForceUnit.SI);
265 }
266
267
268
269
270
271
272 public final Speed divide(final Force v)
273 {
274 return new Speed(this.si / v.si, SpeedUnit.SI);
275 }
276
277
278
279
280
281
282 public final ElectricalCurrent divide(final ElectricalPotential v)
283 {
284 return new ElectricalCurrent(this.si / v.si, ElectricalCurrentUnit.SI);
285 }
286
287
288
289
290
291
292 public final ElectricalPotential divide(final ElectricalCurrent v)
293 {
294 return new ElectricalPotential(this.si / v.si, ElectricalPotentialUnit.SI);
295 }
296
297
298
299
300
301
302 public final Momentum divide(final Acceleration v)
303 {
304 return new Momentum(this.si / v.si, MomentumUnit.SI);
305 }
306
307
308
309
310
311
312 public final Acceleration divide(final Momentum v)
313 {
314 return new Acceleration(this.si / v.si, AccelerationUnit.SI);
315 }
316
317 }