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.DurationUnit;
11 import org.djunits.unit.EnergyUnit;
12 import org.djunits.unit.FlowVolumeUnit;
13 import org.djunits.unit.ForceUnit;
14 import org.djunits.unit.FrequencyUnit;
15 import org.djunits.unit.LengthUnit;
16 import org.djunits.unit.MomentumUnit;
17 import org.djunits.unit.PowerUnit;
18 import org.djunits.unit.SpeedUnit;
19 import org.djunits.value.util.ValueUtil;
20 import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRel;
21 import org.djunits.value.vdouble.scalar.base.DoubleScalar;
22
23
24
25
26
27
28
29
30
31
32 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2022-03-14T11:14:15.180987200Z")
33 public class Speed extends AbstractDoubleScalarRel<SpeedUnit, Speed>
34 {
35
36 private static final long serialVersionUID = 20150905L;
37
38
39 public static final Speedble/scalar/Speed.html#Speed">Speed ZERO = new Speed(0.0, SpeedUnit.SI);
40
41
42 public static final Speeduble/scalar/Speed.html#Speed">Speed ONE = new Speed(1.0, SpeedUnit.SI);
43
44
45 @SuppressWarnings("checkstyle:constantname")
46 public static final Speeduble/scalar/Speed.html#Speed">Speed NaN = new Speed(Double.NaN, SpeedUnit.SI);
47
48
49 public static final Speedeed.html#Speed">Speed POSITIVE_INFINITY = new Speed(Double.POSITIVE_INFINITY, SpeedUnit.SI);
50
51
52 public static final Speedeed.html#Speed">Speed NEGATIVE_INFINITY = new Speed(Double.NEGATIVE_INFINITY, SpeedUnit.SI);
53
54
55 public static final Speedar/Speed.html#Speed">Speed POS_MAXVALUE = new Speed(Double.MAX_VALUE, SpeedUnit.SI);
56
57
58 public static final Speedar/Speed.html#Speed">Speed NEG_MAXVALUE = new Speed(-Double.MAX_VALUE, SpeedUnit.SI);
59
60
61
62
63
64
65 public Speed(final double value, final SpeedUnit unit)
66 {
67 super(value, unit);
68 }
69
70
71
72
73
74 public Speed/vdouble/scalar/Speed.html#Speed">Speed(final Speed value)
75 {
76 super(value);
77 }
78
79
80 @Override
81 public final Speed instantiateRel(final double value, final SpeedUnit unit)
82 {
83 return new Speed(value, unit);
84 }
85
86
87
88
89
90
91 public static final Speed instantiateSI(final double value)
92 {
93 return new Speed(value, SpeedUnit.SI);
94 }
95
96
97
98
99
100
101
102
103 public static Speedle/scalar/Speed.html#Speed">Speedlar/Speed.html#Speed">Speed interpolate(final Speedle/scalar/Speed.html#Speed">Speed zero, final Speed one, final double ratio)
104 {
105 return new Speed(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio, zero.getDisplayUnit());
106 }
107
108
109
110
111
112
113
114 public static Speeduble/scalar/Speed.html#Speed">Speeduble/scalar/Speed.html#Speed">Speed max(final Speeduble/scalar/Speed.html#Speed">Speed r1, final Speed r2)
115 {
116 return r1.gt(r2) ? r1 : r2;
117 }
118
119
120
121
122
123
124
125
126 public static Speeduble/scalar/Speed.html#Speed">Speeduble/scalar/Speed.html#Speed">Speed max(final Speeduble/scalar/Speed.html#Speed">Speed r1, final Speed r2, final Speed... rn)
127 {
128 Speed maxr = r1.gt(r2) ? r1 : r2;
129 for (Speed r : rn)
130 {
131 if (r.gt(maxr))
132 {
133 maxr = r;
134 }
135 }
136 return maxr;
137 }
138
139
140
141
142
143
144
145 public static Speeduble/scalar/Speed.html#Speed">Speeduble/scalar/Speed.html#Speed">Speed min(final Speeduble/scalar/Speed.html#Speed">Speed r1, final Speed r2)
146 {
147 return r1.lt(r2) ? r1 : r2;
148 }
149
150
151
152
153
154
155
156
157 public static Speeduble/scalar/Speed.html#Speed">Speeduble/scalar/Speed.html#Speed">Speed min(final Speeduble/scalar/Speed.html#Speed">Speed r1, final Speed r2, final Speed... rn)
158 {
159 Speed minr = r1.lt(r2) ? r1 : r2;
160 for (Speed r : rn)
161 {
162 if (r.lt(minr))
163 {
164 minr = r;
165 }
166 }
167 return minr;
168 }
169
170
171
172
173
174
175
176
177
178
179 public static Speed valueOf(final String text)
180 {
181 Throw.whenNull(text, "Error parsing Speed: text to parse is null");
182 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Speed: empty text to parse");
183 Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
184 if (matcher.find())
185 {
186 int index = matcher.end();
187 String unitString = text.substring(index).trim();
188 String valueString = text.substring(0, index).trim();
189 SpeedUnit unit = SpeedUnit.BASE.getUnitByAbbreviation(unitString);
190 if (unit != null)
191 {
192 double d = Double.parseDouble(valueString);
193 return new Speed(d, unit);
194 }
195 }
196 throw new IllegalArgumentException("Error parsing Speed from " + text);
197 }
198
199
200
201
202
203
204
205
206
207 public static Speed of(final double value, final String unitString)
208 {
209 Throw.whenNull(unitString, "Error parsing Speed: unitString is null");
210 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Speed: empty unitString");
211 SpeedUnit unit = SpeedUnit.BASE.getUnitByAbbreviation(unitString);
212 if (unit != null)
213 {
214 return new Speed(value, unit);
215 }
216 throw new IllegalArgumentException("Error parsing Speed with unit " + unitString);
217 }
218
219
220
221
222
223
224 public final Dimensionless divide(final Speed v)
225 {
226 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
227 }
228
229
230
231
232
233
234 public final FlowVolume times(final Area v)
235 {
236 return new FlowVolume(this.si * v.si, FlowVolumeUnit.SI);
237 }
238
239
240
241
242
243
244 public final Power times(final Force v)
245 {
246 return new Power(this.si * v.si, PowerUnit.SI);
247 }
248
249
250
251
252
253
254 public final Acceleration times(final Frequency v)
255 {
256 return new Acceleration(this.si * v.si, AccelerationUnit.SI);
257 }
258
259
260
261
262
263
264 public final Frequency divide(final Length v)
265 {
266 return new Frequency(this.si / v.si, FrequencyUnit.SI);
267 }
268
269
270
271
272
273
274 public final Length divide(final Frequency v)
275 {
276 return new Length(this.si / v.si, LengthUnit.SI);
277 }
278
279
280
281
282
283
284 public final Frequency times(final LinearDensity v)
285 {
286 return new Frequency(this.si * v.si, FrequencyUnit.SI);
287 }
288
289
290
291
292
293
294 public final Length times(final Duration v)
295 {
296 return new Length(this.si * v.si, LengthUnit.SI);
297 }
298
299
300
301
302
303
304 public final Acceleration divide(final Duration v)
305 {
306 return new Acceleration(this.si / v.si, AccelerationUnit.SI);
307 }
308
309
310
311
312
313
314 public final Duration divide(final Acceleration v)
315 {
316 return new Duration(this.si / v.si, DurationUnit.SI);
317 }
318
319
320
321
322
323
324 public final Force times(final FlowMass v)
325 {
326 return new Force(this.si * v.si, ForceUnit.SI);
327 }
328
329
330
331
332
333
334 public final Momentum times(final Mass v)
335 {
336 return new Momentum(this.si * v.si, MomentumUnit.SI);
337 }
338
339
340
341
342
343
344 public final Energy times(final Momentum v)
345 {
346 return new Energy(this.si * v.si, EnergyUnit.SI);
347 }
348
349
350 @Override
351 public SIScalar reciprocal()
352 {
353 return DoubleScalar.divide(Dimensionless.ONE, this);
354 }
355
356 }