View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.DimensionlessUnit;
6   import org.djunits.unit.DurationUnit;
7   import org.djunits.unit.ForceUnit;
8   import org.djunits.unit.LengthUnit;
9   import org.djunits.unit.PowerUnit;
10  import org.djunits.unit.PressureUnit;
11  import org.djunits.unit.TorqueUnit;
12  import org.djunits.unit.VolumeUnit;
13  import org.djunits.value.vfloat.scalar.base.AbstractFloatScalarRel;
14  import org.djunits.value.vfloat.scalar.base.FloatScalar;
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 FloatTorque FloatScalar, which is relative by definition.
22   * <p>
23   * Copyright (c) 2013-2023 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 = "2023-04-30T13:59:27.633664900Z")
30  public class FloatTorque extends AbstractFloatScalarRel<TorqueUnit, FloatTorque>
31  {
32      /** */
33      private static final long serialVersionUID = 20150901L;
34  
35      /** Constant with value zero. */
36      public static final FloatTorque ZERO = new FloatTorque(0.0f, TorqueUnit.SI);
37  
38      /** Constant with value one. */
39      public static final FloatTorque ONE = new FloatTorque(1.0f, TorqueUnit.SI);
40  
41      /** Constant with value NaN. */
42      @SuppressWarnings("checkstyle:constantname")
43      public static final FloatTorque NaN = new FloatTorque(Float.NaN, TorqueUnit.SI);
44  
45      /** Constant with value POSITIVE_INFINITY. */
46      public static final FloatTorque POSITIVE_INFINITY = new FloatTorque(Float.POSITIVE_INFINITY, TorqueUnit.SI);
47  
48      /** Constant with value NEGATIVE_INFINITY. */
49      public static final FloatTorque NEGATIVE_INFINITY = new FloatTorque(Float.NEGATIVE_INFINITY, TorqueUnit.SI);
50  
51      /** Constant with value MAX_VALUE. */
52      public static final FloatTorque POS_MAXVALUE = new FloatTorque(Float.MAX_VALUE, TorqueUnit.SI);
53  
54      /** Constant with value -MAX_VALUE. */
55      public static final FloatTorque NEG_MAXVALUE = new FloatTorque(-Float.MAX_VALUE, TorqueUnit.SI);
56  
57      /**
58       * Construct FloatTorque scalar.
59       * @param value float; the float value
60       * @param unit unit for the float value
61       */
62      public FloatTorque(final float value, final TorqueUnit unit)
63      {
64          super(value, unit);
65      }
66  
67      /**
68       * Construct FloatTorque scalar.
69       * @param value Scalar from which to construct this instance
70       */
71      public FloatTorque(final FloatTorque value)
72      {
73          super(value);
74      }
75  
76      /**
77       * Construct FloatTorque scalar using a double value.
78       * @param value double; the double value
79       * @param unit unit for the resulting float value
80       */
81      public FloatTorque(final double value, final TorqueUnit unit)
82      {
83          super((float) value, unit);
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public final FloatTorque instantiateRel(final float value, final TorqueUnit unit)
89      {
90          return new FloatTorque(value, unit);
91      }
92  
93      /**
94       * Construct FloatTorque 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 FloatTorque instantiateSI(final float value)
99      {
100         return new FloatTorque(value, TorqueUnit.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 FloatTorque interpolate(final FloatTorque zero, final FloatTorque one, final float ratio)
111     {
112         return new FloatTorque(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 FloatTorque max(final FloatTorque r1, final FloatTorque 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 FloatTorque max(final FloatTorque r1, final FloatTorque r2, final FloatTorque... rn)
135     {
136         FloatTorque maxr = r1.gt(r2) ? r1 : r2;
137         for (FloatTorque 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 FloatTorque min(final FloatTorque r1, final FloatTorque 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 FloatTorque min(final FloatTorque r1, final FloatTorque r2, final FloatTorque... rn)
166     {
167         FloatTorque minr = r1.lt(r2) ? r1 : r2;
168         for (FloatTorque r : rn)
169         {
170             if (r.lt(minr))
171             {
172                 minr = r;
173             }
174         }
175         return minr;
176     }
177 
178     /**
179      * Returns a FloatTorque 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 FloatTorque
183      * @return FloatTorque; 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 FloatTorque valueOf(final String text)
188     {
189         Throw.whenNull(text, "Error parsing FloatTorque: text to parse is null");
190         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatTorque: 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             TorqueUnit unit = TorqueUnit.BASE.getUnitByAbbreviation(unitString);
197             if (unit == null)
198                 throw new IllegalArgumentException("Unit " + unitString + " not found");
199             return new FloatTorque(f, unit);
200         }
201         catch (Exception exception)
202         {
203             throw new IllegalArgumentException(
204                     "Error parsing FloatTorque from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
205                     exception);
206         }
207     }
208 
209     /**
210      * Returns a FloatTorque 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 FloatTorque; 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 FloatTorque of(final float value, final String unitString)
218     {
219         Throw.whenNull(unitString, "Error parsing FloatTorque: unitString is null");
220         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatTorque: empty unitString");
221         TorqueUnit unit = TorqueUnit.BASE.getUnitByAbbreviation(unitString);
222         if (unit != null)
223         {
224             return new FloatTorque(value, unit);
225         }
226         throw new IllegalArgumentException("Error parsing FloatTorque with unit " + unitString);
227     }
228 
229     /**
230      * Calculate the division of FloatTorque and FloatTorque, which results in a FloatDimensionless scalar.
231      * @param v FloatTorque; scalar
232      * @return FloatDimensionless; scalar as a division of FloatTorque and FloatTorque
233      */
234     public final FloatDimensionless divide(final FloatTorque v)
235     {
236         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
237     }
238 
239     /**
240      * Calculate the division of FloatTorque and FloatForce, which results in a FloatLength scalar.
241      * @param v FloatTorque; scalar
242      * @return FloatLength; scalar as a division of FloatTorque and FloatForce
243      */
244     public final FloatLength divide(final FloatForce v)
245     {
246         return new FloatLength(this.si / v.si, LengthUnit.SI);
247     }
248 
249     /**
250      * Calculate the division of FloatTorque and FloatLength, which results in a FloatForce scalar.
251      * @param v FloatTorque; scalar
252      * @return FloatForce; scalar as a division of FloatTorque and FloatLength
253      */
254     public final FloatForce divide(final FloatLength v)
255     {
256         return new FloatForce(this.si / v.si, ForceUnit.SI);
257     }
258 
259     /**
260      * Calculate the multiplication of FloatTorque and FloatLinearDensity, which results in a FloatForce scalar.
261      * @param v FloatTorque; scalar
262      * @return FloatForce; scalar as a multiplication of FloatTorque and FloatLinearDensity
263      */
264     public final FloatForce times(final FloatLinearDensity v)
265     {
266         return new FloatForce(this.si * v.si, ForceUnit.SI);
267     }
268 
269     /**
270      * Calculate the division of FloatTorque and FloatDuration, which results in a FloatPower scalar.
271      * @param v FloatTorque; scalar
272      * @return FloatPower; scalar as a division of FloatTorque and FloatDuration
273      */
274     public final FloatPower divide(final FloatDuration v)
275     {
276         return new FloatPower(this.si / v.si, PowerUnit.SI);
277     }
278 
279     /**
280      * Calculate the division of FloatTorque and FloatPower, which results in a FloatDuration scalar.
281      * @param v FloatTorque; scalar
282      * @return FloatDuration; scalar as a division of FloatTorque and FloatPower
283      */
284     public final FloatDuration divide(final FloatPower v)
285     {
286         return new FloatDuration(this.si / v.si, DurationUnit.SI);
287     }
288 
289     /**
290      * Calculate the multiplication of FloatTorque and FloatFrequency, which results in a FloatPower scalar.
291      * @param v FloatTorque; scalar
292      * @return FloatPower; scalar as a multiplication of FloatTorque and FloatFrequency
293      */
294     public final FloatPower times(final FloatFrequency v)
295     {
296         return new FloatPower(this.si * v.si, PowerUnit.SI);
297     }
298 
299     /**
300      * Calculate the division of FloatTorque and FloatVolume, which results in a FloatPressure scalar.
301      * @param v FloatTorque; scalar
302      * @return FloatPressure; scalar as a division of FloatTorque and FloatVolume
303      */
304     public final FloatPressure divide(final FloatVolume v)
305     {
306         return new FloatPressure(this.si / v.si, PressureUnit.SI);
307     }
308 
309     /**
310      * Calculate the division of FloatTorque and FloatPressure, which results in a FloatVolume scalar.
311      * @param v FloatTorque; scalar
312      * @return FloatVolume; scalar as a division of FloatTorque and FloatPressure
313      */
314     public final FloatVolume divide(final FloatPressure v)
315     {
316         return new FloatVolume(this.si / v.si, VolumeUnit.SI);
317     }
318 
319     /** {@inheritDoc} */
320     @Override
321     public FloatSIScalar reciprocal()
322     {
323         return FloatScalar.divide(FloatDimensionless.ONE, this);
324     }
325 
326 }