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.AbsorbedDoseUnit;
9   import org.djunits.unit.DimensionlessUnit;
10  import org.djunits.value.util.ValueUtil;
11  import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRel;
12  
13  /**
14   * Easy access methods for the AbsorbedDose DoubleScalar, which is relative by definition.
15   * <p>
16   * Copyright (c) 2013-2019 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 = "2019-10-18T12:12:25.568Z")
23  public class AbsorbedDose extends AbstractDoubleScalarRel<AbsorbedDoseUnit, AbsorbedDose>
24  {
25      /** */
26      private static final long serialVersionUID = 20150905L;
27  
28      /** Constant with value zero. */
29      public static final AbsorbedDoselar/AbsorbedDose.html#AbsorbedDose">AbsorbedDose ZERO = new AbsorbedDose(0.0, AbsorbedDoseUnit.SI);
30  
31      /** Constant with value one. */
32      public static final AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">AbsorbedDose ONE = new AbsorbedDose(1.0, AbsorbedDoseUnit.SI);
33  
34      /** Constant with value NaN. */
35      @SuppressWarnings("checkstyle:constantname")
36      public static final AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">AbsorbedDose NaN = new AbsorbedDose(Double.NaN, AbsorbedDoseUnit.SI);
37  
38      /** Constant with value POSITIVE_INFINITY. */
39      public static final AbsorbedDoseose.html#AbsorbedDose">AbsorbedDose POSITIVE_INFINITY = new AbsorbedDose(Double.POSITIVE_INFINITY, AbsorbedDoseUnit.SI);
40  
41      /** Constant with value NEGATIVE_INFINITY. */
42      public static final AbsorbedDoseose.html#AbsorbedDose">AbsorbedDose NEGATIVE_INFINITY = new AbsorbedDose(Double.NEGATIVE_INFINITY, AbsorbedDoseUnit.SI);
43  
44      /** Constant with value MAX_VALUE. */
45      public static final AbsorbedDoserbedDose.html#AbsorbedDose">AbsorbedDose POS_MAXVALUE = new AbsorbedDose(Double.MAX_VALUE, AbsorbedDoseUnit.SI);
46  
47      /** Constant with value -MAX_VALUE. */
48      public static final AbsorbedDoserbedDose.html#AbsorbedDose">AbsorbedDose NEG_MAXVALUE = new AbsorbedDose(-Double.MAX_VALUE, AbsorbedDoseUnit.SI);
49  
50      /**
51       * Construct AbsorbedDose scalar.
52       * @param value double; the double value
53       * @param unit AbsorbedDoseUnit; unit for the double value
54       */
55      public AbsorbedDose(final double value, final AbsorbedDoseUnit unit)
56      {
57          super(value, unit);
58      }
59  
60      /**
61       * Construct AbsorbedDose scalar.
62       * @param value AbsorbedDose; Scalar from which to construct this instance
63       */
64      public AbsorbedDosee/scalar/AbsorbedDose.html#AbsorbedDose">AbsorbedDose(final AbsorbedDose value)
65      {
66          super(value);
67      }
68  
69      /** {@inheritDoc} */
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 AbsorbedDosear/AbsorbedDose.html#AbsorbedDose">AbsorbedDoseorbedDose.html#AbsorbedDose">AbsorbedDose interpolate(final AbsorbedDosear/AbsorbedDose.html#AbsorbedDose">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 AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">AbsorbedDose max(final AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">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 AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">AbsorbedDose max(final AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">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 AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">AbsorbedDose min(final AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">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 AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">AbsorbedDose min(final AbsorbedDosealar/AbsorbedDose.html#AbsorbedDose">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 the official abbreviation of the unit. Spaces are allowed, but
164      * 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         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
175         if (matcher.find())
176         {
177             int index = matcher.end();
178             String unitString = text.substring(index).trim();
179             String valueString = text.substring(0, index).trim();
180             AbsorbedDoseUnit unit = AbsorbedDoseUnit.BASE.getUnitByAbbreviation(unitString);
181             if (unit != null)
182             {
183                 double d = Double.parseDouble(valueString);
184                 return new AbsorbedDose(d, unit);
185             }
186         }
187         throw new IllegalArgumentException("Error parsing AbsorbedDose from " + text);
188     }
189 
190     /**
191      * Returns a AbsorbedDose based on a value and the textual representation of the unit.
192      * @param value double; the value to use
193      * @param unitString String; the textual representation of the unit
194      * @return AbsorbedDose; the Scalar representation of the value in its unit
195      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
196      * @throws NullPointerException when the unitString argument is null
197      */
198     public static AbsorbedDose of(final double value, final String unitString)
199     {
200         Throw.whenNull(unitString, "Error parsing AbsorbedDose: unitString is null");
201         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing AbsorbedDose: empty unitString");
202         AbsorbedDoseUnit unit = AbsorbedDoseUnit.BASE.getUnitByAbbreviation(unitString);
203         if (unit != null)
204         {
205             return new AbsorbedDose(value, unit);
206         }
207         throw new IllegalArgumentException("Error parsing AbsorbedDose with unit " + unitString);
208     }
209 
210     /**
211      * Calculate the division of AbsorbedDose and AbsorbedDose, which results in a Dimensionless scalar.
212      * @param v AbsorbedDose scalar
213      * @return Dimensionless scalar as a division of AbsorbedDose and AbsorbedDose
214      */
215     public final Dimensionless divide(final AbsorbedDose v)
216     {
217         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
218     }
219 
220 }