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