1 package org.djunits.value.vdouble.scalar;
2
3 import java.util.Locale;
4
5 import org.djunits.unit.DimensionlessUnit;
6 import org.djunits.unit.ElectricalCurrentUnit;
7 import org.djunits.unit.ElectricalPotentialUnit;
8 import org.djunits.unit.ElectricalResistanceUnit;
9 import org.djunits.unit.MagneticFluxUnit;
10 import org.djunits.unit.PowerUnit;
11 import org.djunits.value.vdouble.scalar.base.DoubleScalar;
12 import org.djunits.value.vdouble.scalar.base.DoubleScalarRel;
13 import org.djutils.base.NumberParser;
14 import org.djutils.exceptions.Throw;
15
16 import jakarta.annotation.Generated;
17
18
19
20
21
22
23
24
25
26
27 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
28 public class ElectricalPotential extends DoubleScalarRel<ElectricalPotentialUnit, ElectricalPotential>
29 {
30
31 private static final long serialVersionUID = 20150905L;
32
33
34 public static final ElectricalPotential ZERO = new ElectricalPotential(0.0, ElectricalPotentialUnit.SI);
35
36
37 public static final ElectricalPotential ONE = new ElectricalPotential(1.0, ElectricalPotentialUnit.SI);
38
39
40 @SuppressWarnings("checkstyle:constantname")
41 public static final ElectricalPotential NaN = new ElectricalPotential(Double.NaN, ElectricalPotentialUnit.SI);
42
43
44 public static final ElectricalPotential POSITIVE_INFINITY =
45 new ElectricalPotential(Double.POSITIVE_INFINITY, ElectricalPotentialUnit.SI);
46
47
48 public static final ElectricalPotential NEGATIVE_INFINITY =
49 new ElectricalPotential(Double.NEGATIVE_INFINITY, ElectricalPotentialUnit.SI);
50
51
52 public static final ElectricalPotential POS_MAXVALUE =
53 new ElectricalPotential(Double.MAX_VALUE, ElectricalPotentialUnit.SI);
54
55
56 public static final ElectricalPotential NEG_MAXVALUE =
57 new ElectricalPotential(-Double.MAX_VALUE, ElectricalPotentialUnit.SI);
58
59
60
61
62
63
64 public ElectricalPotential(final double value, final ElectricalPotentialUnit unit)
65 {
66 super(value, unit);
67 }
68
69
70
71
72
73 public ElectricalPotential(final ElectricalPotential value)
74 {
75 super(value);
76 }
77
78 @Override
79 public final ElectricalPotential instantiateRel(final double value, final ElectricalPotentialUnit unit)
80 {
81 return new ElectricalPotential(value, unit);
82 }
83
84
85
86
87
88
89 public static final ElectricalPotential instantiateSI(final double value)
90 {
91 return new ElectricalPotential(value, ElectricalPotentialUnit.SI);
92 }
93
94
95
96
97
98
99
100
101 public static ElectricalPotential interpolate(final ElectricalPotential zero, final ElectricalPotential one,
102 final double ratio)
103 {
104 return new ElectricalPotential(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
105 zero.getDisplayUnit());
106 }
107
108
109
110
111
112
113
114 public static ElectricalPotential max(final ElectricalPotential r1, final ElectricalPotential r2)
115 {
116 return r1.gt(r2) ? r1 : r2;
117 }
118
119
120
121
122
123
124
125
126 public static ElectricalPotential max(final ElectricalPotential r1, final ElectricalPotential r2,
127 final ElectricalPotential... rn)
128 {
129 ElectricalPotential maxr = r1.gt(r2) ? r1 : r2;
130 for (ElectricalPotential r : rn)
131 {
132 if (r.gt(maxr))
133 {
134 maxr = r;
135 }
136 }
137 return maxr;
138 }
139
140
141
142
143
144
145
146 public static ElectricalPotential min(final ElectricalPotential r1, final ElectricalPotential r2)
147 {
148 return r1.lt(r2) ? r1 : r2;
149 }
150
151
152
153
154
155
156
157
158 public static ElectricalPotential min(final ElectricalPotential r1, final ElectricalPotential r2,
159 final ElectricalPotential... rn)
160 {
161 ElectricalPotential minr = r1.lt(r2) ? r1 : r2;
162 for (ElectricalPotential r : rn)
163 {
164 if (r.lt(minr))
165 {
166 minr = r;
167 }
168 }
169 return minr;
170 }
171
172
173
174
175
176
177
178
179
180
181 public static ElectricalPotential valueOf(final String text)
182 {
183 Throw.whenNull(text, "Error parsing ElectricalPotential: text to parse is null");
184 Throw.when(text.length() == 0, IllegalArgumentException.class,
185 "Error parsing ElectricalPotential: empty text to parse");
186 try
187 {
188 NumberParser numberParser = new NumberParser().lenient().trailing();
189 double d = numberParser.parseDouble(text);
190 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
191 ElectricalPotentialUnit unit = ElectricalPotentialUnit.BASE.getUnitByAbbreviation(unitString);
192 if (unit == null)
193 throw new IllegalArgumentException("Unit " + unitString + " not found");
194 return new ElectricalPotential(d, unit);
195 }
196 catch (Exception exception)
197 {
198 throw new IllegalArgumentException("Error parsing ElectricalPotential from " + text + " using Locale "
199 + Locale.getDefault(Locale.Category.FORMAT), exception);
200 }
201 }
202
203
204
205
206
207
208
209
210
211 public static ElectricalPotential of(final double value, final String unitString)
212 {
213 Throw.whenNull(unitString, "Error parsing ElectricalPotential: unitString is null");
214 Throw.when(unitString.length() == 0, IllegalArgumentException.class,
215 "Error parsing ElectricalPotential: empty unitString");
216 ElectricalPotentialUnit unit = ElectricalPotentialUnit.BASE.getUnitByAbbreviation(unitString);
217 if (unit != null)
218 {
219 return new ElectricalPotential(value, unit);
220 }
221 throw new IllegalArgumentException("Error parsing ElectricalPotential with unit " + unitString);
222 }
223
224
225
226
227
228
229 public final Dimensionless divide(final ElectricalPotential v)
230 {
231 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
232 }
233
234
235
236
237
238
239 public final Power times(final ElectricalCurrent v)
240 {
241 return new Power(this.si * v.si, PowerUnit.SI);
242 }
243
244
245
246
247
248
249 public final ElectricalResistance divide(final ElectricalCurrent v)
250 {
251 return new ElectricalResistance(this.si / v.si, ElectricalResistanceUnit.SI);
252 }
253
254
255
256
257
258
259 public final ElectricalCurrent divide(final ElectricalResistance v)
260 {
261 return new ElectricalCurrent(this.si / v.si, ElectricalCurrentUnit.SI);
262 }
263
264
265
266
267
268
269 public final MagneticFlux times(final Duration v)
270 {
271 return new MagneticFlux(this.si * v.si, MagneticFluxUnit.SI);
272 }
273
274 @Override
275 public SIScalar reciprocal()
276 {
277 return DoubleScalar.divide(Dimensionless.ONE, this);
278 }
279
280 }