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.PowerUnit;
14  import org.djunits.unit.PressureUnit;
15  import org.djunits.unit.VolumeUnit;
16  import org.djunits.value.util.ValueUtil;
17  import org.djunits.value.vfloat.scalar.base.AbstractFloatScalarRel;
18  
19  /**
20   * Easy access methods for the FloatEnergy FloatScalar, which is relative by definition.
21   * <p>
22   * Copyright (c) 2013-2019 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 = "2019-10-18T12:12:25.568Z")
29  public class FloatEnergy extends AbstractFloatScalarRel<EnergyUnit, FloatEnergy>
30  {
31      /** */
32      private static final long serialVersionUID = 20150901L;
33  
34      /** Constant with value zero. */
35      public static final FloatEnergylar/FloatEnergy.html#FloatEnergy">FloatEnergy ZERO = new FloatEnergy(0.0f, EnergyUnit.SI);
36  
37      /** Constant with value one. */
38      public static final FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergy ONE = new FloatEnergy(1.0f, EnergyUnit.SI);
39  
40      /** Constant with value NaN. */
41      @SuppressWarnings("checkstyle:constantname")
42      public static final FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergy NaN = new FloatEnergy(Float.NaN, EnergyUnit.SI);
43  
44      /** Constant with value POSITIVE_INFINITY. */
45      public static final FloatEnergygy.html#FloatEnergy">FloatEnergy POSITIVE_INFINITY = new FloatEnergy(Float.POSITIVE_INFINITY, EnergyUnit.SI);
46  
47      /** Constant with value NEGATIVE_INFINITY. */
48      public static final FloatEnergygy.html#FloatEnergy">FloatEnergy NEGATIVE_INFINITY = new FloatEnergy(Float.NEGATIVE_INFINITY, EnergyUnit.SI);
49  
50      /** Constant with value MAX_VALUE. */
51      public static final FloatEnergytEnergy.html#FloatEnergy">FloatEnergy POS_MAXVALUE = new FloatEnergy(Float.MAX_VALUE, EnergyUnit.SI);
52  
53      /** Constant with value -MAX_VALUE. */
54      public static final FloatEnergytEnergy.html#FloatEnergy">FloatEnergy NEG_MAXVALUE = new FloatEnergy(-Float.MAX_VALUE, EnergyUnit.SI);
55  
56      /**
57       * Construct FloatEnergy scalar.
58       * @param value float; the float value
59       * @param unit unit for the float value
60       */
61      public FloatEnergy(final float value, final EnergyUnit unit)
62      {
63          super(value, unit);
64      }
65  
66      /**
67       * Construct FloatEnergy scalar.
68       * @param value Scalar from which to construct this instance
69       */
70      public FloatEnergyt/scalar/FloatEnergy.html#FloatEnergy">FloatEnergy(final FloatEnergy value)
71      {
72          super(value);
73      }
74  
75      /**
76       * Construct FloatEnergy scalar using a double value.
77       * @param value double; the double value
78       * @param unit unit for the resulting float value
79       */
80      public FloatEnergy(final double value, final EnergyUnit unit)
81      {
82          super((float) value, unit);
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public final FloatEnergy instantiateRel(final float value, final EnergyUnit unit)
88      {
89          return new FloatEnergy(value, unit);
90      }
91  
92      /**
93       * Construct FloatEnergy 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 FloatEnergy instantiateSI(final float value)
98      {
99          return new FloatEnergy(value, EnergyUnit.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 FloatEnergyar/FloatEnergy.html#FloatEnergy">FloatEnergyatEnergy.html#FloatEnergy">FloatEnergy interpolate(final FloatEnergyar/FloatEnergy.html#FloatEnergy">FloatEnergy zero, final FloatEnergy one, final float ratio)
110     {
111         return new FloatEnergy(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 FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergy max(final FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergy r1, final FloatEnergy 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 FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergy max(final FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergy r1, final FloatEnergy r2, final FloatEnergy... rn)
134     {
135         FloatEnergy maxr = (r1.gt(r2)) ? r1 : r2;
136         for (FloatEnergy 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 FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergy min(final FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergy r1, final FloatEnergy 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 FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergy min(final FloatEnergyalar/FloatEnergy.html#FloatEnergy">FloatEnergy r1, final FloatEnergy r2, final FloatEnergy... rn)
165     {
166         FloatEnergy minr = (r1.lt(r2)) ? r1 : r2;
167         for (FloatEnergy r : rn)
168         {
169             if (r.lt(minr))
170             {
171                 minr = r;
172             }
173         }
174         return minr;
175     }
176 
177     /**
178      * Returns a FloatEnergy 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 FloatEnergy
182      * @return FloatEnergy; 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 FloatEnergy valueOf(final String text)
187     {
188         Throw.whenNull(text, "Error parsing FloatEnergy: text to parse is null");
189         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatEnergy: 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             EnergyUnit unit = EnergyUnit.BASE.getUnitByAbbreviation(unitString);
197             if (unit != null)
198             {
199                 float f = Float.parseFloat(valueString);
200                 return new FloatEnergy(f, unit);
201             }
202         }
203         throw new IllegalArgumentException("Error parsing FloatEnergy from " + text);
204     }
205 
206     /**
207      * Returns a FloatEnergy 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 FloatEnergy; 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 FloatEnergy of(final float value, final String unitString)
215     {
216         Throw.whenNull(unitString, "Error parsing FloatEnergy: unitString is null");
217         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatEnergy: empty unitString");
218         EnergyUnit unit = EnergyUnit.BASE.getUnitByAbbreviation(unitString);
219         if (unit != null)
220         {
221             return new FloatEnergy(value, unit);
222         }
223         throw new IllegalArgumentException("Error parsing FloatEnergy with unit " + unitString);
224     }
225 
226     /**
227      * Calculate the division of FloatEnergy and FloatEnergy, which results in a FloatDimensionless scalar.
228      * @param v FloatEnergy scalar
229      * @return FloatDimensionless scalar as a division of FloatEnergy and FloatEnergy
230      */
231     public final FloatDimensionless divide(final FloatEnergy v)
232     {
233         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
234     }
235 
236     /**
237      * Calculate the division of FloatEnergy and FloatForce, which results in a FloatLength scalar.
238      * @param v FloatEnergy scalar
239      * @return FloatLength scalar as a division of FloatEnergy and FloatForce
240      */
241     public final FloatLength divide(final FloatForce v)
242     {
243         return new FloatLength(this.si / v.si, LengthUnit.SI);
244     }
245 
246     /**
247      * Calculate the division of FloatEnergy and FloatLength, which results in a FloatForce scalar.
248      * @param v FloatEnergy scalar
249      * @return FloatForce scalar as a division of FloatEnergy and FloatLength
250      */
251     public final FloatForce divide(final FloatLength v)
252     {
253         return new FloatForce(this.si / v.si, ForceUnit.SI);
254     }
255 
256     /**
257      * Calculate the multiplication of FloatEnergy and FloatLinearDensity, which results in a FloatForce scalar.
258      * @param v FloatEnergy scalar
259      * @return FloatForce scalar as a multiplication of FloatEnergy and FloatLinearDensity
260      */
261     public final FloatForce times(final FloatLinearDensity v)
262     {
263         return new FloatForce(this.si * v.si, ForceUnit.SI);
264     }
265 
266     /**
267      * Calculate the division of FloatEnergy and FloatDuration, which results in a FloatPower scalar.
268      * @param v FloatEnergy scalar
269      * @return FloatPower scalar as a division of FloatEnergy and FloatDuration
270      */
271     public final FloatPower divide(final FloatDuration v)
272     {
273         return new FloatPower(this.si / v.si, PowerUnit.SI);
274     }
275 
276     /**
277      * Calculate the division of FloatEnergy and FloatPower, which results in a FloatDuration scalar.
278      * @param v FloatEnergy scalar
279      * @return FloatDuration scalar as a division of FloatEnergy and FloatPower
280      */
281     public final FloatDuration divide(final FloatPower v)
282     {
283         return new FloatDuration(this.si / v.si, DurationUnit.SI);
284     }
285 
286     /**
287      * Calculate the division of FloatEnergy and FloatVolume, which results in a FloatPressure scalar.
288      * @param v FloatEnergy scalar
289      * @return FloatPressure scalar as a division of FloatEnergy and FloatVolume
290      */
291     public final FloatPressure divide(final FloatVolume v)
292     {
293         return new FloatPressure(this.si / v.si, PressureUnit.SI);
294     }
295 
296     /**
297      * Calculate the division of FloatEnergy and FloatPressure, which results in a FloatVolume scalar.
298      * @param v FloatEnergy scalar
299      * @return FloatVolume scalar as a division of FloatEnergy and FloatPressure
300      */
301     public final FloatVolume divide(final FloatPressure v)
302     {
303         return new FloatVolume(this.si / v.si, VolumeUnit.SI);
304     }
305 
306     /**
307      * Calculate the multiplication of FloatEnergy and FloatFrequency, which results in a FloatPower scalar.
308      * @param v FloatEnergy scalar
309      * @return FloatPower scalar as a multiplication of FloatEnergy and FloatFrequency
310      */
311     public final FloatPower times(final FloatFrequency v)
312     {
313         return new FloatPower(this.si * v.si, PowerUnit.SI);
314     }
315 
316 }