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-2025 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 = "2025-09-06T15:16:28.380798Z")
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 with a unit.
35       * @param value the float value, expressed in the given unit
36       * @param unit 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 with a unit using a double value.
45       * @param value the double value, expressed in the given unit
46       * @param unit 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 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 based on an BASE unit.
76       * @param value the float value in BASE units
77       * @return the new scalar with the BASE value
78       */
79      public static final FloatAbsoluteTemperature ofSI(final float value)
80      {
81          return new FloatAbsoluteTemperature(value, AbsoluteTemperatureUnit.DEFAULT);
82      }
83  
84      /**
85       * Interpolate between two values. Note that the first value does not have to be smaller than the second.
86       * @param zero the value at a ratio of zero
87       * @param one the value at a ratio of one
88       * @param ratio the ratio between 0 and 1, inclusive
89       * @return a FloatAbsoluteTemperature at the given ratio between 0 and 1
90       */
91      public static FloatAbsoluteTemperature interpolate(final FloatAbsoluteTemperature zero, final FloatAbsoluteTemperature one,
92              final float ratio)
93      {
94          Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
95                  "ratio for interpolation should be between 0 and 1, but is %f", ratio);
96          return new FloatAbsoluteTemperature(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
97                  zero.getDisplayUnit());
98      }
99  
100     /**
101      * Return the maximum value of two absolute scalars.
102      * @param a1 the first scalar
103      * @param a2 the second scalar
104      * @return the maximum value of two absolute scalars
105      */
106     public static FloatAbsoluteTemperature max(final FloatAbsoluteTemperature a1, final FloatAbsoluteTemperature a2)
107     {
108         return a1.gt(a2) ? a1 : a2;
109     }
110 
111     /**
112      * Return the maximum value of more than two absolute scalars.
113      * @param a1 the first scalar
114      * @param a2 the second scalar
115      * @param an the other scalars
116      * @return the maximum value of more than two absolute scalars
117      */
118     public static FloatAbsoluteTemperature max(final FloatAbsoluteTemperature a1, final FloatAbsoluteTemperature a2,
119             final FloatAbsoluteTemperature... an)
120     {
121         FloatAbsoluteTemperature maxa = a1.gt(a2) ? a1 : a2;
122         for (FloatAbsoluteTemperature a : an)
123         {
124             if (a.gt(maxa))
125             {
126                 maxa = a;
127             }
128         }
129         return maxa;
130     }
131 
132     /**
133      * Return the minimum value of two absolute scalars.
134      * @param a1 the first scalar
135      * @param a2 the second scalar
136      * @return the minimum value of two absolute scalars
137      */
138     public static FloatAbsoluteTemperature min(final FloatAbsoluteTemperature a1, final FloatAbsoluteTemperature a2)
139     {
140         return a1.lt(a2) ? a1 : a2;
141     }
142 
143     /**
144      * Return the minimum value of more than two absolute scalars.
145      * @param a1 the first scalar
146      * @param a2 the second scalar
147      * @param an the other scalars
148      * @return the minimum value of more than two absolute scalars
149      */
150     public static FloatAbsoluteTemperature min(final FloatAbsoluteTemperature a1, final FloatAbsoluteTemperature a2,
151             final FloatAbsoluteTemperature... an)
152     {
153         FloatAbsoluteTemperature mina = a1.lt(a2) ? a1 : a2;
154         for (FloatAbsoluteTemperature a : an)
155         {
156             if (a.lt(mina))
157             {
158                 mina = a;
159             }
160         }
161         return mina;
162     }
163 
164     /**
165      * Returns a FloatAbsoluteTemperature representation of a textual representation of a value with a unit. The String
166      * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
167      * unit. Spaces are allowed, but not required, between the value and the unit.
168      * @param text the textual representation to parse into a FloatAbsoluteTemperature
169      * @return the Scalar representation of the value in its unit
170      * @throws IllegalArgumentException when the text cannot be parsed
171      * @throws NullPointerException when the text argument is null
172      */
173     public static FloatAbsoluteTemperature valueOf(final String text)
174     {
175         Throw.whenNull(text, "Error parsing FloatAbsoluteTemperature: text to parse is null");
176         Throw.when(text.length() == 0, IllegalArgumentException.class,
177                 "Error parsing FloatAbsoluteTemperature: empty text to parse");
178         try
179         {
180             NumberParser numberParser = new NumberParser().lenient().trailing();
181             float f = numberParser.parseFloat(text);
182             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
183             AbsoluteTemperatureUnit unit = AbsoluteTemperatureUnit.BASE.getUnitByAbbreviation(unitString);
184             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity AbsoluteTemperature",
185                     unitString);
186             return new FloatAbsoluteTemperature(f, unit);
187         }
188         catch (Exception exception)
189         {
190             throw new IllegalArgumentException("Error parsing FloatAbsoluteTemperature from " + text + " using Locale "
191                     + Locale.getDefault(Locale.Category.FORMAT), exception);
192         }
193     }
194 
195     /**
196      * Returns a FloatAbsoluteTemperature based on a value and the textual representation of the unit, which can be localized.
197      * @param value the value to use
198      * @param unitString the textual representation of the unit
199      * @return the Scalar representation of the value in its unit
200      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
201      * @throws NullPointerException when the unitString argument is null
202      */
203     public static FloatAbsoluteTemperature of(final float value, final String unitString)
204     {
205         Throw.whenNull(unitString, "Error parsing FloatAbsoluteTemperature: unitString is null");
206         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
207                 "Error parsing FloatAbsoluteTemperature: empty unitString");
208         AbsoluteTemperatureUnit unit = AbsoluteTemperatureUnit.BASE.getUnitByAbbreviation(unitString);
209         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FloatAbsoluteTemperature with unit %s",
210                 unitString);
211         return new FloatAbsoluteTemperature(value, unit);
212     }
213 
214 }