View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import java.util.regex.Matcher;
4   
5   import javax.annotation.Generated;
6   
7   import org.djunits.Throw;
8   import org.djunits.unit.AbsoluteTemperatureUnit;
9   import org.djunits.unit.DimensionlessUnit;
10  import org.djunits.unit.TemperatureUnit;
11  import org.djunits.value.util.ValueUtil;
12  import org.djunits.value.vfloat.scalar.base.AbstractFloatScalarRelWithAbs;
13  
14  /**
15   * Easy access methods for the FloatTemperature FloatScalar.
16   * <p>
17   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br>
18   * All rights reserved. <br>
19   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
20   * </p>
21   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
23   */
24  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2019-10-18T12:12:25.568Z")
25  public class FloatTemperature extends
26          AbstractFloatScalarRelWithAbs<AbsoluteTemperatureUnit, FloatAbsoluteTemperature, TemperatureUnit, FloatTemperature>
27  {
28      /** */
29      private static final long serialVersionUID = 20150901L;
30  
31      /** Constant with value zero. */
32      public static final FloatTemperatureloatTemperature.html#FloatTemperature">FloatTemperature ZERO = new FloatTemperature(0.0f, TemperatureUnit.SI);
33  
34      /** Constant with value one. */
35      public static final FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperature ONE = new FloatTemperature(1.0f, TemperatureUnit.SI);
36  
37      /** Constant with value NaN. */
38      @SuppressWarnings("checkstyle:constantname")
39      public static final FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperature NaN = new FloatTemperature(Float.NaN, TemperatureUnit.SI);
40  
41      /** Constant with value POSITIVE_INFINITY. */
42      public static final FloatTemperaturere.html#FloatTemperature">FloatTemperature POSITIVE_INFINITY = new FloatTemperature(Float.POSITIVE_INFINITY, TemperatureUnit.SI);
43  
44      /** Constant with value NEGATIVE_INFINITY. */
45      public static final FloatTemperaturere.html#FloatTemperature">FloatTemperature NEGATIVE_INFINITY = new FloatTemperature(Float.NEGATIVE_INFINITY, TemperatureUnit.SI);
46  
47      /** Constant with value MAX_VALUE. */
48      public static final FloatTemperatureerature.html#FloatTemperature">FloatTemperature POS_MAXVALUE = new FloatTemperature(Float.MAX_VALUE, TemperatureUnit.SI);
49  
50      /** Constant with value -MAX_VALUE. */
51      public static final FloatTemperatureerature.html#FloatTemperature">FloatTemperature NEG_MAXVALUE = new FloatTemperature(-Float.MAX_VALUE, TemperatureUnit.SI);
52  
53      /**
54       * Construct FloatTemperature scalar.
55       * @param value float; the float value
56       * @param unit TemperatureUnit; unit for the float value
57       */
58      public FloatTemperature(final float value, final TemperatureUnit unit)
59      {
60          super(value, unit);
61      }
62  
63      /**
64       * Construct FloatTemperature scalar.
65       * @param value FloatTemperature; Scalar from which to construct this instance
66       */
67      public FloatTemperaturelar/FloatTemperature.html#FloatTemperature">FloatTemperature(final FloatTemperature value)
68      {
69          super(value);
70      }
71  
72      /**
73       * Construct FloatTemperature scalar using a double value.
74       * @param value double; the double value
75       * @param unit TemperatureUnit; unit for the resulting float value
76       */
77      public FloatTemperature(final double value, final TemperatureUnit unit)
78      {
79          super((float) value, unit);
80      }
81  
82      /** {@inheritDoc} */
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      /** {@inheritDoc} */
100     @Override
101     public final FloatAbsoluteTemperature instantiateAbs(final float value, final AbsoluteTemperatureUnit unit)
102     {
103         return new FloatAbsoluteTemperature(value, unit);
104     }
105 
106     /**
107      * Interpolate between two values.
108      * @param zero FloatTemperature; the low value
109      * @param one FloatTemperature; the high value
110      * @param ratio double; the ratio between 0 and 1, inclusive
111      * @return FloatTemperature; a Scalar at the ratio between
112      */
113     public static FloatTemperatureoatTemperature.html#FloatTemperature">FloatTemperatureperature.html#FloatTemperature">FloatTemperature interpolate(final FloatTemperatureoatTemperature.html#FloatTemperature">FloatTemperature zero, final FloatTemperature one, final float ratio)
114     {
115         return new FloatTemperature(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
116                 zero.getDisplayUnit());
117     }
118 
119     /**
120      * Return the maximum value of two relative scalars.
121      * @param r1 FloatTemperature; the first scalar
122      * @param r2 FloatTemperature; the second scalar
123      * @return FloatTemperature; the maximum value of two relative scalars
124      */
125     public static FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperature max(final FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperature r1, final FloatTemperature r2)
126     {
127         return (r1.gt(r2)) ? r1 : r2;
128     }
129 
130     /**
131      * Return the maximum value of more than two relative scalars.
132      * @param r1 FloatTemperature; the first scalar
133      * @param r2 FloatTemperature; the second scalar
134      * @param rn FloatTemperature...; the other scalars
135      * @return FloatTemperature; the maximum value of more than two relative scalars
136      */
137     public static FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperature max(final FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperature r1, final FloatTemperature r2, final FloatTemperature... rn)
138     {
139         FloatTemperature maxr = (r1.gt(r2)) ? r1 : r2;
140         for (FloatTemperature r : rn)
141         {
142             if (r.gt(maxr))
143             {
144                 maxr = r;
145             }
146         }
147         return maxr;
148     }
149 
150     /**
151      * Return the minimum value of two relative scalars.
152      * @param r1 FloatTemperature; the first scalar
153      * @param r2 FloatTemperature; the second scalar
154      * @return FloatTemperature; the minimum value of two relative scalars
155      */
156     public static FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperature min(final FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperature r1, final FloatTemperature r2)
157     {
158         return (r1.lt(r2)) ? r1 : r2;
159     }
160 
161     /**
162      * Return the minimum value of more than two relative scalars.
163      * @param r1 FloatTemperature; the first scalar
164      * @param r2 FloatTemperature; the second scalar
165      * @param rn FloatTemperature...; the other scalars
166      * @return FloatTemperature; the minimum value of more than two relative scalars
167      */
168     public static FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperature min(final FloatTemperatureFloatTemperature.html#FloatTemperature">FloatTemperature r1, final FloatTemperature r2, final FloatTemperature... rn)
169     {
170         FloatTemperature minr = (r1.lt(r2)) ? r1 : r2;
171         for (FloatTemperature r : rn)
172         {
173             if (r.lt(minr))
174             {
175                 minr = r;
176             }
177         }
178         return minr;
179     }
180 
181     /**
182      * Returns a FloatTemperature representation of a textual representation of a value with a unit. The String representation
183      * that can be parsed is the double value in the unit, followed by the official abbreviation of the unit. Spaces are
184      * allowed, but not required, between the value and the unit.
185      * @param text String; the textual representation to parse into a FloatTemperature
186      * @return FloatTemperature; the Scalar representation of the value in its unit
187      * @throws IllegalArgumentException when the text cannot be parsed
188      * @throws NullPointerException when the text argument is null
189      */
190     public static FloatTemperature valueOf(final String text)
191     {
192         Throw.whenNull(text, "Error parsing FloatTemperature: text to parse is null");
193         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatTemperature: empty text to parse");
194         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
195         if (matcher.find())
196         {
197             int index = matcher.end();
198             String unitString = text.substring(index).trim();
199             String valueString = text.substring(0, index).trim();
200             TemperatureUnit unit = TemperatureUnit.BASE.getUnitByAbbreviation(unitString);
201             if (unit != null)
202             {
203                 float f = Float.parseFloat(valueString);
204                 return new FloatTemperature(f, unit);
205             }
206         }
207         throw new IllegalArgumentException("Error parsing FloatTemperature from " + text);
208     }
209 
210     /**
211      * Returns a FloatTemperature based on a value and the textual representation of the unit.
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 }