View Javadoc
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.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.value.vfloat.scalar.base.FloatScalarRel;
15  import org.djutils.base.NumberParser;
16  import org.djutils.exceptions.Throw;
17  
18  import jakarta.annotation.Generated;
19  
20  /**
21   * Easy access methods for the FloatForce FloatScalar, which is relative by definition.
22   * <p>
23   * Copyright (c) 2013-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
25   * </p>
26   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
27   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
28   */
29  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2025-09-06T15:16:28.380798Z")
30  public class FloatForce extends FloatScalarRel<ForceUnit, FloatForce>
31  {
32      /** */
33      private static final long serialVersionUID = 20150901L;
34  
35      /** Constant with value zero. */
36      public static final FloatForce ZERO = new FloatForce(0.0f, ForceUnit.SI);
37  
38      /** Constant with value one. */
39      public static final FloatForce ONE = new FloatForce(1.0f, ForceUnit.SI);
40  
41      /** Constant with value NaN. */
42      @SuppressWarnings("checkstyle:constantname")
43      public static final FloatForce NaN = new FloatForce(Float.NaN, ForceUnit.SI);
44  
45      /** Constant with value POSITIVE_INFINITY. */
46      public static final FloatForce POSITIVE_INFINITY = new FloatForce(Float.POSITIVE_INFINITY, ForceUnit.SI);
47  
48      /** Constant with value NEGATIVE_INFINITY. */
49      public static final FloatForce NEGATIVE_INFINITY = new FloatForce(Float.NEGATIVE_INFINITY, ForceUnit.SI);
50  
51      /** Constant with value MAX_VALUE. */
52      public static final FloatForce POS_MAXVALUE = new FloatForce(Float.MAX_VALUE, ForceUnit.SI);
53  
54      /** Constant with value -MAX_VALUE. */
55      public static final FloatForce NEG_MAXVALUE = new FloatForce(-Float.MAX_VALUE, ForceUnit.SI);
56  
57      /**
58       * Construct FloatForce scalar with a unit.
59       * @param value the float value, expressed in the given unit
60       * @param unit unit for the float value
61       */
62      public FloatForce(final float value, final ForceUnit unit)
63      {
64          super(value, unit);
65      }
66  
67      /**
68       * Construct FloatForce scalar.
69       * @param value Scalar from which to construct this instance
70       */
71      public FloatForce(final FloatForce value)
72      {
73          super(value);
74      }
75  
76      /**
77       * Construct FloatForce scalar with a unit using a double value.
78       * @param value the double value, expressed in the given unit
79       * @param unit unit for the resulting float value
80       */
81      public FloatForce(final double value, final ForceUnit unit)
82      {
83          super((float) value, unit);
84      }
85  
86      @Override
87      public final FloatForce instantiateRel(final float value, final ForceUnit unit)
88      {
89          return new FloatForce(value, unit);
90      }
91  
92      /**
93       * Construct FloatForce scalar based on an SI value.
94       * @param value the float value in SI units
95       * @return the new scalar with the SI value
96       */
97      public static final FloatForce ofSI(final float value)
98      {
99          return new FloatForce(value, ForceUnit.SI);
100     }
101 
102     /**
103      * Interpolate between two values. Note that the first value does not have to be smaller than the second.
104      * @param zero the value at a ratio of zero
105      * @param one the value at a ratio of one
106      * @param ratio the ratio between 0 and 1, inclusive
107      * @return a FloatForce at the given ratio between 0 and 1
108      */
109     public static FloatForce interpolate(final FloatForce zero, final FloatForce one, final float ratio)
110     {
111         Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
112                 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
113         return new FloatForce(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
114                 zero.getDisplayUnit());
115     }
116 
117     /**
118      * Return the maximum value of two relative scalars.
119      * @param r1 the first scalar
120      * @param r2 the second scalar
121      * @return the maximum value of two relative scalars
122      */
123     public static FloatForce max(final FloatForce r1, final FloatForce r2)
124     {
125         return r1.gt(r2) ? r1 : r2;
126     }
127 
128     /**
129      * Return the maximum value of more than two relative scalars.
130      * @param r1 the first scalar
131      * @param r2 the second scalar
132      * @param rn the other scalars
133      * @return the maximum value of more than two relative scalars
134      */
135     public static FloatForce max(final FloatForce r1, final FloatForce r2, final FloatForce... rn)
136     {
137         FloatForce maxr = r1.gt(r2) ? r1 : r2;
138         for (FloatForce r : rn)
139         {
140             if (r.gt(maxr))
141             {
142                 maxr = r;
143             }
144         }
145         return maxr;
146     }
147 
148     /**
149      * Return the minimum value of two relative scalars.
150      * @param r1 the first scalar
151      * @param r2 the second scalar
152      * @return the minimum value of two relative scalars
153      */
154     public static FloatForce min(final FloatForce r1, final FloatForce r2)
155     {
156         return r1.lt(r2) ? r1 : r2;
157     }
158 
159     /**
160      * Return the minimum value of more than two relative scalars.
161      * @param r1 the first scalar
162      * @param r2 the second scalar
163      * @param rn the other scalars
164      * @return the minimum value of more than two relative scalars
165      */
166     public static FloatForce min(final FloatForce r1, final FloatForce r2, final FloatForce... rn)
167     {
168         FloatForce minr = r1.lt(r2) ? r1 : r2;
169         for (FloatForce r : rn)
170         {
171             if (r.lt(minr))
172             {
173                 minr = r;
174             }
175         }
176         return minr;
177     }
178 
179     /**
180      * Returns a FloatForce representation of a textual representation of a value with a unit. The String representation that
181      * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
182      * allowed, but not required, between the value and the unit.
183      * @param text the textual representation to parse into a FloatForce
184      * @return the Scalar representation of the value in its unit
185      * @throws IllegalArgumentException when the text cannot be parsed
186      * @throws NullPointerException when the text argument is null
187      */
188     public static FloatForce valueOf(final String text)
189     {
190         Throw.whenNull(text, "Error parsing FloatForce: text to parse is null");
191         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatForce: empty text to parse");
192         try
193         {
194             NumberParser numberParser = new NumberParser().lenient().trailing();
195             float f = numberParser.parseFloat(text);
196             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
197             ForceUnit unit = ForceUnit.BASE.getUnitByAbbreviation(unitString);
198             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity Force", unitString);
199             return new FloatForce(f, unit);
200         }
201         catch (Exception exception)
202         {
203             throw new IllegalArgumentException(
204                     "Error parsing FloatForce from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
205                     exception);
206         }
207     }
208 
209     /**
210      * Returns a FloatForce based on a value and the textual representation of the unit, which can be localized.
211      * @param value the value to use
212      * @param unitString the textual representation of the unit
213      * @return the Scalar representation of the value in its unit
214      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
215      * @throws NullPointerException when the unitString argument is null
216      */
217     public static FloatForce of(final float value, final String unitString)
218     {
219         Throw.whenNull(unitString, "Error parsing FloatForce: unitString is null");
220         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatForce: empty unitString");
221         ForceUnit unit = ForceUnit.BASE.getUnitByAbbreviation(unitString);
222         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FloatForce with unit %s", unitString);
223         return new FloatForce(value, unit);
224     }
225 
226     /**
227      * Calculate the division of FloatForce and FloatForce, which results in a FloatDimensionless scalar.
228      * @param v scalar
229      * @return scalar as a division of FloatForce and FloatForce
230      */
231     public final FloatDimensionless divide(final FloatForce v)
232     {
233         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
234     }
235 
236     /**
237      * Calculate the multiplication of FloatForce and FloatLength, which results in a FloatEnergy scalar.
238      * @param v scalar
239      * @return scalar as a multiplication of FloatForce and FloatLength
240      */
241     public final FloatEnergy times(final FloatLength v)
242     {
243         return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
244     }
245 
246     /**
247      * Calculate the division of FloatForce and FloatLinearDensity, which results in a FloatEnergy scalar.
248      * @param v scalar
249      * @return scalar as a division of FloatForce and FloatLinearDensity
250      */
251     public final FloatEnergy divide(final FloatLinearDensity v)
252     {
253         return new FloatEnergy(this.si / v.si, EnergyUnit.SI);
254     }
255 
256     /**
257      * Calculate the division of FloatForce and FloatEnergy, which results in a FloatLinearDensity scalar.
258      * @param v scalar
259      * @return scalar as a division of FloatForce and FloatEnergy
260      */
261     public final FloatLinearDensity divide(final FloatEnergy v)
262     {
263         return new FloatLinearDensity(this.si / v.si, LinearDensityUnit.SI);
264     }
265 
266     /**
267      * Calculate the multiplication of FloatForce and FloatSpeed, which results in a FloatPower scalar.
268      * @param v scalar
269      * @return scalar as a multiplication of FloatForce and FloatSpeed
270      */
271     public final FloatPower times(final FloatSpeed v)
272     {
273         return new FloatPower(this.si * v.si, PowerUnit.SI);
274     }
275 
276     /**
277      * Calculate the division of FloatForce and FloatMass, which results in a FloatAcceleration scalar.
278      * @param v scalar
279      * @return scalar as a division of FloatForce and FloatMass
280      */
281     public final FloatAcceleration divide(final FloatMass v)
282     {
283         return new FloatAcceleration(this.si / v.si, AccelerationUnit.SI);
284     }
285 
286     /**
287      * Calculate the division of FloatForce and FloatAcceleration, which results in a FloatMass scalar.
288      * @param v scalar
289      * @return scalar as a division of FloatForce and FloatAcceleration
290      */
291     public final FloatMass divide(final FloatAcceleration v)
292     {
293         return new FloatMass(this.si / v.si, MassUnit.SI);
294     }
295 
296     /**
297      * Calculate the division of FloatForce and FloatArea, which results in a FloatPressure scalar.
298      * @param v scalar
299      * @return scalar as a division of FloatForce and FloatArea
300      */
301     public final FloatPressure divide(final FloatArea v)
302     {
303         return new FloatPressure(this.si / v.si, PressureUnit.SI);
304     }
305 
306     /**
307      * Calculate the division of FloatForce and FloatPressure, which results in a FloatArea scalar.
308      * @param v scalar
309      * @return scalar as a division of FloatForce and FloatPressure
310      */
311     public final FloatArea divide(final FloatPressure v)
312     {
313         return new FloatArea(this.si / v.si, AreaUnit.SI);
314     }
315 
316     @Override
317     public FloatSIScalar reciprocal()
318     {
319         return FloatSIScalar.divide(FloatDimensionless.ONE, this);
320     }
321 
322     /**
323      * Multiply two scalars that result in a scalar of type FloatForce.
324      * @param scalar1 the first scalar
325      * @param scalar2 the second scalar
326      * @return the multiplication of both scalars as an instance of FloatForce
327      */
328     public static FloatForce multiply(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
329     {
330         Throw.whenNull(scalar1, "scalar1 cannot be null");
331         Throw.whenNull(scalar2, "scalar2 cannot be null");
332         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
333                 .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(ForceUnit.BASE.getSiDimensions()),
334                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type FloatForce",
335                 scalar1.toDisplayString(), scalar2.toDisplayString());
336         return new FloatForce(scalar1.si * scalar2.si, ForceUnit.SI);
337     }
338 
339     /**
340      * Divide two scalars that result in a scalar of type FloatForce.
341      * @param scalar1 the first scalar
342      * @param scalar2 the second scalar
343      * @return the division of scalar1 by scalar2 as an instance of FloatForce
344      */
345     public static FloatForce divide(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
346     {
347         Throw.whenNull(scalar1, "scalar1 cannot be null");
348         Throw.whenNull(scalar2, "scalar2 cannot be null");
349         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
350                 .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(ForceUnit.BASE.getSiDimensions()),
351                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type FloatForce",
352                 scalar1.toDisplayString(), scalar2.toDisplayString());
353         return new FloatForce(scalar1.si / scalar2.si, ForceUnit.SI);
354     }
355 
356 }