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