View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.DimensionlessUnit;
6   import org.djunits.unit.ElectricalCurrentUnit;
7   import org.djunits.unit.ElectricalPotentialUnit;
8   import org.djunits.unit.ElectricalResistanceUnit;
9   import org.djunits.unit.MagneticFluxUnit;
10  import org.djunits.unit.PowerUnit;
11  import org.djunits.value.vfloat.scalar.base.FloatScalar;
12  import org.djunits.value.vfloat.scalar.base.FloatScalarRel;
13  import org.djutils.base.NumberParser;
14  import org.djutils.exceptions.Throw;
15  
16  import jakarta.annotation.Generated;
17  
18  /**
19   * Easy access methods for the FloatElectricalPotential FloatScalar, which is relative by definition.
20   * <p>
21   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
22   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
23   * </p>
24   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
25   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
26   */
27  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
28  public class FloatElectricalPotential extends FloatScalarRel<ElectricalPotentialUnit, FloatElectricalPotential>
29  {
30      /** */
31      private static final long serialVersionUID = 20150901L;
32  
33      /** Constant with value zero. */
34      public static final FloatElectricalPotential ZERO = new FloatElectricalPotential(0.0f, ElectricalPotentialUnit.SI);
35  
36      /** Constant with value one. */
37      public static final FloatElectricalPotential ONE = new FloatElectricalPotential(1.0f, ElectricalPotentialUnit.SI);
38  
39      /** Constant with value NaN. */
40      @SuppressWarnings("checkstyle:constantname")
41      public static final FloatElectricalPotential NaN = new FloatElectricalPotential(Float.NaN, ElectricalPotentialUnit.SI);
42  
43      /** Constant with value POSITIVE_INFINITY. */
44      public static final FloatElectricalPotential POSITIVE_INFINITY =
45              new FloatElectricalPotential(Float.POSITIVE_INFINITY, ElectricalPotentialUnit.SI);
46  
47      /** Constant with value NEGATIVE_INFINITY. */
48      public static final FloatElectricalPotential NEGATIVE_INFINITY =
49              new FloatElectricalPotential(Float.NEGATIVE_INFINITY, ElectricalPotentialUnit.SI);
50  
51      /** Constant with value MAX_VALUE. */
52      public static final FloatElectricalPotential POS_MAXVALUE =
53              new FloatElectricalPotential(Float.MAX_VALUE, ElectricalPotentialUnit.SI);
54  
55      /** Constant with value -MAX_VALUE. */
56      public static final FloatElectricalPotential NEG_MAXVALUE =
57              new FloatElectricalPotential(-Float.MAX_VALUE, ElectricalPotentialUnit.SI);
58  
59      /**
60       * Construct FloatElectricalPotential scalar.
61       * @param value float; the float value
62       * @param unit unit for the float value
63       */
64      public FloatElectricalPotential(final float value, final ElectricalPotentialUnit unit)
65      {
66          super(value, unit);
67      }
68  
69      /**
70       * Construct FloatElectricalPotential scalar.
71       * @param value Scalar from which to construct this instance
72       */
73      public FloatElectricalPotential(final FloatElectricalPotential value)
74      {
75          super(value);
76      }
77  
78      /**
79       * Construct FloatElectricalPotential scalar using a double value.
80       * @param value double; the double value
81       * @param unit unit for the resulting float value
82       */
83      public FloatElectricalPotential(final double value, final ElectricalPotentialUnit unit)
84      {
85          super((float) value, unit);
86      }
87  
88      @Override
89      public final FloatElectricalPotential instantiateRel(final float value, final ElectricalPotentialUnit unit)
90      {
91          return new FloatElectricalPotential(value, unit);
92      }
93  
94      /**
95       * Construct FloatElectricalPotential 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 FloatElectricalPotential instantiateSI(final float value)
100     {
101         return new FloatElectricalPotential(value, ElectricalPotentialUnit.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 FloatElectricalPotential interpolate(final FloatElectricalPotential zero, final FloatElectricalPotential one,
112             final float ratio)
113     {
114         return new FloatElectricalPotential(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 FloatElectricalPotential max(final FloatElectricalPotential r1, final FloatElectricalPotential 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 FloatElectricalPotential max(final FloatElectricalPotential r1, final FloatElectricalPotential r2,
137             final FloatElectricalPotential... rn)
138     {
139         FloatElectricalPotential maxr = r1.gt(r2) ? r1 : r2;
140         for (FloatElectricalPotential r : rn)
141         {
142             if (r.gt(maxr))
143             {
144                 maxr = r;
145             }
146         }
147         return maxr;
148     }
149 
150     /**
151      * Return the minimum value of two relative scalars.
152      * @param r1 the first scalar
153      * @param r2 the second scalar
154      * @return the minimum value of two relative scalars
155      */
156     public static FloatElectricalPotential min(final FloatElectricalPotential r1, final FloatElectricalPotential r2)
157     {
158         return r1.lt(r2) ? r1 : r2;
159     }
160 
161     /**
162      * Return the minimum value of more than two relative scalars.
163      * @param r1 the first scalar
164      * @param r2 the second scalar
165      * @param rn the other scalars
166      * @return the minimum value of more than two relative scalars
167      */
168     public static FloatElectricalPotential min(final FloatElectricalPotential r1, final FloatElectricalPotential r2,
169             final FloatElectricalPotential... rn)
170     {
171         FloatElectricalPotential minr = r1.lt(r2) ? r1 : r2;
172         for (FloatElectricalPotential r : rn)
173         {
174             if (r.lt(minr))
175             {
176                 minr = r;
177             }
178         }
179         return minr;
180     }
181 
182     /**
183      * Returns a FloatElectricalPotential representation of a textual representation of a value with a unit. The String
184      * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
185      * unit. Spaces are allowed, but not required, between the value and the unit.
186      * @param text String; the textual representation to parse into a FloatElectricalPotential
187      * @return FloatElectricalPotential; the Scalar representation of the value in its unit
188      * @throws IllegalArgumentException when the text cannot be parsed
189      * @throws NullPointerException when the text argument is null
190      */
191     public static FloatElectricalPotential valueOf(final String text)
192     {
193         Throw.whenNull(text, "Error parsing FloatElectricalPotential: text to parse is null");
194         Throw.when(text.length() == 0, IllegalArgumentException.class,
195                 "Error parsing FloatElectricalPotential: empty text to parse");
196         try
197         {
198             NumberParser numberParser = new NumberParser().lenient().trailing();
199             float f = numberParser.parseFloat(text);
200             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
201             ElectricalPotentialUnit unit = ElectricalPotentialUnit.BASE.getUnitByAbbreviation(unitString);
202             if (unit == null)
203                 throw new IllegalArgumentException("Unit " + unitString + " not found");
204             return new FloatElectricalPotential(f, unit);
205         }
206         catch (Exception exception)
207         {
208             throw new IllegalArgumentException("Error parsing FloatElectricalPotential from " + text + " using Locale "
209                     + Locale.getDefault(Locale.Category.FORMAT), exception);
210         }
211     }
212 
213     /**
214      * Returns a FloatElectricalPotential based on a value and the textual representation of the unit, which can be localized.
215      * @param value double; the value to use
216      * @param unitString String; the textual representation of the unit
217      * @return FloatElectricalPotential; the Scalar representation of the value in its unit
218      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
219      * @throws NullPointerException when the unitString argument is null
220      */
221     public static FloatElectricalPotential of(final float value, final String unitString)
222     {
223         Throw.whenNull(unitString, "Error parsing FloatElectricalPotential: unitString is null");
224         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
225                 "Error parsing FloatElectricalPotential: empty unitString");
226         ElectricalPotentialUnit unit = ElectricalPotentialUnit.BASE.getUnitByAbbreviation(unitString);
227         if (unit != null)
228         {
229             return new FloatElectricalPotential(value, unit);
230         }
231         throw new IllegalArgumentException("Error parsing FloatElectricalPotential with unit " + unitString);
232     }
233 
234     /**
235      * Calculate the division of FloatElectricalPotential and FloatElectricalPotential, which results in a FloatDimensionless
236      * scalar.
237      * @param v FloatElectricalPotential; scalar
238      * @return FloatDimensionless; scalar as a division of FloatElectricalPotential and FloatElectricalPotential
239      */
240     public final FloatDimensionless divide(final FloatElectricalPotential v)
241     {
242         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
243     }
244 
245     /**
246      * Calculate the multiplication of FloatElectricalPotential and FloatElectricalCurrent, which results in a FloatPower
247      * scalar.
248      * @param v FloatElectricalPotential; scalar
249      * @return FloatPower; scalar as a multiplication of FloatElectricalPotential and FloatElectricalCurrent
250      */
251     public final FloatPower times(final FloatElectricalCurrent v)
252     {
253         return new FloatPower(this.si * v.si, PowerUnit.SI);
254     }
255 
256     /**
257      * Calculate the division of FloatElectricalPotential and FloatElectricalCurrent, which results in a
258      * FloatElectricalResistance scalar.
259      * @param v FloatElectricalPotential; scalar
260      * @return FloatElectricalResistance; scalar as a division of FloatElectricalPotential and FloatElectricalCurrent
261      */
262     public final FloatElectricalResistance divide(final FloatElectricalCurrent v)
263     {
264         return new FloatElectricalResistance(this.si / v.si, ElectricalResistanceUnit.SI);
265     }
266 
267     /**
268      * Calculate the division of FloatElectricalPotential and FloatElectricalResistance, which results in a
269      * FloatElectricalCurrent scalar.
270      * @param v FloatElectricalPotential; scalar
271      * @return FloatElectricalCurrent; scalar as a division of FloatElectricalPotential and FloatElectricalResistance
272      */
273     public final FloatElectricalCurrent divide(final FloatElectricalResistance v)
274     {
275         return new FloatElectricalCurrent(this.si / v.si, ElectricalCurrentUnit.SI);
276     }
277 
278     /**
279      * Calculate the multiplication of FloatElectricalPotential and FloatDuration, which results in a FloatMagneticFlux scalar.
280      * @param v FloatElectricalPotential; scalar
281      * @return FloatMagneticFlux; scalar as a multiplication of FloatElectricalPotential and FloatDuration
282      */
283     public final FloatMagneticFlux times(final FloatDuration v)
284     {
285         return new FloatMagneticFlux(this.si * v.si, MagneticFluxUnit.SI);
286     }
287 
288     @Override
289     public FloatSIScalar reciprocal()
290     {
291         return FloatScalar.divide(FloatDimensionless.ONE, this);
292     }
293 
294 }