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