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