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