View Javadoc
1   package org.djunits.value.vdouble.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.vdouble.scalar.base.AbstractDoubleScalarRel;
20  
21  /**
22   * Easy access methods for the Energy DoubleScalar, 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 Energy extends AbstractDoubleScalarRel<EnergyUnit, Energy>
32  {
33      /** */
34      private static final long serialVersionUID = 20150905L;
35  
36      /** Constant with value zero. */
37      public static final Energyle/scalar/Energy.html#Energy">Energy ZERO = new Energy(0.0, EnergyUnit.SI);
38  
39      /** Constant with value one. */
40      public static final Energyble/scalar/Energy.html#Energy">Energy ONE = new Energy(1.0, EnergyUnit.SI);
41  
42      /** Constant with value NaN. */
43      @SuppressWarnings("checkstyle:constantname")
44      public static final Energyble/scalar/Energy.html#Energy">Energy NaN = new Energy(Double.NaN, EnergyUnit.SI);
45  
46      /** Constant with value POSITIVE_INFINITY. */
47      public static final Energyrgy.html#Energy">Energy POSITIVE_INFINITY = new Energy(Double.POSITIVE_INFINITY, EnergyUnit.SI);
48  
49      /** Constant with value NEGATIVE_INFINITY. */
50      public static final Energyrgy.html#Energy">Energy NEGATIVE_INFINITY = new Energy(Double.NEGATIVE_INFINITY, EnergyUnit.SI);
51  
52      /** Constant with value MAX_VALUE. */
53      public static final Energyr/Energy.html#Energy">Energy POS_MAXVALUE = new Energy(Double.MAX_VALUE, EnergyUnit.SI);
54  
55      /** Constant with value -MAX_VALUE. */
56      public static final Energyr/Energy.html#Energy">Energy NEG_MAXVALUE = new Energy(-Double.MAX_VALUE, EnergyUnit.SI);
57  
58      /**
59       * Construct Energy scalar.
60       * @param value double; the double value
61       * @param unit EnergyUnit; unit for the double value
62       */
63      public Energy(final double value, final EnergyUnit unit)
64      {
65          super(value, unit);
66      }
67  
68      /**
69       * Construct Energy scalar.
70       * @param value Energy; Scalar from which to construct this instance
71       */
72      public Energyvdouble/scalar/Energy.html#Energy">Energy(final Energy value)
73      {
74          super(value);
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public final Energy instantiateRel(final double value, final EnergyUnit unit)
80      {
81          return new Energy(value, unit);
82      }
83  
84      /**
85       * Construct Energy scalar.
86       * @param value double; the double value in SI units
87       * @return Energy; the new scalar with the SI value
88       */
89      public static final Energy instantiateSI(final double value)
90      {
91          return new Energy(value, EnergyUnit.SI);
92      }
93  
94      /**
95       * Interpolate between two values.
96       * @param zero Energy; the low value
97       * @param one Energy; the high value
98       * @param ratio double; the ratio between 0 and 1, inclusive
99       * @return Energy; a Scalar at the ratio between
100      */
101     public static Energye/scalar/Energy.html#Energy">Energyar/Energy.html#Energy">Energy interpolate(final Energye/scalar/Energy.html#Energy">Energy zero, final Energy one, final double ratio)
102     {
103         return new Energy(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio, zero.getDisplayUnit());
104     }
105 
106     /**
107      * Return the maximum value of two relative scalars.
108      * @param r1 Energy; the first scalar
109      * @param r2 Energy; the second scalar
110      * @return Energy; the maximum value of two relative scalars
111      */
112     public static Energyble/scalar/Energy.html#Energy">Energyble/scalar/Energy.html#Energy">Energy max(final Energyble/scalar/Energy.html#Energy">Energy r1, final Energy r2)
113     {
114         return r1.gt(r2) ? r1 : r2;
115     }
116 
117     /**
118      * Return the maximum value of more than two relative scalars.
119      * @param r1 Energy; the first scalar
120      * @param r2 Energy; the second scalar
121      * @param rn Energy...; the other scalars
122      * @return Energy; the maximum value of more than two relative scalars
123      */
124     public static Energyble/scalar/Energy.html#Energy">Energyble/scalar/Energy.html#Energy">Energy max(final Energyble/scalar/Energy.html#Energy">Energy r1, final Energy r2, final Energy... rn)
125     {
126         Energy maxr = r1.gt(r2) ? r1 : r2;
127         for (Energy r : rn)
128         {
129             if (r.gt(maxr))
130             {
131                 maxr = r;
132             }
133         }
134         return maxr;
135     }
136 
137     /**
138      * Return the minimum value of two relative scalars.
139      * @param r1 Energy; the first scalar
140      * @param r2 Energy; the second scalar
141      * @return Energy; the minimum value of two relative scalars
142      */
143     public static Energyble/scalar/Energy.html#Energy">Energyble/scalar/Energy.html#Energy">Energy min(final Energyble/scalar/Energy.html#Energy">Energy r1, final Energy r2)
144     {
145         return r1.lt(r2) ? r1 : r2;
146     }
147 
148     /**
149      * Return the minimum value of more than two relative scalars.
150      * @param r1 Energy; the first scalar
151      * @param r2 Energy; the second scalar
152      * @param rn Energy...; the other scalars
153      * @return Energy; the minimum value of more than two relative scalars
154      */
155     public static Energyble/scalar/Energy.html#Energy">Energyble/scalar/Energy.html#Energy">Energy min(final Energyble/scalar/Energy.html#Energy">Energy r1, final Energy r2, final Energy... rn)
156     {
157         Energy minr = r1.lt(r2) ? r1 : r2;
158         for (Energy r : rn)
159         {
160             if (r.lt(minr))
161             {
162                 minr = r;
163             }
164         }
165         return minr;
166     }
167 
168     /**
169      * Returns a Energy representation of a textual representation of a value with a unit. The String representation that can be
170      * parsed is the double value in the unit, followed by the official abbreviation of the unit. Spaces are allowed, but not
171      * required, between the value and the unit.
172      * @param text String; the textual representation to parse into a Energy
173      * @return Energy; the Scalar representation of the value in its unit
174      * @throws IllegalArgumentException when the text cannot be parsed
175      * @throws NullPointerException when the text argument is null
176      */
177     public static Energy valueOf(final String text)
178     {
179         Throw.whenNull(text, "Error parsing Energy: text to parse is null");
180         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Energy: empty text to parse");
181         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
182         if (matcher.find())
183         {
184             int index = matcher.end();
185             String unitString = text.substring(index).trim();
186             String valueString = text.substring(0, index).trim();
187             EnergyUnit unit = EnergyUnit.BASE.getUnitByAbbreviation(unitString);
188             if (unit != null)
189             {
190                 double d = Double.parseDouble(valueString);
191                 return new Energy(d, unit);
192             }
193         }
194         throw new IllegalArgumentException("Error parsing Energy from " + text);
195     }
196 
197     /**
198      * Returns a Energy based on a value and the textual representation of the unit.
199      * @param value double; the value to use
200      * @param unitString String; the textual representation of the unit
201      * @return Energy; the Scalar representation of the value in its unit
202      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
203      * @throws NullPointerException when the unitString argument is null
204      */
205     public static Energy of(final double value, final String unitString)
206     {
207         Throw.whenNull(unitString, "Error parsing Energy: unitString is null");
208         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Energy: empty unitString");
209         EnergyUnit unit = EnergyUnit.BASE.getUnitByAbbreviation(unitString);
210         if (unit != null)
211         {
212             return new Energy(value, unit);
213         }
214         throw new IllegalArgumentException("Error parsing Energy with unit " + unitString);
215     }
216 
217     /**
218      * Calculate the division of Energy and Energy, which results in a Dimensionless scalar.
219      * @param v Energy scalar
220      * @return Dimensionless scalar as a division of Energy and Energy
221      */
222     public final Dimensionless divide(final Energy v)
223     {
224         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
225     }
226 
227     /**
228      * Calculate the division of Energy and Force, which results in a Length scalar.
229      * @param v Energy scalar
230      * @return Length scalar as a division of Energy and Force
231      */
232     public final Length divide(final Force v)
233     {
234         return new Length(this.si / v.si, LengthUnit.SI);
235     }
236 
237     /**
238      * Calculate the division of Energy and Length, which results in a Force scalar.
239      * @param v Energy scalar
240      * @return Force scalar as a division of Energy and Length
241      */
242     public final Force divide(final Length v)
243     {
244         return new Force(this.si / v.si, ForceUnit.SI);
245     }
246 
247     /**
248      * Calculate the multiplication of Energy and LinearDensity, which results in a Force scalar.
249      * @param v Energy scalar
250      * @return Force scalar as a multiplication of Energy and LinearDensity
251      */
252     public final Force times(final LinearDensity v)
253     {
254         return new Force(this.si * v.si, ForceUnit.SI);
255     }
256 
257     /**
258      * Calculate the division of Energy and Duration, which results in a Power scalar.
259      * @param v Energy scalar
260      * @return Power scalar as a division of Energy and Duration
261      */
262     public final Power divide(final Duration v)
263     {
264         return new Power(this.si / v.si, PowerUnit.SI);
265     }
266 
267     /**
268      * Calculate the division of Energy and Power, which results in a Duration scalar.
269      * @param v Energy scalar
270      * @return Duration scalar as a division of Energy and Power
271      */
272     public final Duration divide(final Power v)
273     {
274         return new Duration(this.si / v.si, DurationUnit.SI);
275     }
276 
277     /**
278      * Calculate the division of Energy and Volume, which results in a Pressure scalar.
279      * @param v Energy scalar
280      * @return Pressure scalar as a division of Energy and Volume
281      */
282     public final Pressure divide(final Volume v)
283     {
284         return new Pressure(this.si / v.si, PressureUnit.SI);
285     }
286 
287     /**
288      * Calculate the division of Energy and Pressure, which results in a Volume scalar.
289      * @param v Energy scalar
290      * @return Volume scalar as a division of Energy and Pressure
291      */
292     public final Volume divide(final Pressure v)
293     {
294         return new Volume(this.si / v.si, VolumeUnit.SI);
295     }
296 
297     /**
298      * Calculate the multiplication of Energy and Frequency, which results in a Power scalar.
299      * @param v Energy scalar
300      * @return Power scalar as a multiplication of Energy and Frequency
301      */
302     public final Power times(final Frequency v)
303     {
304         return new Power(this.si * v.si, PowerUnit.SI);
305     }
306 
307     /**
308      * Calculate the division of Energy and Speed, which results in a Momentum scalar.
309      * @param v Energy scalar
310      * @return Momentum scalar as a division of Energy and Speed
311      */
312     public final Momentum divide(final Speed v)
313     {
314         return new Momentum(this.si / v.si, MomentumUnit.SI);
315     }
316 
317     /**
318      * Calculate the division of Energy and Momentum, which results in a Speed scalar.
319      * @param v Energy scalar
320      * @return Speed scalar as a division of Energy and Momentum
321      */
322     public final Speed divide(final Momentum v)
323     {
324         return new Speed(this.si / v.si, SpeedUnit.SI);
325     }
326 
327 }