View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import java.util.regex.Matcher;
4   
5   import javax.annotation.Generated;
6   
7   import org.djunits.Throw;
8   import org.djunits.unit.AccelerationUnit;
9   import org.djunits.unit.DimensionlessUnit;
10  import org.djunits.unit.DurationUnit;
11  import org.djunits.unit.EnergyUnit;
12  import org.djunits.unit.FlowVolumeUnit;
13  import org.djunits.unit.ForceUnit;
14  import org.djunits.unit.FrequencyUnit;
15  import org.djunits.unit.LengthUnit;
16  import org.djunits.unit.MomentumUnit;
17  import org.djunits.unit.PowerUnit;
18  import org.djunits.unit.SpeedUnit;
19  import org.djunits.value.util.ValueUtil;
20  import org.djunits.value.vfloat.scalar.base.AbstractFloatScalarRel;
21  import org.djunits.value.vfloat.scalar.base.FloatScalar;
22  
23  /**
24   * Easy access methods for the FloatSpeed FloatScalar, which is relative by definition.
25   * <p>
26   * Copyright (c) 2013-2022 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 = "2022-03-14T11:14:15.180987200Z")
33  public class FloatSpeed extends AbstractFloatScalarRel<SpeedUnit, FloatSpeed>
34  {
35      /** */
36      private static final long serialVersionUID = 20150901L;
37  
38      /** Constant with value zero. */
39      public static final FloatSpeedalar/FloatSpeed.html#FloatSpeed">FloatSpeed ZERO = new FloatSpeed(0.0f, SpeedUnit.SI);
40  
41      /** Constant with value one. */
42      public static final FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed ONE = new FloatSpeed(1.0f, SpeedUnit.SI);
43  
44      /** Constant with value NaN. */
45      @SuppressWarnings("checkstyle:constantname")
46      public static final FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed NaN = new FloatSpeed(Float.NaN, SpeedUnit.SI);
47  
48      /** Constant with value POSITIVE_INFINITY. */
49      public static final FloatSpeeded.html#FloatSpeed">FloatSpeed POSITIVE_INFINITY = new FloatSpeed(Float.POSITIVE_INFINITY, SpeedUnit.SI);
50  
51      /** Constant with value NEGATIVE_INFINITY. */
52      public static final FloatSpeeded.html#FloatSpeed">FloatSpeed NEGATIVE_INFINITY = new FloatSpeed(Float.NEGATIVE_INFINITY, SpeedUnit.SI);
53  
54      /** Constant with value MAX_VALUE. */
55      public static final FloatSpeedatSpeed.html#FloatSpeed">FloatSpeed POS_MAXVALUE = new FloatSpeed(Float.MAX_VALUE, SpeedUnit.SI);
56  
57      /** Constant with value -MAX_VALUE. */
58      public static final FloatSpeedatSpeed.html#FloatSpeed">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 FloatSpeedat/scalar/FloatSpeed.html#FloatSpeed">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      /** {@inheritDoc} */
90      @Override
91      public final FloatSpeed instantiateRel(final float value, final SpeedUnit unit)
92      {
93          return new FloatSpeed(value, unit);
94      }
95  
96      /**
97       * Construct FloatSpeed scalar.
98       * @param value float; the float value in SI units
99       * @return the new scalar with the SI value
100      */
101     public static final FloatSpeed instantiateSI(final float value)
102     {
103         return new FloatSpeed(value, SpeedUnit.SI);
104     }
105 
106     /**
107      * Interpolate between two values.
108      * @param zero the low value
109      * @param one the high value
110      * @param ratio double; the ratio between 0 and 1, inclusive
111      * @return a Scalar at the ratio between
112      */
113     public static FloatSpeedlar/FloatSpeed.html#FloatSpeed">FloatSpeedoatSpeed.html#FloatSpeed">FloatSpeed interpolate(final FloatSpeedlar/FloatSpeed.html#FloatSpeed">FloatSpeed zero, final FloatSpeed one, final float ratio)
114     {
115         return new FloatSpeed(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
116                 zero.getDisplayUnit());
117     }
118 
119     /**
120      * Return the maximum value of two relative scalars.
121      * @param r1 the first scalar
122      * @param r2 the second scalar
123      * @return the maximum value of two relative scalars
124      */
125     public static FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed max(final FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed r1, final FloatSpeed r2)
126     {
127         return r1.gt(r2) ? r1 : r2;
128     }
129 
130     /**
131      * Return the maximum value of more than two relative scalars.
132      * @param r1 the first scalar
133      * @param r2 the second scalar
134      * @param rn the other scalars
135      * @return the maximum value of more than two relative scalars
136      */
137     public static FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed max(final FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed r1, final FloatSpeed r2, final FloatSpeed... rn)
138     {
139         FloatSpeed maxr = r1.gt(r2) ? r1 : r2;
140         for (FloatSpeed r : rn)
141         {
142             if (r.gt(maxr))
143             {
144                 maxr = r;
145             }
146         }
147         return maxr;
148     }
149 
150     /**
151      * Return the minimum value of two relative scalars.
152      * @param r1 the first scalar
153      * @param r2 the second scalar
154      * @return the minimum value of two relative scalars
155      */
156     public static FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed min(final FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed r1, final FloatSpeed r2)
157     {
158         return r1.lt(r2) ? r1 : r2;
159     }
160 
161     /**
162      * Return the minimum value of more than two relative scalars.
163      * @param r1 the first scalar
164      * @param r2 the second scalar
165      * @param rn the other scalars
166      * @return the minimum value of more than two relative scalars
167      */
168     public static FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed min(final FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed r1, final FloatSpeed r2, final FloatSpeed... rn)
169     {
170         FloatSpeed minr = r1.lt(r2) ? r1 : r2;
171         for (FloatSpeed r : rn)
172         {
173             if (r.lt(minr))
174             {
175                 minr = r;
176             }
177         }
178         return minr;
179     }
180 
181     /**
182      * Returns a FloatSpeed representation of a textual representation of a value with a unit. The String representation that
183      * can be parsed is the double value in the unit, followed by the official abbreviation of the unit. Spaces are allowed, but
184      * not required, between the value and the unit.
185      * @param text String; the textual representation to parse into a FloatSpeed
186      * @return FloatSpeed; 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 FloatSpeed valueOf(final String text)
191     {
192         Throw.whenNull(text, "Error parsing FloatSpeed: text to parse is null");
193         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatSpeed: empty text to parse");
194         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
195         if (matcher.find())
196         {
197             int index = matcher.end();
198             String unitString = text.substring(index).trim();
199             String valueString = text.substring(0, index).trim();
200             SpeedUnit unit = SpeedUnit.BASE.getUnitByAbbreviation(unitString);
201             if (unit != null)
202             {
203                 float f = Float.parseFloat(valueString);
204                 return new FloatSpeed(f, unit);
205             }
206         }
207         throw new IllegalArgumentException("Error parsing FloatSpeed from " + text);
208     }
209 
210     /**
211      * Returns a FloatSpeed based on a value and the textual representation of the unit.
212      * @param value double; the value to use
213      * @param unitString String; the textual representation of the unit
214      * @return FloatSpeed; the Scalar representation of the value in its unit
215      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
216      * @throws NullPointerException when the unitString argument is null
217      */
218     public static FloatSpeed of(final float value, final String unitString)
219     {
220         Throw.whenNull(unitString, "Error parsing FloatSpeed: unitString is null");
221         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatSpeed: empty unitString");
222         SpeedUnit unit = SpeedUnit.BASE.getUnitByAbbreviation(unitString);
223         if (unit != null)
224         {
225             return new FloatSpeed(value, unit);
226         }
227         throw new IllegalArgumentException("Error parsing FloatSpeed with unit " + unitString);
228     }
229 
230     /**
231      * Calculate the division of FloatSpeed and FloatSpeed, which results in a FloatDimensionless scalar.
232      * @param v FloatSpeed; scalar
233      * @return FloatDimensionless; scalar as a division of FloatSpeed and FloatSpeed
234      */
235     public final FloatDimensionless divide(final FloatSpeed v)
236     {
237         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
238     }
239 
240     /**
241      * Calculate the multiplication of FloatSpeed and FloatArea, which results in a FloatFlowVolume scalar.
242      * @param v FloatSpeed; scalar
243      * @return FloatFlowVolume; scalar as a multiplication of FloatSpeed and FloatArea
244      */
245     public final FloatFlowVolume times(final FloatArea v)
246     {
247         return new FloatFlowVolume(this.si * v.si, FlowVolumeUnit.SI);
248     }
249 
250     /**
251      * Calculate the multiplication of FloatSpeed and FloatForce, which results in a FloatPower scalar.
252      * @param v FloatSpeed; scalar
253      * @return FloatPower; scalar as a multiplication of FloatSpeed and FloatForce
254      */
255     public final FloatPower times(final FloatForce v)
256     {
257         return new FloatPower(this.si * v.si, PowerUnit.SI);
258     }
259 
260     /**
261      * Calculate the multiplication of FloatSpeed and FloatFrequency, which results in a FloatAcceleration scalar.
262      * @param v FloatSpeed; scalar
263      * @return FloatAcceleration; scalar as a multiplication of FloatSpeed and FloatFrequency
264      */
265     public final FloatAcceleration times(final FloatFrequency v)
266     {
267         return new FloatAcceleration(this.si * v.si, AccelerationUnit.SI);
268     }
269 
270     /**
271      * Calculate the division of FloatSpeed and FloatLength, which results in a FloatFrequency scalar.
272      * @param v FloatSpeed; scalar
273      * @return FloatFrequency; scalar as a division of FloatSpeed and FloatLength
274      */
275     public final FloatFrequency divide(final FloatLength v)
276     {
277         return new FloatFrequency(this.si / v.si, FrequencyUnit.SI);
278     }
279 
280     /**
281      * Calculate the division of FloatSpeed and FloatFrequency, which results in a FloatLength scalar.
282      * @param v FloatSpeed; scalar
283      * @return FloatLength; scalar as a division of FloatSpeed and FloatFrequency
284      */
285     public final FloatLength divide(final FloatFrequency v)
286     {
287         return new FloatLength(this.si / v.si, LengthUnit.SI);
288     }
289 
290     /**
291      * Calculate the multiplication of FloatSpeed and FloatLinearDensity, which results in a FloatFrequency scalar.
292      * @param v FloatSpeed; scalar
293      * @return FloatFrequency; scalar as a multiplication of FloatSpeed and FloatLinearDensity
294      */
295     public final FloatFrequency times(final FloatLinearDensity v)
296     {
297         return new FloatFrequency(this.si * v.si, FrequencyUnit.SI);
298     }
299 
300     /**
301      * Calculate the multiplication of FloatSpeed and FloatDuration, which results in a FloatLength scalar.
302      * @param v FloatSpeed; scalar
303      * @return FloatLength; scalar as a multiplication of FloatSpeed and FloatDuration
304      */
305     public final FloatLength times(final FloatDuration v)
306     {
307         return new FloatLength(this.si * v.si, LengthUnit.SI);
308     }
309 
310     /**
311      * Calculate the division of FloatSpeed and FloatDuration, which results in a FloatAcceleration scalar.
312      * @param v FloatSpeed; scalar
313      * @return FloatAcceleration; scalar as a division of FloatSpeed and FloatDuration
314      */
315     public final FloatAcceleration divide(final FloatDuration v)
316     {
317         return new FloatAcceleration(this.si / v.si, AccelerationUnit.SI);
318     }
319 
320     /**
321      * Calculate the division of FloatSpeed and FloatAcceleration, which results in a FloatDuration scalar.
322      * @param v FloatSpeed; scalar
323      * @return FloatDuration; scalar as a division of FloatSpeed and FloatAcceleration
324      */
325     public final FloatDuration divide(final FloatAcceleration v)
326     {
327         return new FloatDuration(this.si / v.si, DurationUnit.SI);
328     }
329 
330     /**
331      * Calculate the multiplication of FloatSpeed and FloatFlowMass, which results in a FloatForce scalar.
332      * @param v FloatSpeed; scalar
333      * @return FloatForce; scalar as a multiplication of FloatSpeed and FloatFlowMass
334      */
335     public final FloatForce times(final FloatFlowMass v)
336     {
337         return new FloatForce(this.si * v.si, ForceUnit.SI);
338     }
339 
340     /**
341      * Calculate the multiplication of FloatSpeed and FloatMass, which results in a FloatMomentum scalar.
342      * @param v FloatSpeed; scalar
343      * @return FloatMomentum; scalar as a multiplication of FloatSpeed and FloatMass
344      */
345     public final FloatMomentum times(final FloatMass v)
346     {
347         return new FloatMomentum(this.si * v.si, MomentumUnit.SI);
348     }
349 
350     /**
351      * Calculate the multiplication of FloatSpeed and FloatMomentum, which results in a FloatEnergy scalar.
352      * @param v FloatSpeed; scalar
353      * @return FloatEnergy; scalar as a multiplication of FloatSpeed and FloatMomentum
354      */
355     public final FloatEnergy times(final FloatMomentum v)
356     {
357         return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
358     }
359 
360     /** {@inheritDoc} */
361     @Override
362     public FloatSIScalar reciprocal()
363     {
364         return FloatScalar.divide(FloatDimensionless.ONE, this);
365     }
366 
367 }