View Javadoc
1   package org.djunits.value.vdouble.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.vdouble.scalar.base.AbstractDoubleScalarRel;
14  import org.djunits.value.vdouble.scalar.base.DoubleScalar;
15  
16  /**
17   * Easy access methods for the AmountOfSubstance DoubleScalar, 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 AmountOfSubstance extends AbstractDoubleScalarRel<AmountOfSubstanceUnit, AmountOfSubstance>
27  {
28      /** */
29      private static final long serialVersionUID = 20150905L;
30  
31      /** Constant with value zero. */
32      public static final AmountOfSubstancemountOfSubstance.html#AmountOfSubstance">AmountOfSubstance ZERO = new AmountOfSubstance(0.0, AmountOfSubstanceUnit.SI);
33  
34      /** Constant with value one. */
35      public static final AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance ONE = new AmountOfSubstance(1.0, AmountOfSubstanceUnit.SI);
36  
37      /** Constant with value NaN. */
38      @SuppressWarnings("checkstyle:constantname")
39      public static final AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance NaN = new AmountOfSubstance(Double.NaN, AmountOfSubstanceUnit.SI);
40  
41      /** Constant with value POSITIVE_INFINITY. */
42      public static final AmountOfSubstance POSITIVE_INFINITY =
43              new AmountOfSubstance(Double.POSITIVE_INFINITY, AmountOfSubstanceUnit.SI);
44  
45      /** Constant with value NEGATIVE_INFINITY. */
46      public static final AmountOfSubstance NEGATIVE_INFINITY =
47              new AmountOfSubstance(Double.NEGATIVE_INFINITY, AmountOfSubstanceUnit.SI);
48  
49      /** Constant with value MAX_VALUE. */
50      public static final AmountOfSubstanceubstance.html#AmountOfSubstance">AmountOfSubstance POS_MAXVALUE = new AmountOfSubstance(Double.MAX_VALUE, AmountOfSubstanceUnit.SI);
51  
52      /** Constant with value -MAX_VALUE. */
53      public static final AmountOfSubstanceubstance.html#AmountOfSubstance">AmountOfSubstance NEG_MAXVALUE = new AmountOfSubstance(-Double.MAX_VALUE, AmountOfSubstanceUnit.SI);
54  
55      /**
56       * Construct AmountOfSubstance scalar.
57       * @param value double; the double value
58       * @param unit AmountOfSubstanceUnit; unit for the double value
59       */
60      public AmountOfSubstance(final double value, final AmountOfSubstanceUnit unit)
61      {
62          super(value, unit);
63      }
64  
65      /**
66       * Construct AmountOfSubstance scalar.
67       * @param value AmountOfSubstance; Scalar from which to construct this instance
68       */
69      public AmountOfSubstancelar/AmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance(final AmountOfSubstance value)
70      {
71          super(value);
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public final AmountOfSubstance instantiateRel(final double value, final AmountOfSubstanceUnit unit)
77      {
78          return new AmountOfSubstance(value, unit);
79      }
80  
81      /**
82       * Construct AmountOfSubstance scalar.
83       * @param value double; the double value in SI units
84       * @return AmountOfSubstance; the new scalar with the SI value
85       */
86      public static final AmountOfSubstance instantiateSI(final double value)
87      {
88          return new AmountOfSubstance(value, AmountOfSubstanceUnit.SI);
89      }
90  
91      /**
92       * Interpolate between two values.
93       * @param zero AmountOfSubstance; the low value
94       * @param one AmountOfSubstance; the high value
95       * @param ratio double; the ratio between 0 and 1, inclusive
96       * @return AmountOfSubstance; a Scalar at the ratio between
97       */
98      public static AmountOfSubstanceountOfSubstance.html#AmountOfSubstance">AmountOfSubstanceSubstance.html#AmountOfSubstance">AmountOfSubstance interpolate(final AmountOfSubstanceountOfSubstance.html#AmountOfSubstance">AmountOfSubstance zero, final AmountOfSubstance one, final double ratio)
99      {
100         return new AmountOfSubstance(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
101                 zero.getDisplayUnit());
102     }
103 
104     /**
105      * Return the maximum value of two relative scalars.
106      * @param r1 AmountOfSubstance; the first scalar
107      * @param r2 AmountOfSubstance; the second scalar
108      * @return AmountOfSubstance; the maximum value of two relative scalars
109      */
110     public static AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance max(final AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance r1, final AmountOfSubstance r2)
111     {
112         return r1.gt(r2) ? r1 : r2;
113     }
114 
115     /**
116      * Return the maximum value of more than two relative scalars.
117      * @param r1 AmountOfSubstance; the first scalar
118      * @param r2 AmountOfSubstance; the second scalar
119      * @param rn AmountOfSubstance...; the other scalars
120      * @return AmountOfSubstance; the maximum value of more than two relative scalars
121      */
122     public static AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance max(final AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance r1, final AmountOfSubstance r2, final AmountOfSubstance... rn)
123     {
124         AmountOfSubstance maxr = r1.gt(r2) ? r1 : r2;
125         for (AmountOfSubstance r : rn)
126         {
127             if (r.gt(maxr))
128             {
129                 maxr = r;
130             }
131         }
132         return maxr;
133     }
134 
135     /**
136      * Return the minimum value of two relative scalars.
137      * @param r1 AmountOfSubstance; the first scalar
138      * @param r2 AmountOfSubstance; the second scalar
139      * @return AmountOfSubstance; the minimum value of two relative scalars
140      */
141     public static AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance min(final AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance r1, final AmountOfSubstance r2)
142     {
143         return r1.lt(r2) ? r1 : r2;
144     }
145 
146     /**
147      * Return the minimum value of more than two relative scalars.
148      * @param r1 AmountOfSubstance; the first scalar
149      * @param r2 AmountOfSubstance; the second scalar
150      * @param rn AmountOfSubstance...; the other scalars
151      * @return AmountOfSubstance; the minimum value of more than two relative scalars
152      */
153     public static AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance min(final AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance r1, final AmountOfSubstance r2, final AmountOfSubstance... rn)
154     {
155         AmountOfSubstance minr = r1.lt(r2) ? r1 : r2;
156         for (AmountOfSubstance r : rn)
157         {
158             if (r.lt(minr))
159             {
160                 minr = r;
161             }
162         }
163         return minr;
164     }
165 
166     /**
167      * Returns a AmountOfSubstance representation of a textual representation of a value with a unit. The String representation
168      * that can be parsed is the double value in the unit, followed by the official abbreviation of the unit. Spaces are
169      * allowed, but not required, between the value and the unit.
170      * @param text String; the textual representation to parse into a AmountOfSubstance
171      * @return AmountOfSubstance; the Scalar representation of the value in its unit
172      * @throws IllegalArgumentException when the text cannot be parsed
173      * @throws NullPointerException when the text argument is null
174      */
175     public static AmountOfSubstance valueOf(final String text)
176     {
177         Throw.whenNull(text, "Error parsing AmountOfSubstance: text to parse is null");
178         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing AmountOfSubstance: empty text to parse");
179         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
180         if (matcher.find())
181         {
182             int index = matcher.end();
183             String unitString = text.substring(index).trim();
184             String valueString = text.substring(0, index).trim();
185             AmountOfSubstanceUnit unit = AmountOfSubstanceUnit.BASE.getUnitByAbbreviation(unitString);
186             if (unit != null)
187             {
188                 double d = Double.parseDouble(valueString);
189                 return new AmountOfSubstance(d, unit);
190             }
191         }
192         throw new IllegalArgumentException("Error parsing AmountOfSubstance from " + text);
193     }
194 
195     /**
196      * Returns a AmountOfSubstance based on a value and the textual representation of the unit.
197      * @param value double; the value to use
198      * @param unitString String; the textual representation of the unit
199      * @return AmountOfSubstance; the Scalar representation of the value in its unit
200      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
201      * @throws NullPointerException when the unitString argument is null
202      */
203     public static AmountOfSubstance of(final double value, final String unitString)
204     {
205         Throw.whenNull(unitString, "Error parsing AmountOfSubstance: unitString is null");
206         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
207                 "Error parsing AmountOfSubstance: empty unitString");
208         AmountOfSubstanceUnit unit = AmountOfSubstanceUnit.BASE.getUnitByAbbreviation(unitString);
209         if (unit != null)
210         {
211             return new AmountOfSubstance(value, unit);
212         }
213         throw new IllegalArgumentException("Error parsing AmountOfSubstance with unit " + unitString);
214     }
215 
216     /**
217      * Calculate the division of AmountOfSubstance and AmountOfSubstance, which results in a Dimensionless scalar.
218      * @param v AmountOfSubstance; scalar
219      * @return Dimensionless; scalar as a division of AmountOfSubstance and AmountOfSubstance
220      */
221     public final Dimensionless divide(final AmountOfSubstance v)
222     {
223         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
224     }
225 
226     /**
227      * Calculate the division of AmountOfSubstance and CatalyticActivity, which results in a Duration scalar.
228      * @param v AmountOfSubstance; scalar
229      * @return Duration; scalar as a division of AmountOfSubstance and CatalyticActivity
230      */
231     public final Duration divide(final CatalyticActivity v)
232     {
233         return new Duration(this.si / v.si, DurationUnit.SI);
234     }
235 
236     /**
237      * Calculate the division of AmountOfSubstance and Duration, which results in a CatalyticActivity scalar.
238      * @param v AmountOfSubstance; scalar
239      * @return CatalyticActivity; scalar as a division of AmountOfSubstance and Duration
240      */
241     public final CatalyticActivity divide(final Duration v)
242     {
243         return new CatalyticActivity(this.si / v.si, CatalyticActivityUnit.SI);
244     }
245 
246     /** {@inheritDoc} */
247     @Override
248     public SIScalar reciprocal()
249     {
250         return DoubleScalar.divide(Dimensionless.ONE, this);
251     }
252 
253 }