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.DimensionlessUnit;
7   import org.djunits.unit.TemperatureUnit;
8   import org.djunits.value.vfloat.scalar.base.FloatScalar;
9   import org.djunits.value.vfloat.scalar.base.FloatScalarRelWithAbs;
10  import org.djutils.base.NumberParser;
11  import org.djutils.exceptions.Throw;
12  
13  import jakarta.annotation.Generated;
14  
15  /**
16   * Easy access methods for the FloatTemperature FloatScalar.
17   * <p>
18   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br>
19   * All rights reserved. <br>
20   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
21   * </p>
22   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
23   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
24   */
25  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
26  public class FloatTemperature
27          extends FloatScalarRelWithAbs<AbsoluteTemperatureUnit, FloatAbsoluteTemperature, TemperatureUnit, FloatTemperature>
28  {
29      /** */
30      private static final long serialVersionUID = 20150901L;
31  
32      /** Constant with value zero. */
33      public static final FloatTemperature ZERO = new FloatTemperature(0.0f, TemperatureUnit.SI);
34  
35      /** Constant with value one. */
36      public static final FloatTemperature ONE = new FloatTemperature(1.0f, TemperatureUnit.SI);
37  
38      /** Constant with value NaN. */
39      @SuppressWarnings("checkstyle:constantname")
40      public static final FloatTemperature NaN = new FloatTemperature(Float.NaN, TemperatureUnit.SI);
41  
42      /** Constant with value POSITIVE_INFINITY. */
43      public static final FloatTemperature POSITIVE_INFINITY = new FloatTemperature(Float.POSITIVE_INFINITY, TemperatureUnit.SI);
44  
45      /** Constant with value NEGATIVE_INFINITY. */
46      public static final FloatTemperature NEGATIVE_INFINITY = new FloatTemperature(Float.NEGATIVE_INFINITY, TemperatureUnit.SI);
47  
48      /** Constant with value MAX_VALUE. */
49      public static final FloatTemperature POS_MAXVALUE = new FloatTemperature(Float.MAX_VALUE, TemperatureUnit.SI);
50  
51      /** Constant with value -MAX_VALUE. */
52      public static final FloatTemperature NEG_MAXVALUE = new FloatTemperature(-Float.MAX_VALUE, TemperatureUnit.SI);
53  
54      /**
55       * Construct FloatTemperature scalar.
56       * @param value float; the float value
57       * @param unit TemperatureUnit; unit for the float value
58       */
59      public FloatTemperature(final float value, final TemperatureUnit unit)
60      {
61          super(value, unit);
62      }
63  
64      /**
65       * Construct FloatTemperature scalar.
66       * @param value FloatTemperature; Scalar from which to construct this instance
67       */
68      public FloatTemperature(final FloatTemperature value)
69      {
70          super(value);
71      }
72  
73      /**
74       * Construct FloatTemperature scalar using a double value.
75       * @param value double; the double value
76       * @param unit TemperatureUnit; unit for the resulting float value
77       */
78      public FloatTemperature(final double value, final TemperatureUnit unit)
79      {
80          super((float) value, unit);
81      }
82  
83      @Override
84      public final FloatTemperature instantiateRel(final float value, final TemperatureUnit unit)
85      {
86          return new FloatTemperature(value, unit);
87      }
88  
89      /**
90       * Construct FloatTemperature scalar.
91       * @param value float; the float value in SI units
92       * @return FloatTemperature; the new scalar with the SI value
93       */
94      public static final FloatTemperature instantiateSI(final float value)
95      {
96          return new FloatTemperature(value, TemperatureUnit.SI);
97      }
98  
99      @Override
100     public final FloatAbsoluteTemperature instantiateAbs(final float value, final AbsoluteTemperatureUnit unit)
101     {
102         return new FloatAbsoluteTemperature(value, unit);
103     }
104 
105     /**
106      * Interpolate between two values.
107      * @param zero FloatTemperature; the low value
108      * @param one FloatTemperature; the high value
109      * @param ratio double; the ratio between 0 and 1, inclusive
110      * @return FloatTemperature; a Scalar at the ratio between
111      */
112     public static FloatTemperature interpolate(final FloatTemperature zero, final FloatTemperature one, final float ratio)
113     {
114         return new FloatTemperature(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
115                 zero.getDisplayUnit());
116     }
117 
118     /**
119      * Return the maximum value of two relative scalars.
120      * @param r1 FloatTemperature; the first scalar
121      * @param r2 FloatTemperature; the second scalar
122      * @return FloatTemperature; the maximum value of two relative scalars
123      */
124     public static FloatTemperature max(final FloatTemperature r1, final FloatTemperature r2)
125     {
126         return r1.gt(r2) ? r1 : r2;
127     }
128 
129     /**
130      * Return the maximum value of more than two relative scalars.
131      * @param r1 FloatTemperature; the first scalar
132      * @param r2 FloatTemperature; the second scalar
133      * @param rn FloatTemperature...; the other scalars
134      * @return FloatTemperature; the maximum value of more than two relative scalars
135      */
136     public static FloatTemperature max(final FloatTemperature r1, final FloatTemperature r2, final FloatTemperature... rn)
137     {
138         FloatTemperature maxr = r1.gt(r2) ? r1 : r2;
139         for (FloatTemperature r : rn)
140         {
141             if (r.gt(maxr))
142             {
143                 maxr = r;
144             }
145         }
146         return maxr;
147     }
148 
149     /**
150      * Return the minimum value of two relative scalars.
151      * @param r1 FloatTemperature; the first scalar
152      * @param r2 FloatTemperature; the second scalar
153      * @return FloatTemperature; the minimum value of two relative scalars
154      */
155     public static FloatTemperature min(final FloatTemperature r1, final FloatTemperature r2)
156     {
157         return r1.lt(r2) ? r1 : r2;
158     }
159 
160     /**
161      * Return the minimum value of more than two relative scalars.
162      * @param r1 FloatTemperature; the first scalar
163      * @param r2 FloatTemperature; the second scalar
164      * @param rn FloatTemperature...; the other scalars
165      * @return FloatTemperature; the minimum value of more than two relative scalars
166      */
167     public static FloatTemperature min(final FloatTemperature r1, final FloatTemperature r2, final FloatTemperature... rn)
168     {
169         FloatTemperature minr = r1.lt(r2) ? r1 : r2;
170         for (FloatTemperature r : rn)
171         {
172             if (r.lt(minr))
173             {
174                 minr = r;
175             }
176         }
177         return minr;
178     }
179 
180     /**
181      * Returns a FloatTemperature representation of a textual representation of a value with a unit. The String representation
182      * that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces
183      * are allowed, but not required, between the value and the unit.
184      * @param text String; the textual representation to parse into a FloatTemperature
185      * @return FloatTemperature; the Scalar representation of the value in its unit
186      * @throws IllegalArgumentException when the text cannot be parsed
187      * @throws NullPointerException when the text argument is null
188      */
189     public static FloatTemperature valueOf(final String text)
190     {
191         Throw.whenNull(text, "Error parsing FloatTemperature: text to parse is null");
192         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatTemperature: empty text to parse");
193         try
194         {
195             NumberParser numberParser = new NumberParser().lenient().trailing();
196             float f = numberParser.parseFloat(text);
197             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
198             TemperatureUnit unit = TemperatureUnit.BASE.getUnitByAbbreviation(unitString);
199             if (unit == null)
200                 throw new IllegalArgumentException("Unit " + unitString + " not found");
201             return new FloatTemperature(f, unit);
202         }
203         catch (Exception exception)
204         {
205             throw new IllegalArgumentException("Error parsing FloatTemperature from " + text + " using Locale "
206                     + Locale.getDefault(Locale.Category.FORMAT), exception);
207         }
208     }
209 
210     /**
211      * Returns a FloatTemperature based on a value and the textual representation of the unit, which can be localized.
212      * @param value double; the value to use
213      * @param unitString String; the textual representation of the unit
214      * @return FloatTemperature; the Scalar representation of the value in its unit
215      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
216      * @throws NullPointerException when the unitString argument is null
217      */
218     public static FloatTemperature of(final float value, final String unitString)
219     {
220         Throw.whenNull(unitString, "Error parsing FloatTemperature: unitString is null");
221         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
222                 "Error parsing FloatTemperature: empty unitString");
223         TemperatureUnit unit = TemperatureUnit.BASE.getUnitByAbbreviation(unitString);
224         if (unit != null)
225         {
226             return new FloatTemperature(value, unit);
227         }
228         throw new IllegalArgumentException("Error parsing FloatTemperature with unit " + unitString);
229     }
230 
231     /**
232      * Calculate the division of FloatTemperature and FloatTemperature, which results in a FloatDimensionless scalar.
233      * @param v FloatTemperature; scalar
234      * @return FloatDimensionless; scalar as a division of FloatTemperature and FloatTemperature
235      */
236     public final FloatDimensionless divide(final FloatTemperature v)
237     {
238         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
239     }
240 
241     @Override
242     public FloatSIScalar reciprocal()
243     {
244         return FloatScalar.divide(FloatDimensionless.ONE, this);
245     }
246 
247 }