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.EquivalentDoseUnit;
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 EquivalentDose 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 EquivalentDose extends DoubleScalarRel<EquivalentDoseUnit, EquivalentDose>
25  {
26      /** */
27      private static final long serialVersionUID = 20150905L;
28  
29      /** Constant with value zero. */
30      public static final EquivalentDose ZERO = new EquivalentDose(0.0, EquivalentDoseUnit.SI);
31  
32      /** Constant with value one. */
33      public static final EquivalentDose ONE = new EquivalentDose(1.0, EquivalentDoseUnit.SI);
34  
35      /** Constant with value NaN. */
36      @SuppressWarnings("checkstyle:constantname")
37      public static final EquivalentDose NaN = new EquivalentDose(Double.NaN, EquivalentDoseUnit.SI);
38  
39      /** Constant with value POSITIVE_INFINITY. */
40      public static final EquivalentDose POSITIVE_INFINITY = new EquivalentDose(Double.POSITIVE_INFINITY, EquivalentDoseUnit.SI);
41  
42      /** Constant with value NEGATIVE_INFINITY. */
43      public static final EquivalentDose NEGATIVE_INFINITY = new EquivalentDose(Double.NEGATIVE_INFINITY, EquivalentDoseUnit.SI);
44  
45      /** Constant with value MAX_VALUE. */
46      public static final EquivalentDose POS_MAXVALUE = new EquivalentDose(Double.MAX_VALUE, EquivalentDoseUnit.SI);
47  
48      /** Constant with value -MAX_VALUE. */
49      public static final EquivalentDose NEG_MAXVALUE = new EquivalentDose(-Double.MAX_VALUE, EquivalentDoseUnit.SI);
50  
51      /**
52       * Construct EquivalentDose scalar.
53       * @param value double; the double value
54       * @param unit EquivalentDoseUnit; unit for the double value
55       */
56      public EquivalentDose(final double value, final EquivalentDoseUnit unit)
57      {
58          super(value, unit);
59      }
60  
61      /**
62       * Construct EquivalentDose scalar.
63       * @param value EquivalentDose; Scalar from which to construct this instance
64       */
65      public EquivalentDose(final EquivalentDose value)
66      {
67          super(value);
68      }
69  
70      @Override
71      public final EquivalentDose instantiateRel(final double value, final EquivalentDoseUnit unit)
72      {
73          return new EquivalentDose(value, unit);
74      }
75  
76      /**
77       * Construct EquivalentDose scalar.
78       * @param value double; the double value in SI units
79       * @return EquivalentDose; the new scalar with the SI value
80       */
81      public static final EquivalentDose instantiateSI(final double value)
82      {
83          return new EquivalentDose(value, EquivalentDoseUnit.SI);
84      }
85  
86      /**
87       * Interpolate between two values.
88       * @param zero EquivalentDose; the low value
89       * @param one EquivalentDose; the high value
90       * @param ratio double; the ratio between 0 and 1, inclusive
91       * @return EquivalentDose; a Scalar at the ratio between
92       */
93      public static EquivalentDose interpolate(final EquivalentDose zero, final EquivalentDose one, final double ratio)
94      {
95          return new EquivalentDose(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 EquivalentDose; the first scalar
102      * @param r2 EquivalentDose; the second scalar
103      * @return EquivalentDose; the maximum value of two relative scalars
104      */
105     public static EquivalentDose max(final EquivalentDose r1, final EquivalentDose 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 EquivalentDose; the first scalar
113      * @param r2 EquivalentDose; the second scalar
114      * @param rn EquivalentDose...; the other scalars
115      * @return EquivalentDose; the maximum value of more than two relative scalars
116      */
117     public static EquivalentDose max(final EquivalentDose r1, final EquivalentDose r2, final EquivalentDose... rn)
118     {
119         EquivalentDose maxr = r1.gt(r2) ? r1 : r2;
120         for (EquivalentDose 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 EquivalentDose; the first scalar
133      * @param r2 EquivalentDose; the second scalar
134      * @return EquivalentDose; the minimum value of two relative scalars
135      */
136     public static EquivalentDose min(final EquivalentDose r1, final EquivalentDose 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 EquivalentDose; the first scalar
144      * @param r2 EquivalentDose; the second scalar
145      * @param rn EquivalentDose...; the other scalars
146      * @return EquivalentDose; the minimum value of more than two relative scalars
147      */
148     public static EquivalentDose min(final EquivalentDose r1, final EquivalentDose r2, final EquivalentDose... rn)
149     {
150         EquivalentDose minr = r1.lt(r2) ? r1 : r2;
151         for (EquivalentDose r : rn)
152         {
153             if (r.lt(minr))
154             {
155                 minr = r;
156             }
157         }
158         return minr;
159     }
160 
161     /**
162      * Returns a EquivalentDose representation of a textual representation of a value with a unit. The String representation
163      * that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces
164      * are allowed, but not required, between the value and the unit.
165      * @param text String; the textual representation to parse into a EquivalentDose
166      * @return EquivalentDose; 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 EquivalentDose valueOf(final String text)
171     {
172         Throw.whenNull(text, "Error parsing EquivalentDose: text to parse is null");
173         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing EquivalentDose: 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             EquivalentDoseUnit unit = EquivalentDoseUnit.BASE.getUnitByAbbreviation(unitString);
180             if (unit == null)
181                 throw new IllegalArgumentException("Unit " + unitString + " not found");
182             return new EquivalentDose(d, unit);
183         }
184         catch (Exception exception)
185         {
186             throw new IllegalArgumentException(
187                     "Error parsing EquivalentDose from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
188                     exception);
189         }
190     }
191 
192     /**
193      * Returns a EquivalentDose 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 EquivalentDose; 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 EquivalentDose of(final double value, final String unitString)
201     {
202         Throw.whenNull(unitString, "Error parsing EquivalentDose: unitString is null");
203         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing EquivalentDose: empty unitString");
204         EquivalentDoseUnit unit = EquivalentDoseUnit.BASE.getUnitByAbbreviation(unitString);
205         if (unit != null)
206         {
207             return new EquivalentDose(value, unit);
208         }
209         throw new IllegalArgumentException("Error parsing EquivalentDose with unit " + unitString);
210     }
211 
212     /**
213      * Calculate the division of EquivalentDose and EquivalentDose, which results in a Dimensionless scalar.
214      * @param v EquivalentDose; scalar
215      * @return Dimensionless; scalar as a division of EquivalentDose and EquivalentDose
216      */
217     public final Dimensionless divide(final EquivalentDose 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 }