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