View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.AngleUnit;
6   import org.djunits.unit.AngularAccelerationUnit;
7   import org.djunits.unit.AngularVelocityUnit;
8   import org.djunits.unit.DimensionlessUnit;
9   import org.djunits.unit.DurationUnit;
10  import org.djunits.unit.FrequencyUnit;
11  import org.djunits.value.vfloat.scalar.base.FloatScalarRel;
12  import org.djutils.base.NumberParser;
13  import org.djutils.exceptions.Throw;
14  
15  import jakarta.annotation.Generated;
16  
17  /**
18   * Easy access methods for the FloatAngularVelocity FloatScalar, which is relative by definition.
19   * <p>
20   * Copyright (c) 2013-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
22   * </p>
23   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
24   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
25   */
26  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2025-09-06T15:16:28.380798Z")
27  public class FloatAngularVelocity extends FloatScalarRel<AngularVelocityUnit, FloatAngularVelocity>
28  {
29      /** */
30      private static final long serialVersionUID = 20150901L;
31  
32      /** Constant with value zero. */
33      public static final FloatAngularVelocity ZERO = new FloatAngularVelocity(0.0f, AngularVelocityUnit.SI);
34  
35      /** Constant with value one. */
36      public static final FloatAngularVelocity ONE = new FloatAngularVelocity(1.0f, AngularVelocityUnit.SI);
37  
38      /** Constant with value NaN. */
39      @SuppressWarnings("checkstyle:constantname")
40      public static final FloatAngularVelocity NaN = new FloatAngularVelocity(Float.NaN, AngularVelocityUnit.SI);
41  
42      /** Constant with value POSITIVE_INFINITY. */
43      public static final FloatAngularVelocity POSITIVE_INFINITY =
44              new FloatAngularVelocity(Float.POSITIVE_INFINITY, AngularVelocityUnit.SI);
45  
46      /** Constant with value NEGATIVE_INFINITY. */
47      public static final FloatAngularVelocity NEGATIVE_INFINITY =
48              new FloatAngularVelocity(Float.NEGATIVE_INFINITY, AngularVelocityUnit.SI);
49  
50      /** Constant with value MAX_VALUE. */
51      public static final FloatAngularVelocity POS_MAXVALUE = new FloatAngularVelocity(Float.MAX_VALUE, AngularVelocityUnit.SI);
52  
53      /** Constant with value -MAX_VALUE. */
54      public static final FloatAngularVelocity NEG_MAXVALUE = new FloatAngularVelocity(-Float.MAX_VALUE, AngularVelocityUnit.SI);
55  
56      /**
57       * Construct FloatAngularVelocity 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 FloatAngularVelocity(final float value, final AngularVelocityUnit unit)
62      {
63          super(value, unit);
64      }
65  
66      /**
67       * Construct FloatAngularVelocity scalar.
68       * @param value Scalar from which to construct this instance
69       */
70      public FloatAngularVelocity(final FloatAngularVelocity value)
71      {
72          super(value);
73      }
74  
75      /**
76       * Construct FloatAngularVelocity 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 FloatAngularVelocity(final double value, final AngularVelocityUnit unit)
81      {
82          super((float) value, unit);
83      }
84  
85      @Override
86      public final FloatAngularVelocity instantiateRel(final float value, final AngularVelocityUnit unit)
87      {
88          return new FloatAngularVelocity(value, unit);
89      }
90  
91      /**
92       * Construct FloatAngularVelocity 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 FloatAngularVelocity ofSI(final float value)
97      {
98          return new FloatAngularVelocity(value, AngularVelocityUnit.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 FloatAngularVelocity at the given ratio between 0 and 1
107      */
108     public static FloatAngularVelocity interpolate(final FloatAngularVelocity zero, final FloatAngularVelocity one,
109             final float ratio)
110     {
111         Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
112                 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
113         return new FloatAngularVelocity(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 FloatAngularVelocity max(final FloatAngularVelocity r1, final FloatAngularVelocity 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 FloatAngularVelocity max(final FloatAngularVelocity r1, final FloatAngularVelocity r2,
136             final FloatAngularVelocity... rn)
137     {
138         FloatAngularVelocity maxr = r1.gt(r2) ? r1 : r2;
139         for (FloatAngularVelocity r : rn)
140         {
141             if (r.gt(maxr))
142             {
143                 maxr = r;
144             }
145         }
146         return maxr;
147     }
148 
149     /**
150      * Return the minimum value of two relative scalars.
151      * @param r1 the first scalar
152      * @param r2 the second scalar
153      * @return the minimum value of two relative scalars
154      */
155     public static FloatAngularVelocity min(final FloatAngularVelocity r1, final FloatAngularVelocity r2)
156     {
157         return r1.lt(r2) ? r1 : r2;
158     }
159 
160     /**
161      * Return the minimum value of more than two relative scalars.
162      * @param r1 the first scalar
163      * @param r2 the second scalar
164      * @param rn the other scalars
165      * @return the minimum value of more than two relative scalars
166      */
167     public static FloatAngularVelocity min(final FloatAngularVelocity r1, final FloatAngularVelocity r2,
168             final FloatAngularVelocity... rn)
169     {
170         FloatAngularVelocity minr = r1.lt(r2) ? r1 : r2;
171         for (FloatAngularVelocity r : rn)
172         {
173             if (r.lt(minr))
174             {
175                 minr = r;
176             }
177         }
178         return minr;
179     }
180 
181     /**
182      * Returns a FloatAngularVelocity representation of a textual representation of a value with a unit. The String
183      * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
184      * unit. Spaces are allowed, but not required, between the value and the unit.
185      * @param text the textual representation to parse into a FloatAngularVelocity
186      * @return the Scalar representation of the value in its unit
187      * @throws IllegalArgumentException when the text cannot be parsed
188      * @throws NullPointerException when the text argument is null
189      */
190     public static FloatAngularVelocity valueOf(final String text)
191     {
192         Throw.whenNull(text, "Error parsing FloatAngularVelocity: text to parse is null");
193         Throw.when(text.length() == 0, IllegalArgumentException.class,
194                 "Error parsing FloatAngularVelocity: empty text to parse");
195         try
196         {
197             NumberParser numberParser = new NumberParser().lenient().trailing();
198             float f = numberParser.parseFloat(text);
199             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
200             AngularVelocityUnit unit = AngularVelocityUnit.BASE.getUnitByAbbreviation(unitString);
201             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity AngularVelocity",
202                     unitString);
203             return new FloatAngularVelocity(f, unit);
204         }
205         catch (Exception exception)
206         {
207             throw new IllegalArgumentException("Error parsing FloatAngularVelocity from " + text + " using Locale "
208                     + Locale.getDefault(Locale.Category.FORMAT), exception);
209         }
210     }
211 
212     /**
213      * Returns a FloatAngularVelocity based on a value and the textual representation of the unit, which can be localized.
214      * @param value the value to use
215      * @param unitString the textual representation of the unit
216      * @return the Scalar representation of the value in its unit
217      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
218      * @throws NullPointerException when the unitString argument is null
219      */
220     public static FloatAngularVelocity of(final float value, final String unitString)
221     {
222         Throw.whenNull(unitString, "Error parsing FloatAngularVelocity: unitString is null");
223         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
224                 "Error parsing FloatAngularVelocity: empty unitString");
225         AngularVelocityUnit unit = AngularVelocityUnit.BASE.getUnitByAbbreviation(unitString);
226         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FloatAngularVelocity with unit %s", unitString);
227         return new FloatAngularVelocity(value, unit);
228     }
229 
230     /**
231      * Calculate the division of FloatAngularVelocity and FloatAngularVelocity, which results in a FloatDimensionless scalar.
232      * @param v scalar
233      * @return scalar as a division of FloatAngularVelocity and FloatAngularVelocity
234      */
235     public final FloatDimensionless divide(final FloatAngularVelocity v)
236     {
237         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
238     }
239 
240     /**
241      * Calculate the division of FloatAngularVelocity and FloatAngle, which results in a FloatFrequency scalar.
242      * @param v scalar
243      * @return scalar as a division of FloatAngularVelocity and FloatAngle
244      */
245     public final FloatFrequency divide(final FloatAngle v)
246     {
247         return new FloatFrequency(this.si / v.si, FrequencyUnit.SI);
248     }
249 
250     /**
251      * Calculate the division of FloatAngularVelocity and FloatFrequency, which results in a FloatAngle scalar.
252      * @param v scalar
253      * @return scalar as a division of FloatAngularVelocity and FloatFrequency
254      */
255     public final FloatAngle divide(final FloatFrequency v)
256     {
257         return new FloatAngle(this.si / v.si, AngleUnit.SI);
258     }
259 
260     /**
261      * Calculate the multiplication of FloatAngularVelocity and FloatDuration, which results in a FloatAngle scalar.
262      * @param v scalar
263      * @return scalar as a multiplication of FloatAngularVelocity and FloatDuration
264      */
265     public final FloatAngle times(final FloatDuration v)
266     {
267         return new FloatAngle(this.si * v.si, AngleUnit.SI);
268     }
269 
270     /**
271      * Calculate the division of FloatAngularVelocity and FloatDuration, which results in a FloatAngularAcceleration scalar.
272      * @param v scalar
273      * @return scalar as a division of FloatAngularVelocity and FloatDuration
274      */
275     public final FloatAngularAcceleration divide(final FloatDuration v)
276     {
277         return new FloatAngularAcceleration(this.si / v.si, AngularAccelerationUnit.SI);
278     }
279 
280     /**
281      * Calculate the division of FloatAngularVelocity and FloatAngularAcceleration, which results in a FloatDuration scalar.
282      * @param v scalar
283      * @return scalar as a division of FloatAngularVelocity and FloatAngularAcceleration
284      */
285     public final FloatDuration divide(final FloatAngularAcceleration v)
286     {
287         return new FloatDuration(this.si / v.si, DurationUnit.SI);
288     }
289 
290     /**
291      * Calculate the multiplication of FloatAngularVelocity and FloatFrequency, which results in a FloatAngularAcceleration
292      * scalar.
293      * @param v scalar
294      * @return scalar as a multiplication of FloatAngularVelocity and FloatFrequency
295      */
296     public final FloatAngularAcceleration times(final FloatFrequency v)
297     {
298         return new FloatAngularAcceleration(this.si * v.si, AngularAccelerationUnit.SI);
299     }
300 
301     @Override
302     public FloatSIScalar reciprocal()
303     {
304         return FloatSIScalar.divide(FloatDimensionless.ONE, this);
305     }
306 
307     /**
308      * Multiply two scalars that result in a scalar of type FloatAngularVelocity.
309      * @param scalar1 the first scalar
310      * @param scalar2 the second scalar
311      * @return the multiplication of both scalars as an instance of FloatAngularVelocity
312      */
313     public static FloatAngularVelocity multiply(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
314     {
315         Throw.whenNull(scalar1, "scalar1 cannot be null");
316         Throw.whenNull(scalar2, "scalar2 cannot be null");
317         Throw.when(
318                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
319                         .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
320                         .equals(AngularVelocityUnit.BASE.getSiDimensions()),
321                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type FloatAngularVelocity",
322                 scalar1.toDisplayString(), scalar2.toDisplayString());
323         return new FloatAngularVelocity(scalar1.si * scalar2.si, AngularVelocityUnit.SI);
324     }
325 
326     /**
327      * Divide two scalars that result in a scalar of type FloatAngularVelocity.
328      * @param scalar1 the first scalar
329      * @param scalar2 the second scalar
330      * @return the division of scalar1 by scalar2 as an instance of FloatAngularVelocity
331      */
332     public static FloatAngularVelocity divide(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
333     {
334         Throw.whenNull(scalar1, "scalar1 cannot be null");
335         Throw.whenNull(scalar2, "scalar2 cannot be null");
336         Throw.when(
337                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
338                         .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
339                         .equals(AngularVelocityUnit.BASE.getSiDimensions()),
340                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type FloatAngularVelocity",
341                 scalar1.toDisplayString(), scalar2.toDisplayString());
342         return new FloatAngularVelocity(scalar1.si / scalar2.si, AngularVelocityUnit.SI);
343     }
344 
345 }