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