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