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