1 package org.djunits.value.vdouble.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.vdouble.scalar.base.AbstractDoubleScalarRelWithAbs;
13
14
15
16
17
18
19
20
21
22
23
24 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2020-01-19T15:21:24.964166400Z")
25 public class Temperature
26 extends AbstractDoubleScalarRelWithAbs<AbsoluteTemperatureUnit, AbsoluteTemperature, TemperatureUnit, Temperature>
27 {
28
29 private static final long serialVersionUID = 20150901L;
30
31
32 public static final Temperaturealar/Temperature.html#Temperature">Temperature ZERO = new Temperature(0.0, TemperatureUnit.SI);
33
34
35 public static final Temperaturecalar/Temperature.html#Temperature">Temperature ONE = new Temperature(1.0, TemperatureUnit.SI);
36
37
38 @SuppressWarnings("checkstyle:constantname")
39 public static final Temperaturecalar/Temperature.html#Temperature">Temperature NaN = new Temperature(Double.NaN, TemperatureUnit.SI);
40
41
42 public static final Temperatureure.html#Temperature">Temperature POSITIVE_INFINITY = new Temperature(Double.POSITIVE_INFINITY, TemperatureUnit.SI);
43
44
45 public static final Temperatureure.html#Temperature">Temperature NEGATIVE_INFINITY = new Temperature(Double.NEGATIVE_INFINITY, TemperatureUnit.SI);
46
47
48 public static final Temperatureperature.html#Temperature">Temperature POS_MAXVALUE = new Temperature(Double.MAX_VALUE, TemperatureUnit.SI);
49
50
51 public static final Temperatureperature.html#Temperature">Temperature NEG_MAXVALUE = new Temperature(-Double.MAX_VALUE, TemperatureUnit.SI);
52
53
54
55
56
57
58 public Temperature(final double value, final TemperatureUnit unit)
59 {
60 super(value, unit);
61 }
62
63
64
65
66
67 public Temperaturele/scalar/Temperature.html#Temperature">Temperature(final Temperature value)
68 {
69 super(value);
70 }
71
72
73 @Override
74 public final Temperature instantiateRel(final double value, final TemperatureUnit unit)
75 {
76 return new Temperature(value, unit);
77 }
78
79
80 @Override
81 public final AbsoluteTemperature instantiateAbs(final double value, final AbsoluteTemperatureUnit unit)
82 {
83 return new AbsoluteTemperature(value, unit);
84 }
85
86
87
88
89
90
91 public static final Temperature instantiateSI(final double value)
92 {
93 return new Temperature(value, TemperatureUnit.SI);
94 }
95
96
97
98
99
100
101
102
103 public static Temperaturelar/Temperature.html#Temperature">Temperaturemperature.html#Temperature">Temperature interpolate(final Temperaturelar/Temperature.html#Temperature">Temperature zero, final Temperature one, final double ratio)
104 {
105 return new Temperature(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
106 zero.getDisplayUnit());
107 }
108
109
110
111
112
113
114
115 public static Temperaturecalar/Temperature.html#Temperature">Temperaturecalar/Temperature.html#Temperature">Temperature max(final Temperaturecalar/Temperature.html#Temperature">Temperature r1, final Temperature r2)
116 {
117 return r1.gt(r2) ? r1 : r2;
118 }
119
120
121
122
123
124
125
126
127 public static Temperaturecalar/Temperature.html#Temperature">Temperaturecalar/Temperature.html#Temperature">Temperature max(final Temperaturecalar/Temperature.html#Temperature">Temperature r1, final Temperature r2, final Temperature... rn)
128 {
129 Temperature maxr = r1.gt(r2) ? r1 : r2;
130 for (Temperature r : rn)
131 {
132 if (r.gt(maxr))
133 {
134 maxr = r;
135 }
136 }
137 return maxr;
138 }
139
140
141
142
143
144
145
146 public static Temperaturecalar/Temperature.html#Temperature">Temperaturecalar/Temperature.html#Temperature">Temperature min(final Temperaturecalar/Temperature.html#Temperature">Temperature r1, final Temperature r2)
147 {
148 return r1.lt(r2) ? r1 : r2;
149 }
150
151
152
153
154
155
156
157
158 public static Temperaturecalar/Temperature.html#Temperature">Temperaturecalar/Temperature.html#Temperature">Temperature min(final Temperaturecalar/Temperature.html#Temperature">Temperature r1, final Temperature r2, final Temperature... rn)
159 {
160 Temperature minr = r1.lt(r2) ? r1 : r2;
161 for (Temperature r : rn)
162 {
163 if (r.lt(minr))
164 {
165 minr = r;
166 }
167 }
168 return minr;
169 }
170
171
172
173
174
175
176
177
178
179
180 public static Temperature valueOf(final String text)
181 {
182 Throw.whenNull(text, "Error parsing Temperature: text to parse is null");
183 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Temperature: empty text to parse");
184 Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
185 if (matcher.find())
186 {
187 int index = matcher.end();
188 String unitString = text.substring(index).trim();
189 String valueString = text.substring(0, index).trim();
190 TemperatureUnit unit = TemperatureUnit.BASE.getUnitByAbbreviation(unitString);
191 if (unit != null)
192 {
193 double d = Double.parseDouble(valueString);
194 return new Temperature(d, unit);
195 }
196 }
197 throw new IllegalArgumentException("Error parsing Temperature from " + text);
198 }
199
200
201
202
203
204
205
206
207
208 public static Temperature of(final double value, final String unitString)
209 {
210 Throw.whenNull(unitString, "Error parsing Temperature: unitString is null");
211 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Temperature: empty unitString");
212 TemperatureUnit unit = TemperatureUnit.BASE.getUnitByAbbreviation(unitString);
213 if (unit != null)
214 {
215 return new Temperature(value, unit);
216 }
217 throw new IllegalArgumentException("Error parsing Temperature with unit " + unitString);
218 }
219
220
221
222
223
224
225 public final Dimensionless divide(final Temperature v)
226 {
227 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
228 }
229
230 }