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.AbstractFloatScalarRelWithAbs;
9   import org.djunits.value.vfloat.scalar.base.FloatScalar;
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-2023 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-04-30T13:59:27.633664900Z")
26  public class FloatTemperature extends
27          AbstractFloatScalarRelWithAbs<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      /** {@inheritDoc} */
84      @Override
85      public final FloatTemperature instantiateRel(final float value, final TemperatureUnit unit)
86      {
87          return new FloatTemperature(value, unit);
88      }
89  
90      /**
91       * Construct FloatTemperature scalar.
92       * @param value float; the float value in SI units
93       * @return FloatTemperature; the new scalar with the SI value
94       */
95      public static final FloatTemperature instantiateSI(final float value)
96      {
97          return new FloatTemperature(value, TemperatureUnit.SI);
98      }
99  
100     /** {@inheritDoc} */
101     @Override
102     public final FloatAbsoluteTemperature instantiateAbs(final float value, final AbsoluteTemperatureUnit unit)
103     {
104         return new FloatAbsoluteTemperature(value, unit);
105     }
106 
107     /**
108      * Interpolate between two values.
109      * @param zero FloatTemperature; the low value
110      * @param one FloatTemperature; the high value
111      * @param ratio double; the ratio between 0 and 1, inclusive
112      * @return FloatTemperature; a Scalar at the ratio between
113      */
114     public static FloatTemperature interpolate(final FloatTemperature zero, final FloatTemperature one, final float ratio)
115     {
116         return new FloatTemperature(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
117                 zero.getDisplayUnit());
118     }
119 
120     /**
121      * Return the maximum value of two relative scalars.
122      * @param r1 FloatTemperature; the first scalar
123      * @param r2 FloatTemperature; the second scalar
124      * @return FloatTemperature; the maximum value of two relative scalars
125      */
126     public static FloatTemperature max(final FloatTemperature r1, final FloatTemperature r2)
127     {
128         return r1.gt(r2) ? r1 : r2;
129     }
130 
131     /**
132      * Return the maximum value of more than two relative scalars.
133      * @param r1 FloatTemperature; the first scalar
134      * @param r2 FloatTemperature; the second scalar
135      * @param rn FloatTemperature...; the other scalars
136      * @return FloatTemperature; the maximum value of more than two relative scalars
137      */
138     public static FloatTemperature max(final FloatTemperature r1, final FloatTemperature r2, final FloatTemperature... rn)
139     {
140         FloatTemperature maxr = r1.gt(r2) ? r1 : r2;
141         for (FloatTemperature r : rn)
142         {
143             if (r.gt(maxr))
144             {
145                 maxr = r;
146             }
147         }
148         return maxr;
149     }
150 
151     /**
152      * Return the minimum value of two relative scalars.
153      * @param r1 FloatTemperature; the first scalar
154      * @param r2 FloatTemperature; the second scalar
155      * @return FloatTemperature; the minimum value of two relative scalars
156      */
157     public static FloatTemperature min(final FloatTemperature r1, final FloatTemperature r2)
158     {
159         return r1.lt(r2) ? r1 : r2;
160     }
161 
162     /**
163      * Return the minimum value of more than two relative scalars.
164      * @param r1 FloatTemperature; the first scalar
165      * @param r2 FloatTemperature; the second scalar
166      * @param rn FloatTemperature...; the other scalars
167      * @return FloatTemperature; the minimum value of more than two relative scalars
168      */
169     public static FloatTemperature min(final FloatTemperature r1, final FloatTemperature r2, final FloatTemperature... rn)
170     {
171         FloatTemperature minr = r1.lt(r2) ? r1 : r2;
172         for (FloatTemperature r : rn)
173         {
174             if (r.lt(minr))
175             {
176                 minr = r;
177             }
178         }
179         return minr;
180     }
181 
182     /**
183      * Returns a FloatTemperature representation of a textual representation of a value with a unit. The String representation
184      * that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces
185      * are allowed, but not required, between the value and the unit.
186      * @param text String; the textual representation to parse into a FloatTemperature
187      * @return FloatTemperature; the Scalar representation of the value in its unit
188      * @throws IllegalArgumentException when the text cannot be parsed
189      * @throws NullPointerException when the text argument is null
190      */
191     public static FloatTemperature valueOf(final String text)
192     {
193         Throw.whenNull(text, "Error parsing FloatTemperature: text to parse is null");
194         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatTemperature: empty text to parse");
195         try
196         {
197             NumberParser numberParser = new NumberParser().lenient().trailing();
198             float f = numberParser.parseFloat(text);
199             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
200             TemperatureUnit unit = TemperatureUnit.BASE.getUnitByAbbreviation(unitString);
201             if (unit == null)
202                 throw new IllegalArgumentException("Unit " + unitString + " not found");
203             return new FloatTemperature(f, unit);
204         }
205         catch (Exception exception)
206         {
207             throw new IllegalArgumentException("Error parsing FloatTemperature from " + text + " using Locale "
208                     + Locale.getDefault(Locale.Category.FORMAT), exception);
209         }
210     }
211 
212     /**
213      * Returns a FloatTemperature based on a value and the textual representation of the unit, which can be localized.
214      * @param value double; the value to use
215      * @param unitString String; the textual representation of the unit
216      * @return FloatTemperature; the Scalar representation of the value in its unit
217      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
218      * @throws NullPointerException when the unitString argument is null
219      */
220     public static FloatTemperature of(final float value, final String unitString)
221     {
222         Throw.whenNull(unitString, "Error parsing FloatTemperature: unitString is null");
223         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
224                 "Error parsing FloatTemperature: empty unitString");
225         TemperatureUnit unit = TemperatureUnit.BASE.getUnitByAbbreviation(unitString);
226         if (unit != null)
227         {
228             return new FloatTemperature(value, unit);
229         }
230         throw new IllegalArgumentException("Error parsing FloatTemperature with unit " + unitString);
231     }
232 
233     /**
234      * Calculate the division of FloatTemperature and FloatTemperature, which results in a FloatDimensionless scalar.
235      * @param v FloatTemperature; scalar
236      * @return FloatDimensionless; scalar as a division of FloatTemperature and FloatTemperature
237      */
238     public final FloatDimensionless divide(final FloatTemperature v)
239     {
240         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
241     }
242 
243     /** {@inheritDoc} */
244     @Override
245     public FloatSIScalar reciprocal()
246     {
247         return FloatScalar.divide(FloatDimensionless.ONE, this);
248     }
249 
250 }