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