View Javadoc
1   package org.djunits.value.vdouble.scalar;
2   
3   import java.util.regex.Matcher;
4   
5   import javax.annotation.Generated;
6   
7   import org.djunits.Throw;
8   import org.djunits.unit.DimensionlessUnit;
9   import org.djunits.unit.MagneticFluxDensityUnit;
10  import org.djunits.unit.MagneticFluxUnit;
11  import org.djunits.value.util.ValueUtil;
12  import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRel;
13  
14  /**
15   * Easy access methods for the MagneticFluxDensity DoubleScalar, which is relative by definition.
16   * <p>
17   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
19   * </p>
20   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
21   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
22   */
23  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2020-01-19T15:21:24.964166400Z")
24  public class MagneticFluxDensity extends AbstractDoubleScalarRel<MagneticFluxDensityUnit, MagneticFluxDensity>
25  {
26      /** */
27      private static final long serialVersionUID = 20150905L;
28  
29      /** Constant with value zero. */
30      public static final MagneticFluxDensityneticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensity ZERO = new MagneticFluxDensity(0.0, MagneticFluxDensityUnit.SI);
31  
32      /** Constant with value one. */
33      public static final MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensity ONE = new MagneticFluxDensity(1.0, MagneticFluxDensityUnit.SI);
34  
35      /** Constant with value NaN. */
36      @SuppressWarnings("checkstyle:constantname")
37      public static final MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensity NaN = new MagneticFluxDensity(Double.NaN, MagneticFluxDensityUnit.SI);
38  
39      /** Constant with value POSITIVE_INFINITY. */
40      public static final MagneticFluxDensity POSITIVE_INFINITY =
41              new MagneticFluxDensity(Double.POSITIVE_INFINITY, MagneticFluxDensityUnit.SI);
42  
43      /** Constant with value NEGATIVE_INFINITY. */
44      public static final MagneticFluxDensity NEGATIVE_INFINITY =
45              new MagneticFluxDensity(Double.NEGATIVE_INFINITY, MagneticFluxDensityUnit.SI);
46  
47      /** Constant with value MAX_VALUE. */
48      public static final MagneticFluxDensity POS_MAXVALUE =
49              new MagneticFluxDensity(Double.MAX_VALUE, MagneticFluxDensityUnit.SI);
50  
51      /** Constant with value -MAX_VALUE. */
52      public static final MagneticFluxDensity NEG_MAXVALUE =
53              new MagneticFluxDensity(-Double.MAX_VALUE, MagneticFluxDensityUnit.SI);
54  
55      /**
56       * Construct MagneticFluxDensity scalar.
57       * @param value double; the double value
58       * @param unit MagneticFluxDensityUnit; unit for the double value
59       */
60      public MagneticFluxDensity(final double value, final MagneticFluxDensityUnit unit)
61      {
62          super(value, unit);
63      }
64  
65      /**
66       * Construct MagneticFluxDensity scalar.
67       * @param value MagneticFluxDensity; Scalar from which to construct this instance
68       */
69      public MagneticFluxDensityr/MagneticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensity(final MagneticFluxDensity value)
70      {
71          super(value);
72      }
73  
74      /** {@inheritDoc} */
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 MagneticFluxDensityeticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensityuxDensity.html#MagneticFluxDensity">MagneticFluxDensity interpolate(final MagneticFluxDensityeticFluxDensity.html#MagneticFluxDensity">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 MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensity max(final MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">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 MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensity max(final MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">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 MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensity min(final MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">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 MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">MagneticFluxDensity min(final MagneticFluxDensitygneticFluxDensity.html#MagneticFluxDensity">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 the official abbreviation of the unit.
172      * 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         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
184         if (matcher.find())
185         {
186             int index = matcher.end();
187             String unitString = text.substring(index).trim();
188             String valueString = text.substring(0, index).trim();
189             MagneticFluxDensityUnit unit = MagneticFluxDensityUnit.BASE.getUnitByAbbreviation(unitString);
190             if (unit != null)
191             {
192                 double d = Double.parseDouble(valueString);
193                 return new MagneticFluxDensity(d, unit);
194             }
195         }
196         throw new IllegalArgumentException("Error parsing MagneticFluxDensity from " + text);
197     }
198 
199     /**
200      * Returns a MagneticFluxDensity based on a value and the textual representation of the unit.
201      * @param value double; the value to use
202      * @param unitString String; the textual representation of the unit
203      * @return MagneticFluxDensity; the Scalar representation of the value in its unit
204      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
205      * @throws NullPointerException when the unitString argument is null
206      */
207     public static MagneticFluxDensity of(final double value, final String unitString)
208     {
209         Throw.whenNull(unitString, "Error parsing MagneticFluxDensity: unitString is null");
210         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
211                 "Error parsing MagneticFluxDensity: empty unitString");
212         MagneticFluxDensityUnit unit = MagneticFluxDensityUnit.BASE.getUnitByAbbreviation(unitString);
213         if (unit != null)
214         {
215             return new MagneticFluxDensity(value, unit);
216         }
217         throw new IllegalArgumentException("Error parsing MagneticFluxDensity with unit " + unitString);
218     }
219 
220     /**
221      * Calculate the division of MagneticFluxDensity and MagneticFluxDensity, which results in a Dimensionless scalar.
222      * @param v MagneticFluxDensity scalar
223      * @return Dimensionless scalar as a division of MagneticFluxDensity and MagneticFluxDensity
224      */
225     public final Dimensionless divide(final MagneticFluxDensity v)
226     {
227         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
228     }
229 
230     /**
231      * Calculate the multiplication of MagneticFluxDensity and Area, which results in a MagneticFlux scalar.
232      * @param v MagneticFluxDensity scalar
233      * @return MagneticFlux scalar as a multiplication of MagneticFluxDensity and Area
234      */
235     public final MagneticFlux times(final Area v)
236     {
237         return new MagneticFlux(this.si * v.si, MagneticFluxUnit.SI);
238     }
239 
240 }