1 package org.djunits.value.vfloat.scalar;
2
3 import java.util.Locale;
4
5 import org.djunits.unit.AbsoluteTemperatureUnit;
6 import org.djunits.unit.DimensionlessUnit;
7 import org.djunits.unit.TemperatureUnit;
8 import org.djunits.value.vfloat.scalar.base.FloatScalar;
9 import org.djunits.value.vfloat.scalar.base.FloatScalarRelWithAbs;
10 import org.djutils.base.NumberParser;
11 import org.djutils.exceptions.Throw;
12
13 import jakarta.annotation.Generated;
14
15
16
17
18
19
20
21
22
23
24
25 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
26 public class FloatTemperature
27 extends FloatScalarRelWithAbs<AbsoluteTemperatureUnit, FloatAbsoluteTemperature, TemperatureUnit, FloatTemperature>
28 {
29
30 private static final long serialVersionUID = 20150901L;
31
32
33 public static final FloatTemperature ZERO = new FloatTemperature(0.0f, TemperatureUnit.SI);
34
35
36 public static final FloatTemperature ONE = new FloatTemperature(1.0f, TemperatureUnit.SI);
37
38
39 @SuppressWarnings("checkstyle:constantname")
40 public static final FloatTemperature NaN = new FloatTemperature(Float.NaN, TemperatureUnit.SI);
41
42
43 public static final FloatTemperature POSITIVE_INFINITY = new FloatTemperature(Float.POSITIVE_INFINITY, TemperatureUnit.SI);
44
45
46 public static final FloatTemperature NEGATIVE_INFINITY = new FloatTemperature(Float.NEGATIVE_INFINITY, TemperatureUnit.SI);
47
48
49 public static final FloatTemperature POS_MAXVALUE = new FloatTemperature(Float.MAX_VALUE, TemperatureUnit.SI);
50
51
52 public static final FloatTemperature NEG_MAXVALUE = new FloatTemperature(-Float.MAX_VALUE, TemperatureUnit.SI);
53
54
55
56
57
58
59 public FloatTemperature(final float value, final TemperatureUnit unit)
60 {
61 super(value, unit);
62 }
63
64
65
66
67
68 public FloatTemperature(final FloatTemperature value)
69 {
70 super(value);
71 }
72
73
74
75
76
77
78 public FloatTemperature(final double value, final TemperatureUnit unit)
79 {
80 super((float) value, unit);
81 }
82
83 @Override
84 public final FloatTemperature instantiateRel(final float value, final TemperatureUnit unit)
85 {
86 return new FloatTemperature(value, unit);
87 }
88
89
90
91
92
93
94 public static final FloatTemperature instantiateSI(final float value)
95 {
96 return new FloatTemperature(value, TemperatureUnit.SI);
97 }
98
99 @Override
100 public final FloatAbsoluteTemperature instantiateAbs(final float value, final AbsoluteTemperatureUnit unit)
101 {
102 return new FloatAbsoluteTemperature(value, unit);
103 }
104
105
106
107
108
109
110
111
112 public static FloatTemperature interpolate(final FloatTemperature zero, final FloatTemperature one, final float ratio)
113 {
114 return new FloatTemperature(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
115 zero.getDisplayUnit());
116 }
117
118
119
120
121
122
123
124 public static FloatTemperature max(final FloatTemperature r1, final FloatTemperature r2)
125 {
126 return r1.gt(r2) ? r1 : r2;
127 }
128
129
130
131
132
133
134
135
136 public static FloatTemperature max(final FloatTemperature r1, final FloatTemperature r2, final FloatTemperature... rn)
137 {
138 FloatTemperature maxr = r1.gt(r2) ? r1 : r2;
139 for (FloatTemperature r : rn)
140 {
141 if (r.gt(maxr))
142 {
143 maxr = r;
144 }
145 }
146 return maxr;
147 }
148
149
150
151
152
153
154
155 public static FloatTemperature min(final FloatTemperature r1, final FloatTemperature r2)
156 {
157 return r1.lt(r2) ? r1 : r2;
158 }
159
160
161
162
163
164
165
166
167 public static FloatTemperature min(final FloatTemperature r1, final FloatTemperature r2, final FloatTemperature... rn)
168 {
169 FloatTemperature minr = r1.lt(r2) ? r1 : r2;
170 for (FloatTemperature r : rn)
171 {
172 if (r.lt(minr))
173 {
174 minr = r;
175 }
176 }
177 return minr;
178 }
179
180
181
182
183
184
185
186
187
188
189 public static FloatTemperature valueOf(final String text)
190 {
191 Throw.whenNull(text, "Error parsing FloatTemperature: text to parse is null");
192 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatTemperature: empty text to parse");
193 try
194 {
195 NumberParser numberParser = new NumberParser().lenient().trailing();
196 float f = numberParser.parseFloat(text);
197 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
198 TemperatureUnit unit = TemperatureUnit.BASE.getUnitByAbbreviation(unitString);
199 if (unit == null)
200 throw new IllegalArgumentException("Unit " + unitString + " not found");
201 return new FloatTemperature(f, unit);
202 }
203 catch (Exception exception)
204 {
205 throw new IllegalArgumentException("Error parsing FloatTemperature from " + text + " using Locale "
206 + Locale.getDefault(Locale.Category.FORMAT), exception);
207 }
208 }
209
210
211
212
213
214
215
216
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
233
234
235
236 public final FloatDimensionless divide(final FloatTemperature v)
237 {
238 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
239 }
240
241 @Override
242 public FloatSIScalar reciprocal()
243 {
244 return FloatScalar.divide(FloatDimensionless.ONE, this);
245 }
246
247 }