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.FloatScalarRel;
14  import org.djutils.base.NumberParser;
15  import org.djutils.exceptions.Throw;
16  
17  import jakarta.annotation.Generated;
18  
19  /**
20   * Easy access methods for the FloatMagneticFlux FloatScalar, which is relative by definition.
21   * <p>
22   * Copyright (c) 2013-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
23   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
24   * </p>
25   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
26   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
27   */
28  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2025-09-06T15:16:28.380798Z")
29  public class FloatMagneticFlux extends FloatScalarRel<MagneticFluxUnit, FloatMagneticFlux>
30  {
31      /** */
32      private static final long serialVersionUID = 20150901L;
33  
34      /** Constant with value zero. */
35      public static final FloatMagneticFlux ZERO = new FloatMagneticFlux(0.0f, MagneticFluxUnit.SI);
36  
37      /** Constant with value one. */
38      public static final FloatMagneticFlux ONE = new FloatMagneticFlux(1.0f, MagneticFluxUnit.SI);
39  
40      /** Constant with value NaN. */
41      @SuppressWarnings("checkstyle:constantname")
42      public static final FloatMagneticFlux NaN = new FloatMagneticFlux(Float.NaN, MagneticFluxUnit.SI);
43  
44      /** Constant with value POSITIVE_INFINITY. */
45      public static final FloatMagneticFlux POSITIVE_INFINITY =
46              new FloatMagneticFlux(Float.POSITIVE_INFINITY, MagneticFluxUnit.SI);
47  
48      /** Constant with value NEGATIVE_INFINITY. */
49      public static final FloatMagneticFlux NEGATIVE_INFINITY =
50              new FloatMagneticFlux(Float.NEGATIVE_INFINITY, MagneticFluxUnit.SI);
51  
52      /** Constant with value MAX_VALUE. */
53      public static final FloatMagneticFlux POS_MAXVALUE = new FloatMagneticFlux(Float.MAX_VALUE, MagneticFluxUnit.SI);
54  
55      /** Constant with value -MAX_VALUE. */
56      public static final FloatMagneticFlux NEG_MAXVALUE = new FloatMagneticFlux(-Float.MAX_VALUE, MagneticFluxUnit.SI);
57  
58      /**
59       * Construct FloatMagneticFlux scalar with a unit.
60       * @param value the float value, expressed in the given unit
61       * @param unit unit for the float value
62       */
63      public FloatMagneticFlux(final float value, final MagneticFluxUnit unit)
64      {
65          super(value, unit);
66      }
67  
68      /**
69       * Construct FloatMagneticFlux scalar.
70       * @param value Scalar from which to construct this instance
71       */
72      public FloatMagneticFlux(final FloatMagneticFlux value)
73      {
74          super(value);
75      }
76  
77      /**
78       * Construct FloatMagneticFlux scalar with a unit using a double value.
79       * @param value the double value, expressed in the given unit
80       * @param unit unit for the resulting float value
81       */
82      public FloatMagneticFlux(final double value, final MagneticFluxUnit unit)
83      {
84          super((float) value, unit);
85      }
86  
87      @Override
88      public final FloatMagneticFlux instantiateRel(final float value, final MagneticFluxUnit unit)
89      {
90          return new FloatMagneticFlux(value, unit);
91      }
92  
93      /**
94       * Construct FloatMagneticFlux scalar based on an SI value.
95       * @param value the float value in SI units
96       * @return the new scalar with the SI value
97       */
98      public static final FloatMagneticFlux ofSI(final float value)
99      {
100         return new FloatMagneticFlux(value, MagneticFluxUnit.SI);
101     }
102 
103     /**
104      * Interpolate between two values. Note that the first value does not have to be smaller than the second.
105      * @param zero the value at a ratio of zero
106      * @param one the value at a ratio of one
107      * @param ratio the ratio between 0 and 1, inclusive
108      * @return a FloatMagneticFlux at the given ratio between 0 and 1
109      */
110     public static FloatMagneticFlux interpolate(final FloatMagneticFlux zero, final FloatMagneticFlux one, final float ratio)
111     {
112         Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
113                 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
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 the textual representation to parse into a FloatMagneticFlux
185      * @return 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             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity MagneticFlux", unitString);
200             return new FloatMagneticFlux(f, unit);
201         }
202         catch (Exception exception)
203         {
204             throw new IllegalArgumentException("Error parsing FloatMagneticFlux from " + text + " using Locale "
205                     + Locale.getDefault(Locale.Category.FORMAT), exception);
206         }
207     }
208 
209     /**
210      * Returns a FloatMagneticFlux based on a value and the textual representation of the unit, which can be localized.
211      * @param value the value to use
212      * @param unitString the textual representation of the unit
213      * @return the Scalar representation of the value in its unit
214      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
215      * @throws NullPointerException when the unitString argument is null
216      */
217     public static FloatMagneticFlux of(final float value, final String unitString)
218     {
219         Throw.whenNull(unitString, "Error parsing FloatMagneticFlux: unitString is null");
220         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
221                 "Error parsing FloatMagneticFlux: empty unitString");
222         MagneticFluxUnit unit = MagneticFluxUnit.BASE.getUnitByAbbreviation(unitString);
223         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FloatMagneticFlux with unit %s", unitString);
224         return new FloatMagneticFlux(value, unit);
225     }
226 
227     /**
228      * Calculate the division of FloatMagneticFlux and FloatMagneticFlux, which results in a FloatDimensionless scalar.
229      * @param v scalar
230      * @return scalar as a division of FloatMagneticFlux and FloatMagneticFlux
231      */
232     public final FloatDimensionless divide(final FloatMagneticFlux v)
233     {
234         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
235     }
236 
237     /**
238      * Calculate the division of FloatMagneticFlux and FloatElectricalPotential, which results in a FloatDuration scalar.
239      * @param v scalar
240      * @return scalar as a division of FloatMagneticFlux and FloatElectricalPotential
241      */
242     public final FloatDuration divide(final FloatElectricalPotential v)
243     {
244         return new FloatDuration(this.si / v.si, DurationUnit.SI);
245     }
246 
247     /**
248      * Calculate the division of FloatMagneticFlux and FloatDuration, which results in a FloatElectricalPotential scalar.
249      * @param v scalar
250      * @return scalar as a division of FloatMagneticFlux and FloatDuration
251      */
252     public final FloatElectricalPotential divide(final FloatDuration v)
253     {
254         return new FloatElectricalPotential(this.si / v.si, ElectricalPotentialUnit.SI);
255     }
256 
257     /**
258      * Calculate the division of FloatMagneticFlux and FloatArea, which results in a FloatMagneticFluxDensity scalar.
259      * @param v scalar
260      * @return scalar as a division of FloatMagneticFlux and FloatArea
261      */
262     public final FloatMagneticFluxDensity divide(final FloatArea v)
263     {
264         return new FloatMagneticFluxDensity(this.si / v.si, MagneticFluxDensityUnit.SI);
265     }
266 
267     /**
268      * Calculate the division of FloatMagneticFlux and FloatMagneticFluxDensity, which results in a FloatArea scalar.
269      * @param v scalar
270      * @return scalar as a division of FloatMagneticFlux and FloatMagneticFluxDensity
271      */
272     public final FloatArea divide(final FloatMagneticFluxDensity v)
273     {
274         return new FloatArea(this.si / v.si, AreaUnit.SI);
275     }
276 
277     /**
278      * Calculate the division of FloatMagneticFlux and FloatElectricalCurrent, which results in a FloatElectricalInductance
279      * scalar.
280      * @param v scalar
281      * @return scalar as a division of FloatMagneticFlux and FloatElectricalCurrent
282      */
283     public final FloatElectricalInductance divide(final FloatElectricalCurrent v)
284     {
285         return new FloatElectricalInductance(this.si / v.si, ElectricalInductanceUnit.SI);
286     }
287 
288     /**
289      * Calculate the division of FloatMagneticFlux and FloatElectricalInductance, which results in a FloatElectricalCurrent
290      * scalar.
291      * @param v scalar
292      * @return scalar as a division of FloatMagneticFlux and FloatElectricalInductance
293      */
294     public final FloatElectricalCurrent divide(final FloatElectricalInductance v)
295     {
296         return new FloatElectricalCurrent(this.si / v.si, ElectricalCurrentUnit.SI);
297     }
298 
299     @Override
300     public FloatSIScalar reciprocal()
301     {
302         return FloatSIScalar.divide(FloatDimensionless.ONE, this);
303     }
304 
305     /**
306      * Multiply two scalars that result in a scalar of type FloatMagneticFlux.
307      * @param scalar1 the first scalar
308      * @param scalar2 the second scalar
309      * @return the multiplication of both scalars as an instance of FloatMagneticFlux
310      */
311     public static FloatMagneticFlux multiply(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
312     {
313         Throw.whenNull(scalar1, "scalar1 cannot be null");
314         Throw.whenNull(scalar2, "scalar2 cannot be null");
315         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
316                 .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(MagneticFluxUnit.BASE.getSiDimensions()),
317                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type FloatMagneticFlux",
318                 scalar1.toDisplayString(), scalar2.toDisplayString());
319         return new FloatMagneticFlux(scalar1.si * scalar2.si, MagneticFluxUnit.SI);
320     }
321 
322     /**
323      * Divide two scalars that result in a scalar of type FloatMagneticFlux.
324      * @param scalar1 the first scalar
325      * @param scalar2 the second scalar
326      * @return the division of scalar1 by scalar2 as an instance of FloatMagneticFlux
327      */
328     public static FloatMagneticFlux divide(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
329     {
330         Throw.whenNull(scalar1, "scalar1 cannot be null");
331         Throw.whenNull(scalar2, "scalar2 cannot be null");
332         Throw.when(
333                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
334                         .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
335                         .equals(MagneticFluxUnit.BASE.getSiDimensions()),
336                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type FloatMagneticFlux",
337                 scalar1.toDisplayString(), scalar2.toDisplayString());
338         return new FloatMagneticFlux(scalar1.si / scalar2.si, MagneticFluxUnit.SI);
339     }
340 
341 }