View Javadoc
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.ElectricalInductanceUnit;
7   import org.djunits.unit.ElectricalPotentialUnit;
8   import org.djunits.unit.ElectricalResistanceUnit;
9   import org.djunits.value.vdouble.scalar.base.DoubleScalarRel;
10  import org.djutils.base.NumberParser;
11  import org.djutils.exceptions.Throw;
12  
13  import jakarta.annotation.Generated;
14  
15  /**
16   * Easy access methods for the ElectricalResistance DoubleScalar, which is relative by definition.
17   * <p>
18   * Copyright (c) 2013-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
19   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
20   * </p>
21   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
23   */
24  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2025-09-06T15:16:28.380798Z")
25  public class ElectricalResistance extends DoubleScalarRel<ElectricalResistanceUnit, ElectricalResistance>
26  {
27      /** */
28      private static final long serialVersionUID = 20150905L;
29  
30      /** Constant with value zero. */
31      public static final ElectricalResistance ZERO = new ElectricalResistance(0.0, ElectricalResistanceUnit.SI);
32  
33      /** Constant with value one. */
34      public static final ElectricalResistance ONE = new ElectricalResistance(1.0, ElectricalResistanceUnit.SI);
35  
36      /** Constant with value NaN. */
37      @SuppressWarnings("checkstyle:constantname")
38      public static final ElectricalResistance NaN = new ElectricalResistance(Double.NaN, ElectricalResistanceUnit.SI);
39  
40      /** Constant with value POSITIVE_INFINITY. */
41      public static final ElectricalResistance POSITIVE_INFINITY =
42              new ElectricalResistance(Double.POSITIVE_INFINITY, ElectricalResistanceUnit.SI);
43  
44      /** Constant with value NEGATIVE_INFINITY. */
45      public static final ElectricalResistance NEGATIVE_INFINITY =
46              new ElectricalResistance(Double.NEGATIVE_INFINITY, ElectricalResistanceUnit.SI);
47  
48      /** Constant with value MAX_VALUE. */
49      public static final ElectricalResistance POS_MAXVALUE =
50              new ElectricalResistance(Double.MAX_VALUE, ElectricalResistanceUnit.SI);
51  
52      /** Constant with value -MAX_VALUE. */
53      public static final ElectricalResistance NEG_MAXVALUE =
54              new ElectricalResistance(-Double.MAX_VALUE, ElectricalResistanceUnit.SI);
55  
56      /**
57       * Construct ElectricalResistance scalar with a unit.
58       * @param value the double value, expressed in the given unit
59       * @param unit unit for the double value
60       */
61      public ElectricalResistance(final double value, final ElectricalResistanceUnit unit)
62      {
63          super(value, unit);
64      }
65  
66      /**
67       * Construct ElectricalResistance scalar.
68       * @param value Scalar from which to construct this instance
69       */
70      public ElectricalResistance(final ElectricalResistance value)
71      {
72          super(value);
73      }
74  
75      @Override
76      public final ElectricalResistance instantiateRel(final double value, final ElectricalResistanceUnit unit)
77      {
78          return new ElectricalResistance(value, unit);
79      }
80  
81      /**
82       * Construct ElectricalResistance scalar based on an SI value.
83       * @param value the double value in SI units
84       * @return the new scalar with the SI value
85       */
86      public static final ElectricalResistance ofSI(final double value)
87      {
88          return new ElectricalResistance(value, ElectricalResistanceUnit.SI);
89      }
90  
91      /**
92       * Interpolate between two values. Note that the first value does not have to be smaller than the second.
93       * @param zero the value at a ratio of zero
94       * @param one the value at a ratio of one
95       * @param ratio the ratio between 0 and 1, inclusive
96       * @return a ElectricalResistance at the given ratio between 0 and 1
97       */
98      public static ElectricalResistance interpolate(final ElectricalResistance zero, final ElectricalResistance one,
99              final double ratio)
100     {
101         Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
102                 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
103         return new ElectricalResistance(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
104                 zero.getDisplayUnit());
105     }
106 
107     /**
108      * Return the maximum value of two relative scalars.
109      * @param r1 the first scalar
110      * @param r2 the second scalar
111      * @return the maximum value of two relative scalars
112      */
113     public static ElectricalResistance max(final ElectricalResistance r1, final ElectricalResistance r2)
114     {
115         return r1.gt(r2) ? r1 : r2;
116     }
117 
118     /**
119      * Return the maximum value of more than two relative scalars.
120      * @param r1 the first scalar
121      * @param r2 the second scalar
122      * @param rn the other scalars
123      * @return the maximum value of more than two relative scalars
124      */
125     public static ElectricalResistance max(final ElectricalResistance r1, final ElectricalResistance r2,
126             final ElectricalResistance... rn)
127     {
128         ElectricalResistance maxr = r1.gt(r2) ? r1 : r2;
129         for (ElectricalResistance r : rn)
130         {
131             if (r.gt(maxr))
132             {
133                 maxr = r;
134             }
135         }
136         return maxr;
137     }
138 
139     /**
140      * Return the minimum value of two relative scalars.
141      * @param r1 the first scalar
142      * @param r2 the second scalar
143      * @return the minimum value of two relative scalars
144      */
145     public static ElectricalResistance min(final ElectricalResistance r1, final ElectricalResistance r2)
146     {
147         return r1.lt(r2) ? r1 : r2;
148     }
149 
150     /**
151      * Return the minimum value of more than two relative scalars.
152      * @param r1 the first scalar
153      * @param r2 the second scalar
154      * @param rn the other scalars
155      * @return the minimum value of more than two relative scalars
156      */
157     public static ElectricalResistance min(final ElectricalResistance r1, final ElectricalResistance r2,
158             final ElectricalResistance... rn)
159     {
160         ElectricalResistance minr = r1.lt(r2) ? r1 : r2;
161         for (ElectricalResistance r : rn)
162         {
163             if (r.lt(minr))
164             {
165                 minr = r;
166             }
167         }
168         return minr;
169     }
170 
171     /**
172      * Returns a ElectricalResistance representation of a textual representation of a value with a unit. The String
173      * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
174      * unit. Spaces are allowed, but not required, between the value and the unit.
175      * @param text the textual representation to parse into a ElectricalResistance
176      * @return the Scalar representation of the value in its unit
177      * @throws IllegalArgumentException when the text cannot be parsed
178      * @throws NullPointerException when the text argument is null
179      */
180     public static ElectricalResistance valueOf(final String text)
181     {
182         Throw.whenNull(text, "Error parsing ElectricalResistance: text to parse is null");
183         Throw.when(text.length() == 0, IllegalArgumentException.class,
184                 "Error parsing ElectricalResistance: empty text to parse");
185         try
186         {
187             NumberParser numberParser = new NumberParser().lenient().trailing();
188             double d = numberParser.parseDouble(text);
189             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
190             ElectricalResistanceUnit unit = ElectricalResistanceUnit.BASE.getUnitByAbbreviation(unitString);
191             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity ElectricalResistance",
192                     unitString);
193             return new ElectricalResistance(d, unit);
194         }
195         catch (Exception exception)
196         {
197             throw new IllegalArgumentException("Error parsing ElectricalResistance from " + text + " using Locale "
198                     + Locale.getDefault(Locale.Category.FORMAT), exception);
199         }
200     }
201 
202     /**
203      * Returns a ElectricalResistance based on a value and the textual representation of the unit, which can be localized.
204      * @param value the value to use
205      * @param unitString the textual representation of the unit
206      * @return the Scalar representation of the value in its unit
207      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
208      * @throws NullPointerException when the unitString argument is null
209      */
210     public static ElectricalResistance of(final double value, final String unitString)
211     {
212         Throw.whenNull(unitString, "Error parsing ElectricalResistance: unitString is null");
213         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
214                 "Error parsing ElectricalResistance: empty unitString");
215         ElectricalResistanceUnit unit = ElectricalResistanceUnit.BASE.getUnitByAbbreviation(unitString);
216         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing ElectricalResistance with unit %s", unitString);
217         return new ElectricalResistance(value, unit);
218     }
219 
220     /**
221      * Calculate the division of ElectricalResistance and ElectricalResistance, which results in a Dimensionless scalar.
222      * @param v scalar
223      * @return scalar as a division of ElectricalResistance and ElectricalResistance
224      */
225     public final Dimensionless divide(final ElectricalResistance v)
226     {
227         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
228     }
229 
230     /**
231      * Calculate the multiplication of ElectricalResistance and ElectricalConductance, which results in a Dimensionless scalar.
232      * @param v scalar
233      * @return scalar as a multiplication of ElectricalResistance and ElectricalConductance
234      */
235     public final Dimensionless times(final ElectricalConductance v)
236     {
237         return new Dimensionless(this.si * v.si, DimensionlessUnit.SI);
238     }
239 
240     /**
241      * Calculate the multiplication of ElectricalResistance and ElectricalCurrent, which results in a ElectricalPotential
242      * scalar.
243      * @param v scalar
244      * @return scalar as a multiplication of ElectricalResistance and ElectricalCurrent
245      */
246     public final ElectricalPotential times(final ElectricalCurrent v)
247     {
248         return new ElectricalPotential(this.si * v.si, ElectricalPotentialUnit.SI);
249     }
250 
251     /**
252      * Calculate the multiplication of ElectricalResistance and Duration, which results in a ElectricalInductance scalar.
253      * @param v scalar
254      * @return scalar as a multiplication of ElectricalResistance and Duration
255      */
256     public final ElectricalInductance times(final Duration v)
257     {
258         return new ElectricalInductance(this.si * v.si, ElectricalInductanceUnit.SI);
259     }
260 
261     @Override
262     public ElectricalConductance reciprocal()
263     {
264         return ElectricalConductance.ofSI(1.0 / this.si);
265     }
266 
267     /**
268      * Multiply two scalars that result in a scalar of type ElectricalResistance.
269      * @param scalar1 the first scalar
270      * @param scalar2 the second scalar
271      * @return the multiplication of both scalars as an instance of ElectricalResistance
272      */
273     public static ElectricalResistance multiply(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
274     {
275         Throw.whenNull(scalar1, "scalar1 cannot be null");
276         Throw.whenNull(scalar2, "scalar2 cannot be null");
277         Throw.when(
278                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
279                         .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
280                         .equals(ElectricalResistanceUnit.BASE.getSiDimensions()),
281                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type ElectricalResistance",
282                 scalar1.toDisplayString(), scalar2.toDisplayString());
283         return new ElectricalResistance(scalar1.si * scalar2.si, ElectricalResistanceUnit.SI);
284     }
285 
286     /**
287      * Divide two scalars that result in a scalar of type ElectricalResistance.
288      * @param scalar1 the first scalar
289      * @param scalar2 the second scalar
290      * @return the division of scalar1 by scalar2 as an instance of ElectricalResistance
291      */
292     public static ElectricalResistance divide(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
293     {
294         Throw.whenNull(scalar1, "scalar1 cannot be null");
295         Throw.whenNull(scalar2, "scalar2 cannot be null");
296         Throw.when(
297                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
298                         .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
299                         .equals(ElectricalResistanceUnit.BASE.getSiDimensions()),
300                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type ElectricalResistance",
301                 scalar1.toDisplayString(), scalar2.toDisplayString());
302         return new ElectricalResistance(scalar1.si / scalar2.si, ElectricalResistanceUnit.SI);
303     }
304 
305 }