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.AbstractDoubleScalarRel;
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-2023 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 = "2023-04-30T13:59:27.633664900Z")
25  public class ElectricalResistance extends AbstractDoubleScalarRel<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.
58       * @param value double; the double value
59       * @param unit ElectricalResistanceUnit; 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 ElectricalResistance; Scalar from which to construct this instance
69       */
70      public ElectricalResistance(final ElectricalResistance value)
71      {
72          super(value);
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      public final ElectricalResistance instantiateRel(final double value, final ElectricalResistanceUnit unit)
78      {
79          return new ElectricalResistance(value, unit);
80      }
81  
82      /**
83       * Construct ElectricalResistance scalar.
84       * @param value double; the double value in SI units
85       * @return ElectricalResistance; the new scalar with the SI value
86       */
87      public static final ElectricalResistance instantiateSI(final double value)
88      {
89          return new ElectricalResistance(value, ElectricalResistanceUnit.SI);
90      }
91  
92      /**
93       * Interpolate between two values.
94       * @param zero ElectricalResistance; the low value
95       * @param one ElectricalResistance; the high value
96       * @param ratio double; the ratio between 0 and 1, inclusive
97       * @return ElectricalResistance; a Scalar at the ratio between
98       */
99      public static ElectricalResistance interpolate(final ElectricalResistance zero, final ElectricalResistance one,
100             final double ratio)
101     {
102         return new ElectricalResistance(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
103                 zero.getDisplayUnit());
104     }
105 
106     /**
107      * Return the maximum value of two relative scalars.
108      * @param r1 ElectricalResistance; the first scalar
109      * @param r2 ElectricalResistance; the second scalar
110      * @return ElectricalResistance; the maximum value of two relative scalars
111      */
112     public static ElectricalResistance max(final ElectricalResistance r1, final ElectricalResistance r2)
113     {
114         return r1.gt(r2) ? r1 : r2;
115     }
116 
117     /**
118      * Return the maximum value of more than two relative scalars.
119      * @param r1 ElectricalResistance; the first scalar
120      * @param r2 ElectricalResistance; the second scalar
121      * @param rn ElectricalResistance...; the other scalars
122      * @return ElectricalResistance; the maximum value of more than two relative scalars
123      */
124     public static ElectricalResistance max(final ElectricalResistance r1, final ElectricalResistance r2,
125             final ElectricalResistance... rn)
126     {
127         ElectricalResistance maxr = r1.gt(r2) ? r1 : r2;
128         for (ElectricalResistance r : rn)
129         {
130             if (r.gt(maxr))
131             {
132                 maxr = r;
133             }
134         }
135         return maxr;
136     }
137 
138     /**
139      * Return the minimum value of two relative scalars.
140      * @param r1 ElectricalResistance; the first scalar
141      * @param r2 ElectricalResistance; the second scalar
142      * @return ElectricalResistance; the minimum value of two relative scalars
143      */
144     public static ElectricalResistance min(final ElectricalResistance r1, final ElectricalResistance r2)
145     {
146         return r1.lt(r2) ? r1 : r2;
147     }
148 
149     /**
150      * Return the minimum value of more than two relative scalars.
151      * @param r1 ElectricalResistance; the first scalar
152      * @param r2 ElectricalResistance; the second scalar
153      * @param rn ElectricalResistance...; the other scalars
154      * @return ElectricalResistance; the minimum value of more than two relative scalars
155      */
156     public static ElectricalResistance min(final ElectricalResistance r1, final ElectricalResistance r2,
157             final ElectricalResistance... rn)
158     {
159         ElectricalResistance minr = r1.lt(r2) ? r1 : r2;
160         for (ElectricalResistance r : rn)
161         {
162             if (r.lt(minr))
163             {
164                 minr = r;
165             }
166         }
167         return minr;
168     }
169 
170     /**
171      * Returns a ElectricalResistance representation of a textual representation of a value with a unit. The String
172      * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
173      * unit. Spaces are allowed, but not required, between the value and the unit.
174      * @param text String; the textual representation to parse into a ElectricalResistance
175      * @return ElectricalResistance; the Scalar representation of the value in its unit
176      * @throws IllegalArgumentException when the text cannot be parsed
177      * @throws NullPointerException when the text argument is null
178      */
179     public static ElectricalResistance valueOf(final String text)
180     {
181         Throw.whenNull(text, "Error parsing ElectricalResistance: text to parse is null");
182         Throw.when(text.length() == 0, IllegalArgumentException.class,
183                 "Error parsing ElectricalResistance: empty text to parse");
184         try
185         {
186             NumberParser numberParser = new NumberParser().lenient().trailing();
187             double d = numberParser.parseDouble(text);
188             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
189             ElectricalResistanceUnit unit = ElectricalResistanceUnit.BASE.getUnitByAbbreviation(unitString);
190             if (unit == null)
191                 throw new IllegalArgumentException("Unit " + unitString + " not found");
192             return new ElectricalResistance(d, unit);
193         }
194         catch (Exception exception)
195         {
196             throw new IllegalArgumentException("Error parsing ElectricalResistance from " + text + " using Locale "
197                     + Locale.getDefault(Locale.Category.FORMAT), exception);
198         }
199     }
200 
201     /**
202      * Returns a ElectricalResistance based on a value and the textual representation of the unit, which can be localized.
203      * @param value double; the value to use
204      * @param unitString String; the textual representation of the unit
205      * @return ElectricalResistance; the Scalar representation of the value in its unit
206      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
207      * @throws NullPointerException when the unitString argument is null
208      */
209     public static ElectricalResistance of(final double value, final String unitString)
210     {
211         Throw.whenNull(unitString, "Error parsing ElectricalResistance: unitString is null");
212         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
213                 "Error parsing ElectricalResistance: empty unitString");
214         ElectricalResistanceUnit unit = ElectricalResistanceUnit.BASE.getUnitByAbbreviation(unitString);
215         if (unit != null)
216         {
217             return new ElectricalResistance(value, unit);
218         }
219         throw new IllegalArgumentException("Error parsing ElectricalResistance with unit " + unitString);
220     }
221 
222     /**
223      * Calculate the division of ElectricalResistance and ElectricalResistance, which results in a Dimensionless scalar.
224      * @param v ElectricalResistance; scalar
225      * @return Dimensionless; scalar as a division of ElectricalResistance and ElectricalResistance
226      */
227     public final Dimensionless divide(final ElectricalResistance v)
228     {
229         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
230     }
231 
232     /**
233      * Calculate the multiplication of ElectricalResistance and ElectricalConductance, which results in a Dimensionless scalar.
234      * @param v ElectricalResistance; scalar
235      * @return Dimensionless; scalar as a multiplication of ElectricalResistance and ElectricalConductance
236      */
237     public final Dimensionless times(final ElectricalConductance v)
238     {
239         return new Dimensionless(this.si * v.si, DimensionlessUnit.SI);
240     }
241 
242     /**
243      * Calculate the multiplication of ElectricalResistance and ElectricalCurrent, which results in a ElectricalPotential
244      * scalar.
245      * @param v ElectricalResistance; scalar
246      * @return ElectricalPotential; scalar as a multiplication of ElectricalResistance and ElectricalCurrent
247      */
248     public final ElectricalPotential times(final ElectricalCurrent v)
249     {
250         return new ElectricalPotential(this.si * v.si, ElectricalPotentialUnit.SI);
251     }
252 
253     /**
254      * Calculate the multiplication of ElectricalResistance and Duration, which results in a ElectricalInductance scalar.
255      * @param v ElectricalResistance; scalar
256      * @return ElectricalInductance; scalar as a multiplication of ElectricalResistance and Duration
257      */
258     public final ElectricalInductance times(final Duration v)
259     {
260         return new ElectricalInductance(this.si * v.si, ElectricalInductanceUnit.SI);
261     }
262 
263     /** {@inheritDoc} */
264     @Override
265     public ElectricalConductance reciprocal()
266     {
267         return ElectricalConductance.instantiateSI(1.0 / this.si);
268     }
269 
270 }