View Javadoc
1   package org.djunits.quantity;
2   
3   import org.djunits.quantity.def.Quantity;
4   import org.djunits.unit.AbstractUnit;
5   import org.djunits.unit.UnitInterface;
6   import org.djunits.unit.UnitRuntimeException;
7   import org.djunits.unit.Unitless;
8   import org.djunits.unit.scale.IdentityScale;
9   import org.djunits.unit.scale.LinearScale;
10  import org.djunits.unit.scale.Scale;
11  import org.djunits.unit.si.SIPrefix;
12  import org.djunits.unit.si.SIPrefixes;
13  import org.djunits.unit.si.SIUnit;
14  import org.djunits.unit.system.UnitSystem;
15  
16  /**
17   * Inductance is the tendency of an electrical conductor to oppose a change in the electric current flowing through it.
18   * <p>
19   * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
20   * for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
21   * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
22   * @author Alexander Verbraeck
23   */
24  public class ElectricalInductance extends Quantity<ElectricalInductance>
25  {
26      /** Constant with value zero. */
27      public static final ElectricalInductance ZERO = ofSi(0.0);
28  
29      /** Constant with value one. */
30      public static final ElectricalInductance ONE = ofSi(1.0);
31  
32      /** Constant with value NaN. */
33      @SuppressWarnings("checkstyle:constantname")
34      public static final ElectricalInductance NaN = ofSi(Double.NaN);
35  
36      /** Constant with value POSITIVE_INFINITY. */
37      public static final ElectricalInductance POSITIVE_INFINITY = ofSi(Double.POSITIVE_INFINITY);
38  
39      /** Constant with value NEGATIVE_INFINITY. */
40      public static final ElectricalInductance NEGATIVE_INFINITY = ofSi(Double.NEGATIVE_INFINITY);
41  
42      /** Constant with value MAX_VALUE. */
43      public static final ElectricalInductance POS_MAXVALUE = ofSi(Double.MAX_VALUE);
44  
45      /** Constant with value -MAX_VALUE. */
46      public static final ElectricalInductance NEG_MAXVALUE = ofSi(-Double.MAX_VALUE);
47  
48      /** */
49      private static final long serialVersionUID = 600L;
50  
51      /**
52       * Instantiate a ElectricalInductance quantity with an SI or base value and a display unit.
53       * @param value the quantity value expressed in the SI or base unit
54       * @param displayUnit the display unit to use
55       * @param useSi use SI value when true, use value in unit when false
56       */
57      public ElectricalInductance(final double value, final ElectricalInductance.Unit displayUnit, final boolean useSi)
58      {
59          super(value, displayUnit, useSi);
60      }
61  
62      /**
63       * Instantiate a ElectricalInductance quantity expressed in the given unit.
64       * @param valueInUnit the quantity value expressed in the given unit
65       * @param unit the unit of the value, also acts as the display unit
66       */
67      public ElectricalInductance(final double valueInUnit, final ElectricalInductance.Unit unit)
68      {
69          this(valueInUnit, unit, false);
70      }
71  
72      /**
73       * Return a ElectricalInductance instance based on an SI value.
74       * @param si the si value
75       * @return the ElectricalInductance instance based on an SI value
76       */
77      public static ElectricalInductance ofSi(final double si)
78      {
79          return new ElectricalInductance(si, ElectricalInductance.Unit.SI, true);
80      }
81  
82      /**
83       * Instantiate a ElectricalInductance quantity with an SI or base value and a display unit.
84       * @param siValue the quantity value expressed in the SI or base unit
85       * @param displayUnit the display unit to use
86       * @return the ElectricalInductance instance based on an SI value with the given display unit
87       */
88      public static ElectricalInductance ofSi(final double siValue, final ElectricalInductance.Unit displayUnit)
89      {
90          return new ElectricalInductance(siValue, displayUnit, true);
91      }
92  
93      @Override
94      public ElectricalInductance instantiateSi(final double siValue, final UnitInterface<ElectricalInductance> displayUnit)
95      {
96          return new ElectricalInductance(siValue, (ElectricalInductance.Unit) displayUnit, true);
97      }
98  
99      /**
100      * Returns a ElectricalInductance representation of a textual representation of a value with a unit. The String
101      * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
102      * unit. Spaces are allowed, but not required, between the value and the unit.
103      * @param text the textual representation to parse into a ElectricalInductance
104      * @return the Scalar representation of the value in its unit
105      * @throws IllegalArgumentException when the text cannot be parsed
106      * @throws NullPointerException when the text argument is null
107      */
108     public static ElectricalInductance valueOf(final String text)
109     {
110         return Quantity.valueOf(text, ZERO);
111     }
112 
113     /**
114      * Returns a ElectricalInductance based on a value expressed in the unit.
115      * @param valueInUnit the value, expressed in the given unit
116      * @param unit the unit of the value, also acts as the display unit
117      * @return ab ElectricalInductance representation of the value in its unit
118      */
119     public static ElectricalInductance of(final double valueInUnit, final ElectricalInductance.Unit unit)
120     {
121         return new ElectricalInductance(valueInUnit, unit);
122     }
123 
124     /**
125      * Returns a ElectricalInductance based on a value and the textual representation of the unit, which can be localized.
126      * @param valueInUnit the value, expressed in the unit as given by unitString
127      * @param unitString the textual representation of the unit
128      * @return the Scalar representation of the value in its unit
129      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
130      * @throws NullPointerException when the unitString argument is null
131      */
132     public static ElectricalInductance of(final double valueInUnit, final String unitString)
133     {
134         return Quantity.of(valueInUnit, unitString, ZERO);
135     }
136 
137     @Override
138     public ElectricalInductance.Unit getDisplayUnit()
139     {
140         return (ElectricalInductance.Unit) super.getDisplayUnit();
141     }
142 
143     /**
144      * Calculate the division of ElectricalInductance and ElectricalInductance, which results in a Dimensionless quantity.
145      * @param v quantity
146      * @return quantity as a division of ElectricalInductance and ElectricalInductance
147      */
148     public Dimensionless divide(final ElectricalInductance v)
149     {
150         return new Dimensionless(this.si() / v.si(), Unitless.BASE);
151     }
152 
153     /******************************************************************************************************/
154     /********************************************** UNIT CLASS ********************************************/
155     /******************************************************************************************************/
156 
157     /**
158      * ElectricalInductance.Unit encodes the units of electromagnetic inductance.
159      * <p>
160      * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved.
161      * See for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
162      * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
163      * @author Alexander Verbraeck
164      */
165     @SuppressWarnings("checkstyle:constantname")
166     public static class Unit extends AbstractUnit<ElectricalInductance>
167     {
168         /** The dimensions of electromagnetic induction: kgm2/s2A2. */
169         public static final SIUnit SI_UNIT = SIUnit.of("kgm2/s2A2");
170 
171         /** henry. */
172         public static final ElectricalInductance.Unit H = new ElectricalInductance.Unit("H", "H", "henry", IdentityScale.SCALE,
173                 UnitSystem.SI_DERIVED, SIPrefixes.getSiPrefix(""));
174 
175         /** The SI or BASE unit. */
176         public static final ElectricalInductance.Unit SI = (Unit) H.generateSiPrefixes(false, false);
177 
178         /**
179          * Create a new ElectricalInductance unit.
180          * @param id the id or main abbreviation of the unit
181          * @param name the full name of the unit
182          * @param scaleFactorToBaseUnit the scale factor of the unit to convert it TO the base (SI) unit
183          * @param unitSystem the unit system such as SI or IMPERIAL
184          */
185         public Unit(final String id, final String name, final double scaleFactorToBaseUnit, final UnitSystem unitSystem)
186         {
187             super(id, name, scaleFactorToBaseUnit, unitSystem);
188         }
189 
190         /**
191          * Return a derived unit for this unit, with textual abbreviation(s) and a display abbreviation.
192          * @param textualAbbreviation the textual abbreviation of the unit, which doubles as the id
193          * @param displayAbbreviation the display abbreviation of the unit
194          * @param name the full name of the unit
195          * @param scale the scale to use to convert from this unit to the standard (e.g., SI, BASE) unit
196          * @param unitSystem unit system, e.g. SI or Imperial
197          * @param siPrefix the SI Prefix of this unit
198          */
199         public Unit(final String textualAbbreviation, final String displayAbbreviation, final String name, final Scale scale,
200                 final UnitSystem unitSystem, final SIPrefix siPrefix)
201         {
202             super(textualAbbreviation, displayAbbreviation, name, scale, unitSystem, siPrefix);
203         }
204 
205         @Override
206         public SIUnit siUnit()
207         {
208             return SI_UNIT;
209         }
210 
211         @Override
212         public Unit getBaseUnit()
213         {
214             return SI;
215         }
216 
217         @Override
218         public ElectricalInductance ofSi(final double si, final UnitInterface<ElectricalInductance> displayUnit)
219         {
220             return new ElectricalInductance(si, (Unit) displayUnit, true);
221         }
222 
223         @Override
224         public ElectricalInductance.Unit deriveUnit(final String abbreviation, final String name, final double scaleFactor,
225                 final UnitSystem unitSystem)
226         {
227             return (Unit) super.deriveUnit(abbreviation, name, scaleFactor, unitSystem);
228         }
229 
230         @Override
231         public ElectricalInductance.Unit deriveUnit(final String textualAbbreviation, final String displayAbbreviation,
232                 final String name, final double scaleFactor, final UnitSystem unitSystem, final SIPrefix siPrefix)
233         {
234             if (getScale() instanceof LinearScale ls)
235             {
236                 return new ElectricalInductance.Unit(textualAbbreviation, displayAbbreviation, name,
237                         new LinearScale(ls.getScaleFactorToBaseUnit() * scaleFactor), unitSystem, siPrefix);
238             }
239             throw new UnitRuntimeException("Only possible to derive a unit from a unit with a linear scale");
240         }
241 
242     }
243 
244 }