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.DurationUnit;
11  import org.djunits.unit.FlowMassUnit;
12  import org.djunits.unit.ForceUnit;
13  import org.djunits.unit.MassUnit;
14  import org.djunits.unit.VolumeUnit;
15  import org.djunits.value.util.ValueUtil;
16  import org.djunits.value.vfloat.scalar.base.AbstractFloatScalarRel;
17  
18  /**
19   * Easy access methods for the FloatMass FloatScalar, which is relative by definition.
20   * <p>
21   * Copyright (c) 2013-2019 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 = "2019-10-18T12:12:25.568Z")
28  public class FloatMass extends AbstractFloatScalarRel<MassUnit, FloatMass>
29  {
30      /** */
31      private static final long serialVersionUID = 20150901L;
32  
33      /** Constant with value zero. */
34      public static final FloatMasscalar/FloatMass.html#FloatMass">FloatMass ZERO = new FloatMass(0.0f, MassUnit.SI);
35  
36      /** Constant with value one. */
37      public static final FloatMassscalar/FloatMass.html#FloatMass">FloatMass ONE = new FloatMass(1.0f, MassUnit.SI);
38  
39      /** Constant with value NaN. */
40      @SuppressWarnings("checkstyle:constantname")
41      public static final FloatMassscalar/FloatMass.html#FloatMass">FloatMass NaN = new FloatMass(Float.NaN, MassUnit.SI);
42  
43      /** Constant with value POSITIVE_INFINITY. */
44      public static final FloatMassss.html#FloatMass">FloatMass POSITIVE_INFINITY = new FloatMass(Float.POSITIVE_INFINITY, MassUnit.SI);
45  
46      /** Constant with value NEGATIVE_INFINITY. */
47      public static final FloatMassss.html#FloatMass">FloatMass NEGATIVE_INFINITY = new FloatMass(Float.NEGATIVE_INFINITY, MassUnit.SI);
48  
49      /** Constant with value MAX_VALUE. */
50      public static final FloatMassoatMass.html#FloatMass">FloatMass POS_MAXVALUE = new FloatMass(Float.MAX_VALUE, MassUnit.SI);
51  
52      /** Constant with value -MAX_VALUE. */
53      public static final FloatMassoatMass.html#FloatMass">FloatMass NEG_MAXVALUE = new FloatMass(-Float.MAX_VALUE, MassUnit.SI);
54  
55      /**
56       * Construct FloatMass scalar.
57       * @param value float; the float value
58       * @param unit unit for the float value
59       */
60      public FloatMass(final float value, final MassUnit unit)
61      {
62          super(value, unit);
63      }
64  
65      /**
66       * Construct FloatMass scalar.
67       * @param value Scalar from which to construct this instance
68       */
69      public FloatMassoat/scalar/FloatMass.html#FloatMass">FloatMass(final FloatMass value)
70      {
71          super(value);
72      }
73  
74      /**
75       * Construct FloatMass scalar using a double value.
76       * @param value double; the double value
77       * @param unit unit for the resulting float value
78       */
79      public FloatMass(final double value, final MassUnit unit)
80      {
81          super((float) value, unit);
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public final FloatMass instantiateRel(final float value, final MassUnit unit)
87      {
88          return new FloatMass(value, unit);
89      }
90  
91      /**
92       * Construct FloatMass scalar.
93       * @param value float; the float value in SI units
94       * @return the new scalar with the SI value
95       */
96      public static final FloatMass instantiateSI(final float value)
97      {
98          return new FloatMass(value, MassUnit.SI);
99      }
100 
101     /**
102      * Interpolate between two values.
103      * @param zero the low value
104      * @param one the high value
105      * @param ratio double; the ratio between 0 and 1, inclusive
106      * @return a Scalar at the ratio between
107      */
108     public static FloatMassalar/FloatMass.html#FloatMass">FloatMassloatMass.html#FloatMass">FloatMass interpolate(final FloatMassalar/FloatMass.html#FloatMass">FloatMass zero, final FloatMass one, final float ratio)
109     {
110         return new FloatMass(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
111                 zero.getDisplayUnit());
112     }
113 
114     /**
115      * Return the maximum value of two relative scalars.
116      * @param r1 the first scalar
117      * @param r2 the second scalar
118      * @return the maximum value of two relative scalars
119      */
120     public static FloatMassscalar/FloatMass.html#FloatMass">FloatMassscalar/FloatMass.html#FloatMass">FloatMass max(final FloatMassscalar/FloatMass.html#FloatMass">FloatMass r1, final FloatMass r2)
121     {
122         return (r1.gt(r2)) ? r1 : r2;
123     }
124 
125     /**
126      * Return the maximum value of more than two relative scalars.
127      * @param r1 the first scalar
128      * @param r2 the second scalar
129      * @param rn the other scalars
130      * @return the maximum value of more than two relative scalars
131      */
132     public static FloatMassscalar/FloatMass.html#FloatMass">FloatMassscalar/FloatMass.html#FloatMass">FloatMass max(final FloatMassscalar/FloatMass.html#FloatMass">FloatMass r1, final FloatMass r2, final FloatMass... rn)
133     {
134         FloatMass maxr = (r1.gt(r2)) ? r1 : r2;
135         for (FloatMass r : rn)
136         {
137             if (r.gt(maxr))
138             {
139                 maxr = r;
140             }
141         }
142         return maxr;
143     }
144 
145     /**
146      * Return the minimum value of two relative scalars.
147      * @param r1 the first scalar
148      * @param r2 the second scalar
149      * @return the minimum value of two relative scalars
150      */
151     public static FloatMassscalar/FloatMass.html#FloatMass">FloatMassscalar/FloatMass.html#FloatMass">FloatMass min(final FloatMassscalar/FloatMass.html#FloatMass">FloatMass r1, final FloatMass r2)
152     {
153         return (r1.lt(r2)) ? r1 : r2;
154     }
155 
156     /**
157      * Return the minimum value of more than two relative scalars.
158      * @param r1 the first scalar
159      * @param r2 the second scalar
160      * @param rn the other scalars
161      * @return the minimum value of more than two relative scalars
162      */
163     public static FloatMassscalar/FloatMass.html#FloatMass">FloatMassscalar/FloatMass.html#FloatMass">FloatMass min(final FloatMassscalar/FloatMass.html#FloatMass">FloatMass r1, final FloatMass r2, final FloatMass... rn)
164     {
165         FloatMass minr = (r1.lt(r2)) ? r1 : r2;
166         for (FloatMass r : rn)
167         {
168             if (r.lt(minr))
169             {
170                 minr = r;
171             }
172         }
173         return minr;
174     }
175 
176     /**
177      * Returns a FloatMass representation of a textual representation of a value with a unit. The String representation that can
178      * be parsed is the double value in the unit, followed by the official abbreviation of the unit. Spaces are allowed, but not
179      * required, between the value and the unit.
180      * @param text String; the textual representation to parse into a FloatMass
181      * @return FloatMass; the Scalar representation of the value in its unit
182      * @throws IllegalArgumentException when the text cannot be parsed
183      * @throws NullPointerException when the text argument is null
184      */
185     public static FloatMass valueOf(final String text)
186     {
187         Throw.whenNull(text, "Error parsing FloatMass: text to parse is null");
188         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatMass: empty text to parse");
189         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
190         if (matcher.find())
191         {
192             int index = matcher.end();
193             String unitString = text.substring(index).trim();
194             String valueString = text.substring(0, index).trim();
195             MassUnit unit = MassUnit.BASE.getUnitByAbbreviation(unitString);
196             if (unit != null)
197             {
198                 float f = Float.parseFloat(valueString);
199                 return new FloatMass(f, unit);
200             }
201         }
202         throw new IllegalArgumentException("Error parsing FloatMass from " + text);
203     }
204 
205     /**
206      * Returns a FloatMass based on a value and the textual representation of the unit.
207      * @param value double; the value to use
208      * @param unitString String; the textual representation of the unit
209      * @return FloatMass; the Scalar representation of the value in its unit
210      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
211      * @throws NullPointerException when the unitString argument is null
212      */
213     public static FloatMass of(final float value, final String unitString)
214     {
215         Throw.whenNull(unitString, "Error parsing FloatMass: unitString is null");
216         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatMass: empty unitString");
217         MassUnit unit = MassUnit.BASE.getUnitByAbbreviation(unitString);
218         if (unit != null)
219         {
220             return new FloatMass(value, unit);
221         }
222         throw new IllegalArgumentException("Error parsing FloatMass with unit " + unitString);
223     }
224 
225     /**
226      * Calculate the division of FloatMass and FloatMass, which results in a FloatDimensionless scalar.
227      * @param v FloatMass scalar
228      * @return FloatDimensionless scalar as a division of FloatMass and FloatMass
229      */
230     public final FloatDimensionless divide(final FloatMass v)
231     {
232         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
233     }
234 
235     /**
236      * Calculate the division of FloatMass and FloatFlowMass, which results in a FloatDuration scalar.
237      * @param v FloatMass scalar
238      * @return FloatDuration scalar as a division of FloatMass and FloatFlowMass
239      */
240     public final FloatDuration divide(final FloatFlowMass v)
241     {
242         return new FloatDuration(this.si / v.si, DurationUnit.SI);
243     }
244 
245     /**
246      * Calculate the division of FloatMass and FloatDuration, which results in a FloatFlowMass scalar.
247      * @param v FloatMass scalar
248      * @return FloatFlowMass scalar as a division of FloatMass and FloatDuration
249      */
250     public final FloatFlowMass divide(final FloatDuration v)
251     {
252         return new FloatFlowMass(this.si / v.si, FlowMassUnit.SI);
253     }
254 
255     /**
256      * Calculate the multiplication of FloatMass and FloatAcceleration, which results in a FloatForce scalar.
257      * @param v FloatMass scalar
258      * @return FloatForce scalar as a multiplication of FloatMass and FloatAcceleration
259      */
260     public final FloatForce times(final FloatAcceleration v)
261     {
262         return new FloatForce(this.si * v.si, ForceUnit.SI);
263     }
264 
265     /**
266      * Calculate the multiplication of FloatMass and FloatFrequency, which results in a FloatFlowMass scalar.
267      * @param v FloatMass scalar
268      * @return FloatFlowMass scalar as a multiplication of FloatMass and FloatFrequency
269      */
270     public final FloatFlowMass times(final FloatFrequency v)
271     {
272         return new FloatFlowMass(this.si * v.si, FlowMassUnit.SI);
273     }
274 
275     /**
276      * Calculate the division of FloatMass and FloatDensity, which results in a FloatVolume scalar.
277      * @param v FloatMass scalar
278      * @return FloatVolume scalar as a division of FloatMass and FloatDensity
279      */
280     public final FloatVolume divide(final FloatDensity v)
281     {
282         return new FloatVolume(this.si / v.si, VolumeUnit.SI);
283     }
284 
285     /**
286      * Calculate the division of FloatMass and FloatVolume, which results in a FloatDensity scalar.
287      * @param v FloatMass scalar
288      * @return FloatDensity scalar as a division of FloatMass and FloatVolume
289      */
290     public final FloatDensity divide(final FloatVolume v)
291     {
292         return new FloatDensity(this.si / v.si, DensityUnit.SI);
293     }
294 
295 }