View Javadoc
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.FlowMassUnit;
8   import org.djunits.unit.FlowVolumeUnit;
9   import org.djunits.unit.FrequencyUnit;
10  import org.djunits.unit.SpeedUnit;
11  import org.djunits.unit.VolumeUnit;
12  import org.djunits.value.vfloat.scalar.base.FloatScalarRel;
13  import org.djutils.base.NumberParser;
14  import org.djutils.exceptions.Throw;
15  
16  import jakarta.annotation.Generated;
17  
18  /**
19   * Easy access methods for the FloatFlowVolume FloatScalar, which is relative by definition.
20   * <p>
21   * Copyright (c) 2013-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
22   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
23   * </p>
24   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
25   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
26   */
27  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2025-09-06T15:16:28.380798Z")
28  public class FloatFlowVolume extends FloatScalarRel<FlowVolumeUnit, FloatFlowVolume>
29  {
30      /** */
31      private static final long serialVersionUID = 20150901L;
32  
33      /** Constant with value zero. */
34      public static final FloatFlowVolume ZERO = new FloatFlowVolume(0.0f, FlowVolumeUnit.SI);
35  
36      /** Constant with value one. */
37      public static final FloatFlowVolume ONE = new FloatFlowVolume(1.0f, FlowVolumeUnit.SI);
38  
39      /** Constant with value NaN. */
40      @SuppressWarnings("checkstyle:constantname")
41      public static final FloatFlowVolume NaN = new FloatFlowVolume(Float.NaN, FlowVolumeUnit.SI);
42  
43      /** Constant with value POSITIVE_INFINITY. */
44      public static final FloatFlowVolume POSITIVE_INFINITY = new FloatFlowVolume(Float.POSITIVE_INFINITY, FlowVolumeUnit.SI);
45  
46      /** Constant with value NEGATIVE_INFINITY. */
47      public static final FloatFlowVolume NEGATIVE_INFINITY = new FloatFlowVolume(Float.NEGATIVE_INFINITY, FlowVolumeUnit.SI);
48  
49      /** Constant with value MAX_VALUE. */
50      public static final FloatFlowVolume POS_MAXVALUE = new FloatFlowVolume(Float.MAX_VALUE, FlowVolumeUnit.SI);
51  
52      /** Constant with value -MAX_VALUE. */
53      public static final FloatFlowVolume NEG_MAXVALUE = new FloatFlowVolume(-Float.MAX_VALUE, FlowVolumeUnit.SI);
54  
55      /**
56       * Construct FloatFlowVolume scalar with a unit.
57       * @param value the float value, expressed in the given unit
58       * @param unit unit for the float value
59       */
60      public FloatFlowVolume(final float value, final FlowVolumeUnit unit)
61      {
62          super(value, unit);
63      }
64  
65      /**
66       * Construct FloatFlowVolume scalar.
67       * @param value Scalar from which to construct this instance
68       */
69      public FloatFlowVolume(final FloatFlowVolume value)
70      {
71          super(value);
72      }
73  
74      /**
75       * Construct FloatFlowVolume scalar with a unit using a double value.
76       * @param value the double value, expressed in the given unit
77       * @param unit unit for the resulting float value
78       */
79      public FloatFlowVolume(final double value, final FlowVolumeUnit unit)
80      {
81          super((float) value, unit);
82      }
83  
84      @Override
85      public final FloatFlowVolume instantiateRel(final float value, final FlowVolumeUnit unit)
86      {
87          return new FloatFlowVolume(value, unit);
88      }
89  
90      /**
91       * Construct FloatFlowVolume scalar based on an SI value.
92       * @param value the float value in SI units
93       * @return the new scalar with the SI value
94       */
95      public static final FloatFlowVolume ofSI(final float value)
96      {
97          return new FloatFlowVolume(value, FlowVolumeUnit.SI);
98      }
99  
100     /**
101      * Interpolate between two values. Note that the first value does not have to be smaller than the second.
102      * @param zero the value at a ratio of zero
103      * @param one the value at a ratio of one
104      * @param ratio the ratio between 0 and 1, inclusive
105      * @return a FloatFlowVolume at the given ratio between 0 and 1
106      */
107     public static FloatFlowVolume interpolate(final FloatFlowVolume zero, final FloatFlowVolume one, final float ratio)
108     {
109         Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
110                 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
111         return new FloatFlowVolume(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
112                 zero.getDisplayUnit());
113     }
114 
115     /**
116      * Return the maximum value of two relative scalars.
117      * @param r1 the first scalar
118      * @param r2 the second scalar
119      * @return the maximum value of two relative scalars
120      */
121     public static FloatFlowVolume max(final FloatFlowVolume r1, final FloatFlowVolume r2)
122     {
123         return r1.gt(r2) ? r1 : r2;
124     }
125 
126     /**
127      * Return the maximum value of more than two relative scalars.
128      * @param r1 the first scalar
129      * @param r2 the second scalar
130      * @param rn the other scalars
131      * @return the maximum value of more than two relative scalars
132      */
133     public static FloatFlowVolume max(final FloatFlowVolume r1, final FloatFlowVolume r2, final FloatFlowVolume... rn)
134     {
135         FloatFlowVolume maxr = r1.gt(r2) ? r1 : r2;
136         for (FloatFlowVolume r : rn)
137         {
138             if (r.gt(maxr))
139             {
140                 maxr = r;
141             }
142         }
143         return maxr;
144     }
145 
146     /**
147      * Return the minimum value of two relative scalars.
148      * @param r1 the first scalar
149      * @param r2 the second scalar
150      * @return the minimum value of two relative scalars
151      */
152     public static FloatFlowVolume min(final FloatFlowVolume r1, final FloatFlowVolume r2)
153     {
154         return r1.lt(r2) ? r1 : r2;
155     }
156 
157     /**
158      * Return the minimum value of more than two relative scalars.
159      * @param r1 the first scalar
160      * @param r2 the second scalar
161      * @param rn the other scalars
162      * @return the minimum value of more than two relative scalars
163      */
164     public static FloatFlowVolume min(final FloatFlowVolume r1, final FloatFlowVolume r2, final FloatFlowVolume... rn)
165     {
166         FloatFlowVolume minr = r1.lt(r2) ? r1 : r2;
167         for (FloatFlowVolume r : rn)
168         {
169             if (r.lt(minr))
170             {
171                 minr = r;
172             }
173         }
174         return minr;
175     }
176 
177     /**
178      * Returns a FloatFlowVolume representation of a textual representation of a value with a unit. The String representation
179      * that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces
180      * are allowed, but not required, between the value and the unit.
181      * @param text the textual representation to parse into a FloatFlowVolume
182      * @return the Scalar representation of the value in its unit
183      * @throws IllegalArgumentException when the text cannot be parsed
184      * @throws NullPointerException when the text argument is null
185      */
186     public static FloatFlowVolume valueOf(final String text)
187     {
188         Throw.whenNull(text, "Error parsing FloatFlowVolume: text to parse is null");
189         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatFlowVolume: 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             FlowVolumeUnit unit = FlowVolumeUnit.BASE.getUnitByAbbreviation(unitString);
196             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity FlowVolume", unitString);
197             return new FloatFlowVolume(f, unit);
198         }
199         catch (Exception exception)
200         {
201             throw new IllegalArgumentException(
202                     "Error parsing FloatFlowVolume from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
203                     exception);
204         }
205     }
206 
207     /**
208      * Returns a FloatFlowVolume based on a value and the textual representation of the unit, which can be localized.
209      * @param value the value to use
210      * @param unitString the textual representation of the unit
211      * @return the Scalar representation of the value in its unit
212      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
213      * @throws NullPointerException when the unitString argument is null
214      */
215     public static FloatFlowVolume of(final float value, final String unitString)
216     {
217         Throw.whenNull(unitString, "Error parsing FloatFlowVolume: unitString is null");
218         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatFlowVolume: empty unitString");
219         FlowVolumeUnit unit = FlowVolumeUnit.BASE.getUnitByAbbreviation(unitString);
220         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FloatFlowVolume with unit %s", unitString);
221         return new FloatFlowVolume(value, unit);
222     }
223 
224     /**
225      * Calculate the division of FloatFlowVolume and FloatFlowVolume, which results in a FloatDimensionless scalar.
226      * @param v scalar
227      * @return scalar as a division of FloatFlowVolume and FloatFlowVolume
228      */
229     public final FloatDimensionless divide(final FloatFlowVolume v)
230     {
231         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
232     }
233 
234     /**
235      * Calculate the multiplication of FloatFlowVolume and FloatDuration, which results in a FloatVolume scalar.
236      * @param v scalar
237      * @return scalar as a multiplication of FloatFlowVolume and FloatDuration
238      */
239     public final FloatVolume times(final FloatDuration v)
240     {
241         return new FloatVolume(this.si * v.si, VolumeUnit.SI);
242     }
243 
244     /**
245      * Calculate the division of FloatFlowVolume and FloatFrequency, which results in a FloatVolume scalar.
246      * @param v scalar
247      * @return scalar as a division of FloatFlowVolume and FloatFrequency
248      */
249     public final FloatVolume divide(final FloatFrequency v)
250     {
251         return new FloatVolume(this.si / v.si, VolumeUnit.SI);
252     }
253 
254     /**
255      * Calculate the division of FloatFlowVolume and FloatVolume, which results in a FloatFrequency scalar.
256      * @param v scalar
257      * @return scalar as a division of FloatFlowVolume and FloatVolume
258      */
259     public final FloatFrequency divide(final FloatVolume v)
260     {
261         return new FloatFrequency(this.si / v.si, FrequencyUnit.SI);
262     }
263 
264     /**
265      * Calculate the division of FloatFlowVolume and FloatArea, which results in a FloatSpeed scalar.
266      * @param v scalar
267      * @return scalar as a division of FloatFlowVolume and FloatArea
268      */
269     public final FloatSpeed divide(final FloatArea v)
270     {
271         return new FloatSpeed(this.si / v.si, SpeedUnit.SI);
272     }
273 
274     /**
275      * Calculate the division of FloatFlowVolume and FloatSpeed, which results in a FloatArea scalar.
276      * @param v scalar
277      * @return scalar as a division of FloatFlowVolume and FloatSpeed
278      */
279     public final FloatArea divide(final FloatSpeed v)
280     {
281         return new FloatArea(this.si / v.si, AreaUnit.SI);
282     }
283 
284     /**
285      * Calculate the multiplication of FloatFlowVolume and FloatDensity, which results in a FloatFlowMass scalar.
286      * @param v scalar
287      * @return scalar as a multiplication of FloatFlowVolume and FloatDensity
288      */
289     public final FloatFlowMass times(final FloatDensity v)
290     {
291         return new FloatFlowMass(this.si * v.si, FlowMassUnit.SI);
292     }
293 
294     @Override
295     public FloatSIScalar reciprocal()
296     {
297         return FloatSIScalar.divide(FloatDimensionless.ONE, this);
298     }
299 
300     /**
301      * Multiply two scalars that result in a scalar of type FloatFlowVolume.
302      * @param scalar1 the first scalar
303      * @param scalar2 the second scalar
304      * @return the multiplication of both scalars as an instance of FloatFlowVolume
305      */
306     public static FloatFlowVolume multiply(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
307     {
308         Throw.whenNull(scalar1, "scalar1 cannot be null");
309         Throw.whenNull(scalar2, "scalar2 cannot be null");
310         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
311                 .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(FlowVolumeUnit.BASE.getSiDimensions()),
312                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type FloatFlowVolume",
313                 scalar1.toDisplayString(), scalar2.toDisplayString());
314         return new FloatFlowVolume(scalar1.si * scalar2.si, FlowVolumeUnit.SI);
315     }
316 
317     /**
318      * Divide two scalars that result in a scalar of type FloatFlowVolume.
319      * @param scalar1 the first scalar
320      * @param scalar2 the second scalar
321      * @return the division of scalar1 by scalar2 as an instance of FloatFlowVolume
322      */
323     public static FloatFlowVolume divide(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
324     {
325         Throw.whenNull(scalar1, "scalar1 cannot be null");
326         Throw.whenNull(scalar2, "scalar2 cannot be null");
327         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
328                 .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(FlowVolumeUnit.BASE.getSiDimensions()),
329                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type FloatFlowVolume",
330                 scalar1.toDisplayString(), scalar2.toDisplayString());
331         return new FloatFlowVolume(scalar1.si / scalar2.si, FlowVolumeUnit.SI);
332     }
333 
334 }