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