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