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  import org.djunits.value.vfloat.scalar.base.FloatScalar;
13  
14  /**
15   * Easy access methods for the FloatAbsorbedDose FloatScalar, which is relative by definition.
16   * <p>
17   * Copyright (c) 2013-2022 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 = "2022-03-14T11:14:15.180987200Z")
24  public class FloatAbsorbedDose extends AbstractFloatScalarRel<AbsorbedDoseUnit, FloatAbsorbedDose>
25  {
26      /** */
27      private static final long serialVersionUID = 20150901L;
28  
29      /** Constant with value zero. */
30      public static final FloatAbsorbedDoseoatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose ZERO = new FloatAbsorbedDose(0.0f, AbsorbedDoseUnit.SI);
31  
32      /** Constant with value one. */
33      public static final FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose ONE = new FloatAbsorbedDose(1.0f, AbsorbedDoseUnit.SI);
34  
35      /** Constant with value NaN. */
36      @SuppressWarnings("checkstyle:constantname")
37      public static final FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose NaN = new FloatAbsorbedDose(Float.NaN, AbsorbedDoseUnit.SI);
38  
39      /** Constant with value POSITIVE_INFINITY. */
40      public static final FloatAbsorbedDose POSITIVE_INFINITY =
41              new FloatAbsorbedDose(Float.POSITIVE_INFINITY, AbsorbedDoseUnit.SI);
42  
43      /** Constant with value NEGATIVE_INFINITY. */
44      public static final FloatAbsorbedDose NEGATIVE_INFINITY =
45              new FloatAbsorbedDose(Float.NEGATIVE_INFINITY, AbsorbedDoseUnit.SI);
46  
47      /** Constant with value MAX_VALUE. */
48      public static final FloatAbsorbedDosebedDose.html#FloatAbsorbedDose">FloatAbsorbedDose POS_MAXVALUE = new FloatAbsorbedDose(Float.MAX_VALUE, AbsorbedDoseUnit.SI);
49  
50      /** Constant with value -MAX_VALUE. */
51      public static final FloatAbsorbedDosebedDose.html#FloatAbsorbedDose">FloatAbsorbedDose NEG_MAXVALUE = new FloatAbsorbedDose(-Float.MAX_VALUE, AbsorbedDoseUnit.SI);
52  
53      /**
54       * Construct FloatAbsorbedDose scalar.
55       * @param value float; the float value
56       * @param unit unit for the float value
57       */
58      public FloatAbsorbedDose(final float value, final AbsorbedDoseUnit unit)
59      {
60          super(value, unit);
61      }
62  
63      /**
64       * Construct FloatAbsorbedDose scalar.
65       * @param value Scalar from which to construct this instance
66       */
67      public FloatAbsorbedDosear/FloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose(final FloatAbsorbedDose value)
68      {
69          super(value);
70      }
71  
72      /**
73       * Construct FloatAbsorbedDose scalar using a double value.
74       * @param value double; the double value
75       * @param unit unit for the resulting float value
76       */
77      public FloatAbsorbedDose(final double value, final AbsorbedDoseUnit unit)
78      {
79          super((float) value, unit);
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public final FloatAbsorbedDose instantiateRel(final float value, final AbsorbedDoseUnit unit)
85      {
86          return new FloatAbsorbedDose(value, unit);
87      }
88  
89      /**
90       * Construct FloatAbsorbedDose scalar.
91       * @param value float; the float value in SI units
92       * @return the new scalar with the SI value
93       */
94      public static final FloatAbsorbedDose instantiateSI(final float value)
95      {
96          return new FloatAbsorbedDose(value, AbsorbedDoseUnit.SI);
97      }
98  
99      /**
100      * Interpolate between two values.
101      * @param zero the low value
102      * @param one the high value
103      * @param ratio double; the ratio between 0 and 1, inclusive
104      * @return a Scalar at the ratio between
105      */
106     public static FloatAbsorbedDoseatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDoserbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose interpolate(final FloatAbsorbedDoseatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose zero, final FloatAbsorbedDose one, final float ratio)
107     {
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 FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose max(final FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">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 FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose max(final FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">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 FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose min(final FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">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 FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">FloatAbsorbedDose min(final FloatAbsorbedDoseloatAbsorbedDose.html#FloatAbsorbedDose">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 the official abbreviation of the unit. Spaces are
177      * allowed, but not required, between the value and the unit.
178      * @param text String; the textual representation to parse into a FloatAbsorbedDose
179      * @return FloatAbsorbedDose; 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         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
188         if (matcher.find())
189         {
190             int index = matcher.end();
191             String unitString = text.substring(index).trim();
192             String valueString = text.substring(0, index).trim();
193             AbsorbedDoseUnit unit = AbsorbedDoseUnit.BASE.getUnitByAbbreviation(unitString);
194             if (unit != null)
195             {
196                 float f = Float.parseFloat(valueString);
197                 return new FloatAbsorbedDose(f, unit);
198             }
199         }
200         throw new IllegalArgumentException("Error parsing FloatAbsorbedDose from " + text);
201     }
202 
203     /**
204      * Returns a FloatAbsorbedDose based on a value and the textual representation of the unit.
205      * @param value double; the value to use
206      * @param unitString String; the textual representation of the unit
207      * @return FloatAbsorbedDose; 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         if (unit != null)
218         {
219             return new FloatAbsorbedDose(value, unit);
220         }
221         throw new IllegalArgumentException("Error parsing FloatAbsorbedDose with unit " + unitString);
222     }
223 
224     /**
225      * Calculate the division of FloatAbsorbedDose and FloatAbsorbedDose, which results in a FloatDimensionless scalar.
226      * @param v FloatAbsorbedDose; scalar
227      * @return FloatDimensionless; scalar as a division of FloatAbsorbedDose and FloatAbsorbedDose
228      */
229     public final FloatDimensionless divide(final FloatAbsorbedDose v)
230     {
231         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
232     }
233 
234     /** {@inheritDoc} */
235     @Override
236     public FloatSIScalar reciprocal()
237     {
238         return FloatScalar.divide(FloatDimensionless.ONE, this);
239     }
240 
241 }