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.EquivalentDoseUnit;
7   import org.djunits.value.vfloat.scalar.base.FloatScalarRel;
8   import org.djutils.base.NumberParser;
9   import org.djutils.exceptions.Throw;
10  
11  import jakarta.annotation.Generated;
12  
13  /**
14   * Easy access methods for the FloatEquivalentDose FloatScalar, which is relative by definition.
15   * <p>
16   * Copyright (c) 2013-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
17   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
18   * </p>
19   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
21   */
22  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2025-09-06T15:16:28.380798Z")
23  public class FloatEquivalentDose extends FloatScalarRel<EquivalentDoseUnit, FloatEquivalentDose>
24  {
25      /** */
26      private static final long serialVersionUID = 20150901L;
27  
28      /** Constant with value zero. */
29      public static final FloatEquivalentDose ZERO = new FloatEquivalentDose(0.0f, EquivalentDoseUnit.SI);
30  
31      /** Constant with value one. */
32      public static final FloatEquivalentDose ONE = new FloatEquivalentDose(1.0f, EquivalentDoseUnit.SI);
33  
34      /** Constant with value NaN. */
35      @SuppressWarnings("checkstyle:constantname")
36      public static final FloatEquivalentDose NaN = new FloatEquivalentDose(Float.NaN, EquivalentDoseUnit.SI);
37  
38      /** Constant with value POSITIVE_INFINITY. */
39      public static final FloatEquivalentDose POSITIVE_INFINITY =
40              new FloatEquivalentDose(Float.POSITIVE_INFINITY, EquivalentDoseUnit.SI);
41  
42      /** Constant with value NEGATIVE_INFINITY. */
43      public static final FloatEquivalentDose NEGATIVE_INFINITY =
44              new FloatEquivalentDose(Float.NEGATIVE_INFINITY, EquivalentDoseUnit.SI);
45  
46      /** Constant with value MAX_VALUE. */
47      public static final FloatEquivalentDose POS_MAXVALUE = new FloatEquivalentDose(Float.MAX_VALUE, EquivalentDoseUnit.SI);
48  
49      /** Constant with value -MAX_VALUE. */
50      public static final FloatEquivalentDose NEG_MAXVALUE = new FloatEquivalentDose(-Float.MAX_VALUE, EquivalentDoseUnit.SI);
51  
52      /**
53       * Construct FloatEquivalentDose scalar with a unit.
54       * @param value the float value, expressed in the given unit
55       * @param unit unit for the float value
56       */
57      public FloatEquivalentDose(final float value, final EquivalentDoseUnit unit)
58      {
59          super(value, unit);
60      }
61  
62      /**
63       * Construct FloatEquivalentDose scalar.
64       * @param value Scalar from which to construct this instance
65       */
66      public FloatEquivalentDose(final FloatEquivalentDose value)
67      {
68          super(value);
69      }
70  
71      /**
72       * Construct FloatEquivalentDose scalar with a unit using a double value.
73       * @param value the double value, expressed in the given unit
74       * @param unit unit for the resulting float value
75       */
76      public FloatEquivalentDose(final double value, final EquivalentDoseUnit unit)
77      {
78          super((float) value, unit);
79      }
80  
81      @Override
82      public final FloatEquivalentDose instantiateRel(final float value, final EquivalentDoseUnit unit)
83      {
84          return new FloatEquivalentDose(value, unit);
85      }
86  
87      /**
88       * Construct FloatEquivalentDose scalar based on an SI value.
89       * @param value the float value in SI units
90       * @return the new scalar with the SI value
91       */
92      public static final FloatEquivalentDose ofSI(final float value)
93      {
94          return new FloatEquivalentDose(value, EquivalentDoseUnit.SI);
95      }
96  
97      /**
98       * Interpolate between two values. Note that the first value does not have to be smaller than the second.
99       * @param zero the value at a ratio of zero
100      * @param one the value at a ratio of one
101      * @param ratio the ratio between 0 and 1, inclusive
102      * @return a FloatEquivalentDose at the given ratio between 0 and 1
103      */
104     public static FloatEquivalentDose interpolate(final FloatEquivalentDose zero, final FloatEquivalentDose one,
105             final float ratio)
106     {
107         Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
108                 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
109         return new FloatEquivalentDose(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
110                 zero.getDisplayUnit());
111     }
112 
113     /**
114      * Return the maximum value of two relative scalars.
115      * @param r1 the first scalar
116      * @param r2 the second scalar
117      * @return the maximum value of two relative scalars
118      */
119     public static FloatEquivalentDose max(final FloatEquivalentDose r1, final FloatEquivalentDose r2)
120     {
121         return r1.gt(r2) ? r1 : r2;
122     }
123 
124     /**
125      * Return the maximum value of more than two relative scalars.
126      * @param r1 the first scalar
127      * @param r2 the second scalar
128      * @param rn the other scalars
129      * @return the maximum value of more than two relative scalars
130      */
131     public static FloatEquivalentDose max(final FloatEquivalentDose r1, final FloatEquivalentDose r2,
132             final FloatEquivalentDose... rn)
133     {
134         FloatEquivalentDose maxr = r1.gt(r2) ? r1 : r2;
135         for (FloatEquivalentDose r : rn)
136         {
137             if (r.gt(maxr))
138             {
139                 maxr = r;
140             }
141         }
142         return maxr;
143     }
144 
145     /**
146      * Return the minimum value of two relative scalars.
147      * @param r1 the first scalar
148      * @param r2 the second scalar
149      * @return the minimum value of two relative scalars
150      */
151     public static FloatEquivalentDose min(final FloatEquivalentDose r1, final FloatEquivalentDose r2)
152     {
153         return r1.lt(r2) ? r1 : r2;
154     }
155 
156     /**
157      * Return the minimum value of more than two relative scalars.
158      * @param r1 the first scalar
159      * @param r2 the second scalar
160      * @param rn the other scalars
161      * @return the minimum value of more than two relative scalars
162      */
163     public static FloatEquivalentDose min(final FloatEquivalentDose r1, final FloatEquivalentDose r2,
164             final FloatEquivalentDose... rn)
165     {
166         FloatEquivalentDose minr = r1.lt(r2) ? r1 : r2;
167         for (FloatEquivalentDose r : rn)
168         {
169             if (r.lt(minr))
170             {
171                 minr = r;
172             }
173         }
174         return minr;
175     }
176 
177     /**
178      * Returns a FloatEquivalentDose representation of a textual representation of a value with a unit. The String
179      * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
180      * unit. Spaces are allowed, but not required, between the value and the unit.
181      * @param text the textual representation to parse into a FloatEquivalentDose
182      * @return the Scalar representation of the value in its unit
183      * @throws IllegalArgumentException when the text cannot be parsed
184      * @throws NullPointerException when the text argument is null
185      */
186     public static FloatEquivalentDose valueOf(final String text)
187     {
188         Throw.whenNull(text, "Error parsing FloatEquivalentDose: text to parse is null");
189         Throw.when(text.length() == 0, IllegalArgumentException.class,
190                 "Error parsing FloatEquivalentDose: empty text to parse");
191         try
192         {
193             NumberParser numberParser = new NumberParser().lenient().trailing();
194             float f = numberParser.parseFloat(text);
195             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
196             EquivalentDoseUnit unit = EquivalentDoseUnit.BASE.getUnitByAbbreviation(unitString);
197             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity EquivalentDose",
198                     unitString);
199             return new FloatEquivalentDose(f, unit);
200         }
201         catch (Exception exception)
202         {
203             throw new IllegalArgumentException("Error parsing FloatEquivalentDose from " + text + " using Locale "
204                     + Locale.getDefault(Locale.Category.FORMAT), exception);
205         }
206     }
207 
208     /**
209      * Returns a FloatEquivalentDose based on a value and the textual representation of the unit, which can be localized.
210      * @param value the value to use
211      * @param unitString the textual representation of the unit
212      * @return the Scalar representation of the value in its unit
213      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
214      * @throws NullPointerException when the unitString argument is null
215      */
216     public static FloatEquivalentDose of(final float value, final String unitString)
217     {
218         Throw.whenNull(unitString, "Error parsing FloatEquivalentDose: unitString is null");
219         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
220                 "Error parsing FloatEquivalentDose: empty unitString");
221         EquivalentDoseUnit unit = EquivalentDoseUnit.BASE.getUnitByAbbreviation(unitString);
222         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FloatEquivalentDose with unit %s", unitString);
223         return new FloatEquivalentDose(value, unit);
224     }
225 
226     /**
227      * Calculate the division of FloatEquivalentDose and FloatEquivalentDose, which results in a FloatDimensionless scalar.
228      * @param v scalar
229      * @return scalar as a division of FloatEquivalentDose and FloatEquivalentDose
230      */
231     public final FloatDimensionless divide(final FloatEquivalentDose v)
232     {
233         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
234     }
235 
236     @Override
237     public FloatSIScalar reciprocal()
238     {
239         return FloatSIScalar.divide(FloatDimensionless.ONE, this);
240     }
241 
242     /**
243      * Multiply two scalars that result in a scalar of type FloatEquivalentDose.
244      * @param scalar1 the first scalar
245      * @param scalar2 the second scalar
246      * @return the multiplication of both scalars as an instance of FloatEquivalentDose
247      */
248     public static FloatEquivalentDose multiply(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
249     {
250         Throw.whenNull(scalar1, "scalar1 cannot be null");
251         Throw.whenNull(scalar2, "scalar2 cannot be null");
252         Throw.when(
253                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
254                         .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
255                         .equals(EquivalentDoseUnit.BASE.getSiDimensions()),
256                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type FloatEquivalentDose",
257                 scalar1.toDisplayString(), scalar2.toDisplayString());
258         return new FloatEquivalentDose(scalar1.si * scalar2.si, EquivalentDoseUnit.SI);
259     }
260 
261     /**
262      * Divide two scalars that result in a scalar of type FloatEquivalentDose.
263      * @param scalar1 the first scalar
264      * @param scalar2 the second scalar
265      * @return the division of scalar1 by scalar2 as an instance of FloatEquivalentDose
266      */
267     public static FloatEquivalentDose divide(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
268     {
269         Throw.whenNull(scalar1, "scalar1 cannot be null");
270         Throw.whenNull(scalar2, "scalar2 cannot be null");
271         Throw.when(
272                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
273                         .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
274                         .equals(EquivalentDoseUnit.BASE.getSiDimensions()),
275                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type FloatEquivalentDose",
276                 scalar1.toDisplayString(), scalar2.toDisplayString());
277         return new FloatEquivalentDose(scalar1.si / scalar2.si, EquivalentDoseUnit.SI);
278     }
279 
280 }