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