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  
22  /**
23   * Easy access methods for the FloatSpeed FloatScalar, which is relative by definition.
24   * <p>
25   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
26   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
27   * </p>
28   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
30   */
31  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2020-01-19T15:21:24.964166400Z")
32  public class FloatSpeed extends AbstractFloatScalarRel<SpeedUnit, FloatSpeed>
33  {
34      /** */
35      private static final long serialVersionUID = 20150901L;
36  
37      /** Constant with value zero. */
38      public static final FloatSpeedalar/FloatSpeed.html#FloatSpeed">FloatSpeed ZERO = new FloatSpeed(0.0f, SpeedUnit.SI);
39  
40      /** Constant with value one. */
41      public static final FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed ONE = new FloatSpeed(1.0f, SpeedUnit.SI);
42  
43      /** Constant with value NaN. */
44      @SuppressWarnings("checkstyle:constantname")
45      public static final FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed NaN = new FloatSpeed(Float.NaN, SpeedUnit.SI);
46  
47      /** Constant with value POSITIVE_INFINITY. */
48      public static final FloatSpeeded.html#FloatSpeed">FloatSpeed POSITIVE_INFINITY = new FloatSpeed(Float.POSITIVE_INFINITY, SpeedUnit.SI);
49  
50      /** Constant with value NEGATIVE_INFINITY. */
51      public static final FloatSpeeded.html#FloatSpeed">FloatSpeed NEGATIVE_INFINITY = new FloatSpeed(Float.NEGATIVE_INFINITY, SpeedUnit.SI);
52  
53      /** Constant with value MAX_VALUE. */
54      public static final FloatSpeedatSpeed.html#FloatSpeed">FloatSpeed POS_MAXVALUE = new FloatSpeed(Float.MAX_VALUE, SpeedUnit.SI);
55  
56      /** Constant with value -MAX_VALUE. */
57      public static final FloatSpeedatSpeed.html#FloatSpeed">FloatSpeed NEG_MAXVALUE = new FloatSpeed(-Float.MAX_VALUE, SpeedUnit.SI);
58  
59      /**
60       * Construct FloatSpeed scalar.
61       * @param value float; the float value
62       * @param unit unit for the float value
63       */
64      public FloatSpeed(final float value, final SpeedUnit unit)
65      {
66          super(value, unit);
67      }
68  
69      /**
70       * Construct FloatSpeed scalar.
71       * @param value Scalar from which to construct this instance
72       */
73      public FloatSpeedat/scalar/FloatSpeed.html#FloatSpeed">FloatSpeed(final FloatSpeed value)
74      {
75          super(value);
76      }
77  
78      /**
79       * Construct FloatSpeed scalar using a double value.
80       * @param value double; the double value
81       * @param unit unit for the resulting float value
82       */
83      public FloatSpeed(final double value, final SpeedUnit unit)
84      {
85          super((float) value, unit);
86      }
87  
88      /** {@inheritDoc} */
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 FloatSpeedlar/FloatSpeed.html#FloatSpeed">FloatSpeedoatSpeed.html#FloatSpeed">FloatSpeed interpolate(final FloatSpeedlar/FloatSpeed.html#FloatSpeed">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 FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed max(final FloatSpeedcalar/FloatSpeed.html#FloatSpeed">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 FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed max(final FloatSpeedcalar/FloatSpeed.html#FloatSpeed">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 FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed min(final FloatSpeedcalar/FloatSpeed.html#FloatSpeed">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 FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeedcalar/FloatSpeed.html#FloatSpeed">FloatSpeed min(final FloatSpeedcalar/FloatSpeed.html#FloatSpeed">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 the official abbreviation of the unit. Spaces are allowed, but
183      * 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         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
194         if (matcher.find())
195         {
196             int index = matcher.end();
197             String unitString = text.substring(index).trim();
198             String valueString = text.substring(0, index).trim();
199             SpeedUnit unit = SpeedUnit.BASE.getUnitByAbbreviation(unitString);
200             if (unit != null)
201             {
202                 float f = Float.parseFloat(valueString);
203                 return new FloatSpeed(f, unit);
204             }
205         }
206         throw new IllegalArgumentException("Error parsing FloatSpeed from " + text);
207     }
208 
209     /**
210      * Returns a FloatSpeed based on a value and the textual representation of the unit.
211      * @param value double; the value to use
212      * @param unitString String; the textual representation of the unit
213      * @return FloatSpeed; the Scalar representation of the value in its unit
214      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
215      * @throws NullPointerException when the unitString argument is null
216      */
217     public static FloatSpeed of(final float value, final String unitString)
218     {
219         Throw.whenNull(unitString, "Error parsing FloatSpeed: unitString is null");
220         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatSpeed: empty unitString");
221         SpeedUnit unit = SpeedUnit.BASE.getUnitByAbbreviation(unitString);
222         if (unit != null)
223         {
224             return new FloatSpeed(value, unit);
225         }
226         throw new IllegalArgumentException("Error parsing FloatSpeed with unit " + unitString);
227     }
228 
229     /**
230      * Calculate the division of FloatSpeed and FloatSpeed, which results in a FloatDimensionless scalar.
231      * @param v FloatSpeed scalar
232      * @return FloatDimensionless scalar as a division of FloatSpeed and FloatSpeed
233      */
234     public final FloatDimensionless divide(final FloatSpeed v)
235     {
236         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
237     }
238 
239     /**
240      * Calculate the multiplication of FloatSpeed and FloatArea, which results in a FloatFlowVolume scalar.
241      * @param v FloatSpeed scalar
242      * @return FloatFlowVolume scalar as a multiplication of FloatSpeed and FloatArea
243      */
244     public final FloatFlowVolume times(final FloatArea v)
245     {
246         return new FloatFlowVolume(this.si * v.si, FlowVolumeUnit.SI);
247     }
248 
249     /**
250      * Calculate the multiplication of FloatSpeed and FloatForce, which results in a FloatPower scalar.
251      * @param v FloatSpeed scalar
252      * @return FloatPower scalar as a multiplication of FloatSpeed and FloatForce
253      */
254     public final FloatPower times(final FloatForce v)
255     {
256         return new FloatPower(this.si * v.si, PowerUnit.SI);
257     }
258 
259     /**
260      * Calculate the multiplication of FloatSpeed and FloatFrequency, which results in a FloatAcceleration scalar.
261      * @param v FloatSpeed scalar
262      * @return FloatAcceleration scalar as a multiplication of FloatSpeed and FloatFrequency
263      */
264     public final FloatAcceleration times(final FloatFrequency v)
265     {
266         return new FloatAcceleration(this.si * v.si, AccelerationUnit.SI);
267     }
268 
269     /**
270      * Calculate the division of FloatSpeed and FloatLength, which results in a FloatFrequency scalar.
271      * @param v FloatSpeed scalar
272      * @return FloatFrequency scalar as a division of FloatSpeed and FloatLength
273      */
274     public final FloatFrequency divide(final FloatLength v)
275     {
276         return new FloatFrequency(this.si / v.si, FrequencyUnit.SI);
277     }
278 
279     /**
280      * Calculate the division of FloatSpeed and FloatFrequency, which results in a FloatLength scalar.
281      * @param v FloatSpeed scalar
282      * @return FloatLength scalar as a division of FloatSpeed and FloatFrequency
283      */
284     public final FloatLength divide(final FloatFrequency v)
285     {
286         return new FloatLength(this.si / v.si, LengthUnit.SI);
287     }
288 
289     /**
290      * Calculate the multiplication of FloatSpeed and FloatLinearDensity, which results in a FloatFrequency scalar.
291      * @param v FloatSpeed scalar
292      * @return FloatFrequency scalar as a multiplication of FloatSpeed and FloatLinearDensity
293      */
294     public final FloatFrequency times(final FloatLinearDensity v)
295     {
296         return new FloatFrequency(this.si * v.si, FrequencyUnit.SI);
297     }
298 
299     /**
300      * Calculate the multiplication of FloatSpeed and FloatDuration, which results in a FloatLength scalar.
301      * @param v FloatSpeed scalar
302      * @return FloatLength scalar as a multiplication of FloatSpeed and FloatDuration
303      */
304     public final FloatLength times(final FloatDuration v)
305     {
306         return new FloatLength(this.si * v.si, LengthUnit.SI);
307     }
308 
309     /**
310      * Calculate the division of FloatSpeed and FloatDuration, which results in a FloatAcceleration scalar.
311      * @param v FloatSpeed scalar
312      * @return FloatAcceleration scalar as a division of FloatSpeed and FloatDuration
313      */
314     public final FloatAcceleration divide(final FloatDuration v)
315     {
316         return new FloatAcceleration(this.si / v.si, AccelerationUnit.SI);
317     }
318 
319     /**
320      * Calculate the division of FloatSpeed and FloatAcceleration, which results in a FloatDuration scalar.
321      * @param v FloatSpeed scalar
322      * @return FloatDuration scalar as a division of FloatSpeed and FloatAcceleration
323      */
324     public final FloatDuration divide(final FloatAcceleration v)
325     {
326         return new FloatDuration(this.si / v.si, DurationUnit.SI);
327     }
328 
329     /**
330      * Calculate the multiplication of FloatSpeed and FloatFlowMass, which results in a FloatForce scalar.
331      * @param v FloatSpeed scalar
332      * @return FloatForce scalar as a multiplication of FloatSpeed and FloatFlowMass
333      */
334     public final FloatForce times(final FloatFlowMass v)
335     {
336         return new FloatForce(this.si * v.si, ForceUnit.SI);
337     }
338 
339     /**
340      * Calculate the multiplication of FloatSpeed and FloatMass, which results in a FloatMomentum scalar.
341      * @param v FloatSpeed scalar
342      * @return FloatMomentum scalar as a multiplication of FloatSpeed and FloatMass
343      */
344     public final FloatMomentum times(final FloatMass v)
345     {
346         return new FloatMomentum(this.si * v.si, MomentumUnit.SI);
347     }
348 
349     /**
350      * Calculate the multiplication of FloatSpeed and FloatMomentum, which results in a FloatEnergy scalar.
351      * @param v FloatSpeed scalar
352      * @return FloatEnergy scalar as a multiplication of FloatSpeed and FloatMomentum
353      */
354     public final FloatEnergy times(final FloatMomentum v)
355     {
356         return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
357     }
358 
359 }