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