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.ElectricalChargeUnit;
7   import org.djunits.unit.ElectricalConductanceUnit;
8   import org.djunits.unit.ElectricalCurrentUnit;
9   import org.djunits.unit.ElectricalPotentialUnit;
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 FloatElectricalCurrent 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 FloatElectricalCurrent extends FloatScalarRel<ElectricalCurrentUnit, FloatElectricalCurrent>
28  {
29      /** */
30      private static final long serialVersionUID = 20150901L;
31  
32      /** Constant with value zero. */
33      public static final FloatElectricalCurrent ZERO = new FloatElectricalCurrent(0.0f, ElectricalCurrentUnit.SI);
34  
35      /** Constant with value one. */
36      public static final FloatElectricalCurrent ONE = new FloatElectricalCurrent(1.0f, ElectricalCurrentUnit.SI);
37  
38      /** Constant with value NaN. */
39      @SuppressWarnings("checkstyle:constantname")
40      public static final FloatElectricalCurrent NaN = new FloatElectricalCurrent(Float.NaN, ElectricalCurrentUnit.SI);
41  
42      /** Constant with value POSITIVE_INFINITY. */
43      public static final FloatElectricalCurrent POSITIVE_INFINITY =
44              new FloatElectricalCurrent(Float.POSITIVE_INFINITY, ElectricalCurrentUnit.SI);
45  
46      /** Constant with value NEGATIVE_INFINITY. */
47      public static final FloatElectricalCurrent NEGATIVE_INFINITY =
48              new FloatElectricalCurrent(Float.NEGATIVE_INFINITY, ElectricalCurrentUnit.SI);
49  
50      /** Constant with value MAX_VALUE. */
51      public static final FloatElectricalCurrent POS_MAXVALUE =
52              new FloatElectricalCurrent(Float.MAX_VALUE, ElectricalCurrentUnit.SI);
53  
54      /** Constant with value -MAX_VALUE. */
55      public static final FloatElectricalCurrent NEG_MAXVALUE =
56              new FloatElectricalCurrent(-Float.MAX_VALUE, ElectricalCurrentUnit.SI);
57  
58      /**
59       * Construct FloatElectricalCurrent 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 FloatElectricalCurrent(final float value, final ElectricalCurrentUnit unit)
64      {
65          super(value, unit);
66      }
67  
68      /**
69       * Construct FloatElectricalCurrent scalar.
70       * @param value Scalar from which to construct this instance
71       */
72      public FloatElectricalCurrent(final FloatElectricalCurrent value)
73      {
74          super(value);
75      }
76  
77      /**
78       * Construct FloatElectricalCurrent 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 FloatElectricalCurrent(final double value, final ElectricalCurrentUnit unit)
83      {
84          super((float) value, unit);
85      }
86  
87      @Override
88      public final FloatElectricalCurrent instantiateRel(final float value, final ElectricalCurrentUnit unit)
89      {
90          return new FloatElectricalCurrent(value, unit);
91      }
92  
93      /**
94       * Construct FloatElectricalCurrent 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 FloatElectricalCurrent ofSI(final float value)
99      {
100         return new FloatElectricalCurrent(value, ElectricalCurrentUnit.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 FloatElectricalCurrent at the given ratio between 0 and 1
109      */
110     public static FloatElectricalCurrent interpolate(final FloatElectricalCurrent zero, final FloatElectricalCurrent 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 FloatElectricalCurrent(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 FloatElectricalCurrent max(final FloatElectricalCurrent r1, final FloatElectricalCurrent 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 FloatElectricalCurrent max(final FloatElectricalCurrent r1, final FloatElectricalCurrent r2,
138             final FloatElectricalCurrent... rn)
139     {
140         FloatElectricalCurrent maxr = r1.gt(r2) ? r1 : r2;
141         for (FloatElectricalCurrent 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 FloatElectricalCurrent min(final FloatElectricalCurrent r1, final FloatElectricalCurrent 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 FloatElectricalCurrent min(final FloatElectricalCurrent r1, final FloatElectricalCurrent r2,
170             final FloatElectricalCurrent... rn)
171     {
172         FloatElectricalCurrent minr = r1.lt(r2) ? r1 : r2;
173         for (FloatElectricalCurrent r : rn)
174         {
175             if (r.lt(minr))
176             {
177                 minr = r;
178             }
179         }
180         return minr;
181     }
182 
183     /**
184      * Returns a FloatElectricalCurrent 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 FloatElectricalCurrent
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 FloatElectricalCurrent valueOf(final String text)
193     {
194         Throw.whenNull(text, "Error parsing FloatElectricalCurrent: text to parse is null");
195         Throw.when(text.length() == 0, IllegalArgumentException.class,
196                 "Error parsing FloatElectricalCurrent: 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             ElectricalCurrentUnit unit = ElectricalCurrentUnit.BASE.getUnitByAbbreviation(unitString);
203             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity ElectricalCurrent",
204                     unitString);
205             return new FloatElectricalCurrent(f, unit);
206         }
207         catch (Exception exception)
208         {
209             throw new IllegalArgumentException("Error parsing FloatElectricalCurrent from " + text + " using Locale "
210                     + Locale.getDefault(Locale.Category.FORMAT), exception);
211         }
212     }
213 
214     /**
215      * Returns a FloatElectricalCurrent 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 FloatElectricalCurrent of(final float value, final String unitString)
223     {
224         Throw.whenNull(unitString, "Error parsing FloatElectricalCurrent: unitString is null");
225         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
226                 "Error parsing FloatElectricalCurrent: empty unitString");
227         ElectricalCurrentUnit unit = ElectricalCurrentUnit.BASE.getUnitByAbbreviation(unitString);
228         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FloatElectricalCurrent with unit %s",
229                 unitString);
230         return new FloatElectricalCurrent(value, unit);
231     }
232 
233     /**
234      * Calculate the division of FloatElectricalCurrent and FloatElectricalCurrent, which results in a FloatDimensionless
235      * scalar.
236      * @param v scalar
237      * @return scalar as a division of FloatElectricalCurrent and FloatElectricalCurrent
238      */
239     public final FloatDimensionless divide(final FloatElectricalCurrent v)
240     {
241         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
242     }
243 
244     /**
245      * Calculate the multiplication of FloatElectricalCurrent and FloatElectricalPotential, which results in a FloatPower
246      * scalar.
247      * @param v scalar
248      * @return scalar as a multiplication of FloatElectricalCurrent and FloatElectricalPotential
249      */
250     public final FloatPower times(final FloatElectricalPotential v)
251     {
252         return new FloatPower(this.si * v.si, PowerUnit.SI);
253     }
254 
255     /**
256      * Calculate the multiplication of FloatElectricalCurrent and FloatDuration, which results in a FloatElectricalCharge
257      * scalar.
258      * @param v scalar
259      * @return scalar as a multiplication of FloatElectricalCurrent and FloatDuration
260      */
261     public final FloatElectricalCharge times(final FloatDuration v)
262     {
263         return new FloatElectricalCharge(this.si * v.si, ElectricalChargeUnit.SI);
264     }
265 
266     /**
267      * Calculate the multiplication of FloatElectricalCurrent and FloatElectricalResistance, which results in a
268      * FloatElectricalPotential scalar.
269      * @param v scalar
270      * @return scalar as a multiplication of FloatElectricalCurrent and FloatElectricalResistance
271      */
272     public final FloatElectricalPotential times(final FloatElectricalResistance v)
273     {
274         return new FloatElectricalPotential(this.si * v.si, ElectricalPotentialUnit.SI);
275     }
276 
277     /**
278      * Calculate the division of FloatElectricalCurrent and FloatElectricalPotential, which results in a
279      * FloatElectricalConductance scalar.
280      * @param v scalar
281      * @return scalar as a division of FloatElectricalCurrent and FloatElectricalPotential
282      */
283     public final FloatElectricalConductance divide(final FloatElectricalPotential v)
284     {
285         return new FloatElectricalConductance(this.si / v.si, ElectricalConductanceUnit.SI);
286     }
287 
288     /**
289      * Calculate the division of FloatElectricalCurrent and FloatElectricalConductance, which results in a
290      * FloatElectricalPotential scalar.
291      * @param v scalar
292      * @return scalar as a division of FloatElectricalCurrent and FloatElectricalConductance
293      */
294     public final FloatElectricalPotential divide(final FloatElectricalConductance v)
295     {
296         return new FloatElectricalPotential(this.si / v.si, ElectricalPotentialUnit.SI);
297     }
298 
299     @Override
300     public FloatSIScalar reciprocal()
301     {
302         return FloatSIScalar.divide(FloatDimensionless.ONE, this);
303     }
304 
305     /**
306      * Multiply two scalars that result in a scalar of type FloatElectricalCurrent.
307      * @param scalar1 the first scalar
308      * @param scalar2 the second scalar
309      * @return the multiplication of both scalars as an instance of FloatElectricalCurrent
310      */
311     public static FloatElectricalCurrent multiply(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
312     {
313         Throw.whenNull(scalar1, "scalar1 cannot be null");
314         Throw.whenNull(scalar2, "scalar2 cannot be null");
315         Throw.when(
316                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
317                         .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
318                         .equals(ElectricalCurrentUnit.BASE.getSiDimensions()),
319                 IllegalArgumentException.class,
320                 "Multiplying %s by %s does not result in instance of type FloatElectricalCurrent", scalar1.toDisplayString(),
321                 scalar2.toDisplayString());
322         return new FloatElectricalCurrent(scalar1.si * scalar2.si, ElectricalCurrentUnit.SI);
323     }
324 
325     /**
326      * Divide two scalars that result in a scalar of type FloatElectricalCurrent.
327      * @param scalar1 the first scalar
328      * @param scalar2 the second scalar
329      * @return the division of scalar1 by scalar2 as an instance of FloatElectricalCurrent
330      */
331     public static FloatElectricalCurrent divide(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
332     {
333         Throw.whenNull(scalar1, "scalar1 cannot be null");
334         Throw.whenNull(scalar2, "scalar2 cannot be null");
335         Throw.when(
336                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
337                         .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
338                         .equals(ElectricalCurrentUnit.BASE.getSiDimensions()),
339                 IllegalArgumentException.class,
340                 "Dividing %s by %s does not result in an instance of type FloatElectricalCurrent", scalar1.toDisplayString(),
341                 scalar2.toDisplayString());
342         return new FloatElectricalCurrent(scalar1.si / scalar2.si, ElectricalCurrentUnit.SI);
343     }
344 
345 }