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.DimensionlessUnit;
9 import org.djunits.unit.DurationUnit;
10 import org.djunits.unit.EnergyUnit;
11 import org.djunits.unit.ForceUnit;
12 import org.djunits.unit.LengthUnit;
13 import org.djunits.unit.MomentumUnit;
14 import org.djunits.unit.PowerUnit;
15 import org.djunits.unit.PressureUnit;
16 import org.djunits.unit.SpeedUnit;
17 import org.djunits.unit.VolumeUnit;
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 Energy extends AbstractDoubleScalarRel<EnergyUnit, Energy>
32 {
33
34 private static final long serialVersionUID = 20150905L;
35
36
37 public static final Energyle/scalar/Energy.html#Energy">Energy ZERO = new Energy(0.0, EnergyUnit.SI);
38
39
40 public static final Energyble/scalar/Energy.html#Energy">Energy ONE = new Energy(1.0, EnergyUnit.SI);
41
42
43 @SuppressWarnings("checkstyle:constantname")
44 public static final Energyble/scalar/Energy.html#Energy">Energy NaN = new Energy(Double.NaN, EnergyUnit.SI);
45
46
47 public static final Energyrgy.html#Energy">Energy POSITIVE_INFINITY = new Energy(Double.POSITIVE_INFINITY, EnergyUnit.SI);
48
49
50 public static final Energyrgy.html#Energy">Energy NEGATIVE_INFINITY = new Energy(Double.NEGATIVE_INFINITY, EnergyUnit.SI);
51
52
53 public static final Energyr/Energy.html#Energy">Energy POS_MAXVALUE = new Energy(Double.MAX_VALUE, EnergyUnit.SI);
54
55
56 public static final Energyr/Energy.html#Energy">Energy NEG_MAXVALUE = new Energy(-Double.MAX_VALUE, EnergyUnit.SI);
57
58
59
60
61
62
63 public Energy(final double value, final EnergyUnit unit)
64 {
65 super(value, unit);
66 }
67
68
69
70
71
72 public Energyvdouble/scalar/Energy.html#Energy">Energy(final Energy value)
73 {
74 super(value);
75 }
76
77
78 @Override
79 public final Energy instantiateRel(final double value, final EnergyUnit unit)
80 {
81 return new Energy(value, unit);
82 }
83
84
85
86
87
88
89 public static final Energy instantiateSI(final double value)
90 {
91 return new Energy(value, EnergyUnit.SI);
92 }
93
94
95
96
97
98
99
100
101 public static Energye/scalar/Energy.html#Energy">Energyar/Energy.html#Energy">Energy interpolate(final Energye/scalar/Energy.html#Energy">Energy zero, final Energy one, final double ratio)
102 {
103 return new Energy(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio, zero.getDisplayUnit());
104 }
105
106
107
108
109
110
111
112 public static Energyble/scalar/Energy.html#Energy">Energyble/scalar/Energy.html#Energy">Energy max(final Energyble/scalar/Energy.html#Energy">Energy r1, final Energy r2)
113 {
114 return r1.gt(r2) ? r1 : r2;
115 }
116
117
118
119
120
121
122
123
124 public static Energyble/scalar/Energy.html#Energy">Energyble/scalar/Energy.html#Energy">Energy max(final Energyble/scalar/Energy.html#Energy">Energy r1, final Energy r2, final Energy... rn)
125 {
126 Energy maxr = r1.gt(r2) ? r1 : r2;
127 for (Energy 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 Energyble/scalar/Energy.html#Energy">Energyble/scalar/Energy.html#Energy">Energy min(final Energyble/scalar/Energy.html#Energy">Energy r1, final Energy r2)
144 {
145 return r1.lt(r2) ? r1 : r2;
146 }
147
148
149
150
151
152
153
154
155 public static Energyble/scalar/Energy.html#Energy">Energyble/scalar/Energy.html#Energy">Energy min(final Energyble/scalar/Energy.html#Energy">Energy r1, final Energy r2, final Energy... rn)
156 {
157 Energy minr = r1.lt(r2) ? r1 : r2;
158 for (Energy 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 Energy valueOf(final String text)
178 {
179 Throw.whenNull(text, "Error parsing Energy: text to parse is null");
180 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Energy: 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 EnergyUnit unit = EnergyUnit.BASE.getUnitByAbbreviation(unitString);
188 if (unit != null)
189 {
190 double d = Double.parseDouble(valueString);
191 return new Energy(d, unit);
192 }
193 }
194 throw new IllegalArgumentException("Error parsing Energy from " + text);
195 }
196
197
198
199
200
201
202
203
204
205 public static Energy of(final double value, final String unitString)
206 {
207 Throw.whenNull(unitString, "Error parsing Energy: unitString is null");
208 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Energy: empty unitString");
209 EnergyUnit unit = EnergyUnit.BASE.getUnitByAbbreviation(unitString);
210 if (unit != null)
211 {
212 return new Energy(value, unit);
213 }
214 throw new IllegalArgumentException("Error parsing Energy with unit " + unitString);
215 }
216
217
218
219
220
221
222 public final Dimensionless divide(final Energy v)
223 {
224 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
225 }
226
227
228
229
230
231
232 public final Length divide(final Force v)
233 {
234 return new Length(this.si / v.si, LengthUnit.SI);
235 }
236
237
238
239
240
241
242 public final Force divide(final Length v)
243 {
244 return new Force(this.si / v.si, ForceUnit.SI);
245 }
246
247
248
249
250
251
252 public final Force times(final LinearDensity v)
253 {
254 return new Force(this.si * v.si, ForceUnit.SI);
255 }
256
257
258
259
260
261
262 public final Power divide(final Duration v)
263 {
264 return new Power(this.si / v.si, PowerUnit.SI);
265 }
266
267
268
269
270
271
272 public final Duration divide(final Power v)
273 {
274 return new Duration(this.si / v.si, DurationUnit.SI);
275 }
276
277
278
279
280
281
282 public final Pressure divide(final Volume v)
283 {
284 return new Pressure(this.si / v.si, PressureUnit.SI);
285 }
286
287
288
289
290
291
292 public final Volume divide(final Pressure v)
293 {
294 return new Volume(this.si / v.si, VolumeUnit.SI);
295 }
296
297
298
299
300
301
302 public final Power times(final Frequency v)
303 {
304 return new Power(this.si * v.si, PowerUnit.SI);
305 }
306
307
308
309
310
311
312 public final Momentum divide(final Speed v)
313 {
314 return new Momentum(this.si / v.si, MomentumUnit.SI);
315 }
316
317
318
319
320
321
322 public final Speed divide(final Momentum v)
323 {
324 return new Speed(this.si / v.si, SpeedUnit.SI);
325 }
326
327 }