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.DimensionlessUnit;
9   import org.djunits.unit.EnergyUnit;
10  import org.djunits.unit.FlowMassUnit;
11  import org.djunits.unit.LengthUnit;
12  import org.djunits.unit.MassUnit;
13  import org.djunits.unit.MomentumUnit;
14  import org.djunits.unit.PowerUnit;
15  import org.djunits.unit.SpeedUnit;
16  import org.djunits.value.util.ValueUtil;
17  import org.djunits.value.vfloat.scalar.base.AbstractFloatScalarRel;
18  import org.djunits.value.vfloat.scalar.base.FloatScalar;
19  
20  /**
21   * Easy access methods for the FloatMomentum FloatScalar, which is relative by definition.
22   * <p>
23   * Copyright (c) 2013-2022 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
25   * </p>
26   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
27   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
28   */
29  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2022-03-14T11:14:15.180987200Z")
30  public class FloatMomentum extends AbstractFloatScalarRel<MomentumUnit, FloatMomentum>
31  {
32      /** */
33      private static final long serialVersionUID = 20150901L;
34  
35      /** Constant with value zero. */
36      public static final FloatMomentumr/FloatMomentum.html#FloatMomentum">FloatMomentum ZERO = new FloatMomentum(0.0f, MomentumUnit.SI);
37  
38      /** Constant with value one. */
39      public static final FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentum ONE = new FloatMomentum(1.0f, MomentumUnit.SI);
40  
41      /** Constant with value NaN. */
42      @SuppressWarnings("checkstyle:constantname")
43      public static final FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentum NaN = new FloatMomentum(Float.NaN, MomentumUnit.SI);
44  
45      /** Constant with value POSITIVE_INFINITY. */
46      public static final FloatMomentumum.html#FloatMomentum">FloatMomentum POSITIVE_INFINITY = new FloatMomentum(Float.POSITIVE_INFINITY, MomentumUnit.SI);
47  
48      /** Constant with value NEGATIVE_INFINITY. */
49      public static final FloatMomentumum.html#FloatMomentum">FloatMomentum NEGATIVE_INFINITY = new FloatMomentum(Float.NEGATIVE_INFINITY, MomentumUnit.SI);
50  
51      /** Constant with value MAX_VALUE. */
52      public static final FloatMomentumomentum.html#FloatMomentum">FloatMomentum POS_MAXVALUE = new FloatMomentum(Float.MAX_VALUE, MomentumUnit.SI);
53  
54      /** Constant with value -MAX_VALUE. */
55      public static final FloatMomentumomentum.html#FloatMomentum">FloatMomentum NEG_MAXVALUE = new FloatMomentum(-Float.MAX_VALUE, MomentumUnit.SI);
56  
57      /**
58       * Construct FloatMomentum scalar.
59       * @param value float; the float value
60       * @param unit unit for the float value
61       */
62      public FloatMomentum(final float value, final MomentumUnit unit)
63      {
64          super(value, unit);
65      }
66  
67      /**
68       * Construct FloatMomentum scalar.
69       * @param value Scalar from which to construct this instance
70       */
71      public FloatMomentumscalar/FloatMomentum.html#FloatMomentum">FloatMomentum(final FloatMomentum value)
72      {
73          super(value);
74      }
75  
76      /**
77       * Construct FloatMomentum scalar using a double value.
78       * @param value double; the double value
79       * @param unit unit for the resulting float value
80       */
81      public FloatMomentum(final double value, final MomentumUnit unit)
82      {
83          super((float) value, unit);
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public final FloatMomentum instantiateRel(final float value, final MomentumUnit unit)
89      {
90          return new FloatMomentum(value, unit);
91      }
92  
93      /**
94       * Construct FloatMomentum scalar.
95       * @param value float; the float value in SI units
96       * @return the new scalar with the SI value
97       */
98      public static final FloatMomentum instantiateSI(final float value)
99      {
100         return new FloatMomentum(value, MomentumUnit.SI);
101     }
102 
103     /**
104      * Interpolate between two values.
105      * @param zero the low value
106      * @param one the high value
107      * @param ratio double; the ratio between 0 and 1, inclusive
108      * @return a Scalar at the ratio between
109      */
110     public static FloatMomentum/FloatMomentum.html#FloatMomentum">FloatMomentumMomentum.html#FloatMomentum">FloatMomentum interpolate(final FloatMomentum/FloatMomentum.html#FloatMomentum">FloatMomentum zero, final FloatMomentum one, final float ratio)
111     {
112         return new FloatMomentum(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
113                 zero.getDisplayUnit());
114     }
115 
116     /**
117      * Return the maximum value of two relative scalars.
118      * @param r1 the first scalar
119      * @param r2 the second scalar
120      * @return the maximum value of two relative scalars
121      */
122     public static FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentum max(final FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentum r1, final FloatMomentum r2)
123     {
124         return r1.gt(r2) ? r1 : r2;
125     }
126 
127     /**
128      * Return the maximum value of more than two relative scalars.
129      * @param r1 the first scalar
130      * @param r2 the second scalar
131      * @param rn the other scalars
132      * @return the maximum value of more than two relative scalars
133      */
134     public static FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentum max(final FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentum r1, final FloatMomentum r2, final FloatMomentum... rn)
135     {
136         FloatMomentum maxr = r1.gt(r2) ? r1 : r2;
137         for (FloatMomentum r : rn)
138         {
139             if (r.gt(maxr))
140             {
141                 maxr = r;
142             }
143         }
144         return maxr;
145     }
146 
147     /**
148      * Return the minimum value of two relative scalars.
149      * @param r1 the first scalar
150      * @param r2 the second scalar
151      * @return the minimum value of two relative scalars
152      */
153     public static FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentum min(final FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentum r1, final FloatMomentum r2)
154     {
155         return r1.lt(r2) ? r1 : r2;
156     }
157 
158     /**
159      * Return the minimum value of more than two relative scalars.
160      * @param r1 the first scalar
161      * @param r2 the second scalar
162      * @param rn the other scalars
163      * @return the minimum value of more than two relative scalars
164      */
165     public static FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentum min(final FloatMomentumar/FloatMomentum.html#FloatMomentum">FloatMomentum r1, final FloatMomentum r2, final FloatMomentum... rn)
166     {
167         FloatMomentum minr = r1.lt(r2) ? r1 : r2;
168         for (FloatMomentum r : rn)
169         {
170             if (r.lt(minr))
171             {
172                 minr = r;
173             }
174         }
175         return minr;
176     }
177 
178     /**
179      * Returns a FloatMomentum representation of a textual representation of a value with a unit. The String representation that
180      * can be parsed is the double value in the unit, followed by the official abbreviation of the unit. Spaces are allowed, but
181      * not required, between the value and the unit.
182      * @param text String; the textual representation to parse into a FloatMomentum
183      * @return FloatMomentum; the Scalar representation of the value in its unit
184      * @throws IllegalArgumentException when the text cannot be parsed
185      * @throws NullPointerException when the text argument is null
186      */
187     public static FloatMomentum valueOf(final String text)
188     {
189         Throw.whenNull(text, "Error parsing FloatMomentum: text to parse is null");
190         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatMomentum: empty text to parse");
191         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
192         if (matcher.find())
193         {
194             int index = matcher.end();
195             String unitString = text.substring(index).trim();
196             String valueString = text.substring(0, index).trim();
197             MomentumUnit unit = MomentumUnit.BASE.getUnitByAbbreviation(unitString);
198             if (unit != null)
199             {
200                 float f = Float.parseFloat(valueString);
201                 return new FloatMomentum(f, unit);
202             }
203         }
204         throw new IllegalArgumentException("Error parsing FloatMomentum from " + text);
205     }
206 
207     /**
208      * Returns a FloatMomentum based on a value and the textual representation of the unit.
209      * @param value double; the value to use
210      * @param unitString String; the textual representation of the unit
211      * @return FloatMomentum; the Scalar representation of the value in its unit
212      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
213      * @throws NullPointerException when the unitString argument is null
214      */
215     public static FloatMomentum of(final float value, final String unitString)
216     {
217         Throw.whenNull(unitString, "Error parsing FloatMomentum: unitString is null");
218         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatMomentum: empty unitString");
219         MomentumUnit unit = MomentumUnit.BASE.getUnitByAbbreviation(unitString);
220         if (unit != null)
221         {
222             return new FloatMomentum(value, unit);
223         }
224         throw new IllegalArgumentException("Error parsing FloatMomentum with unit " + unitString);
225     }
226 
227     /**
228      * Calculate the division of FloatMomentum and FloatMomentum, which results in a FloatDimensionless scalar.
229      * @param v FloatMomentum; scalar
230      * @return FloatDimensionless; scalar as a division of FloatMomentum and FloatMomentum
231      */
232     public final FloatDimensionless divide(final FloatMomentum v)
233     {
234         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
235     }
236 
237     /**
238      * Calculate the division of FloatMomentum and FloatSpeed, which results in a FloatMass scalar.
239      * @param v FloatMomentum; scalar
240      * @return FloatMass; scalar as a division of FloatMomentum and FloatSpeed
241      */
242     public final FloatMass divide(final FloatSpeed v)
243     {
244         return new FloatMass(this.si / v.si, MassUnit.SI);
245     }
246 
247     /**
248      * Calculate the division of FloatMomentum and FloatMass, which results in a FloatSpeed scalar.
249      * @param v FloatMomentum; scalar
250      * @return FloatSpeed; scalar as a division of FloatMomentum and FloatMass
251      */
252     public final FloatSpeed divide(final FloatMass v)
253     {
254         return new FloatSpeed(this.si / v.si, SpeedUnit.SI);
255     }
256 
257     /**
258      * Calculate the division of FloatMomentum and FloatLength, which results in a FloatFlowMass scalar.
259      * @param v FloatMomentum; scalar
260      * @return FloatFlowMass; scalar as a division of FloatMomentum and FloatLength
261      */
262     public final FloatFlowMass divide(final FloatLength v)
263     {
264         return new FloatFlowMass(this.si / v.si, FlowMassUnit.SI);
265     }
266 
267     /**
268      * Calculate the division of FloatMomentum and FloatFlowMass, which results in a FloatLength scalar.
269      * @param v FloatMomentum; scalar
270      * @return FloatLength; scalar as a division of FloatMomentum and FloatFlowMass
271      */
272     public final FloatLength divide(final FloatFlowMass v)
273     {
274         return new FloatLength(this.si / v.si, LengthUnit.SI);
275     }
276 
277     /**
278      * Calculate the multiplication of FloatMomentum and FloatSpeed, which results in a FloatEnergy scalar.
279      * @param v FloatMomentum; scalar
280      * @return FloatEnergy; scalar as a multiplication of FloatMomentum and FloatSpeed
281      */
282     public final FloatEnergy times(final FloatSpeed v)
283     {
284         return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
285     }
286 
287     /**
288      * Calculate the multiplication of FloatMomentum and FloatAcceleration, which results in a FloatPower scalar.
289      * @param v FloatMomentum; scalar
290      * @return FloatPower; scalar as a multiplication of FloatMomentum and FloatAcceleration
291      */
292     public final FloatPower times(final FloatAcceleration v)
293     {
294         return new FloatPower(this.si * v.si, PowerUnit.SI);
295     }
296 
297     /** {@inheritDoc} */
298     @Override
299     public FloatSIScalar reciprocal()
300     {
301         return FloatScalar.divide(FloatDimensionless.ONE, this);
302     }
303 
304 }