View Javadoc
1   package org.djunits.value.vdouble.scalar;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.AbsoluteTemperatureUnit;
6   import org.djunits.unit.TemperatureUnit;
7   import org.djunits.value.vdouble.scalar.base.DoubleScalarAbs;
8   import org.djutils.base.NumberParser;
9   import org.djutils.exceptions.Throw;
10  
11  import jakarta.annotation.Generated;
12  
13  /**
14   * Easy access methods for the Absolute AbsoluteTemperature DoubleScalar.
15   * <p>
16   * Copyright (c) 2013-2024 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://djunits.org/docs/license.html">DJUNITS 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 = "2023-07-23T14:06:38.224104100Z")
24  public class AbsoluteTemperature
25          extends DoubleScalarAbs<AbsoluteTemperatureUnit, AbsoluteTemperature, TemperatureUnit, Temperature>
26  {
27      /** */
28      private static final long serialVersionUID = 20150901L;
29  
30      /** Constant with value zero. */
31      public static final 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 AbsoluteTemperature(final AbsoluteTemperature value)
48      {
49          super(value);
50      }
51  
52      @Override
53      public final AbsoluteTemperature instantiateAbs(final double value, final AbsoluteTemperatureUnit unit)
54      {
55          return new AbsoluteTemperature(value, unit);
56      }
57  
58      @Override
59      public final Temperature instantiateRel(final double value, final TemperatureUnit unit)
60      {
61          return new Temperature(value, unit);
62      }
63  
64      /**
65       * Construct AbsoluteTemperature scalar.
66       * @param value double; value in SI units
67       * @return AbsoluteTemperature; the new scalar with the SI value
68       */
69      public static final AbsoluteTemperature instantiateSI(final double value)
70      {
71          return new AbsoluteTemperature(value, AbsoluteTemperatureUnit.DEFAULT);
72      }
73  
74      /**
75       * Interpolate between two values.
76       * @param zero AbsoluteTemperature; the low value
77       * @param one AbsoluteTemperature; the high value
78       * @param ratio double; the ratio between 0 and 1, inclusive
79       * @return AbsoluteTemperature; a Scalar at the ratio between
80       */
81      public static AbsoluteTemperature interpolate(final AbsoluteTemperature zero, final AbsoluteTemperature one,
82              final double ratio)
83      {
84          return new AbsoluteTemperature(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
85                  zero.getDisplayUnit());
86      }
87  
88      /**
89       * Return the maximum value of two absolute scalars.
90       * @param a1 AbsoluteTemperature; the first scalar
91       * @param a2 AbsoluteTemperature; the second scalar
92       * @return AbsoluteTemperature; the maximum value of two absolute scalars
93       */
94      public static AbsoluteTemperature max(final AbsoluteTemperature a1, final AbsoluteTemperature a2)
95      {
96          return a1.gt(a2) ? a1 : a2;
97      }
98  
99      /**
100      * Return the maximum value of more than two absolute scalars.
101      * @param a1 AbsoluteTemperature; the first scalar
102      * @param a2 AbsoluteTemperature; the second scalar
103      * @param an AbsoluteTemperature...; the other scalars
104      * @return the maximum value of more than two absolute scalars
105      */
106     public static AbsoluteTemperature max(final AbsoluteTemperature a1, final AbsoluteTemperature a2,
107             final AbsoluteTemperature... an)
108     {
109         AbsoluteTemperature maxa = a1.gt(a2) ? a1 : a2;
110         for (AbsoluteTemperature a : an)
111         {
112             if (a.gt(maxa))
113             {
114                 maxa = a;
115             }
116         }
117         return maxa;
118     }
119 
120     /**
121      * Return the minimum value of two absolute scalars.
122      * @param a1 AbsoluteTemperature; the first scalar
123      * @param a2 AbsoluteTemperature; the second scalar
124      * @return the minimum value of two absolute scalars
125      */
126     public static AbsoluteTemperature min(final AbsoluteTemperature a1, final AbsoluteTemperature a2)
127     {
128         return a1.lt(a2) ? a1 : a2;
129     }
130 
131     /**
132      * Return the minimum value of more than two absolute scalars.
133      * @param a1 AbsoluteTemperature; the first scalar
134      * @param a2 AbsoluteTemperature; the second scalar
135      * @param an AbsoluteTemperature...; the other scalars
136      * @return the minimum value of more than two absolute scalars
137      */
138     public static AbsoluteTemperature min(final AbsoluteTemperature a1, final AbsoluteTemperature a2,
139             final AbsoluteTemperature... an)
140     {
141         AbsoluteTemperature mina = a1.lt(a2) ? a1 : a2;
142         for (AbsoluteTemperature a : an)
143         {
144             if (a.lt(mina))
145             {
146                 mina = a;
147             }
148         }
149         return mina;
150     }
151 
152     /**
153      * Returns a AbsoluteTemperature representation of a textual representation of a value with a unit. The String
154      * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
155      * unit. Spaces are allowed, but not required, between the value and the unit.
156      * @param text String; the textual representation to parse into a AbsoluteTemperature
157      * @return AbsoluteTemperature; the Scalar representation of the value in its unit
158      * @throws IllegalArgumentException when the text cannot be parsed
159      * @throws NullPointerException when the text argument is null
160      */
161     public static AbsoluteTemperature valueOf(final String text)
162     {
163         Throw.whenNull(text, "Error parsing AbsoluteTemperature: text to parse is null");
164         Throw.when(text.length() == 0, IllegalArgumentException.class,
165                 "Error parsing AbsoluteTemperature: empty text to parse");
166         try
167         {
168             NumberParser numberParser = new NumberParser().lenient().trailing();
169             double d = numberParser.parseDouble(text);
170             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
171             AbsoluteTemperatureUnit unit = AbsoluteTemperatureUnit.BASE.getUnitByAbbreviation(unitString);
172             if (unit == null)
173                 throw new IllegalArgumentException("Unit " + unitString + " not found");
174             return new AbsoluteTemperature(d, unit);
175         }
176         catch (Exception exception)
177         {
178             throw new IllegalArgumentException("Error parsing AbsoluteTemperature from " + text + " using Locale "
179                     + Locale.getDefault(Locale.Category.FORMAT), exception);
180         }
181     }
182 
183     /**
184      * Returns a AbsoluteTemperature based on a value and the textual representation of the unit, which can be localized.
185      * @param value double; the value to use
186      * @param unitString String; the textual representation of the unit
187      * @return AbsoluteTemperature; the Scalar representation of the value in its unit
188      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
189      * @throws NullPointerException when the unitString argument is null
190      */
191     public static AbsoluteTemperature of(final double value, final String unitString)
192     {
193         Throw.whenNull(unitString, "Error parsing AbsoluteTemperature: unitString is null");
194         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
195                 "Error parsing AbsoluteTemperature: empty unitString");
196         AbsoluteTemperatureUnit unit = AbsoluteTemperatureUnit.BASE.getUnitByAbbreviation(unitString);
197         if (unit != null)
198         {
199             return new AbsoluteTemperature(value, unit);
200         }
201         throw new IllegalArgumentException("Error parsing AbsoluteTemperature with unit " + unitString);
202     }
203 
204 }