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