View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import org.djunits.unit.AbsoluteTemperatureUnit;
4   import org.djunits.unit.TemperatureUnit;
5   
6   /**
7    * Easy access methods for the AbsoluteTemperature FloatScalar. Instead of:
8    * 
9    * <pre>
10   * FloatScalar.Abs&lt;AbsoluteTemperatureUnit&gt; value =
11   *         new FloatScalar.Abs&lt;AbsoluteTemperatureUnit&gt;(100.0, AbsoluteTemperatureUnit.SI);
12   * </pre>
13   * 
14   * we can now write:
15   * 
16   * <pre>
17   * FloatAbsoluteTemperature value = new FloatAbsoluteTemperature(100.0, AbsoluteTemperatureUnit.SI);
18   * </pre>
19   * 
20   * The compiler will automatically recognize which units belong to which quantity, and whether the quantity type and the unit
21   * used are compatible.
22   * <p>
23   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br>
24   * All rights reserved. <br>
25   * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
26   * <p>
27   * $LastChangedDate: 2017-01-30 14:23:11 +0100 (Mon, 30 Jan 2017) $, @version $Revision: 234 $, by $Author: averbraeck $,
28   * initial version Sep 1, 2015 <br>
29   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
30   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
31   */
32  public class FloatAbsoluteTemperature
33          extends AbstractFloatScalarAbs<AbsoluteTemperatureUnit, FloatAbsoluteTemperature, TemperatureUnit, FloatTemperature>
34  {
35      /** */
36      private static final long serialVersionUID = 20150901L;
37  
38      /** constant with value zero. */
39      public static final FloatAbsoluteTemperature ZERO = new FloatAbsoluteTemperature(0.0f, AbsoluteTemperatureUnit.BASE);
40  
41      /**
42       * Construct FloatAbsoluteTemperature scalar.
43       * @param value float value
44       * @param unit unit for the float value
45       */
46      public FloatAbsoluteTemperature(final float value, final AbsoluteTemperatureUnit unit)
47      {
48          super(value, unit);
49      }
50  
51      /**
52       * Construct FloatAbsoluteTemperature scalar using a double value.
53       * @param value double value
54       * @param unit unit for the resulting float value
55       */
56      public FloatAbsoluteTemperature(final double value, final AbsoluteTemperatureUnit unit)
57      {
58          super((float) value, unit);
59      }
60  
61      /**
62       * Construct FloatAbsoluteTemperature scalar.
63       * @param value Scalar from which to construct this instance
64       */
65      public FloatAbsoluteTemperature(final FloatAbsoluteTemperature value)
66      {
67          super(value);
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public final FloatAbsoluteTemperature instantiateAbs(final float value, final AbsoluteTemperatureUnit unit)
73      {
74          return new FloatAbsoluteTemperature(value, unit);
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public final FloatTemperature instantiateRel(final float value, final TemperatureUnit unit)
80      {
81          return new FloatTemperature(value, unit);
82      }
83  
84      /**
85       * Construct FloatAbsoluteTemperature scalar.
86       * @param value float value in BASE units
87       * @return the new scalar with the BASE value
88       */
89      public static final FloatAbsoluteTemperature createSI(final float value)
90      {
91          return new FloatAbsoluteTemperature(value, AbsoluteTemperatureUnit.BASE);
92      }
93  
94      /**
95       * Interpolate between two values.
96       * @param zero the low value
97       * @param one the high value
98       * @param ratio the ratio between 0 and 1, inclusive
99       * @return a Scalar at the ratio between
100      */
101     public static FloatAbsoluteTemperature interpolate(final FloatAbsoluteTemperature zero, final FloatAbsoluteTemperature one,
102             final float ratio)
103     {
104         return new FloatAbsoluteTemperature(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio,
105                 zero.getUnit());
106     }
107 
108     /**
109      * Return the maximum value of two absolute scalars.
110      * @param a1 the first scalar
111      * @param a2 the second scalar
112      * @return the maximum value of two absolute scalars
113      */
114     public static FloatAbsoluteTemperature max(final FloatAbsoluteTemperature a1, final FloatAbsoluteTemperature a2)
115     {
116         return (a1.gt(a2)) ? a1 : a2;
117     }
118 
119     /**
120      * Return the maximum value of more than two absolute scalars.
121      * @param a1 the first scalar
122      * @param a2 the second scalar
123      * @param an the other scalars
124      * @return the maximum value of more than two absolute scalars
125      */
126     public static FloatAbsoluteTemperature max(final FloatAbsoluteTemperature a1, final FloatAbsoluteTemperature a2,
127             final FloatAbsoluteTemperature... an)
128     {
129         FloatAbsoluteTemperature maxa = (a1.gt(a2)) ? a1 : a2;
130         for (FloatAbsoluteTemperature a : an)
131         {
132             if (a.gt(maxa))
133             {
134                 maxa = a;
135             }
136         }
137         return maxa;
138     }
139 
140     /**
141      * Return the minimum value of two absolute scalars.
142      * @param a1 the first scalar
143      * @param a2 the second scalar
144      * @return the minimum value of two absolute scalars
145      */
146     public static FloatAbsoluteTemperature min(final FloatAbsoluteTemperature a1, final FloatAbsoluteTemperature a2)
147     {
148         return (a1.lt(a2)) ? a1 : a2;
149     }
150 
151     /**
152      * Return the minimum value of more than two absolute scalars.
153      * @param a1 the first scalar
154      * @param a2 the second scalar
155      * @param an the other scalars
156      * @return the minimum value of more than two absolute scalars
157      */
158     public static FloatAbsoluteTemperature min(final FloatAbsoluteTemperature a1, final FloatAbsoluteTemperature a2,
159             final FloatAbsoluteTemperature... an)
160     {
161         FloatAbsoluteTemperature mina = (a1.lt(a2)) ? a1 : a2;
162         for (FloatAbsoluteTemperature a : an)
163         {
164             if (a.lt(mina))
165             {
166                 mina = a;
167             }
168         }
169         return mina;
170     }
171 
172 }