1 package org.djunits.value.vfloat.scalar;
2
3 import org.djunits.unit.AbsoluteTemperatureUnit;
4 import org.djunits.unit.DimensionlessUnit;
5 import org.djunits.unit.TemperatureUnit;
6
7 /**
8 * Easy access methods for the %Type% FloatScalar. Instead of:
9 *
10 * <pre>
11 * FloatScalar.Rel<TemperatureUnit> value = new FloatScalar.Rel<TemperatureUnit>(100.0, TemperatureUnit.SI);
12 * </pre>
13 *
14 * we can now write:
15 *
16 * <pre>
17 * FloatTemperature value = new FloatTemperature(100.0, TemperatureUnit.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: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, 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 FloatTemperature extends AbstractFloatScalarRel<TemperatureUnit, FloatTemperature>
33 {
34 /** */
35 private static final long serialVersionUID = 20150901L;
36
37 /** constant with value zero. */
38 public static final FloatTemperature ZERO = new FloatTemperature(0.0f, TemperatureUnit.SI);
39
40 /** constant with value NaN. */
41 @SuppressWarnings("checkstyle:constantname")
42 public static final FloatTemperature NaN = new FloatTemperature(Float.NaN, TemperatureUnit.SI);
43
44 /** constant with value POSITIVE_INFINITY. */
45 public static final FloatTemperature POSITIVE_INFINITY = new FloatTemperature(Float.POSITIVE_INFINITY, TemperatureUnit.SI);
46
47 /** constant with value NEGATIVE_INFINITY. */
48 public static final FloatTemperature NEGATIVE_INFINITY = new FloatTemperature(Float.NEGATIVE_INFINITY, TemperatureUnit.SI);
49
50 /** constant with value MAX_VALUE. */
51 public static final FloatTemperature POS_MAXVALUE = new FloatTemperature(Float.MAX_VALUE, TemperatureUnit.SI);
52
53 /** constant with value -MAX_VALUE. */
54 public static final FloatTemperature NEG_MAXVALUE = new FloatTemperature(-Float.MAX_VALUE, TemperatureUnit.SI);
55
56 /**
57 * Construct FloatTemperature scalar.
58 * @param value float value
59 * @param unit unit for the float value
60 */
61 public FloatTemperature(final float value, final TemperatureUnit unit)
62 {
63 super(value, unit);
64 }
65
66 /**
67 * Construct FloatTemperature scalar.
68 * @param value Scalar from which to construct this instance
69 */
70 public FloatTemperature(final FloatTemperature value)
71 {
72 super(value);
73 }
74
75 /**
76 * Construct FloatTemperature scalar using a double value.
77 * @param value double value
78 * @param unit unit for the resulting float value
79 */
80 public FloatTemperature(final double value, final TemperatureUnit unit)
81 {
82 super((float) value, unit);
83 }
84
85 /** {@inheritDoc} */
86 @Override
87 public final FloatTemperature instantiateRel(final float value, final TemperatureUnit unit)
88 {
89 return new FloatTemperature(value, unit);
90 }
91
92 /**
93 * Construct FloatTemperature scalar.
94 * @param value float value in SI units
95 * @return the new scalar with the SI value
96 */
97 public static final FloatTemperature createSI(final float value)
98 {
99 return new FloatTemperature(value, TemperatureUnit.SI);
100 }
101
102 /**
103 * Construct a new Absolute Immutable FloatScalar of the right type. Each extending class must implement this method.
104 * @param value the float value
105 * @param unit the unit
106 * @return A a new absolute instance of the FloatScalar of the right type
107 */
108 public final FloatAbsoluteTemperature instantiateAbs(final float value, final AbsoluteTemperatureUnit unit)
109 {
110 return new FloatAbsoluteTemperature(value, unit);
111 }
112
113 /**
114 * Interpolate between two values.
115 * @param zero the low value
116 * @param one the high value
117 * @param ratio the ratio between 0 and 1, inclusive
118 * @return a Scalar at the ratio between
119 */
120 public static FloatTemperature interpolate(final FloatTemperature zero, final FloatTemperature one, final float ratio)
121 {
122 return new FloatTemperature(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
123 }
124
125 /**
126 * Relative scalar plus Absolute scalar = Absolute scalar.
127 * @param v the value to add
128 * @return sum of this value and v as a new object
129 */
130 public final FloatAbsoluteTemperature plus(final FloatAbsoluteTemperature v)
131 {
132 AbsoluteTemperatureUnit targetUnit = v.getUnit();
133 return instantiateAbs(v.getInUnit() + getInUnit(targetUnit.getRelativeUnit()), targetUnit);
134 }
135
136 /**
137 * Return the maximum value of two relative scalars.
138 * @param r1 the first scalar
139 * @param r2 the second scalar
140 * @return the maximum value of two relative scalars
141 */
142 public static FloatTemperature max(final FloatTemperature r1, final FloatTemperature r2)
143 {
144 return (r1.gt(r2)) ? r1 : r2;
145 }
146
147 /**
148 * Return the maximum value of more than two relative scalars.
149 * @param r1 the first scalar
150 * @param r2 the second scalar
151 * @param rn the other scalars
152 * @return the maximum value of more than two relative scalars
153 */
154 public static FloatTemperature max(final FloatTemperature r1, final FloatTemperature r2, final FloatTemperature... rn)
155 {
156 FloatTemperature maxr = (r1.gt(r2)) ? r1 : r2;
157 for (FloatTemperature r : rn)
158 {
159 if (r.gt(maxr))
160 {
161 maxr = r;
162 }
163 }
164 return maxr;
165 }
166
167 /**
168 * Return the minimum value of two relative scalars.
169 * @param r1 the first scalar
170 * @param r2 the second scalar
171 * @return the minimum value of two relative scalars
172 */
173 public static FloatTemperature min(final FloatTemperature r1, final FloatTemperature r2)
174 {
175 return (r1.lt(r2)) ? r1 : r2;
176 }
177
178 /**
179 * Return the minimum value of more than two relative scalars.
180 * @param r1 the first scalar
181 * @param r2 the second scalar
182 * @param rn the other scalars
183 * @return the minimum value of more than two relative scalars
184 */
185 public static FloatTemperature min(final FloatTemperature r1, final FloatTemperature r2, final FloatTemperature... rn)
186 {
187 FloatTemperature minr = (r1.lt(r2)) ? r1 : r2;
188 for (FloatTemperature r : rn)
189 {
190 if (r.lt(minr))
191 {
192 minr = r;
193 }
194 }
195 return minr;
196 }
197
198 /**
199 * Calculate the division of FloatTemperature and FloatTemperature, which results in a FloatDimensionless scalar.
200 * @param v FloatTemperature scalar
201 * @return FloatDimensionless scalar as a division of FloatTemperature and FloatTemperature
202 */
203 public final FloatDimensionless divideBy(final FloatTemperature v)
204 {
205 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
206 }
207
208 }