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