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