View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.AbsorbedDoseUnit;
6   import org.djunits.unit.DimensionlessUnit;
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 FloatAbsorbedDose 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 FloatAbsorbedDose extends FloatScalarRel<AbsorbedDoseUnit, FloatAbsorbedDose>
24  {
25      /** */
26      private static final long serialVersionUID = 20150901L;
27  
28      /** Constant with value zero. */
29      public static final FloatAbsorbedDose ZERO = new FloatAbsorbedDose(0.0f, AbsorbedDoseUnit.SI);
30  
31      /** Constant with value one. */
32      public static final FloatAbsorbedDose ONE = new FloatAbsorbedDose(1.0f, AbsorbedDoseUnit.SI);
33  
34      /** Constant with value NaN. */
35      @SuppressWarnings("checkstyle:constantname")
36      public static final FloatAbsorbedDose NaN = new FloatAbsorbedDose(Float.NaN, AbsorbedDoseUnit.SI);
37  
38      /** Constant with value POSITIVE_INFINITY. */
39      public static final FloatAbsorbedDose POSITIVE_INFINITY =
40              new FloatAbsorbedDose(Float.POSITIVE_INFINITY, AbsorbedDoseUnit.SI);
41  
42      /** Constant with value NEGATIVE_INFINITY. */
43      public static final FloatAbsorbedDose NEGATIVE_INFINITY =
44              new FloatAbsorbedDose(Float.NEGATIVE_INFINITY, AbsorbedDoseUnit.SI);
45  
46      /** Constant with value MAX_VALUE. */
47      public static final FloatAbsorbedDose POS_MAXVALUE = new FloatAbsorbedDose(Float.MAX_VALUE, AbsorbedDoseUnit.SI);
48  
49      /** Constant with value -MAX_VALUE. */
50      public static final FloatAbsorbedDose NEG_MAXVALUE = new FloatAbsorbedDose(-Float.MAX_VALUE, AbsorbedDoseUnit.SI);
51  
52      /**
53       * Construct FloatAbsorbedDose 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 FloatAbsorbedDose(final float value, final AbsorbedDoseUnit unit)
58      {
59          super(value, unit);
60      }
61  
62      /**
63       * Construct FloatAbsorbedDose scalar.
64       * @param value Scalar from which to construct this instance
65       */
66      public FloatAbsorbedDose(final FloatAbsorbedDose value)
67      {
68          super(value);
69      }
70  
71      /**
72       * Construct FloatAbsorbedDose 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 FloatAbsorbedDose(final double value, final AbsorbedDoseUnit unit)
77      {
78          super((float) value, unit);
79      }
80  
81      @Override
82      public final FloatAbsorbedDose instantiateRel(final float value, final AbsorbedDoseUnit unit)
83      {
84          return new FloatAbsorbedDose(value, unit);
85      }
86  
87      /**
88       * Construct FloatAbsorbedDose 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 FloatAbsorbedDose ofSI(final float value)
93      {
94          return new FloatAbsorbedDose(value, AbsorbedDoseUnit.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 FloatAbsorbedDose at the given ratio between 0 and 1
103      */
104     public static FloatAbsorbedDose interpolate(final FloatAbsorbedDose zero, final FloatAbsorbedDose one, final float ratio)
105     {
106         Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
107                 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
108         return new FloatAbsorbedDose(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
109                 zero.getDisplayUnit());
110     }
111 
112     /**
113      * Return the maximum value of two relative scalars.
114      * @param r1 the first scalar
115      * @param r2 the second scalar
116      * @return the maximum value of two relative scalars
117      */
118     public static FloatAbsorbedDose max(final FloatAbsorbedDose r1, final FloatAbsorbedDose r2)
119     {
120         return r1.gt(r2) ? r1 : r2;
121     }
122 
123     /**
124      * Return the maximum value of more than two relative scalars.
125      * @param r1 the first scalar
126      * @param r2 the second scalar
127      * @param rn the other scalars
128      * @return the maximum value of more than two relative scalars
129      */
130     public static FloatAbsorbedDose max(final FloatAbsorbedDose r1, final FloatAbsorbedDose r2, final FloatAbsorbedDose... rn)
131     {
132         FloatAbsorbedDose maxr = r1.gt(r2) ? r1 : r2;
133         for (FloatAbsorbedDose r : rn)
134         {
135             if (r.gt(maxr))
136             {
137                 maxr = r;
138             }
139         }
140         return maxr;
141     }
142 
143     /**
144      * Return the minimum value of two relative scalars.
145      * @param r1 the first scalar
146      * @param r2 the second scalar
147      * @return the minimum value of two relative scalars
148      */
149     public static FloatAbsorbedDose min(final FloatAbsorbedDose r1, final FloatAbsorbedDose r2)
150     {
151         return r1.lt(r2) ? r1 : r2;
152     }
153 
154     /**
155      * Return the minimum value of more than two relative scalars.
156      * @param r1 the first scalar
157      * @param r2 the second scalar
158      * @param rn the other scalars
159      * @return the minimum value of more than two relative scalars
160      */
161     public static FloatAbsorbedDose min(final FloatAbsorbedDose r1, final FloatAbsorbedDose r2, final FloatAbsorbedDose... rn)
162     {
163         FloatAbsorbedDose minr = r1.lt(r2) ? r1 : r2;
164         for (FloatAbsorbedDose r : rn)
165         {
166             if (r.lt(minr))
167             {
168                 minr = r;
169             }
170         }
171         return minr;
172     }
173 
174     /**
175      * Returns a FloatAbsorbedDose representation of a textual representation of a value with a unit. The String representation
176      * that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces
177      * are allowed, but not required, between the value and the unit.
178      * @param text the textual representation to parse into a FloatAbsorbedDose
179      * @return the Scalar representation of the value in its unit
180      * @throws IllegalArgumentException when the text cannot be parsed
181      * @throws NullPointerException when the text argument is null
182      */
183     public static FloatAbsorbedDose valueOf(final String text)
184     {
185         Throw.whenNull(text, "Error parsing FloatAbsorbedDose: text to parse is null");
186         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatAbsorbedDose: empty text to parse");
187         try
188         {
189             NumberParser numberParser = new NumberParser().lenient().trailing();
190             float f = numberParser.parseFloat(text);
191             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
192             AbsorbedDoseUnit unit = AbsorbedDoseUnit.BASE.getUnitByAbbreviation(unitString);
193             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity AbsorbedDose", unitString);
194             return new FloatAbsorbedDose(f, unit);
195         }
196         catch (Exception exception)
197         {
198             throw new IllegalArgumentException("Error parsing FloatAbsorbedDose from " + text + " using Locale "
199                     + Locale.getDefault(Locale.Category.FORMAT), exception);
200         }
201     }
202 
203     /**
204      * Returns a FloatAbsorbedDose based on a value and the textual representation of the unit, which can be localized.
205      * @param value the value to use
206      * @param unitString the textual representation of the unit
207      * @return the Scalar representation of the value in its unit
208      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
209      * @throws NullPointerException when the unitString argument is null
210      */
211     public static FloatAbsorbedDose of(final float value, final String unitString)
212     {
213         Throw.whenNull(unitString, "Error parsing FloatAbsorbedDose: unitString is null");
214         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
215                 "Error parsing FloatAbsorbedDose: empty unitString");
216         AbsorbedDoseUnit unit = AbsorbedDoseUnit.BASE.getUnitByAbbreviation(unitString);
217         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FloatAbsorbedDose with unit %s", unitString);
218         return new FloatAbsorbedDose(value, unit);
219     }
220 
221     /**
222      * Calculate the division of FloatAbsorbedDose and FloatAbsorbedDose, which results in a FloatDimensionless scalar.
223      * @param v scalar
224      * @return scalar as a division of FloatAbsorbedDose and FloatAbsorbedDose
225      */
226     public final FloatDimensionless divide(final FloatAbsorbedDose v)
227     {
228         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
229     }
230 
231     @Override
232     public FloatSIScalar reciprocal()
233     {
234         return FloatSIScalar.divide(FloatDimensionless.ONE, this);
235     }
236 
237     /**
238      * Multiply two scalars that result in a scalar of type FloatAbsorbedDose.
239      * @param scalar1 the first scalar
240      * @param scalar2 the second scalar
241      * @return the multiplication of both scalars as an instance of FloatAbsorbedDose
242      */
243     public static FloatAbsorbedDose multiply(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
244     {
245         Throw.whenNull(scalar1, "scalar1 cannot be null");
246         Throw.whenNull(scalar2, "scalar2 cannot be null");
247         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
248                 .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(AbsorbedDoseUnit.BASE.getSiDimensions()),
249                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type FloatAbsorbedDose",
250                 scalar1.toDisplayString(), scalar2.toDisplayString());
251         return new FloatAbsorbedDose(scalar1.si * scalar2.si, AbsorbedDoseUnit.SI);
252     }
253 
254     /**
255      * Divide two scalars that result in a scalar of type FloatAbsorbedDose.
256      * @param scalar1 the first scalar
257      * @param scalar2 the second scalar
258      * @return the division of scalar1 by scalar2 as an instance of FloatAbsorbedDose
259      */
260     public static FloatAbsorbedDose divide(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
261     {
262         Throw.whenNull(scalar1, "scalar1 cannot be null");
263         Throw.whenNull(scalar2, "scalar2 cannot be null");
264         Throw.when(
265                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
266                         .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
267                         .equals(AbsorbedDoseUnit.BASE.getSiDimensions()),
268                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type FloatAbsorbedDose",
269                 scalar1.toDisplayString(), scalar2.toDisplayString());
270         return new FloatAbsorbedDose(scalar1.si / scalar2.si, AbsorbedDoseUnit.SI);
271     }
272 
273 }