1 package org.djunits.value.vfloat.scalar;
2
3 import java.util.Locale;
4
5 import org.djunits.unit.AccelerationUnit;
6 import org.djunits.unit.AngularAccelerationUnit;
7 import org.djunits.unit.AngularVelocityUnit;
8 import org.djunits.unit.DimensionlessUnit;
9 import org.djunits.unit.FrequencyUnit;
10 import org.djunits.unit.PowerUnit;
11 import org.djunits.unit.SpeedUnit;
12 import org.djunits.value.vfloat.scalar.base.FloatScalarRel;
13 import org.djutils.base.NumberParser;
14 import org.djutils.exceptions.Throw;
15
16 import jakarta.annotation.Generated;
17
18
19
20
21
22
23
24
25
26
27 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
28 public class FloatFrequency extends FloatScalarRel<FrequencyUnit, FloatFrequency>
29 {
30
31 private static final long serialVersionUID = 20150901L;
32
33
34 public static final FloatFrequency ZERO = new FloatFrequency(0.0f, FrequencyUnit.SI);
35
36
37 public static final FloatFrequency ONE = new FloatFrequency(1.0f, FrequencyUnit.SI);
38
39
40 @SuppressWarnings("checkstyle:constantname")
41 public static final FloatFrequency NaN = new FloatFrequency(Float.NaN, FrequencyUnit.SI);
42
43
44 public static final FloatFrequency POSITIVE_INFINITY = new FloatFrequency(Float.POSITIVE_INFINITY, FrequencyUnit.SI);
45
46
47 public static final FloatFrequency NEGATIVE_INFINITY = new FloatFrequency(Float.NEGATIVE_INFINITY, FrequencyUnit.SI);
48
49
50 public static final FloatFrequency POS_MAXVALUE = new FloatFrequency(Float.MAX_VALUE, FrequencyUnit.SI);
51
52
53 public static final FloatFrequency NEG_MAXVALUE = new FloatFrequency(-Float.MAX_VALUE, FrequencyUnit.SI);
54
55
56
57
58
59
60 public FloatFrequency(final float value, final FrequencyUnit unit)
61 {
62 super(value, unit);
63 }
64
65
66
67
68
69 public FloatFrequency(final FloatFrequency value)
70 {
71 super(value);
72 }
73
74
75
76
77
78
79 public FloatFrequency(final double value, final FrequencyUnit unit)
80 {
81 super((float) value, unit);
82 }
83
84 @Override
85 public final FloatFrequency instantiateRel(final float value, final FrequencyUnit unit)
86 {
87 return new FloatFrequency(value, unit);
88 }
89
90
91
92
93
94
95 public static final FloatFrequency instantiateSI(final float value)
96 {
97 return new FloatFrequency(value, FrequencyUnit.SI);
98 }
99
100
101
102
103
104
105
106
107 public static FloatFrequency interpolate(final FloatFrequency zero, final FloatFrequency one, final float ratio)
108 {
109 return new FloatFrequency(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
110 zero.getDisplayUnit());
111 }
112
113
114
115
116
117
118
119 public static FloatFrequency max(final FloatFrequency r1, final FloatFrequency r2)
120 {
121 return r1.gt(r2) ? r1 : r2;
122 }
123
124
125
126
127
128
129
130
131 public static FloatFrequency max(final FloatFrequency r1, final FloatFrequency r2, final FloatFrequency... rn)
132 {
133 FloatFrequency maxr = r1.gt(r2) ? r1 : r2;
134 for (FloatFrequency r : rn)
135 {
136 if (r.gt(maxr))
137 {
138 maxr = r;
139 }
140 }
141 return maxr;
142 }
143
144
145
146
147
148
149
150 public static FloatFrequency min(final FloatFrequency r1, final FloatFrequency r2)
151 {
152 return r1.lt(r2) ? r1 : r2;
153 }
154
155
156
157
158
159
160
161
162 public static FloatFrequency min(final FloatFrequency r1, final FloatFrequency r2, final FloatFrequency... rn)
163 {
164 FloatFrequency minr = r1.lt(r2) ? r1 : r2;
165 for (FloatFrequency r : rn)
166 {
167 if (r.lt(minr))
168 {
169 minr = r;
170 }
171 }
172 return minr;
173 }
174
175
176
177
178
179
180
181
182
183
184 public static FloatFrequency valueOf(final String text)
185 {
186 Throw.whenNull(text, "Error parsing FloatFrequency: text to parse is null");
187 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatFrequency: empty text to parse");
188 try
189 {
190 NumberParser numberParser = new NumberParser().lenient().trailing();
191 float f = numberParser.parseFloat(text);
192 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
193 FrequencyUnit unit = FrequencyUnit.BASE.getUnitByAbbreviation(unitString);
194 if (unit == null)
195 throw new IllegalArgumentException("Unit " + unitString + " not found");
196 return new FloatFrequency(f, unit);
197 }
198 catch (Exception exception)
199 {
200 throw new IllegalArgumentException(
201 "Error parsing FloatFrequency from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
202 exception);
203 }
204 }
205
206
207
208
209
210
211
212
213
214 public static FloatFrequency of(final float value, final String unitString)
215 {
216 Throw.whenNull(unitString, "Error parsing FloatFrequency: unitString is null");
217 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatFrequency: empty unitString");
218 FrequencyUnit unit = FrequencyUnit.BASE.getUnitByAbbreviation(unitString);
219 if (unit != null)
220 {
221 return new FloatFrequency(value, unit);
222 }
223 throw new IllegalArgumentException("Error parsing FloatFrequency with unit " + unitString);
224 }
225
226
227
228
229
230
231 public final FloatDimensionless divide(final FloatFrequency v)
232 {
233 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
234 }
235
236
237
238
239
240
241 public final FloatDimensionless times(final FloatDuration v)
242 {
243 return new FloatDimensionless(this.si * v.si, DimensionlessUnit.SI);
244 }
245
246
247
248
249
250
251 public final FloatSpeed times(final FloatLength v)
252 {
253 return new FloatSpeed(this.si * v.si, SpeedUnit.SI);
254 }
255
256
257
258
259
260
261 public final FloatAcceleration times(final FloatSpeed v)
262 {
263 return new FloatAcceleration(this.si * v.si, AccelerationUnit.SI);
264 }
265
266
267
268
269
270
271 public final FloatPower times(final FloatEnergy v)
272 {
273 return new FloatPower(this.si * v.si, PowerUnit.SI);
274 }
275
276
277
278
279
280
281 public final FloatAngularVelocity times(final FloatAngle v)
282 {
283 return new FloatAngularVelocity(this.si * v.si, AngularVelocityUnit.SI);
284 }
285
286
287
288
289
290
291
292 public final FloatAngularAcceleration times(final FloatAngularVelocity v)
293 {
294 return new FloatAngularAcceleration(this.si * v.si, AngularAccelerationUnit.SI);
295 }
296
297 @Override
298 public FloatDuration reciprocal()
299 {
300 return FloatDuration.instantiateSI(1.0f / this.si);
301 }
302
303 }