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.FloatScalarRel;
14  import org.djutils.base.NumberParser;
15  import org.djutils.exceptions.Throw;
16  
17  import jakarta.annotation.Generated;
18  
19  /**
20   * Easy access methods for the FloatTorque FloatScalar, which is relative by definition.
21   * <p>
22   * Copyright (c) 2013-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
23   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
24   * </p>
25   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
26   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
27   */
28  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2025-09-06T15:16:28.380798Z")
29  public class FloatTorque extends FloatScalarRel<TorqueUnit, FloatTorque>
30  {
31      /** */
32      private static final long serialVersionUID = 20150901L;
33  
34      /** Constant with value zero. */
35      public static final FloatTorque ZERO = new FloatTorque(0.0f, TorqueUnit.SI);
36  
37      /** Constant with value one. */
38      public static final FloatTorque ONE = new FloatTorque(1.0f, TorqueUnit.SI);
39  
40      /** Constant with value NaN. */
41      @SuppressWarnings("checkstyle:constantname")
42      public static final FloatTorque NaN = new FloatTorque(Float.NaN, TorqueUnit.SI);
43  
44      /** Constant with value POSITIVE_INFINITY. */
45      public static final FloatTorque POSITIVE_INFINITY = new FloatTorque(Float.POSITIVE_INFINITY, TorqueUnit.SI);
46  
47      /** Constant with value NEGATIVE_INFINITY. */
48      public static final FloatTorque NEGATIVE_INFINITY = new FloatTorque(Float.NEGATIVE_INFINITY, TorqueUnit.SI);
49  
50      /** Constant with value MAX_VALUE. */
51      public static final FloatTorque POS_MAXVALUE = new FloatTorque(Float.MAX_VALUE, TorqueUnit.SI);
52  
53      /** Constant with value -MAX_VALUE. */
54      public static final FloatTorque NEG_MAXVALUE = new FloatTorque(-Float.MAX_VALUE, TorqueUnit.SI);
55  
56      /**
57       * Construct FloatTorque scalar with a unit.
58       * @param value the float value, expressed in the given unit
59       * @param unit unit for the float value
60       */
61      public FloatTorque(final float value, final TorqueUnit unit)
62      {
63          super(value, unit);
64      }
65  
66      /**
67       * Construct FloatTorque scalar.
68       * @param value Scalar from which to construct this instance
69       */
70      public FloatTorque(final FloatTorque value)
71      {
72          super(value);
73      }
74  
75      /**
76       * Construct FloatTorque scalar with a unit using a double value.
77       * @param value the double value, expressed in the given unit
78       * @param unit unit for the resulting float value
79       */
80      public FloatTorque(final double value, final TorqueUnit unit)
81      {
82          super((float) value, unit);
83      }
84  
85      @Override
86      public final FloatTorque instantiateRel(final float value, final TorqueUnit unit)
87      {
88          return new FloatTorque(value, unit);
89      }
90  
91      /**
92       * Construct FloatTorque scalar based on an SI value.
93       * @param value the float value in SI units
94       * @return the new scalar with the SI value
95       */
96      public static final FloatTorque ofSI(final float value)
97      {
98          return new FloatTorque(value, TorqueUnit.SI);
99      }
100 
101     /**
102      * Interpolate between two values. Note that the first value does not have to be smaller than the second.
103      * @param zero the value at a ratio of zero
104      * @param one the value at a ratio of one
105      * @param ratio the ratio between 0 and 1, inclusive
106      * @return a FloatTorque at the given ratio between 0 and 1
107      */
108     public static FloatTorque interpolate(final FloatTorque zero, final FloatTorque one, final float ratio)
109     {
110         Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
111                 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
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 the textual representation to parse into a FloatTorque
183      * @return 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             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity Torque", unitString);
198             return new FloatTorque(f, unit);
199         }
200         catch (Exception exception)
201         {
202             throw new IllegalArgumentException(
203                     "Error parsing FloatTorque from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
204                     exception);
205         }
206     }
207 
208     /**
209      * Returns a FloatTorque based on a value and the textual representation of the unit, which can be localized.
210      * @param value the value to use
211      * @param unitString the textual representation of the unit
212      * @return the Scalar representation of the value in its unit
213      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
214      * @throws NullPointerException when the unitString argument is null
215      */
216     public static FloatTorque of(final float value, final String unitString)
217     {
218         Throw.whenNull(unitString, "Error parsing FloatTorque: unitString is null");
219         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatTorque: empty unitString");
220         TorqueUnit unit = TorqueUnit.BASE.getUnitByAbbreviation(unitString);
221         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FloatTorque with unit %s", unitString);
222         return new FloatTorque(value, unit);
223     }
224 
225     /**
226      * Calculate the division of FloatTorque and FloatTorque, which results in a FloatDimensionless scalar.
227      * @param v scalar
228      * @return scalar as a division of FloatTorque and FloatTorque
229      */
230     public final FloatDimensionless divide(final FloatTorque v)
231     {
232         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
233     }
234 
235     /**
236      * Calculate the division of FloatTorque and FloatForce, which results in a FloatLength scalar.
237      * @param v scalar
238      * @return scalar as a division of FloatTorque and FloatForce
239      */
240     public final FloatLength divide(final FloatForce v)
241     {
242         return new FloatLength(this.si / v.si, LengthUnit.SI);
243     }
244 
245     /**
246      * Calculate the division of FloatTorque and FloatLength, which results in a FloatForce scalar.
247      * @param v scalar
248      * @return scalar as a division of FloatTorque and FloatLength
249      */
250     public final FloatForce divide(final FloatLength v)
251     {
252         return new FloatForce(this.si / v.si, ForceUnit.SI);
253     }
254 
255     /**
256      * Calculate the multiplication of FloatTorque and FloatLinearDensity, which results in a FloatForce scalar.
257      * @param v scalar
258      * @return scalar as a multiplication of FloatTorque and FloatLinearDensity
259      */
260     public final FloatForce times(final FloatLinearDensity v)
261     {
262         return new FloatForce(this.si * v.si, ForceUnit.SI);
263     }
264 
265     /**
266      * Calculate the division of FloatTorque and FloatDuration, which results in a FloatPower scalar.
267      * @param v scalar
268      * @return scalar as a division of FloatTorque and FloatDuration
269      */
270     public final FloatPower divide(final FloatDuration v)
271     {
272         return new FloatPower(this.si / v.si, PowerUnit.SI);
273     }
274 
275     /**
276      * Calculate the division of FloatTorque and FloatPower, which results in a FloatDuration scalar.
277      * @param v scalar
278      * @return scalar as a division of FloatTorque and FloatPower
279      */
280     public final FloatDuration divide(final FloatPower v)
281     {
282         return new FloatDuration(this.si / v.si, DurationUnit.SI);
283     }
284 
285     /**
286      * Calculate the multiplication of FloatTorque and FloatFrequency, which results in a FloatPower scalar.
287      * @param v scalar
288      * @return scalar as a multiplication of FloatTorque and FloatFrequency
289      */
290     public final FloatPower times(final FloatFrequency v)
291     {
292         return new FloatPower(this.si * v.si, PowerUnit.SI);
293     }
294 
295     /**
296      * Calculate the division of FloatTorque and FloatVolume, which results in a FloatPressure scalar.
297      * @param v scalar
298      * @return scalar as a division of FloatTorque and FloatVolume
299      */
300     public final FloatPressure divide(final FloatVolume v)
301     {
302         return new FloatPressure(this.si / v.si, PressureUnit.SI);
303     }
304 
305     /**
306      * Calculate the division of FloatTorque and FloatPressure, which results in a FloatVolume scalar.
307      * @param v scalar
308      * @return scalar as a division of FloatTorque and FloatPressure
309      */
310     public final FloatVolume divide(final FloatPressure v)
311     {
312         return new FloatVolume(this.si / v.si, VolumeUnit.SI);
313     }
314 
315     @Override
316     public FloatSIScalar reciprocal()
317     {
318         return FloatSIScalar.divide(FloatDimensionless.ONE, this);
319     }
320 
321     /**
322      * Multiply two scalars that result in a scalar of type FloatTorque.
323      * @param scalar1 the first scalar
324      * @param scalar2 the second scalar
325      * @return the multiplication of both scalars as an instance of FloatTorque
326      */
327     public static FloatTorque multiply(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
328     {
329         Throw.whenNull(scalar1, "scalar1 cannot be null");
330         Throw.whenNull(scalar2, "scalar2 cannot be null");
331         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
332                 .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(TorqueUnit.BASE.getSiDimensions()),
333                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type FloatTorque",
334                 scalar1.toDisplayString(), scalar2.toDisplayString());
335         return new FloatTorque(scalar1.si * scalar2.si, TorqueUnit.SI);
336     }
337 
338     /**
339      * Divide two scalars that result in a scalar of type FloatTorque.
340      * @param scalar1 the first scalar
341      * @param scalar2 the second scalar
342      * @return the division of scalar1 by scalar2 as an instance of FloatTorque
343      */
344     public static FloatTorque divide(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
345     {
346         Throw.whenNull(scalar1, "scalar1 cannot be null");
347         Throw.whenNull(scalar2, "scalar2 cannot be null");
348         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
349                 .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(TorqueUnit.BASE.getSiDimensions()),
350                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type FloatTorque",
351                 scalar1.toDisplayString(), scalar2.toDisplayString());
352         return new FloatTorque(scalar1.si / scalar2.si, TorqueUnit.SI);
353     }
354 
355 }