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