View Javadoc
1   package org.djunits.value.vfloat.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.vfloat.scalar.base.AbstractFloatScalarRel;
12  
13  /**
14   * Easy access methods for the FloatAbsorbedDose FloatScalar, 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 FloatAbsorbedDose extends AbstractFloatScalarRel<AbsorbedDoseUnit, FloatAbsorbedDose>
24  {
25      /** */
26      private static final long serialVersionUID = 20150901L;
27  
28      /** Constant with value zero. */
29      public static final FloatAbsorbedDoseoatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose ZERO = new FloatAbsorbedDose(0.0f, AbsorbedDoseUnit.SI);
30  
31      /** Constant with value one. */
32      public static final FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose ONE = new FloatAbsorbedDose(1.0f, AbsorbedDoseUnit.SI);
33  
34      /** Constant with value NaN. */
35      @SuppressWarnings("checkstyle:constantname")
36      public static final FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">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 FloatAbsorbedDosebedDose.html#FloatAbsorbedDose">FloatAbsorbedDose POS_MAXVALUE = new FloatAbsorbedDose(Float.MAX_VALUE, AbsorbedDoseUnit.SI);
48  
49      /** Constant with value -MAX_VALUE. */
50      public static final FloatAbsorbedDosebedDose.html#FloatAbsorbedDose">FloatAbsorbedDose NEG_MAXVALUE = new FloatAbsorbedDose(-Float.MAX_VALUE, AbsorbedDoseUnit.SI);
51  
52      /**
53       * Construct FloatAbsorbedDose scalar.
54       * @param value float; the float value
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 FloatAbsorbedDosear/FloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose(final FloatAbsorbedDose value)
67      {
68          super(value);
69      }
70  
71      /**
72       * Construct FloatAbsorbedDose scalar using a double value.
73       * @param value double; the double value
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      /** {@inheritDoc} */
82      @Override
83      public final FloatAbsorbedDose instantiateRel(final float value, final AbsorbedDoseUnit unit)
84      {
85          return new FloatAbsorbedDose(value, unit);
86      }
87  
88      /**
89       * Construct FloatAbsorbedDose scalar.
90       * @param value float; the float value in SI units
91       * @return the new scalar with the SI value
92       */
93      public static final FloatAbsorbedDose instantiateSI(final float value)
94      {
95          return new FloatAbsorbedDose(value, AbsorbedDoseUnit.SI);
96      }
97  
98      /**
99       * Interpolate between two values.
100      * @param zero the low value
101      * @param one the high value
102      * @param ratio double; the ratio between 0 and 1, inclusive
103      * @return a Scalar at the ratio between
104      */
105     public static FloatAbsorbedDoseatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDoserbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose interpolate(final FloatAbsorbedDoseatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose zero, final FloatAbsorbedDose one, final float ratio)
106     {
107         return new FloatAbsorbedDose(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
108                 zero.getDisplayUnit());
109     }
110 
111     /**
112      * Return the maximum value of two relative scalars.
113      * @param r1 the first scalar
114      * @param r2 the second scalar
115      * @return the maximum value of two relative scalars
116      */
117     public static FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose max(final FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose r1, final FloatAbsorbedDose r2)
118     {
119         return (r1.gt(r2)) ? r1 : r2;
120     }
121 
122     /**
123      * Return the maximum value of more than two relative scalars.
124      * @param r1 the first scalar
125      * @param r2 the second scalar
126      * @param rn the other scalars
127      * @return the maximum value of more than two relative scalars
128      */
129     public static FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose max(final FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose r1, final FloatAbsorbedDose r2, final FloatAbsorbedDose... rn)
130     {
131         FloatAbsorbedDose maxr = (r1.gt(r2)) ? r1 : r2;
132         for (FloatAbsorbedDose r : rn)
133         {
134             if (r.gt(maxr))
135             {
136                 maxr = r;
137             }
138         }
139         return maxr;
140     }
141 
142     /**
143      * Return the minimum value of two relative scalars.
144      * @param r1 the first scalar
145      * @param r2 the second scalar
146      * @return the minimum value of two relative scalars
147      */
148     public static FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose min(final FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose r1, final FloatAbsorbedDose r2)
149     {
150         return (r1.lt(r2)) ? r1 : r2;
151     }
152 
153     /**
154      * Return the minimum value of more than two relative scalars.
155      * @param r1 the first scalar
156      * @param r2 the second scalar
157      * @param rn the other scalars
158      * @return the minimum value of more than two relative scalars
159      */
160     public static FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose min(final FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose r1, final FloatAbsorbedDose r2, final FloatAbsorbedDose... rn)
161     {
162         FloatAbsorbedDose minr = (r1.lt(r2)) ? r1 : r2;
163         for (FloatAbsorbedDose r : rn)
164         {
165             if (r.lt(minr))
166             {
167                 minr = r;
168             }
169         }
170         return minr;
171     }
172 
173     /**
174      * Returns a FloatAbsorbedDose representation of a textual representation of a value with a unit. The String representation
175      * that can be parsed is the double value in the unit, followed by the official abbreviation of the unit. Spaces are
176      * allowed, but not required, between the value and the unit.
177      * @param text String; the textual representation to parse into a FloatAbsorbedDose
178      * @return FloatAbsorbedDose; the Scalar representation of the value in its unit
179      * @throws IllegalArgumentException when the text cannot be parsed
180      * @throws NullPointerException when the text argument is null
181      */
182     public static FloatAbsorbedDose valueOf(final String text)
183     {
184         Throw.whenNull(text, "Error parsing FloatAbsorbedDose: text to parse is null");
185         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatAbsorbedDose: empty text to parse");
186         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
187         if (matcher.find())
188         {
189             int index = matcher.end();
190             String unitString = text.substring(index).trim();
191             String valueString = text.substring(0, index).trim();
192             AbsorbedDoseUnit unit = AbsorbedDoseUnit.BASE.getUnitByAbbreviation(unitString);
193             if (unit != null)
194             {
195                 float f = Float.parseFloat(valueString);
196                 return new FloatAbsorbedDose(f, unit);
197             }
198         }
199         throw new IllegalArgumentException("Error parsing FloatAbsorbedDose from " + text);
200     }
201 
202     /**
203      * Returns a FloatAbsorbedDose based on a value and the textual representation of the unit.
204      * @param value double; the value to use
205      * @param unitString String; the textual representation of the unit
206      * @return FloatAbsorbedDose; the Scalar representation of the value in its unit
207      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
208      * @throws NullPointerException when the unitString argument is null
209      */
210     public static FloatAbsorbedDose of(final float value, final String unitString)
211     {
212         Throw.whenNull(unitString, "Error parsing FloatAbsorbedDose: unitString is null");
213         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
214                 "Error parsing FloatAbsorbedDose: empty unitString");
215         AbsorbedDoseUnit unit = AbsorbedDoseUnit.BASE.getUnitByAbbreviation(unitString);
216         if (unit != null)
217         {
218             return new FloatAbsorbedDose(value, unit);
219         }
220         throw new IllegalArgumentException("Error parsing FloatAbsorbedDose with unit " + unitString);
221     }
222 
223     /**
224      * Calculate the division of FloatAbsorbedDose and FloatAbsorbedDose, which results in a FloatDimensionless scalar.
225      * @param v FloatAbsorbedDose scalar
226      * @return FloatDimensionless scalar as a division of FloatAbsorbedDose and FloatAbsorbedDose
227      */
228     public final FloatDimensionless divide(final FloatAbsorbedDose v)
229     {
230         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
231     }
232 
233 }