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.MagneticFluxDensityUnit;
7   import org.djunits.unit.MagneticFluxUnit;
8   import org.djunits.value.vfloat.scalar.base.FloatScalar;
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 FloatMagneticFluxDensity FloatScalar, which is relative by definition.
17   * <p>
18   * Copyright (c) 2013-2024 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-07-23T14:06:38.224104100Z")
25  public class FloatMagneticFluxDensity extends FloatScalarRel<MagneticFluxDensityUnit, FloatMagneticFluxDensity>
26  {
27      /** */
28      private static final long serialVersionUID = 20150901L;
29  
30      /** Constant with value zero. */
31      public static final FloatMagneticFluxDensity ZERO = new FloatMagneticFluxDensity(0.0f, MagneticFluxDensityUnit.SI);
32  
33      /** Constant with value one. */
34      public static final FloatMagneticFluxDensity ONE = new FloatMagneticFluxDensity(1.0f, MagneticFluxDensityUnit.SI);
35  
36      /** Constant with value NaN. */
37      @SuppressWarnings("checkstyle:constantname")
38      public static final FloatMagneticFluxDensity NaN = new FloatMagneticFluxDensity(Float.NaN, MagneticFluxDensityUnit.SI);
39  
40      /** Constant with value POSITIVE_INFINITY. */
41      public static final FloatMagneticFluxDensity POSITIVE_INFINITY =
42              new FloatMagneticFluxDensity(Float.POSITIVE_INFINITY, MagneticFluxDensityUnit.SI);
43  
44      /** Constant with value NEGATIVE_INFINITY. */
45      public static final FloatMagneticFluxDensity NEGATIVE_INFINITY =
46              new FloatMagneticFluxDensity(Float.NEGATIVE_INFINITY, MagneticFluxDensityUnit.SI);
47  
48      /** Constant with value MAX_VALUE. */
49      public static final FloatMagneticFluxDensity POS_MAXVALUE =
50              new FloatMagneticFluxDensity(Float.MAX_VALUE, MagneticFluxDensityUnit.SI);
51  
52      /** Constant with value -MAX_VALUE. */
53      public static final FloatMagneticFluxDensity NEG_MAXVALUE =
54              new FloatMagneticFluxDensity(-Float.MAX_VALUE, MagneticFluxDensityUnit.SI);
55  
56      /**
57       * Construct FloatMagneticFluxDensity scalar.
58       * @param value float; the float value
59       * @param unit unit for the float value
60       */
61      public FloatMagneticFluxDensity(final float value, final MagneticFluxDensityUnit unit)
62      {
63          super(value, unit);
64      }
65  
66      /**
67       * Construct FloatMagneticFluxDensity scalar.
68       * @param value Scalar from which to construct this instance
69       */
70      public FloatMagneticFluxDensity(final FloatMagneticFluxDensity value)
71      {
72          super(value);
73      }
74  
75      /**
76       * Construct FloatMagneticFluxDensity scalar using a double value.
77       * @param value double; the double value
78       * @param unit unit for the resulting float value
79       */
80      public FloatMagneticFluxDensity(final double value, final MagneticFluxDensityUnit unit)
81      {
82          super((float) value, unit);
83      }
84  
85      @Override
86      public final FloatMagneticFluxDensity instantiateRel(final float value, final MagneticFluxDensityUnit unit)
87      {
88          return new FloatMagneticFluxDensity(value, unit);
89      }
90  
91      /**
92       * Construct FloatMagneticFluxDensity scalar.
93       * @param value float; the float value in SI units
94       * @return the new scalar with the SI value
95       */
96      public static final FloatMagneticFluxDensity instantiateSI(final float value)
97      {
98          return new FloatMagneticFluxDensity(value, MagneticFluxDensityUnit.SI);
99      }
100 
101     /**
102      * Interpolate between two values.
103      * @param zero the low value
104      * @param one the high value
105      * @param ratio double; the ratio between 0 and 1, inclusive
106      * @return a Scalar at the ratio between
107      */
108     public static FloatMagneticFluxDensity interpolate(final FloatMagneticFluxDensity zero, final FloatMagneticFluxDensity one,
109             final float ratio)
110     {
111         return new FloatMagneticFluxDensity(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
112                 zero.getDisplayUnit());
113     }
114 
115     /**
116      * Return the maximum value of two relative scalars.
117      * @param r1 the first scalar
118      * @param r2 the second scalar
119      * @return the maximum value of two relative scalars
120      */
121     public static FloatMagneticFluxDensity max(final FloatMagneticFluxDensity r1, final FloatMagneticFluxDensity r2)
122     {
123         return r1.gt(r2) ? r1 : r2;
124     }
125 
126     /**
127      * Return the maximum value of more than two relative scalars.
128      * @param r1 the first scalar
129      * @param r2 the second scalar
130      * @param rn the other scalars
131      * @return the maximum value of more than two relative scalars
132      */
133     public static FloatMagneticFluxDensity max(final FloatMagneticFluxDensity r1, final FloatMagneticFluxDensity r2,
134             final FloatMagneticFluxDensity... rn)
135     {
136         FloatMagneticFluxDensity maxr = r1.gt(r2) ? r1 : r2;
137         for (FloatMagneticFluxDensity r : rn)
138         {
139             if (r.gt(maxr))
140             {
141                 maxr = r;
142             }
143         }
144         return maxr;
145     }
146 
147     /**
148      * Return the minimum value of two relative scalars.
149      * @param r1 the first scalar
150      * @param r2 the second scalar
151      * @return the minimum value of two relative scalars
152      */
153     public static FloatMagneticFluxDensity min(final FloatMagneticFluxDensity r1, final FloatMagneticFluxDensity r2)
154     {
155         return r1.lt(r2) ? r1 : r2;
156     }
157 
158     /**
159      * Return the minimum value of more than two relative scalars.
160      * @param r1 the first scalar
161      * @param r2 the second scalar
162      * @param rn the other scalars
163      * @return the minimum value of more than two relative scalars
164      */
165     public static FloatMagneticFluxDensity min(final FloatMagneticFluxDensity r1, final FloatMagneticFluxDensity r2,
166             final FloatMagneticFluxDensity... rn)
167     {
168         FloatMagneticFluxDensity minr = r1.lt(r2) ? r1 : r2;
169         for (FloatMagneticFluxDensity r : rn)
170         {
171             if (r.lt(minr))
172             {
173                 minr = r;
174             }
175         }
176         return minr;
177     }
178 
179     /**
180      * Returns a FloatMagneticFluxDensity representation of a textual representation of a value with a unit. The String
181      * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
182      * unit. Spaces are allowed, but not required, between the value and the unit.
183      * @param text String; the textual representation to parse into a FloatMagneticFluxDensity
184      * @return FloatMagneticFluxDensity; the Scalar representation of the value in its unit
185      * @throws IllegalArgumentException when the text cannot be parsed
186      * @throws NullPointerException when the text argument is null
187      */
188     public static FloatMagneticFluxDensity valueOf(final String text)
189     {
190         Throw.whenNull(text, "Error parsing FloatMagneticFluxDensity: text to parse is null");
191         Throw.when(text.length() == 0, IllegalArgumentException.class,
192                 "Error parsing FloatMagneticFluxDensity: 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             MagneticFluxDensityUnit unit = MagneticFluxDensityUnit.BASE.getUnitByAbbreviation(unitString);
199             if (unit == null)
200                 throw new IllegalArgumentException("Unit " + unitString + " not found");
201             return new FloatMagneticFluxDensity(f, unit);
202         }
203         catch (Exception exception)
204         {
205             throw new IllegalArgumentException("Error parsing FloatMagneticFluxDensity from " + text + " using Locale "
206                     + Locale.getDefault(Locale.Category.FORMAT), exception);
207         }
208     }
209 
210     /**
211      * Returns a FloatMagneticFluxDensity 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 FloatMagneticFluxDensity; 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 FloatMagneticFluxDensity of(final float value, final String unitString)
219     {
220         Throw.whenNull(unitString, "Error parsing FloatMagneticFluxDensity: unitString is null");
221         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
222                 "Error parsing FloatMagneticFluxDensity: empty unitString");
223         MagneticFluxDensityUnit unit = MagneticFluxDensityUnit.BASE.getUnitByAbbreviation(unitString);
224         if (unit != null)
225         {
226             return new FloatMagneticFluxDensity(value, unit);
227         }
228         throw new IllegalArgumentException("Error parsing FloatMagneticFluxDensity with unit " + unitString);
229     }
230 
231     /**
232      * Calculate the division of FloatMagneticFluxDensity and FloatMagneticFluxDensity, which results in a FloatDimensionless
233      * scalar.
234      * @param v FloatMagneticFluxDensity; scalar
235      * @return FloatDimensionless; scalar as a division of FloatMagneticFluxDensity and FloatMagneticFluxDensity
236      */
237     public final FloatDimensionless divide(final FloatMagneticFluxDensity v)
238     {
239         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
240     }
241 
242     /**
243      * Calculate the multiplication of FloatMagneticFluxDensity and FloatArea, which results in a FloatMagneticFlux scalar.
244      * @param v FloatMagneticFluxDensity; scalar
245      * @return FloatMagneticFlux; scalar as a multiplication of FloatMagneticFluxDensity and FloatArea
246      */
247     public final FloatMagneticFlux times(final FloatArea v)
248     {
249         return new FloatMagneticFlux(this.si * v.si, MagneticFluxUnit.SI);
250     }
251 
252     @Override
253     public FloatSIScalar reciprocal()
254     {
255         return FloatScalar.divide(FloatDimensionless.ONE, this);
256     }
257 
258 }