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