View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import java.util.regex.Matcher;
4   
5   import javax.annotation.Generated;
6   
7   import org.djunits.Throw;
8   import org.djunits.unit.DensityUnit;
9   import org.djunits.unit.DimensionlessUnit;
10  import org.djunits.unit.FlowMassUnit;
11  import org.djunits.unit.MassUnit;
12  import org.djunits.value.util.ValueUtil;
13  import org.djunits.value.vfloat.scalar.base.AbstractFloatScalarRel;
14  import org.djunits.value.vfloat.scalar.base.FloatScalar;
15  
16  /**
17   * Easy access methods for the FloatDensity FloatScalar, which is relative by definition.
18   * <p>
19   * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
20   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
21   * </p>
22   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
23   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
24   */
25  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2022-03-14T11:14:15.180987200Z")
26  public class FloatDensity extends AbstractFloatScalarRel<DensityUnit, FloatDensity>
27  {
28      /** */
29      private static final long serialVersionUID = 20150901L;
30  
31      /** Constant with value zero. */
32      public static final FloatDensityar/FloatDensity.html#FloatDensity">FloatDensity ZERO = new FloatDensity(0.0f, DensityUnit.SI);
33  
34      /** Constant with value one. */
35      public static final FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensity ONE = new FloatDensity(1.0f, DensityUnit.SI);
36  
37      /** Constant with value NaN. */
38      @SuppressWarnings("checkstyle:constantname")
39      public static final FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensity NaN = new FloatDensity(Float.NaN, DensityUnit.SI);
40  
41      /** Constant with value POSITIVE_INFINITY. */
42      public static final FloatDensityty.html#FloatDensity">FloatDensity POSITIVE_INFINITY = new FloatDensity(Float.POSITIVE_INFINITY, DensityUnit.SI);
43  
44      /** Constant with value NEGATIVE_INFINITY. */
45      public static final FloatDensityty.html#FloatDensity">FloatDensity NEGATIVE_INFINITY = new FloatDensity(Float.NEGATIVE_INFINITY, DensityUnit.SI);
46  
47      /** Constant with value MAX_VALUE. */
48      public static final FloatDensityDensity.html#FloatDensity">FloatDensity POS_MAXVALUE = new FloatDensity(Float.MAX_VALUE, DensityUnit.SI);
49  
50      /** Constant with value -MAX_VALUE. */
51      public static final FloatDensityDensity.html#FloatDensity">FloatDensity NEG_MAXVALUE = new FloatDensity(-Float.MAX_VALUE, DensityUnit.SI);
52  
53      /**
54       * Construct FloatDensity scalar.
55       * @param value float; the float value
56       * @param unit unit for the float value
57       */
58      public FloatDensity(final float value, final DensityUnit unit)
59      {
60          super(value, unit);
61      }
62  
63      /**
64       * Construct FloatDensity scalar.
65       * @param value Scalar from which to construct this instance
66       */
67      public FloatDensity/scalar/FloatDensity.html#FloatDensity">FloatDensity(final FloatDensity value)
68      {
69          super(value);
70      }
71  
72      /**
73       * Construct FloatDensity scalar using a double value.
74       * @param value double; the double value
75       * @param unit unit for the resulting float value
76       */
77      public FloatDensity(final double value, final DensityUnit unit)
78      {
79          super((float) value, unit);
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public final FloatDensity instantiateRel(final float value, final DensityUnit unit)
85      {
86          return new FloatDensity(value, unit);
87      }
88  
89      /**
90       * Construct FloatDensity scalar.
91       * @param value float; the float value in SI units
92       * @return the new scalar with the SI value
93       */
94      public static final FloatDensity instantiateSI(final float value)
95      {
96          return new FloatDensity(value, DensityUnit.SI);
97      }
98  
99      /**
100      * Interpolate between two values.
101      * @param zero the low value
102      * @param one the high value
103      * @param ratio double; the ratio between 0 and 1, inclusive
104      * @return a Scalar at the ratio between
105      */
106     public static FloatDensityr/FloatDensity.html#FloatDensity">FloatDensitytDensity.html#FloatDensity">FloatDensity interpolate(final FloatDensityr/FloatDensity.html#FloatDensity">FloatDensity zero, final FloatDensity one, final float ratio)
107     {
108         return new FloatDensity(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
109                 zero.getDisplayUnit());
110     }
111 
112     /**
113      * Return the maximum value of two relative scalars.
114      * @param r1 the first scalar
115      * @param r2 the second scalar
116      * @return the maximum value of two relative scalars
117      */
118     public static FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensity max(final FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensity r1, final FloatDensity r2)
119     {
120         return r1.gt(r2) ? r1 : r2;
121     }
122 
123     /**
124      * Return the maximum value of more than two relative scalars.
125      * @param r1 the first scalar
126      * @param r2 the second scalar
127      * @param rn the other scalars
128      * @return the maximum value of more than two relative scalars
129      */
130     public static FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensity max(final FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensity r1, final FloatDensity r2, final FloatDensity... rn)
131     {
132         FloatDensity maxr = r1.gt(r2) ? r1 : r2;
133         for (FloatDensity r : rn)
134         {
135             if (r.gt(maxr))
136             {
137                 maxr = r;
138             }
139         }
140         return maxr;
141     }
142 
143     /**
144      * Return the minimum value of two relative scalars.
145      * @param r1 the first scalar
146      * @param r2 the second scalar
147      * @return the minimum value of two relative scalars
148      */
149     public static FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensity min(final FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensity r1, final FloatDensity r2)
150     {
151         return r1.lt(r2) ? r1 : r2;
152     }
153 
154     /**
155      * Return the minimum value of more than two relative scalars.
156      * @param r1 the first scalar
157      * @param r2 the second scalar
158      * @param rn the other scalars
159      * @return the minimum value of more than two relative scalars
160      */
161     public static FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensity min(final FloatDensitylar/FloatDensity.html#FloatDensity">FloatDensity r1, final FloatDensity r2, final FloatDensity... rn)
162     {
163         FloatDensity minr = r1.lt(r2) ? r1 : r2;
164         for (FloatDensity r : rn)
165         {
166             if (r.lt(minr))
167             {
168                 minr = r;
169             }
170         }
171         return minr;
172     }
173 
174     /**
175      * Returns a FloatDensity representation of a textual representation of a value with a unit. The String representation that
176      * can be parsed is the double value in the unit, followed by the official abbreviation of the unit. Spaces are allowed, but
177      * not required, between the value and the unit.
178      * @param text String; the textual representation to parse into a FloatDensity
179      * @return FloatDensity; the Scalar representation of the value in its unit
180      * @throws IllegalArgumentException when the text cannot be parsed
181      * @throws NullPointerException when the text argument is null
182      */
183     public static FloatDensity valueOf(final String text)
184     {
185         Throw.whenNull(text, "Error parsing FloatDensity: text to parse is null");
186         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatDensity: empty text to parse");
187         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
188         if (matcher.find())
189         {
190             int index = matcher.end();
191             String unitString = text.substring(index).trim();
192             String valueString = text.substring(0, index).trim();
193             DensityUnit unit = DensityUnit.BASE.getUnitByAbbreviation(unitString);
194             if (unit != null)
195             {
196                 float f = Float.parseFloat(valueString);
197                 return new FloatDensity(f, unit);
198             }
199         }
200         throw new IllegalArgumentException("Error parsing FloatDensity from " + text);
201     }
202 
203     /**
204      * Returns a FloatDensity based on a value and the textual representation of the unit.
205      * @param value double; the value to use
206      * @param unitString String; the textual representation of the unit
207      * @return FloatDensity; the Scalar representation of the value in its unit
208      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
209      * @throws NullPointerException when the unitString argument is null
210      */
211     public static FloatDensity of(final float value, final String unitString)
212     {
213         Throw.whenNull(unitString, "Error parsing FloatDensity: unitString is null");
214         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatDensity: empty unitString");
215         DensityUnit unit = DensityUnit.BASE.getUnitByAbbreviation(unitString);
216         if (unit != null)
217         {
218             return new FloatDensity(value, unit);
219         }
220         throw new IllegalArgumentException("Error parsing FloatDensity with unit " + unitString);
221     }
222 
223     /**
224      * Calculate the division of FloatDensity and FloatDensity, which results in a FloatDimensionless scalar.
225      * @param v FloatDensity; scalar
226      * @return FloatDimensionless; scalar as a division of FloatDensity and FloatDensity
227      */
228     public final FloatDimensionless divide(final FloatDensity v)
229     {
230         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
231     }
232 
233     /**
234      * Calculate the multiplication of FloatDensity and FloatVolume, which results in a FloatMass scalar.
235      * @param v FloatDensity; scalar
236      * @return FloatMass; scalar as a multiplication of FloatDensity and FloatVolume
237      */
238     public final FloatMass times(final FloatVolume v)
239     {
240         return new FloatMass(this.si * v.si, MassUnit.SI);
241     }
242 
243     /**
244      * Calculate the multiplication of FloatDensity and FloatFlowVolume, which results in a FloatFlowMass scalar.
245      * @param v FloatDensity; scalar
246      * @return FloatFlowMass; scalar as a multiplication of FloatDensity and FloatFlowVolume
247      */
248     public final FloatFlowMass times(final FloatFlowVolume v)
249     {
250         return new FloatFlowMass(this.si * v.si, FlowMassUnit.SI);
251     }
252 
253     /** {@inheritDoc} */
254     @Override
255     public FloatSIScalar reciprocal()
256     {
257         return FloatScalar.divide(FloatDimensionless.ONE, this);
258     }
259 
260 }