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.AbstractFloatScalarRel;
15  import org.djunits.value.vfloat.scalar.base.FloatScalar;
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-2023 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-04-30T13:59:27.633664900Z")
31  public class FloatForce extends AbstractFloatScalarRel<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      /** {@inheritDoc} */
88      @Override
89      public final FloatForce instantiateRel(final float value, final ForceUnit unit)
90      {
91          return new FloatForce(value, unit);
92      }
93  
94      /**
95       * Construct FloatForce scalar.
96       * @param value float; the float value in SI units
97       * @return the new scalar with the SI value
98       */
99      public static final FloatForce instantiateSI(final float value)
100     {
101         return new FloatForce(value, ForceUnit.SI);
102     }
103 
104     /**
105      * Interpolate between two values.
106      * @param zero the low value
107      * @param one the high value
108      * @param ratio double; the ratio between 0 and 1, inclusive
109      * @return a Scalar at the ratio between
110      */
111     public static FloatForce interpolate(final FloatForce zero, final FloatForce one, final float ratio)
112     {
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 String; the textual representation to parse into a FloatForce
184      * @return FloatForce; 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             if (unit == null)
199                 throw new IllegalArgumentException("Unit " + unitString + " not found");
200             return new FloatForce(f, unit);
201         }
202         catch (Exception exception)
203         {
204             throw new IllegalArgumentException(
205                     "Error parsing FloatForce from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
206                     exception);
207         }
208     }
209 
210     /**
211      * Returns a FloatForce based on a value and the textual representation of the unit, which can be localized.
212      * @param value double; the value to use
213      * @param unitString String; the textual representation of the unit
214      * @return FloatForce; the Scalar representation of the value in its unit
215      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
216      * @throws NullPointerException when the unitString argument is null
217      */
218     public static FloatForce of(final float value, final String unitString)
219     {
220         Throw.whenNull(unitString, "Error parsing FloatForce: unitString is null");
221         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatForce: empty unitString");
222         ForceUnit unit = ForceUnit.BASE.getUnitByAbbreviation(unitString);
223         if (unit != null)
224         {
225             return new FloatForce(value, unit);
226         }
227         throw new IllegalArgumentException("Error parsing FloatForce with unit " + unitString);
228     }
229 
230     /**
231      * Calculate the division of FloatForce and FloatForce, which results in a FloatDimensionless scalar.
232      * @param v FloatForce; scalar
233      * @return FloatDimensionless; scalar as a division of FloatForce and FloatForce
234      */
235     public final FloatDimensionless divide(final FloatForce v)
236     {
237         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
238     }
239 
240     /**
241      * Calculate the multiplication of FloatForce and FloatLength, which results in a FloatEnergy scalar.
242      * @param v FloatForce; scalar
243      * @return FloatEnergy; scalar as a multiplication of FloatForce and FloatLength
244      */
245     public final FloatEnergy times(final FloatLength v)
246     {
247         return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
248     }
249 
250     /**
251      * Calculate the division of FloatForce and FloatLinearDensity, which results in a FloatEnergy scalar.
252      * @param v FloatForce; scalar
253      * @return FloatEnergy; scalar as a division of FloatForce and FloatLinearDensity
254      */
255     public final FloatEnergy divide(final FloatLinearDensity v)
256     {
257         return new FloatEnergy(this.si / v.si, EnergyUnit.SI);
258     }
259 
260     /**
261      * Calculate the division of FloatForce and FloatEnergy, which results in a FloatLinearDensity scalar.
262      * @param v FloatForce; scalar
263      * @return FloatLinearDensity; scalar as a division of FloatForce and FloatEnergy
264      */
265     public final FloatLinearDensity divide(final FloatEnergy v)
266     {
267         return new FloatLinearDensity(this.si / v.si, LinearDensityUnit.SI);
268     }
269 
270     /**
271      * Calculate the multiplication of FloatForce and FloatSpeed, which results in a FloatPower scalar.
272      * @param v FloatForce; scalar
273      * @return FloatPower; scalar as a multiplication of FloatForce and FloatSpeed
274      */
275     public final FloatPower times(final FloatSpeed v)
276     {
277         return new FloatPower(this.si * v.si, PowerUnit.SI);
278     }
279 
280     /**
281      * Calculate the division of FloatForce and FloatMass, which results in a FloatAcceleration scalar.
282      * @param v FloatForce; scalar
283      * @return FloatAcceleration; scalar as a division of FloatForce and FloatMass
284      */
285     public final FloatAcceleration divide(final FloatMass v)
286     {
287         return new FloatAcceleration(this.si / v.si, AccelerationUnit.SI);
288     }
289 
290     /**
291      * Calculate the division of FloatForce and FloatAcceleration, which results in a FloatMass scalar.
292      * @param v FloatForce; scalar
293      * @return FloatMass; scalar as a division of FloatForce and FloatAcceleration
294      */
295     public final FloatMass divide(final FloatAcceleration v)
296     {
297         return new FloatMass(this.si / v.si, MassUnit.SI);
298     }
299 
300     /**
301      * Calculate the division of FloatForce and FloatArea, which results in a FloatPressure scalar.
302      * @param v FloatForce; scalar
303      * @return FloatPressure; scalar as a division of FloatForce and FloatArea
304      */
305     public final FloatPressure divide(final FloatArea v)
306     {
307         return new FloatPressure(this.si / v.si, PressureUnit.SI);
308     }
309 
310     /**
311      * Calculate the division of FloatForce and FloatPressure, which results in a FloatArea scalar.
312      * @param v FloatForce; scalar
313      * @return FloatArea; scalar as a division of FloatForce and FloatPressure
314      */
315     public final FloatArea divide(final FloatPressure v)
316     {
317         return new FloatArea(this.si / v.si, AreaUnit.SI);
318     }
319 
320     /** {@inheritDoc} */
321     @Override
322     public FloatSIScalar reciprocal()
323     {
324         return FloatScalar.divide(FloatDimensionless.ONE, this);
325     }
326 
327 }