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