1 package org.djunits.value.vfloat.scalar;
2
3 import java.util.regex.Matcher;
4
5 import org.djunits.unit.AccelerationUnit;
6 import org.djunits.unit.DimensionlessUnit;
7 import org.djunits.unit.DurationUnit;
8 import org.djunits.unit.FlowVolumeUnit;
9 import org.djunits.unit.ForceUnit;
10 import org.djunits.unit.FrequencyUnit;
11 import org.djunits.unit.LengthUnit;
12 import org.djunits.unit.PowerUnit;
13 import org.djunits.unit.SpeedUnit;
14 import org.djunits.unit.Unit;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public class FloatSpeed extends AbstractFloatScalarRel<SpeedUnit, FloatSpeed>
41 {
42
43 private static final long serialVersionUID = 20150901L;
44
45
46 public static final FloatSpeed ZERO = new FloatSpeed(0.0f, SpeedUnit.SI);
47
48
49 @SuppressWarnings("checkstyle:constantname")
50 public static final FloatSpeed NaN = new FloatSpeed(Float.NaN, SpeedUnit.SI);
51
52
53 public static final FloatSpeed POSITIVE_INFINITY = new FloatSpeed(Float.POSITIVE_INFINITY, SpeedUnit.SI);
54
55
56 public static final FloatSpeed NEGATIVE_INFINITY = new FloatSpeed(Float.NEGATIVE_INFINITY, SpeedUnit.SI);
57
58
59 public static final FloatSpeed POS_MAXVALUE = new FloatSpeed(Float.MAX_VALUE, SpeedUnit.SI);
60
61
62 public static final FloatSpeed NEG_MAXVALUE = new FloatSpeed(-Float.MAX_VALUE, SpeedUnit.SI);
63
64
65
66
67
68
69 public FloatSpeed(final float value, final SpeedUnit unit)
70 {
71 super(value, unit);
72 }
73
74
75
76
77
78 public FloatSpeed(final FloatSpeed value)
79 {
80 super(value);
81 }
82
83
84
85
86
87
88 public FloatSpeed(final double value, final SpeedUnit unit)
89 {
90 super((float) value, unit);
91 }
92
93
94 @Override
95 public final FloatSpeed instantiateRel(final float value, final SpeedUnit unit)
96 {
97 return new FloatSpeed(value, unit);
98 }
99
100
101
102
103
104
105 public static final FloatSpeed createSI(final float value)
106 {
107 return new FloatSpeed(value, SpeedUnit.SI);
108 }
109
110
111
112
113
114
115
116
117 public static FloatSpeed interpolate(final FloatSpeed zero, final FloatSpeed one, final float ratio)
118 {
119 return new FloatSpeed(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
120 }
121
122
123
124
125
126
127
128 public static FloatSpeed max(final FloatSpeed r1, final FloatSpeed r2)
129 {
130 return (r1.gt(r2)) ? r1 : r2;
131 }
132
133
134
135
136
137
138
139
140 public static FloatSpeed max(final FloatSpeed r1, final FloatSpeed r2, final FloatSpeed... rn)
141 {
142 FloatSpeed maxr = (r1.gt(r2)) ? r1 : r2;
143 for (FloatSpeed r : rn)
144 {
145 if (r.gt(maxr))
146 {
147 maxr = r;
148 }
149 }
150 return maxr;
151 }
152
153
154
155
156
157
158
159 public static FloatSpeed min(final FloatSpeed r1, final FloatSpeed r2)
160 {
161 return (r1.lt(r2)) ? r1 : r2;
162 }
163
164
165
166
167
168
169
170
171 public static FloatSpeed min(final FloatSpeed r1, final FloatSpeed r2, final FloatSpeed... rn)
172 {
173 FloatSpeed minr = (r1.lt(r2)) ? r1 : r2;
174 for (FloatSpeed r : rn)
175 {
176 if (r.lt(minr))
177 {
178 minr = r;
179 }
180 }
181 return minr;
182 }
183
184
185
186
187
188
189
190
191
192 public static FloatSpeed valueOf(final String text) throws IllegalArgumentException
193 {
194 if (text == null || text.length() == 0)
195 {
196 throw new IllegalArgumentException("Error parsing FloatSpeed -- null or empty argument");
197 }
198 Matcher matcher = NUMBER_PATTERN.matcher(text);
199 if (matcher.find())
200 {
201 int index = matcher.end();
202 try
203 {
204 String unitString = text.substring(index).trim();
205 String valueString = text.substring(0, index).trim();
206 for (SpeedUnit unit : Unit.getUnits(SpeedUnit.class))
207 {
208 if (unit.getDefaultLocaleTextualRepresentations().contains(unitString))
209 {
210 float f = Float.parseFloat(valueString);
211 return new FloatSpeed(f, unit);
212 }
213 }
214 }
215 catch (Exception exception)
216 {
217 throw new IllegalArgumentException("Error parsing FloatSpeed from " + text, exception);
218 }
219 }
220 throw new IllegalArgumentException("Error parsing FloatSpeed from " + text);
221 }
222
223
224
225
226
227
228 public final FloatDimensionless divideBy(final FloatSpeed v)
229 {
230 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
231 }
232
233
234
235
236
237
238 public final FloatFlowVolume multiplyBy(final FloatArea v)
239 {
240 return new FloatFlowVolume(this.si * v.si, FlowVolumeUnit.SI);
241 }
242
243
244
245
246
247
248 public final FloatPower multiplyBy(final FloatForce v)
249 {
250 return new FloatPower(this.si * v.si, PowerUnit.SI);
251 }
252
253
254
255
256
257
258 public final FloatAcceleration multiplyBy(final FloatFrequency v)
259 {
260 return new FloatAcceleration(this.si * v.si, AccelerationUnit.SI);
261 }
262
263
264
265
266
267
268 public final FloatFrequency divideBy(final FloatLength v)
269 {
270 return new FloatFrequency(this.si / v.si, FrequencyUnit.SI);
271 }
272
273
274
275
276
277
278 public final FloatLength divideBy(final FloatFrequency v)
279 {
280 return new FloatLength(this.si / v.si, LengthUnit.SI);
281 }
282
283
284
285
286
287
288 public final FloatFrequency multiplyBy(final FloatLinearDensity v)
289 {
290 return new FloatFrequency(this.si * v.si, FrequencyUnit.SI);
291 }
292
293
294
295
296
297
298 public final FloatLength multiplyBy(final FloatDuration v)
299 {
300 return new FloatLength(this.si * v.si, LengthUnit.SI);
301 }
302
303
304
305
306
307
308 public final FloatAcceleration divideBy(final FloatDuration v)
309 {
310 return new FloatAcceleration(this.si / v.si, AccelerationUnit.SI);
311 }
312
313
314
315
316
317
318 public final FloatDuration divideBy(final FloatAcceleration v)
319 {
320 return new FloatDuration(this.si / v.si, DurationUnit.SI);
321 }
322
323
324
325
326
327
328 public final FloatForce multiplyBy(final FloatFlowMass v)
329 {
330 return new FloatForce(this.si * v.si, ForceUnit.SI);
331 }
332
333 }