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