View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.DensityUnit;
6   import org.djunits.unit.DimensionlessUnit;
7   import org.djunits.unit.FlowMassUnit;
8   import org.djunits.unit.FlowVolumeUnit;
9   import org.djunits.unit.ForceUnit;
10  import org.djunits.unit.FrequencyUnit;
11  import org.djunits.unit.MassUnit;
12  import org.djunits.unit.MomentumUnit;
13  import org.djunits.value.vfloat.scalar.base.FloatScalar;
14  import org.djunits.value.vfloat.scalar.base.FloatScalarRel;
15  import org.djutils.base.NumberParser;
16  import org.djutils.exceptions.Throw;
17  
18  import jakarta.annotation.Generated;
19  
20  /**
21   * Easy access methods for the FloatFlowMass FloatScalar, which is relative by definition.
22   * <p>
23   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
25   * </p>
26   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
27   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
28   */
29  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
30  public class FloatFlowMass extends FloatScalarRel<FlowMassUnit, FloatFlowMass>
31  {
32      /** */
33      private static final long serialVersionUID = 20150901L;
34  
35      /** Constant with value zero. */
36      public static final FloatFlowMass ZERO = new FloatFlowMass(0.0f, FlowMassUnit.SI);
37  
38      /** Constant with value one. */
39      public static final FloatFlowMass ONE = new FloatFlowMass(1.0f, FlowMassUnit.SI);
40  
41      /** Constant with value NaN. */
42      @SuppressWarnings("checkstyle:constantname")
43      public static final FloatFlowMass NaN = new FloatFlowMass(Float.NaN, FlowMassUnit.SI);
44  
45      /** Constant with value POSITIVE_INFINITY. */
46      public static final FloatFlowMass POSITIVE_INFINITY = new FloatFlowMass(Float.POSITIVE_INFINITY, FlowMassUnit.SI);
47  
48      /** Constant with value NEGATIVE_INFINITY. */
49      public static final FloatFlowMass NEGATIVE_INFINITY = new FloatFlowMass(Float.NEGATIVE_INFINITY, FlowMassUnit.SI);
50  
51      /** Constant with value MAX_VALUE. */
52      public static final FloatFlowMass POS_MAXVALUE = new FloatFlowMass(Float.MAX_VALUE, FlowMassUnit.SI);
53  
54      /** Constant with value -MAX_VALUE. */
55      public static final FloatFlowMass NEG_MAXVALUE = new FloatFlowMass(-Float.MAX_VALUE, FlowMassUnit.SI);
56  
57      /**
58       * Construct FloatFlowMass scalar.
59       * @param value float; the float value
60       * @param unit unit for the float value
61       */
62      public FloatFlowMass(final float value, final FlowMassUnit unit)
63      {
64          super(value, unit);
65      }
66  
67      /**
68       * Construct FloatFlowMass scalar.
69       * @param value Scalar from which to construct this instance
70       */
71      public FloatFlowMass(final FloatFlowMass value)
72      {
73          super(value);
74      }
75  
76      /**
77       * Construct FloatFlowMass scalar using a double value.
78       * @param value double; the double value
79       * @param unit unit for the resulting float value
80       */
81      public FloatFlowMass(final double value, final FlowMassUnit unit)
82      {
83          super((float) value, unit);
84      }
85  
86      @Override
87      public final FloatFlowMass instantiateRel(final float value, final FlowMassUnit unit)
88      {
89          return new FloatFlowMass(value, unit);
90      }
91  
92      /**
93       * Construct FloatFlowMass scalar.
94       * @param value float; the float value in SI units
95       * @return the new scalar with the SI value
96       */
97      public static final FloatFlowMass instantiateSI(final float value)
98      {
99          return new FloatFlowMass(value, FlowMassUnit.SI);
100     }
101 
102     /**
103      * Interpolate between two values.
104      * @param zero the low value
105      * @param one the high value
106      * @param ratio double; the ratio between 0 and 1, inclusive
107      * @return a Scalar at the ratio between
108      */
109     public static FloatFlowMass interpolate(final FloatFlowMass zero, final FloatFlowMass one, final float ratio)
110     {
111         return new FloatFlowMass(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 FloatFlowMass max(final FloatFlowMass r1, final FloatFlowMass 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 FloatFlowMass max(final FloatFlowMass r1, final FloatFlowMass r2, final FloatFlowMass... rn)
134     {
135         FloatFlowMass maxr = r1.gt(r2) ? r1 : r2;
136         for (FloatFlowMass 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 FloatFlowMass min(final FloatFlowMass r1, final FloatFlowMass 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 FloatFlowMass min(final FloatFlowMass r1, final FloatFlowMass r2, final FloatFlowMass... rn)
165     {
166         FloatFlowMass minr = r1.lt(r2) ? r1 : r2;
167         for (FloatFlowMass r : rn)
168         {
169             if (r.lt(minr))
170             {
171                 minr = r;
172             }
173         }
174         return minr;
175     }
176 
177     /**
178      * Returns a FloatFlowMass representation of a textual representation of a value with a unit. The String representation that
179      * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
180      * allowed, but not required, between the value and the unit.
181      * @param text String; the textual representation to parse into a FloatFlowMass
182      * @return FloatFlowMass; 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 FloatFlowMass valueOf(final String text)
187     {
188         Throw.whenNull(text, "Error parsing FloatFlowMass: text to parse is null");
189         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatFlowMass: 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             FlowMassUnit unit = FlowMassUnit.BASE.getUnitByAbbreviation(unitString);
196             if (unit == null)
197                 throw new IllegalArgumentException("Unit " + unitString + " not found");
198             return new FloatFlowMass(f, unit);
199         }
200         catch (Exception exception)
201         {
202             throw new IllegalArgumentException(
203                     "Error parsing FloatFlowMass from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
204                     exception);
205         }
206     }
207 
208     /**
209      * Returns a FloatFlowMass based on a value and the textual representation of the unit, which can be localized.
210      * @param value double; the value to use
211      * @param unitString String; the textual representation of the unit
212      * @return FloatFlowMass; the Scalar representation of the value in its unit
213      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
214      * @throws NullPointerException when the unitString argument is null
215      */
216     public static FloatFlowMass of(final float value, final String unitString)
217     {
218         Throw.whenNull(unitString, "Error parsing FloatFlowMass: unitString is null");
219         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatFlowMass: empty unitString");
220         FlowMassUnit unit = FlowMassUnit.BASE.getUnitByAbbreviation(unitString);
221         if (unit != null)
222         {
223             return new FloatFlowMass(value, unit);
224         }
225         throw new IllegalArgumentException("Error parsing FloatFlowMass with unit " + unitString);
226     }
227 
228     /**
229      * Calculate the division of FloatFlowMass and FloatFlowMass, which results in a FloatDimensionless scalar.
230      * @param v FloatFlowMass; scalar
231      * @return FloatDimensionless; scalar as a division of FloatFlowMass and FloatFlowMass
232      */
233     public final FloatDimensionless divide(final FloatFlowMass v)
234     {
235         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
236     }
237 
238     /**
239      * Calculate the multiplication of FloatFlowMass and FloatDuration, which results in a FloatMass scalar.
240      * @param v FloatFlowMass; scalar
241      * @return FloatMass; scalar as a multiplication of FloatFlowMass and FloatDuration
242      */
243     public final FloatMass times(final FloatDuration v)
244     {
245         return new FloatMass(this.si * v.si, MassUnit.SI);
246     }
247 
248     /**
249      * Calculate the division of FloatFlowMass and FloatFrequency, which results in a FloatMass scalar.
250      * @param v FloatFlowMass; scalar
251      * @return FloatMass; scalar as a division of FloatFlowMass and FloatFrequency
252      */
253     public final FloatMass divide(final FloatFrequency v)
254     {
255         return new FloatMass(this.si / v.si, MassUnit.SI);
256     }
257 
258     /**
259      * Calculate the division of FloatFlowMass and FloatMass, which results in a FloatFrequency scalar.
260      * @param v FloatFlowMass; scalar
261      * @return FloatFrequency; scalar as a division of FloatFlowMass and FloatMass
262      */
263     public final FloatFrequency divide(final FloatMass v)
264     {
265         return new FloatFrequency(this.si / v.si, FrequencyUnit.SI);
266     }
267 
268     /**
269      * Calculate the multiplication of FloatFlowMass and FloatSpeed, which results in a FloatForce scalar.
270      * @param v FloatFlowMass; scalar
271      * @return FloatForce; scalar as a multiplication of FloatFlowMass and FloatSpeed
272      */
273     public final FloatForce times(final FloatSpeed v)
274     {
275         return new FloatForce(this.si * v.si, ForceUnit.SI);
276     }
277 
278     /**
279      * Calculate the division of FloatFlowMass and FloatFlowVolume, which results in a FloatDensity scalar.
280      * @param v FloatFlowMass; scalar
281      * @return FloatDensity; scalar as a division of FloatFlowMass and FloatFlowVolume
282      */
283     public final FloatDensity divide(final FloatFlowVolume v)
284     {
285         return new FloatDensity(this.si / v.si, DensityUnit.SI);
286     }
287 
288     /**
289      * Calculate the division of FloatFlowMass and FloatDensity, which results in a FloatFlowVolume scalar.
290      * @param v FloatFlowMass; scalar
291      * @return FloatFlowVolume; scalar as a division of FloatFlowMass and FloatDensity
292      */
293     public final FloatFlowVolume divide(final FloatDensity v)
294     {
295         return new FloatFlowVolume(this.si / v.si, FlowVolumeUnit.SI);
296     }
297 
298     /**
299      * Calculate the multiplication of FloatFlowMass and FloatLength, which results in a FloatMomentum scalar.
300      * @param v FloatFlowMass; scalar
301      * @return FloatMomentum; scalar as a multiplication of FloatFlowMass and FloatLength
302      */
303     public final FloatMomentum times(final FloatLength v)
304     {
305         return new FloatMomentum(this.si * v.si, MomentumUnit.SI);
306     }
307 
308     @Override
309     public FloatSIScalar reciprocal()
310     {
311         return FloatScalar.divide(FloatDimensionless.ONE, this);
312     }
313 
314 }