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