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