View Javadoc
1   package org.djunits.value.vfloat.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.vfloat.scalar.base.FloatScalarAbs;
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 FloatAbsoluteTemperature FloatScalar.
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 FloatAbsoluteTemperature
25          extends FloatScalarAbs<AbsoluteTemperatureUnit, FloatAbsoluteTemperature, TemperatureUnit, FloatTemperature>
26  {
27      /** */
28      private static final long serialVersionUID = 20150901L;
29  
30      /** Constant with value zero. */
31      public static final FloatAbsoluteTemperature ZERO = new FloatAbsoluteTemperature(0.0f, AbsoluteTemperatureUnit.DEFAULT);
32  
33      /**
34       * Construct FloatAbsoluteTemperature scalar.
35       * @param value float; the float value
36       * @param unit AbsoluteTemperatureUnit; unit for the float value
37       */
38      public FloatAbsoluteTemperature(final float value, final AbsoluteTemperatureUnit unit)
39      {
40          super(value, unit);
41      }
42  
43      /**
44       * Construct FloatAbsoluteTemperature scalar using a double value.
45       * @param value double; the double value
46       * @param unit AbsoluteTemperatureUnit; unit for the resulting float value
47       */
48      public FloatAbsoluteTemperature(final double value, final AbsoluteTemperatureUnit unit)
49      {
50          super((float) value, unit);
51      }
52  
53      /**
54       * Construct FloatAbsoluteTemperature scalar.
55       * @param value FloatAbsoluteTemperature; Scalar from which to construct this instance
56       */
57      public FloatAbsoluteTemperature(final FloatAbsoluteTemperature value)
58      {
59          super(value);
60      }
61  
62      @Override
63      public final FloatAbsoluteTemperature instantiateAbs(final float value, final AbsoluteTemperatureUnit unit)
64      {
65          return new FloatAbsoluteTemperature(value, unit);
66      }
67  
68      @Override
69      public final FloatTemperature instantiateRel(final float value, final TemperatureUnit unit)
70      {
71          return new FloatTemperature(value, unit);
72      }
73  
74      /**
75       * Construct FloatAbsoluteTemperature scalar.
76       * @param value float; the float value in BASE units
77       * @return FloatAbsoluteTemperature; the new scalar with the BASE value
78       */
79      public static final FloatAbsoluteTemperature instantiateSI(final float value)
80      {
81          return new FloatAbsoluteTemperature(value, AbsoluteTemperatureUnit.DEFAULT);
82      }
83  
84      /**
85       * Interpolate between two values.
86       * @param zero FloatAbsoluteTemperature; the low value
87       * @param one FloatAbsoluteTemperature; the high value
88       * @param ratio float; the ratio between 0 and 1, inclusive
89       * @return FloatAbsoluteTemperature; a Scalar at the ratio between
90       */
91      public static FloatAbsoluteTemperature interpolate(final FloatAbsoluteTemperature zero, final FloatAbsoluteTemperature one,
92              final float ratio)
93      {
94          return new FloatAbsoluteTemperature(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
95                  zero.getDisplayUnit());
96      }
97  
98      /**
99       * Return the maximum value of two absolute scalars.
100      * @param a1 FloatAbsoluteTemperature; the first scalar
101      * @param a2 FloatAbsoluteTemperature; the second scalar
102      * @return FloatAbsoluteTemperature; the maximum value of two absolute scalars
103      */
104     public static FloatAbsoluteTemperature max(final FloatAbsoluteTemperature a1, final FloatAbsoluteTemperature a2)
105     {
106         return a1.gt(a2) ? a1 : a2;
107     }
108 
109     /**
110      * Return the maximum value of more than two absolute scalars.
111      * @param a1 FloatAbsoluteTemperature; the first scalar
112      * @param a2 FloatAbsoluteTemperature; the second scalar
113      * @param an FloatAbsoluteTemperature...; the other scalars
114      * @return FloatAbsoluteTemperature; the maximum value of more than two absolute scalars
115      */
116     public static FloatAbsoluteTemperature max(final FloatAbsoluteTemperature a1, final FloatAbsoluteTemperature a2,
117             final FloatAbsoluteTemperature... an)
118     {
119         FloatAbsoluteTemperature maxa = a1.gt(a2) ? a1 : a2;
120         for (FloatAbsoluteTemperature a : an)
121         {
122             if (a.gt(maxa))
123             {
124                 maxa = a;
125             }
126         }
127         return maxa;
128     }
129 
130     /**
131      * Return the minimum value of two absolute scalars.
132      * @param a1 FloatAbsoluteTemperature; the first scalar
133      * @param a2 FloatAbsoluteTemperature; the second scalar
134      * @return FloatAbsoluteTemperature; the minimum value of two absolute scalars
135      */
136     public static FloatAbsoluteTemperature min(final FloatAbsoluteTemperature a1, final FloatAbsoluteTemperature a2)
137     {
138         return a1.lt(a2) ? a1 : a2;
139     }
140 
141     /**
142      * Return the minimum value of more than two absolute scalars.
143      * @param a1 FloatAbsoluteTemperature; the first scalar
144      * @param a2 FloatAbsoluteTemperature; the second scalar
145      * @param an FloatAbsoluteTemperature...; the other scalars
146      * @return FloatAbsoluteTemperature; the minimum value of more than two absolute scalars
147      */
148     public static FloatAbsoluteTemperature min(final FloatAbsoluteTemperature a1, final FloatAbsoluteTemperature a2,
149             final FloatAbsoluteTemperature... an)
150     {
151         FloatAbsoluteTemperature mina = a1.lt(a2) ? a1 : a2;
152         for (FloatAbsoluteTemperature a : an)
153         {
154             if (a.lt(mina))
155             {
156                 mina = a;
157             }
158         }
159         return mina;
160     }
161 
162     /**
163      * Returns a FloatAbsoluteTemperature representation of a textual representation of a value with a unit. The String
164      * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
165      * unit. Spaces are allowed, but not required, between the value and the unit.
166      * @param text String; the textual representation to parse into a FloatAbsoluteTemperature
167      * @return FloatAbsoluteTemperature; the Scalar representation of the value in its unit
168      * @throws IllegalArgumentException when the text cannot be parsed
169      * @throws NullPointerException when the text argument is null
170      */
171     public static FloatAbsoluteTemperature valueOf(final String text)
172     {
173         Throw.whenNull(text, "Error parsing FloatAbsoluteTemperature: text to parse is null");
174         Throw.when(text.length() == 0, IllegalArgumentException.class,
175                 "Error parsing FloatAbsoluteTemperature: empty text to parse");
176         try
177         {
178             NumberParser numberParser = new NumberParser().lenient().trailing();
179             float f = numberParser.parseFloat(text);
180             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
181             AbsoluteTemperatureUnit unit = AbsoluteTemperatureUnit.BASE.getUnitByAbbreviation(unitString);
182             if (unit == null)
183                 throw new IllegalArgumentException("Unit " + unitString + " not found");
184             return new FloatAbsoluteTemperature(f, unit);
185         }
186         catch (Exception exception)
187         {
188             throw new IllegalArgumentException("Error parsing FloatAbsoluteTemperature from " + text + " using Locale "
189                     + Locale.getDefault(Locale.Category.FORMAT), exception);
190         }
191     }
192 
193     /**
194      * Returns a FloatAbsoluteTemperature based on a value and the textual representation of the unit, which can be localized.
195      * @param value double; the value to use
196      * @param unitString String; the textual representation of the unit
197      * @return FloatAbsoluteTemperature; the Scalar representation of the value in its unit
198      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
199      * @throws NullPointerException when the unitString argument is null
200      */
201     public static FloatAbsoluteTemperature of(final float value, final String unitString)
202     {
203         Throw.whenNull(unitString, "Error parsing FloatAbsoluteTemperature: unitString is null");
204         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
205                 "Error parsing FloatAbsoluteTemperature: empty unitString");
206         AbsoluteTemperatureUnit unit = AbsoluteTemperatureUnit.BASE.getUnitByAbbreviation(unitString);
207         if (unit != null)
208         {
209             return new FloatAbsoluteTemperature(value, unit);
210         }
211         throw new IllegalArgumentException("Error parsing FloatAbsoluteTemperature with unit " + unitString);
212     }
213 
214 }