1 package org.djunits.value.vfloat.scalar;
2
3 import java.util.Locale;
4
5 import org.djunits.unit.DimensionlessUnit;
6 import org.djunits.unit.ForceUnit;
7 import org.djunits.unit.FrequencyUnit;
8 import org.djunits.unit.LengthUnit;
9 import org.djunits.unit.LinearDensityUnit;
10 import org.djunits.value.vfloat.scalar.base.FloatScalarRel;
11 import org.djutils.base.NumberParser;
12 import org.djutils.exceptions.Throw;
13
14 import jakarta.annotation.Generated;
15
16
17
18
19
20
21
22
23
24
25 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
26 public class FloatLinearDensity extends FloatScalarRel<LinearDensityUnit, FloatLinearDensity>
27 {
28
29 private static final long serialVersionUID = 20150901L;
30
31
32 public static final FloatLinearDensity ZERO = new FloatLinearDensity(0.0f, LinearDensityUnit.SI);
33
34
35 public static final FloatLinearDensity ONE = new FloatLinearDensity(1.0f, LinearDensityUnit.SI);
36
37
38 @SuppressWarnings("checkstyle:constantname")
39 public static final FloatLinearDensity NaN = new FloatLinearDensity(Float.NaN, LinearDensityUnit.SI);
40
41
42 public static final FloatLinearDensity POSITIVE_INFINITY =
43 new FloatLinearDensity(Float.POSITIVE_INFINITY, LinearDensityUnit.SI);
44
45
46 public static final FloatLinearDensity NEGATIVE_INFINITY =
47 new FloatLinearDensity(Float.NEGATIVE_INFINITY, LinearDensityUnit.SI);
48
49
50 public static final FloatLinearDensity POS_MAXVALUE = new FloatLinearDensity(Float.MAX_VALUE, LinearDensityUnit.SI);
51
52
53 public static final FloatLinearDensity NEG_MAXVALUE = new FloatLinearDensity(-Float.MAX_VALUE, LinearDensityUnit.SI);
54
55
56
57
58
59
60 public FloatLinearDensity(final float value, final LinearDensityUnit unit)
61 {
62 super(value, unit);
63 }
64
65
66
67
68
69 public FloatLinearDensity(final FloatLinearDensity value)
70 {
71 super(value);
72 }
73
74
75
76
77
78
79 public FloatLinearDensity(final double value, final LinearDensityUnit unit)
80 {
81 super((float) value, unit);
82 }
83
84 @Override
85 public final FloatLinearDensity instantiateRel(final float value, final LinearDensityUnit unit)
86 {
87 return new FloatLinearDensity(value, unit);
88 }
89
90
91
92
93
94
95 public static final FloatLinearDensity instantiateSI(final float value)
96 {
97 return new FloatLinearDensity(value, LinearDensityUnit.SI);
98 }
99
100
101
102
103
104
105
106
107 public static FloatLinearDensity interpolate(final FloatLinearDensity zero, final FloatLinearDensity one, final float ratio)
108 {
109 return new FloatLinearDensity(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
110 zero.getDisplayUnit());
111 }
112
113
114
115
116
117
118
119 public static FloatLinearDensity max(final FloatLinearDensity r1, final FloatLinearDensity r2)
120 {
121 return r1.gt(r2) ? r1 : r2;
122 }
123
124
125
126
127
128
129
130
131 public static FloatLinearDensity max(final FloatLinearDensity r1, final FloatLinearDensity r2,
132 final FloatLinearDensity... rn)
133 {
134 FloatLinearDensity maxr = r1.gt(r2) ? r1 : r2;
135 for (FloatLinearDensity 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 FloatLinearDensity min(final FloatLinearDensity r1, final FloatLinearDensity r2)
152 {
153 return r1.lt(r2) ? r1 : r2;
154 }
155
156
157
158
159
160
161
162
163 public static FloatLinearDensity min(final FloatLinearDensity r1, final FloatLinearDensity r2,
164 final FloatLinearDensity... rn)
165 {
166 FloatLinearDensity minr = r1.lt(r2) ? r1 : r2;
167 for (FloatLinearDensity r : rn)
168 {
169 if (r.lt(minr))
170 {
171 minr = r;
172 }
173 }
174 return minr;
175 }
176
177
178
179
180
181
182
183
184
185
186 public static FloatLinearDensity valueOf(final String text)
187 {
188 Throw.whenNull(text, "Error parsing FloatLinearDensity: text to parse is null");
189 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatLinearDensity: empty text to parse");
190 try
191 {
192 NumberParser numberParser = new NumberParser().lenient().trailing();
193 float f = numberParser.parseFloat(text);
194 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
195 LinearDensityUnit unit = LinearDensityUnit.BASE.getUnitByAbbreviation(unitString);
196 if (unit == null)
197 throw new IllegalArgumentException("Unit " + unitString + " not found");
198 return new FloatLinearDensity(f, unit);
199 }
200 catch (Exception exception)
201 {
202 throw new IllegalArgumentException("Error parsing FloatLinearDensity from " + text + " using Locale "
203 + Locale.getDefault(Locale.Category.FORMAT), exception);
204 }
205 }
206
207
208
209
210
211
212
213
214
215 public static FloatLinearDensity of(final float value, final String unitString)
216 {
217 Throw.whenNull(unitString, "Error parsing FloatLinearDensity: unitString is null");
218 Throw.when(unitString.length() == 0, IllegalArgumentException.class,
219 "Error parsing FloatLinearDensity: empty unitString");
220 LinearDensityUnit unit = LinearDensityUnit.BASE.getUnitByAbbreviation(unitString);
221 if (unit != null)
222 {
223 return new FloatLinearDensity(value, unit);
224 }
225 throw new IllegalArgumentException("Error parsing FloatLinearDensity with unit " + unitString);
226 }
227
228
229
230
231
232
233 public final FloatDimensionless divide(final FloatLinearDensity v)
234 {
235 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
236 }
237
238
239
240
241
242
243 public final FloatDimensionless times(final FloatLength v)
244 {
245 return new FloatDimensionless(this.si * v.si, DimensionlessUnit.SI);
246 }
247
248
249
250
251
252
253 public final FloatLength times(final FloatArea v)
254 {
255 return new FloatLength(this.si * v.si, LengthUnit.SI);
256 }
257
258
259
260
261
262
263 public final FloatForce times(final FloatEnergy v)
264 {
265 return new FloatForce(this.si * v.si, ForceUnit.SI);
266 }
267
268
269
270
271
272
273 public final FloatFrequency times(final FloatSpeed v)
274 {
275 return new FloatFrequency(this.si * v.si, FrequencyUnit.SI);
276 }
277
278 @Override
279 public FloatLength reciprocal()
280 {
281 return FloatLength.instantiateSI(1.0f / this.si);
282 }
283
284 }