View Javadoc
1   package org.djunits.value.vdouble.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.vdouble.scalar.base.DoubleScalarRel;
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 FlowVolume DoubleScalar, 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 FlowVolume extends DoubleScalarRel<FlowVolumeUnit, FlowVolume>
29  {
30      /** */
31      private static final long serialVersionUID = 20150905L;
32  
33      /** Constant with value zero. */
34      public static final FlowVolume ZERO = new FlowVolume(0.0, FlowVolumeUnit.SI);
35  
36      /** Constant with value one. */
37      public static final FlowVolume ONE = new FlowVolume(1.0, FlowVolumeUnit.SI);
38  
39      /** Constant with value NaN. */
40      @SuppressWarnings("checkstyle:constantname")
41      public static final FlowVolume NaN = new FlowVolume(Double.NaN, FlowVolumeUnit.SI);
42  
43      /** Constant with value POSITIVE_INFINITY. */
44      public static final FlowVolume POSITIVE_INFINITY = new FlowVolume(Double.POSITIVE_INFINITY, FlowVolumeUnit.SI);
45  
46      /** Constant with value NEGATIVE_INFINITY. */
47      public static final FlowVolume NEGATIVE_INFINITY = new FlowVolume(Double.NEGATIVE_INFINITY, FlowVolumeUnit.SI);
48  
49      /** Constant with value MAX_VALUE. */
50      public static final FlowVolume POS_MAXVALUE = new FlowVolume(Double.MAX_VALUE, FlowVolumeUnit.SI);
51  
52      /** Constant with value -MAX_VALUE. */
53      public static final FlowVolume NEG_MAXVALUE = new FlowVolume(-Double.MAX_VALUE, FlowVolumeUnit.SI);
54  
55      /**
56       * Construct FlowVolume scalar with a unit.
57       * @param value the double value, expressed in the given unit
58       * @param unit unit for the double value
59       */
60      public FlowVolume(final double value, final FlowVolumeUnit unit)
61      {
62          super(value, unit);
63      }
64  
65      /**
66       * Construct FlowVolume scalar.
67       * @param value Scalar from which to construct this instance
68       */
69      public FlowVolume(final FlowVolume value)
70      {
71          super(value);
72      }
73  
74      @Override
75      public final FlowVolume instantiateRel(final double value, final FlowVolumeUnit unit)
76      {
77          return new FlowVolume(value, unit);
78      }
79  
80      /**
81       * Construct FlowVolume scalar based on an SI value.
82       * @param value the double value in SI units
83       * @return the new scalar with the SI value
84       */
85      public static final FlowVolume ofSI(final double value)
86      {
87          return new FlowVolume(value, FlowVolumeUnit.SI);
88      }
89  
90      /**
91       * Interpolate between two values. Note that the first value does not have to be smaller than the second.
92       * @param zero the value at a ratio of zero
93       * @param one the value at a ratio of one
94       * @param ratio the ratio between 0 and 1, inclusive
95       * @return a FlowVolume at the given ratio between 0 and 1
96       */
97      public static FlowVolume interpolate(final FlowVolume zero, final FlowVolume one, final double ratio)
98      {
99          Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
100                 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
101         return new FlowVolume(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
102                 zero.getDisplayUnit());
103     }
104 
105     /**
106      * Return the maximum value of two relative scalars.
107      * @param r1 the first scalar
108      * @param r2 the second scalar
109      * @return the maximum value of two relative scalars
110      */
111     public static FlowVolume max(final FlowVolume r1, final FlowVolume r2)
112     {
113         return r1.gt(r2) ? r1 : r2;
114     }
115 
116     /**
117      * Return the maximum value of more than two relative scalars.
118      * @param r1 the first scalar
119      * @param r2 the second scalar
120      * @param rn the other scalars
121      * @return the maximum value of more than two relative scalars
122      */
123     public static FlowVolume max(final FlowVolume r1, final FlowVolume r2, final FlowVolume... rn)
124     {
125         FlowVolume maxr = r1.gt(r2) ? r1 : r2;
126         for (FlowVolume r : rn)
127         {
128             if (r.gt(maxr))
129             {
130                 maxr = r;
131             }
132         }
133         return maxr;
134     }
135 
136     /**
137      * Return the minimum value of two relative scalars.
138      * @param r1 the first scalar
139      * @param r2 the second scalar
140      * @return the minimum value of two relative scalars
141      */
142     public static FlowVolume min(final FlowVolume r1, final FlowVolume r2)
143     {
144         return r1.lt(r2) ? r1 : r2;
145     }
146 
147     /**
148      * Return the minimum value of more than two relative scalars.
149      * @param r1 the first scalar
150      * @param r2 the second scalar
151      * @param rn the other scalars
152      * @return the minimum value of more than two relative scalars
153      */
154     public static FlowVolume min(final FlowVolume r1, final FlowVolume r2, final FlowVolume... rn)
155     {
156         FlowVolume minr = r1.lt(r2) ? r1 : r2;
157         for (FlowVolume r : rn)
158         {
159             if (r.lt(minr))
160             {
161                 minr = r;
162             }
163         }
164         return minr;
165     }
166 
167     /**
168      * Returns a FlowVolume representation of a textual representation of a value with a unit. The String representation that
169      * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
170      * allowed, but not required, between the value and the unit.
171      * @param text the textual representation to parse into a FlowVolume
172      * @return the Scalar representation of the value in its unit
173      * @throws IllegalArgumentException when the text cannot be parsed
174      * @throws NullPointerException when the text argument is null
175      */
176     public static FlowVolume valueOf(final String text)
177     {
178         Throw.whenNull(text, "Error parsing FlowVolume: text to parse is null");
179         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FlowVolume: empty text to parse");
180         try
181         {
182             NumberParser numberParser = new NumberParser().lenient().trailing();
183             double d = numberParser.parseDouble(text);
184             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
185             FlowVolumeUnit unit = FlowVolumeUnit.BASE.getUnitByAbbreviation(unitString);
186             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity FlowVolume", unitString);
187             return new FlowVolume(d, unit);
188         }
189         catch (Exception exception)
190         {
191             throw new IllegalArgumentException(
192                     "Error parsing FlowVolume from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
193                     exception);
194         }
195     }
196 
197     /**
198      * Returns a FlowVolume based on a value and the textual representation of the unit, which can be localized.
199      * @param value the value to use
200      * @param unitString the textual representation of the unit
201      * @return the Scalar representation of the value in its unit
202      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
203      * @throws NullPointerException when the unitString argument is null
204      */
205     public static FlowVolume of(final double value, final String unitString)
206     {
207         Throw.whenNull(unitString, "Error parsing FlowVolume: unitString is null");
208         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FlowVolume: empty unitString");
209         FlowVolumeUnit unit = FlowVolumeUnit.BASE.getUnitByAbbreviation(unitString);
210         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FlowVolume with unit %s", unitString);
211         return new FlowVolume(value, unit);
212     }
213 
214     /**
215      * Calculate the division of FlowVolume and FlowVolume, which results in a Dimensionless scalar.
216      * @param v scalar
217      * @return scalar as a division of FlowVolume and FlowVolume
218      */
219     public final Dimensionless divide(final FlowVolume v)
220     {
221         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
222     }
223 
224     /**
225      * Calculate the multiplication of FlowVolume and Duration, which results in a Volume scalar.
226      * @param v scalar
227      * @return scalar as a multiplication of FlowVolume and Duration
228      */
229     public final Volume times(final Duration v)
230     {
231         return new Volume(this.si * v.si, VolumeUnit.SI);
232     }
233 
234     /**
235      * Calculate the division of FlowVolume and Frequency, which results in a Volume scalar.
236      * @param v scalar
237      * @return scalar as a division of FlowVolume and Frequency
238      */
239     public final Volume divide(final Frequency v)
240     {
241         return new Volume(this.si / v.si, VolumeUnit.SI);
242     }
243 
244     /**
245      * Calculate the division of FlowVolume and Volume, which results in a Frequency scalar.
246      * @param v scalar
247      * @return scalar as a division of FlowVolume and Volume
248      */
249     public final Frequency divide(final Volume v)
250     {
251         return new Frequency(this.si / v.si, FrequencyUnit.SI);
252     }
253 
254     /**
255      * Calculate the division of FlowVolume and Area, which results in a Speed scalar.
256      * @param v scalar
257      * @return scalar as a division of FlowVolume and Area
258      */
259     public final Speed divide(final Area v)
260     {
261         return new Speed(this.si / v.si, SpeedUnit.SI);
262     }
263 
264     /**
265      * Calculate the division of FlowVolume and Speed, which results in a Area scalar.
266      * @param v scalar
267      * @return scalar as a division of FlowVolume and Speed
268      */
269     public final Area divide(final Speed v)
270     {
271         return new Area(this.si / v.si, AreaUnit.SI);
272     }
273 
274     /**
275      * Calculate the multiplication of FlowVolume and Density, which results in a FlowMass scalar.
276      * @param v scalar
277      * @return scalar as a multiplication of FlowVolume and Density
278      */
279     public final FlowMass times(final Density v)
280     {
281         return new FlowMass(this.si * v.si, FlowMassUnit.SI);
282     }
283 
284     @Override
285     public SIScalar reciprocal()
286     {
287         return SIScalar.divide(Dimensionless.ONE, this);
288     }
289 
290     /**
291      * Multiply two scalars that result in a scalar of type FlowVolume.
292      * @param scalar1 the first scalar
293      * @param scalar2 the second scalar
294      * @return the multiplication of both scalars as an instance of FlowVolume
295      */
296     public static FlowVolume multiply(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
297     {
298         Throw.whenNull(scalar1, "scalar1 cannot be null");
299         Throw.whenNull(scalar2, "scalar2 cannot be null");
300         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
301                 .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(FlowVolumeUnit.BASE.getSiDimensions()),
302                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type FlowVolume",
303                 scalar1.toDisplayString(), scalar2.toDisplayString());
304         return new FlowVolume(scalar1.si * scalar2.si, FlowVolumeUnit.SI);
305     }
306 
307     /**
308      * Divide two scalars that result in a scalar of type FlowVolume.
309      * @param scalar1 the first scalar
310      * @param scalar2 the second scalar
311      * @return the division of scalar1 by scalar2 as an instance of FlowVolume
312      */
313     public static FlowVolume divide(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
314     {
315         Throw.whenNull(scalar1, "scalar1 cannot be null");
316         Throw.whenNull(scalar2, "scalar2 cannot be null");
317         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
318                 .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(FlowVolumeUnit.BASE.getSiDimensions()),
319                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type FlowVolume",
320                 scalar1.toDisplayString(), scalar2.toDisplayString());
321         return new FlowVolume(scalar1.si / scalar2.si, FlowVolumeUnit.SI);
322     }
323 
324 }