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