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