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