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.TemperatureUnit;
10  import org.djunits.value.util.ValueUtil;
11  import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarAbs;
12  
13  /**
14   * Easy access methods for the Absolute AbsoluteTemperature DoubleScalar.
15   * <p>
16   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br>
17   * All rights reserved. <br>
18   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
19   * </p>
20   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
21   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
22   */
23  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2020-01-19T15:21:24.964166400Z")
24  public class AbsoluteTemperature
25          extends AbstractDoubleScalarAbs<AbsoluteTemperatureUnit, AbsoluteTemperature, TemperatureUnit, Temperature>
26  {
27      /** */
28      private static final long serialVersionUID = 20150901L;
29  
30      /** Constant with value zero. */
31      public static final AbsoluteTemperatureoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperature ZERO = new AbsoluteTemperature(0.0, AbsoluteTemperatureUnit.DEFAULT);
32  
33      /**
34       * Construct AbsoluteTemperature scalar.
35       * @param value double; value
36       * @param unit AbsoluteTemperatureUnit; unit for the double value
37       */
38      public AbsoluteTemperature(final double value, final AbsoluteTemperatureUnit unit)
39      {
40          super(value, unit);
41      }
42  
43      /**
44       * Construct AbsoluteTemperature scalar.
45       * @param value AbsoluteTemperature; Scalar from which to construct this instance
46       */
47      public AbsoluteTemperaturer/AbsoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperature(final AbsoluteTemperature value)
48      {
49          super(value);
50      }
51  
52      /** {@inheritDoc} */
53      @Override
54      public final AbsoluteTemperature instantiateAbs(final double value, final AbsoluteTemperatureUnit unit)
55      {
56          return new AbsoluteTemperature(value, unit);
57      }
58  
59      /** {@inheritDoc} */
60      @Override
61      public final Temperature instantiateRel(final double value, final TemperatureUnit unit)
62      {
63          return new Temperature(value, unit);
64      }
65  
66      /**
67       * Construct AbsoluteTemperature scalar.
68       * @param value double; value in SI units
69       * @return AbsoluteTemperature; the new scalar with the SI value
70       */
71      public static final AbsoluteTemperature instantiateSI(final double value)
72      {
73          return new AbsoluteTemperature(value, AbsoluteTemperatureUnit.DEFAULT);
74      }
75  
76      /**
77       * Interpolate between two values.
78       * @param zero AbsoluteTemperature; the low value
79       * @param one AbsoluteTemperature; the high value
80       * @param ratio double; the ratio between 0 and 1, inclusive
81       * @return AbsoluteTemperature; a Scalar at the ratio between
82       */
83      public static AbsoluteTemperatureluteTemperature.html#AbsoluteTemperature">AbsoluteTemperaturemperature.html#AbsoluteTemperature">AbsoluteTemperature interpolate(final AbsoluteTemperatureluteTemperature.html#AbsoluteTemperature">AbsoluteTemperature zero, final AbsoluteTemperature one,
84              final double ratio)
85      {
86          return new AbsoluteTemperature(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
87                  zero.getDisplayUnit());
88      }
89  
90      /**
91       * Return the maximum value of two absolute scalars.
92       * @param a1 AbsoluteTemperature; the first scalar
93       * @param a2 AbsoluteTemperature; the second scalar
94       * @return AbsoluteTemperature; the maximum value of two absolute scalars
95       */
96      public static AbsoluteTemperaturesoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperaturesoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperature max(final AbsoluteTemperaturesoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperature a1, final AbsoluteTemperature a2)
97      {
98          return a1.gt(a2) ? a1 : a2;
99      }
100 
101     /**
102      * Return the maximum value of more than two absolute scalars.
103      * @param a1 AbsoluteTemperature; the first scalar
104      * @param a2 AbsoluteTemperature; the second scalar
105      * @param an AbsoluteTemperature...; the other scalars
106      * @return the maximum value of more than two absolute scalars
107      */
108     public static AbsoluteTemperaturesoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperaturesoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperature max(final AbsoluteTemperaturesoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperature a1, final AbsoluteTemperature a2,
109             final AbsoluteTemperature... an)
110     {
111         AbsoluteTemperature maxa = a1.gt(a2) ? a1 : a2;
112         for (AbsoluteTemperature a : an)
113         {
114             if (a.gt(maxa))
115             {
116                 maxa = a;
117             }
118         }
119         return maxa;
120     }
121 
122     /**
123      * Return the minimum value of two absolute scalars.
124      * @param a1 AbsoluteTemperature; the first scalar
125      * @param a2 AbsoluteTemperature; the second scalar
126      * @return the minimum value of two absolute scalars
127      */
128     public static AbsoluteTemperaturesoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperaturesoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperature min(final AbsoluteTemperaturesoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperature a1, final AbsoluteTemperature a2)
129     {
130         return a1.lt(a2) ? a1 : a2;
131     }
132 
133     /**
134      * Return the minimum value of more than two absolute scalars.
135      * @param a1 AbsoluteTemperature; the first scalar
136      * @param a2 AbsoluteTemperature; the second scalar
137      * @param an AbsoluteTemperature...; the other scalars
138      * @return the minimum value of more than two absolute scalars
139      */
140     public static AbsoluteTemperaturesoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperaturesoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperature min(final AbsoluteTemperaturesoluteTemperature.html#AbsoluteTemperature">AbsoluteTemperature a1, final AbsoluteTemperature a2,
141             final AbsoluteTemperature... an)
142     {
143         AbsoluteTemperature mina = a1.lt(a2) ? a1 : a2;
144         for (AbsoluteTemperature a : an)
145         {
146             if (a.lt(mina))
147             {
148                 mina = a;
149             }
150         }
151         return mina;
152     }
153 
154     /**
155      * Returns a AbsoluteTemperature representation of a textual representation of a value with a unit. The String
156      * representation that can be parsed is the double value in the unit, followed by the official abbreviation of the unit.
157      * Spaces are allowed, but not required, between the value and the unit.
158      * @param text String; the textual representation to parse into a AbsoluteTemperature
159      * @return AbsoluteTemperature; the Scalar representation of the value in its unit
160      * @throws IllegalArgumentException when the text cannot be parsed
161      * @throws NullPointerException when the text argument is null
162      */
163     public static AbsoluteTemperature valueOf(final String text)
164     {
165         Throw.whenNull(text, "Error parsing AbsoluteTemperature: text to parse is null");
166         Throw.when(text.length() == 0, IllegalArgumentException.class,
167                 "Error parsing AbsoluteTemperature: empty text to parse");
168         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
169         if (matcher.find())
170         {
171             int index = matcher.end();
172             String unitString = text.substring(index).trim();
173             String valueString = text.substring(0, index).trim();
174             AbsoluteTemperatureUnit unit = AbsoluteTemperatureUnit.BASE.getUnitByAbbreviation(unitString);
175             if (unit != null)
176             {
177                 double d = Double.parseDouble(valueString);
178                 return new AbsoluteTemperature(d, unit);
179             }
180         }
181         throw new IllegalArgumentException("Error parsing AbsoluteTemperature from " + text);
182     }
183 
184     /**
185      * Returns a AbsoluteTemperature based on a value and the textual representation of the unit.
186      * @param value double; the value to use
187      * @param unitString String; the textual representation of the unit
188      * @return AbsoluteTemperature; the Scalar representation of the value in its unit
189      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
190      * @throws NullPointerException when the unitString argument is null
191      */
192     public static AbsoluteTemperature of(final double value, final String unitString)
193     {
194         Throw.whenNull(unitString, "Error parsing AbsoluteTemperature: unitString is null");
195         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
196                 "Error parsing AbsoluteTemperature: empty unitString");
197         AbsoluteTemperatureUnit unit = AbsoluteTemperatureUnit.BASE.getUnitByAbbreviation(unitString);
198         if (unit != null)
199         {
200             return new AbsoluteTemperature(value, unit);
201         }
202         throw new IllegalArgumentException("Error parsing AbsoluteTemperature with unit " + unitString);
203     }
204 
205 }