View Javadoc
1   package org.djunits.value.vdouble.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.vdouble.scalar.base.DoubleScalar;
15  import org.djunits.value.vdouble.scalar.base.DoubleScalarRel;
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 Force DoubleScalar, 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 Force extends DoubleScalarRel<ForceUnit, Force>
32  {
33      /** */
34      private static final long serialVersionUID = 20150905L;
35  
36      /** Constant with value zero. */
37      public static final Force ZERO = new Force(0.0, ForceUnit.SI);
38  
39      /** Constant with value one. */
40      public static final Force ONE = new Force(1.0, ForceUnit.SI);
41  
42      /** Constant with value NaN. */
43      @SuppressWarnings("checkstyle:constantname")
44      public static final Force NaN = new Force(Double.NaN, ForceUnit.SI);
45  
46      /** Constant with value POSITIVE_INFINITY. */
47      public static final Force POSITIVE_INFINITY = new Force(Double.POSITIVE_INFINITY, ForceUnit.SI);
48  
49      /** Constant with value NEGATIVE_INFINITY. */
50      public static final Force NEGATIVE_INFINITY = new Force(Double.NEGATIVE_INFINITY, ForceUnit.SI);
51  
52      /** Constant with value MAX_VALUE. */
53      public static final Force POS_MAXVALUE = new Force(Double.MAX_VALUE, ForceUnit.SI);
54  
55      /** Constant with value -MAX_VALUE. */
56      public static final Force NEG_MAXVALUE = new Force(-Double.MAX_VALUE, ForceUnit.SI);
57  
58      /**
59       * Construct Force scalar.
60       * @param value double; the double value
61       * @param unit ForceUnit; unit for the double value
62       */
63      public Force(final double value, final ForceUnit unit)
64      {
65          super(value, unit);
66      }
67  
68      /**
69       * Construct Force scalar.
70       * @param value Force; Scalar from which to construct this instance
71       */
72      public Force(final Force value)
73      {
74          super(value);
75      }
76  
77      @Override
78      public final Force instantiateRel(final double value, final ForceUnit unit)
79      {
80          return new Force(value, unit);
81      }
82  
83      /**
84       * Construct Force scalar.
85       * @param value double; the double value in SI units
86       * @return Force; the new scalar with the SI value
87       */
88      public static final Force instantiateSI(final double value)
89      {
90          return new Force(value, ForceUnit.SI);
91      }
92  
93      /**
94       * Interpolate between two values.
95       * @param zero Force; the low value
96       * @param one Force; the high value
97       * @param ratio double; the ratio between 0 and 1, inclusive
98       * @return Force; a Scalar at the ratio between
99       */
100     public static Force interpolate(final Force zero, final Force one, final double ratio)
101     {
102         return new Force(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio, zero.getDisplayUnit());
103     }
104 
105     /**
106      * Return the maximum value of two relative scalars.
107      * @param r1 Force; the first scalar
108      * @param r2 Force; the second scalar
109      * @return Force; the maximum value of two relative scalars
110      */
111     public static Force max(final Force r1, final Force r2)
112     {
113         return r1.gt(r2) ? r1 : r2;
114     }
115 
116     /**
117      * Return the maximum value of more than two relative scalars.
118      * @param r1 Force; the first scalar
119      * @param r2 Force; the second scalar
120      * @param rn Force...; the other scalars
121      * @return Force; the maximum value of more than two relative scalars
122      */
123     public static Force max(final Force r1, final Force r2, final Force... rn)
124     {
125         Force maxr = r1.gt(r2) ? r1 : r2;
126         for (Force r : rn)
127         {
128             if (r.gt(maxr))
129             {
130                 maxr = r;
131             }
132         }
133         return maxr;
134     }
135 
136     /**
137      * Return the minimum value of two relative scalars.
138      * @param r1 Force; the first scalar
139      * @param r2 Force; the second scalar
140      * @return Force; the minimum value of two relative scalars
141      */
142     public static Force min(final Force r1, final Force r2)
143     {
144         return r1.lt(r2) ? r1 : r2;
145     }
146 
147     /**
148      * Return the minimum value of more than two relative scalars.
149      * @param r1 Force; the first scalar
150      * @param r2 Force; the second scalar
151      * @param rn Force...; the other scalars
152      * @return Force; the minimum value of more than two relative scalars
153      */
154     public static Force min(final Force r1, final Force r2, final Force... rn)
155     {
156         Force minr = r1.lt(r2) ? r1 : r2;
157         for (Force r : rn)
158         {
159             if (r.lt(minr))
160             {
161                 minr = r;
162             }
163         }
164         return minr;
165     }
166 
167     /**
168      * Returns a Force representation of a textual representation of a value with a unit. The String representation that can be
169      * parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are allowed,
170      * but not required, between the value and the unit.
171      * @param text String; the textual representation to parse into a Force
172      * @return Force; the Scalar representation of the value in its unit
173      * @throws IllegalArgumentException when the text cannot be parsed
174      * @throws NullPointerException when the text argument is null
175      */
176     public static Force valueOf(final String text)
177     {
178         Throw.whenNull(text, "Error parsing Force: text to parse is null");
179         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Force: empty text to parse");
180         try
181         {
182             NumberParser numberParser = new NumberParser().lenient().trailing();
183             double d = numberParser.parseDouble(text);
184             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
185             ForceUnit unit = ForceUnit.BASE.getUnitByAbbreviation(unitString);
186             if (unit == null)
187                 throw new IllegalArgumentException("Unit " + unitString + " not found");
188             return new Force(d, unit);
189         }
190         catch (Exception exception)
191         {
192             throw new IllegalArgumentException(
193                     "Error parsing Force from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
194                     exception);
195         }
196     }
197 
198     /**
199      * Returns a Force based on a value and the textual representation of the unit, which can be localized.
200      * @param value double; the value to use
201      * @param unitString String; the textual representation of the unit
202      * @return Force; the Scalar representation of the value in its unit
203      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
204      * @throws NullPointerException when the unitString argument is null
205      */
206     public static Force of(final double value, final String unitString)
207     {
208         Throw.whenNull(unitString, "Error parsing Force: unitString is null");
209         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Force: empty unitString");
210         ForceUnit unit = ForceUnit.BASE.getUnitByAbbreviation(unitString);
211         if (unit != null)
212         {
213             return new Force(value, unit);
214         }
215         throw new IllegalArgumentException("Error parsing Force with unit " + unitString);
216     }
217 
218     /**
219      * Calculate the division of Force and Force, which results in a Dimensionless scalar.
220      * @param v Force; scalar
221      * @return Dimensionless; scalar as a division of Force and Force
222      */
223     public final Dimensionless divide(final Force v)
224     {
225         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
226     }
227 
228     /**
229      * Calculate the multiplication of Force and Length, which results in a Energy scalar.
230      * @param v Force; scalar
231      * @return Energy; scalar as a multiplication of Force and Length
232      */
233     public final Energy times(final Length v)
234     {
235         return new Energy(this.si * v.si, EnergyUnit.SI);
236     }
237 
238     /**
239      * Calculate the division of Force and LinearDensity, which results in a Energy scalar.
240      * @param v Force; scalar
241      * @return Energy; scalar as a division of Force and LinearDensity
242      */
243     public final Energy divide(final LinearDensity v)
244     {
245         return new Energy(this.si / v.si, EnergyUnit.SI);
246     }
247 
248     /**
249      * Calculate the division of Force and Energy, which results in a LinearDensity scalar.
250      * @param v Force; scalar
251      * @return LinearDensity; scalar as a division of Force and Energy
252      */
253     public final LinearDensity divide(final Energy v)
254     {
255         return new LinearDensity(this.si / v.si, LinearDensityUnit.SI);
256     }
257 
258     /**
259      * Calculate the multiplication of Force and Speed, which results in a Power scalar.
260      * @param v Force; scalar
261      * @return Power; scalar as a multiplication of Force and Speed
262      */
263     public final Power times(final Speed v)
264     {
265         return new Power(this.si * v.si, PowerUnit.SI);
266     }
267 
268     /**
269      * Calculate the division of Force and Mass, which results in a Acceleration scalar.
270      * @param v Force; scalar
271      * @return Acceleration; scalar as a division of Force and Mass
272      */
273     public final Acceleration divide(final Mass v)
274     {
275         return new Acceleration(this.si / v.si, AccelerationUnit.SI);
276     }
277 
278     /**
279      * Calculate the division of Force and Acceleration, which results in a Mass scalar.
280      * @param v Force; scalar
281      * @return Mass; scalar as a division of Force and Acceleration
282      */
283     public final Mass divide(final Acceleration v)
284     {
285         return new Mass(this.si / v.si, MassUnit.SI);
286     }
287 
288     /**
289      * Calculate the division of Force and Area, which results in a Pressure scalar.
290      * @param v Force; scalar
291      * @return Pressure; scalar as a division of Force and Area
292      */
293     public final Pressure divide(final Area v)
294     {
295         return new Pressure(this.si / v.si, PressureUnit.SI);
296     }
297 
298     /**
299      * Calculate the division of Force and Pressure, which results in a Area scalar.
300      * @param v Force; scalar
301      * @return Area; scalar as a division of Force and Pressure
302      */
303     public final Area divide(final Pressure v)
304     {
305         return new Area(this.si / v.si, AreaUnit.SI);
306     }
307 
308     @Override
309     public SIScalar reciprocal()
310     {
311         return DoubleScalar.divide(Dimensionless.ONE, this);
312     }
313 
314 }