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