View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.AccelerationUnit;
6   import org.djunits.unit.DimensionlessUnit;
7   import org.djunits.unit.DurationUnit;
8   import org.djunits.unit.EnergyUnit;
9   import org.djunits.unit.FlowVolumeUnit;
10  import org.djunits.unit.ForceUnit;
11  import org.djunits.unit.FrequencyUnit;
12  import org.djunits.unit.LengthUnit;
13  import org.djunits.unit.MomentumUnit;
14  import org.djunits.unit.PowerUnit;
15  import org.djunits.unit.SpeedUnit;
16  import org.djunits.value.vfloat.scalar.base.FloatScalar;
17  import org.djunits.value.vfloat.scalar.base.FloatScalarRel;
18  import org.djutils.base.NumberParser;
19  import org.djutils.exceptions.Throw;
20  
21  import jakarta.annotation.Generated;
22  
23  /**
24   * Easy access methods for the FloatSpeed FloatScalar, which is relative by definition.
25   * <p>
26   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
27   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
28   * </p>
29   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
30   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
31   */
32  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
33  public class FloatSpeed extends FloatScalarRel<SpeedUnit, FloatSpeed>
34  {
35      /** */
36      private static final long serialVersionUID = 20150901L;
37  
38      /** Constant with value zero. */
39      public static final FloatSpeed ZERO = new FloatSpeed(0.0f, SpeedUnit.SI);
40  
41      /** Constant with value one. */
42      public static final FloatSpeed ONE = new FloatSpeed(1.0f, SpeedUnit.SI);
43  
44      /** Constant with value NaN. */
45      @SuppressWarnings("checkstyle:constantname")
46      public static final FloatSpeed NaN = new FloatSpeed(Float.NaN, SpeedUnit.SI);
47  
48      /** Constant with value POSITIVE_INFINITY. */
49      public static final FloatSpeed POSITIVE_INFINITY = new FloatSpeed(Float.POSITIVE_INFINITY, SpeedUnit.SI);
50  
51      /** Constant with value NEGATIVE_INFINITY. */
52      public static final FloatSpeed NEGATIVE_INFINITY = new FloatSpeed(Float.NEGATIVE_INFINITY, SpeedUnit.SI);
53  
54      /** Constant with value MAX_VALUE. */
55      public static final FloatSpeed POS_MAXVALUE = new FloatSpeed(Float.MAX_VALUE, SpeedUnit.SI);
56  
57      /** Constant with value -MAX_VALUE. */
58      public static final FloatSpeed NEG_MAXVALUE = new FloatSpeed(-Float.MAX_VALUE, SpeedUnit.SI);
59  
60      /**
61       * Construct FloatSpeed scalar.
62       * @param value float; the float value
63       * @param unit unit for the float value
64       */
65      public FloatSpeed(final float value, final SpeedUnit unit)
66      {
67          super(value, unit);
68      }
69  
70      /**
71       * Construct FloatSpeed scalar.
72       * @param value Scalar from which to construct this instance
73       */
74      public FloatSpeed(final FloatSpeed value)
75      {
76          super(value);
77      }
78  
79      /**
80       * Construct FloatSpeed scalar using a double value.
81       * @param value double; the double value
82       * @param unit unit for the resulting float value
83       */
84      public FloatSpeed(final double value, final SpeedUnit unit)
85      {
86          super((float) value, unit);
87      }
88  
89      @Override
90      public final FloatSpeed instantiateRel(final float value, final SpeedUnit unit)
91      {
92          return new FloatSpeed(value, unit);
93      }
94  
95      /**
96       * Construct FloatSpeed scalar.
97       * @param value float; the float value in SI units
98       * @return the new scalar with the SI value
99       */
100     public static final FloatSpeed instantiateSI(final float value)
101     {
102         return new FloatSpeed(value, SpeedUnit.SI);
103     }
104 
105     /**
106      * Interpolate between two values.
107      * @param zero the low value
108      * @param one the high value
109      * @param ratio double; the ratio between 0 and 1, inclusive
110      * @return a Scalar at the ratio between
111      */
112     public static FloatSpeed interpolate(final FloatSpeed zero, final FloatSpeed one, final float ratio)
113     {
114         return new FloatSpeed(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
115                 zero.getDisplayUnit());
116     }
117 
118     /**
119      * Return the maximum value of two relative scalars.
120      * @param r1 the first scalar
121      * @param r2 the second scalar
122      * @return the maximum value of two relative scalars
123      */
124     public static FloatSpeed max(final FloatSpeed r1, final FloatSpeed r2)
125     {
126         return r1.gt(r2) ? r1 : r2;
127     }
128 
129     /**
130      * Return the maximum value of more than two relative scalars.
131      * @param r1 the first scalar
132      * @param r2 the second scalar
133      * @param rn the other scalars
134      * @return the maximum value of more than two relative scalars
135      */
136     public static FloatSpeed max(final FloatSpeed r1, final FloatSpeed r2, final FloatSpeed... rn)
137     {
138         FloatSpeed maxr = r1.gt(r2) ? r1 : r2;
139         for (FloatSpeed 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 FloatSpeed min(final FloatSpeed r1, final FloatSpeed 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 FloatSpeed min(final FloatSpeed r1, final FloatSpeed r2, final FloatSpeed... rn)
168     {
169         FloatSpeed minr = r1.lt(r2) ? r1 : r2;
170         for (FloatSpeed r : rn)
171         {
172             if (r.lt(minr))
173             {
174                 minr = r;
175             }
176         }
177         return minr;
178     }
179 
180     /**
181      * Returns a FloatSpeed representation of a textual representation of a value with a unit. The String representation that
182      * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
183      * allowed, but not required, between the value and the unit.
184      * @param text String; the textual representation to parse into a FloatSpeed
185      * @return FloatSpeed; the Scalar representation of the value in its unit
186      * @throws IllegalArgumentException when the text cannot be parsed
187      * @throws NullPointerException when the text argument is null
188      */
189     public static FloatSpeed valueOf(final String text)
190     {
191         Throw.whenNull(text, "Error parsing FloatSpeed: text to parse is null");
192         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatSpeed: empty text to parse");
193         try
194         {
195             NumberParser numberParser = new NumberParser().lenient().trailing();
196             float f = numberParser.parseFloat(text);
197             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
198             SpeedUnit unit = SpeedUnit.BASE.getUnitByAbbreviation(unitString);
199             if (unit == null)
200                 throw new IllegalArgumentException("Unit " + unitString + " not found");
201             return new FloatSpeed(f, unit);
202         }
203         catch (Exception exception)
204         {
205             throw new IllegalArgumentException(
206                     "Error parsing FloatSpeed from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
207                     exception);
208         }
209     }
210 
211     /**
212      * Returns a FloatSpeed based on a value and the textual representation of the unit, which can be localized.
213      * @param value double; the value to use
214      * @param unitString String; the textual representation of the unit
215      * @return FloatSpeed; the Scalar representation of the value in its unit
216      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
217      * @throws NullPointerException when the unitString argument is null
218      */
219     public static FloatSpeed of(final float value, final String unitString)
220     {
221         Throw.whenNull(unitString, "Error parsing FloatSpeed: unitString is null");
222         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatSpeed: empty unitString");
223         SpeedUnit unit = SpeedUnit.BASE.getUnitByAbbreviation(unitString);
224         if (unit != null)
225         {
226             return new FloatSpeed(value, unit);
227         }
228         throw new IllegalArgumentException("Error parsing FloatSpeed with unit " + unitString);
229     }
230 
231     /**
232      * Calculate the division of FloatSpeed and FloatSpeed, which results in a FloatDimensionless scalar.
233      * @param v FloatSpeed; scalar
234      * @return FloatDimensionless; scalar as a division of FloatSpeed and FloatSpeed
235      */
236     public final FloatDimensionless divide(final FloatSpeed v)
237     {
238         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
239     }
240 
241     /**
242      * Calculate the multiplication of FloatSpeed and FloatArea, which results in a FloatFlowVolume scalar.
243      * @param v FloatSpeed; scalar
244      * @return FloatFlowVolume; scalar as a multiplication of FloatSpeed and FloatArea
245      */
246     public final FloatFlowVolume times(final FloatArea v)
247     {
248         return new FloatFlowVolume(this.si * v.si, FlowVolumeUnit.SI);
249     }
250 
251     /**
252      * Calculate the multiplication of FloatSpeed and FloatForce, which results in a FloatPower scalar.
253      * @param v FloatSpeed; scalar
254      * @return FloatPower; scalar as a multiplication of FloatSpeed and FloatForce
255      */
256     public final FloatPower times(final FloatForce v)
257     {
258         return new FloatPower(this.si * v.si, PowerUnit.SI);
259     }
260 
261     /**
262      * Calculate the multiplication of FloatSpeed and FloatFrequency, which results in a FloatAcceleration scalar.
263      * @param v FloatSpeed; scalar
264      * @return FloatAcceleration; scalar as a multiplication of FloatSpeed and FloatFrequency
265      */
266     public final FloatAcceleration times(final FloatFrequency v)
267     {
268         return new FloatAcceleration(this.si * v.si, AccelerationUnit.SI);
269     }
270 
271     /**
272      * Calculate the division of FloatSpeed and FloatLength, which results in a FloatFrequency scalar.
273      * @param v FloatSpeed; scalar
274      * @return FloatFrequency; scalar as a division of FloatSpeed and FloatLength
275      */
276     public final FloatFrequency divide(final FloatLength v)
277     {
278         return new FloatFrequency(this.si / v.si, FrequencyUnit.SI);
279     }
280 
281     /**
282      * Calculate the division of FloatSpeed and FloatFrequency, which results in a FloatLength scalar.
283      * @param v FloatSpeed; scalar
284      * @return FloatLength; scalar as a division of FloatSpeed and FloatFrequency
285      */
286     public final FloatLength divide(final FloatFrequency v)
287     {
288         return new FloatLength(this.si / v.si, LengthUnit.SI);
289     }
290 
291     /**
292      * Calculate the multiplication of FloatSpeed and FloatLinearDensity, which results in a FloatFrequency scalar.
293      * @param v FloatSpeed; scalar
294      * @return FloatFrequency; scalar as a multiplication of FloatSpeed and FloatLinearDensity
295      */
296     public final FloatFrequency times(final FloatLinearDensity v)
297     {
298         return new FloatFrequency(this.si * v.si, FrequencyUnit.SI);
299     }
300 
301     /**
302      * Calculate the multiplication of FloatSpeed and FloatDuration, which results in a FloatLength scalar.
303      * @param v FloatSpeed; scalar
304      * @return FloatLength; scalar as a multiplication of FloatSpeed and FloatDuration
305      */
306     public final FloatLength times(final FloatDuration v)
307     {
308         return new FloatLength(this.si * v.si, LengthUnit.SI);
309     }
310 
311     /**
312      * Calculate the division of FloatSpeed and FloatDuration, which results in a FloatAcceleration scalar.
313      * @param v FloatSpeed; scalar
314      * @return FloatAcceleration; scalar as a division of FloatSpeed and FloatDuration
315      */
316     public final FloatAcceleration divide(final FloatDuration v)
317     {
318         return new FloatAcceleration(this.si / v.si, AccelerationUnit.SI);
319     }
320 
321     /**
322      * Calculate the division of FloatSpeed and FloatAcceleration, which results in a FloatDuration scalar.
323      * @param v FloatSpeed; scalar
324      * @return FloatDuration; scalar as a division of FloatSpeed and FloatAcceleration
325      */
326     public final FloatDuration divide(final FloatAcceleration v)
327     {
328         return new FloatDuration(this.si / v.si, DurationUnit.SI);
329     }
330 
331     /**
332      * Calculate the multiplication of FloatSpeed and FloatFlowMass, which results in a FloatForce scalar.
333      * @param v FloatSpeed; scalar
334      * @return FloatForce; scalar as a multiplication of FloatSpeed and FloatFlowMass
335      */
336     public final FloatForce times(final FloatFlowMass v)
337     {
338         return new FloatForce(this.si * v.si, ForceUnit.SI);
339     }
340 
341     /**
342      * Calculate the multiplication of FloatSpeed and FloatMass, which results in a FloatMomentum scalar.
343      * @param v FloatSpeed; scalar
344      * @return FloatMomentum; scalar as a multiplication of FloatSpeed and FloatMass
345      */
346     public final FloatMomentum times(final FloatMass v)
347     {
348         return new FloatMomentum(this.si * v.si, MomentumUnit.SI);
349     }
350 
351     /**
352      * Calculate the multiplication of FloatSpeed and FloatMomentum, which results in a FloatEnergy scalar.
353      * @param v FloatSpeed; scalar
354      * @return FloatEnergy; scalar as a multiplication of FloatSpeed and FloatMomentum
355      */
356     public final FloatEnergy times(final FloatMomentum v)
357     {
358         return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
359     }
360 
361     @Override
362     public FloatSIScalar reciprocal()
363     {
364         return FloatScalar.divide(FloatDimensionless.ONE, this);
365     }
366 
367 }