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