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