View Javadoc
1   package org.djunits.value.vdouble.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.vdouble.scalar.base.DoubleScalarRel;
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 ElectricalInductance DoubleScalar, 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 ElectricalInductance extends DoubleScalarRel<ElectricalInductanceUnit, ElectricalInductance>
25  {
26      /** */
27      private static final long serialVersionUID = 20150905L;
28  
29      /** Constant with value zero. */
30      public static final ElectricalInductance ZERO = new ElectricalInductance(0.0, ElectricalInductanceUnit.SI);
31  
32      /** Constant with value one. */
33      public static final ElectricalInductance ONE = new ElectricalInductance(1.0, ElectricalInductanceUnit.SI);
34  
35      /** Constant with value NaN. */
36      @SuppressWarnings("checkstyle:constantname")
37      public static final ElectricalInductance NaN = new ElectricalInductance(Double.NaN, ElectricalInductanceUnit.SI);
38  
39      /** Constant with value POSITIVE_INFINITY. */
40      public static final ElectricalInductance POSITIVE_INFINITY =
41              new ElectricalInductance(Double.POSITIVE_INFINITY, ElectricalInductanceUnit.SI);
42  
43      /** Constant with value NEGATIVE_INFINITY. */
44      public static final ElectricalInductance NEGATIVE_INFINITY =
45              new ElectricalInductance(Double.NEGATIVE_INFINITY, ElectricalInductanceUnit.SI);
46  
47      /** Constant with value MAX_VALUE. */
48      public static final ElectricalInductance POS_MAXVALUE =
49              new ElectricalInductance(Double.MAX_VALUE, ElectricalInductanceUnit.SI);
50  
51      /** Constant with value -MAX_VALUE. */
52      public static final ElectricalInductance NEG_MAXVALUE =
53              new ElectricalInductance(-Double.MAX_VALUE, ElectricalInductanceUnit.SI);
54  
55      /**
56       * Construct ElectricalInductance scalar with a unit.
57       * @param value the double value, expressed in the given unit
58       * @param unit unit for the double value
59       */
60      public ElectricalInductance(final double value, final ElectricalInductanceUnit unit)
61      {
62          super(value, unit);
63      }
64  
65      /**
66       * Construct ElectricalInductance scalar.
67       * @param value Scalar from which to construct this instance
68       */
69      public ElectricalInductance(final ElectricalInductance value)
70      {
71          super(value);
72      }
73  
74      @Override
75      public final ElectricalInductance instantiateRel(final double value, final ElectricalInductanceUnit unit)
76      {
77          return new ElectricalInductance(value, unit);
78      }
79  
80      /**
81       * Construct ElectricalInductance scalar based on an SI value.
82       * @param value the double value in SI units
83       * @return the new scalar with the SI value
84       */
85      public static final ElectricalInductance ofSI(final double value)
86      {
87          return new ElectricalInductance(value, ElectricalInductanceUnit.SI);
88      }
89  
90      /**
91       * Interpolate between two values. Note that the first value does not have to be smaller than the second.
92       * @param zero the value at a ratio of zero
93       * @param one the value at a ratio of one
94       * @param ratio the ratio between 0 and 1, inclusive
95       * @return a ElectricalInductance at the given ratio between 0 and 1
96       */
97      public static ElectricalInductance interpolate(final ElectricalInductance zero, final ElectricalInductance one,
98              final double ratio)
99      {
100         Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
101                 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
102         return new ElectricalInductance(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
103                 zero.getDisplayUnit());
104     }
105 
106     /**
107      * Return the maximum value of two relative scalars.
108      * @param r1 the first scalar
109      * @param r2 the second scalar
110      * @return the maximum value of two relative scalars
111      */
112     public static ElectricalInductance max(final ElectricalInductance r1, final ElectricalInductance r2)
113     {
114         return r1.gt(r2) ? r1 : r2;
115     }
116 
117     /**
118      * Return the maximum value of more than two relative scalars.
119      * @param r1 the first scalar
120      * @param r2 the second scalar
121      * @param rn the other scalars
122      * @return the maximum value of more than two relative scalars
123      */
124     public static ElectricalInductance max(final ElectricalInductance r1, final ElectricalInductance r2,
125             final ElectricalInductance... rn)
126     {
127         ElectricalInductance maxr = r1.gt(r2) ? r1 : r2;
128         for (ElectricalInductance r : rn)
129         {
130             if (r.gt(maxr))
131             {
132                 maxr = r;
133             }
134         }
135         return maxr;
136     }
137 
138     /**
139      * Return the minimum value of two relative scalars.
140      * @param r1 the first scalar
141      * @param r2 the second scalar
142      * @return the minimum value of two relative scalars
143      */
144     public static ElectricalInductance min(final ElectricalInductance r1, final ElectricalInductance r2)
145     {
146         return r1.lt(r2) ? r1 : r2;
147     }
148 
149     /**
150      * Return the minimum value of more than two relative scalars.
151      * @param r1 the first scalar
152      * @param r2 the second scalar
153      * @param rn the other scalars
154      * @return the minimum value of more than two relative scalars
155      */
156     public static ElectricalInductance min(final ElectricalInductance r1, final ElectricalInductance r2,
157             final ElectricalInductance... rn)
158     {
159         ElectricalInductance minr = r1.lt(r2) ? r1 : r2;
160         for (ElectricalInductance r : rn)
161         {
162             if (r.lt(minr))
163             {
164                 minr = r;
165             }
166         }
167         return minr;
168     }
169 
170     /**
171      * Returns a ElectricalInductance representation of a textual representation of a value with a unit. The String
172      * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
173      * unit. Spaces are allowed, but not required, between the value and the unit.
174      * @param text the textual representation to parse into a ElectricalInductance
175      * @return the Scalar representation of the value in its unit
176      * @throws IllegalArgumentException when the text cannot be parsed
177      * @throws NullPointerException when the text argument is null
178      */
179     public static ElectricalInductance valueOf(final String text)
180     {
181         Throw.whenNull(text, "Error parsing ElectricalInductance: text to parse is null");
182         Throw.when(text.length() == 0, IllegalArgumentException.class,
183                 "Error parsing ElectricalInductance: empty text to parse");
184         try
185         {
186             NumberParser numberParser = new NumberParser().lenient().trailing();
187             double d = numberParser.parseDouble(text);
188             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
189             ElectricalInductanceUnit unit = ElectricalInductanceUnit.BASE.getUnitByAbbreviation(unitString);
190             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity ElectricalInductance",
191                     unitString);
192             return new ElectricalInductance(d, unit);
193         }
194         catch (Exception exception)
195         {
196             throw new IllegalArgumentException("Error parsing ElectricalInductance from " + text + " using Locale "
197                     + Locale.getDefault(Locale.Category.FORMAT), exception);
198         }
199     }
200 
201     /**
202      * Returns a ElectricalInductance based on a value and the textual representation of the unit, which can be localized.
203      * @param value the value to use
204      * @param unitString the textual representation of the unit
205      * @return the Scalar representation of the value in its unit
206      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
207      * @throws NullPointerException when the unitString argument is null
208      */
209     public static ElectricalInductance of(final double value, final String unitString)
210     {
211         Throw.whenNull(unitString, "Error parsing ElectricalInductance: unitString is null");
212         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
213                 "Error parsing ElectricalInductance: empty unitString");
214         ElectricalInductanceUnit unit = ElectricalInductanceUnit.BASE.getUnitByAbbreviation(unitString);
215         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing ElectricalInductance with unit %s", unitString);
216         return new ElectricalInductance(value, unit);
217     }
218 
219     /**
220      * Calculate the division of ElectricalInductance and ElectricalInductance, which results in a Dimensionless scalar.
221      * @param v scalar
222      * @return scalar as a division of ElectricalInductance and ElectricalInductance
223      */
224     public final Dimensionless divide(final ElectricalInductance v)
225     {
226         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
227     }
228 
229     /**
230      * Calculate the multiplication of ElectricalInductance and ElectricalCurrent, which results in a MagneticFlux scalar.
231      * @param v scalar
232      * @return scalar as a multiplication of ElectricalInductance and ElectricalCurrent
233      */
234     public final MagneticFlux times(final ElectricalCurrent v)
235     {
236         return new MagneticFlux(this.si * v.si, MagneticFluxUnit.SI);
237     }
238 
239     @Override
240     public SIScalar reciprocal()
241     {
242         return SIScalar.divide(Dimensionless.ONE, this);
243     }
244 
245     /**
246      * Multiply two scalars that result in a scalar of type ElectricalInductance.
247      * @param scalar1 the first scalar
248      * @param scalar2 the second scalar
249      * @return the multiplication of both scalars as an instance of ElectricalInductance
250      */
251     public static ElectricalInductance multiply(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
252     {
253         Throw.whenNull(scalar1, "scalar1 cannot be null");
254         Throw.whenNull(scalar2, "scalar2 cannot be null");
255         Throw.when(
256                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
257                         .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
258                         .equals(ElectricalInductanceUnit.BASE.getSiDimensions()),
259                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type ElectricalInductance",
260                 scalar1.toDisplayString(), scalar2.toDisplayString());
261         return new ElectricalInductance(scalar1.si * scalar2.si, ElectricalInductanceUnit.SI);
262     }
263 
264     /**
265      * Divide two scalars that result in a scalar of type ElectricalInductance.
266      * @param scalar1 the first scalar
267      * @param scalar2 the second scalar
268      * @return the division of scalar1 by scalar2 as an instance of ElectricalInductance
269      */
270     public static ElectricalInductance divide(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
271     {
272         Throw.whenNull(scalar1, "scalar1 cannot be null");
273         Throw.whenNull(scalar2, "scalar2 cannot be null");
274         Throw.when(
275                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
276                         .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
277                         .equals(ElectricalInductanceUnit.BASE.getSiDimensions()),
278                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type ElectricalInductance",
279                 scalar1.toDisplayString(), scalar2.toDisplayString());
280         return new ElectricalInductance(scalar1.si / scalar2.si, ElectricalInductanceUnit.SI);
281     }
282 
283 }