View Javadoc
1   package org.djunits.value.vfloat.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.vfloat.scalar.base.FloatScalar;
8   import org.djunits.value.vfloat.scalar.base.FloatScalarRel;
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 FloatEquivalentDose FloatScalar, 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 FloatEquivalentDose extends FloatScalarRel<EquivalentDoseUnit, FloatEquivalentDose>
25  {
26      /** */
27      private static final long serialVersionUID = 20150901L;
28  
29      /** Constant with value zero. */
30      public static final FloatEquivalentDose ZERO = new FloatEquivalentDose(0.0f, EquivalentDoseUnit.SI);
31  
32      /** Constant with value one. */
33      public static final FloatEquivalentDose ONE = new FloatEquivalentDose(1.0f, EquivalentDoseUnit.SI);
34  
35      /** Constant with value NaN. */
36      @SuppressWarnings("checkstyle:constantname")
37      public static final FloatEquivalentDose NaN = new FloatEquivalentDose(Float.NaN, EquivalentDoseUnit.SI);
38  
39      /** Constant with value POSITIVE_INFINITY. */
40      public static final FloatEquivalentDose POSITIVE_INFINITY =
41              new FloatEquivalentDose(Float.POSITIVE_INFINITY, EquivalentDoseUnit.SI);
42  
43      /** Constant with value NEGATIVE_INFINITY. */
44      public static final FloatEquivalentDose NEGATIVE_INFINITY =
45              new FloatEquivalentDose(Float.NEGATIVE_INFINITY, EquivalentDoseUnit.SI);
46  
47      /** Constant with value MAX_VALUE. */
48      public static final FloatEquivalentDose POS_MAXVALUE = new FloatEquivalentDose(Float.MAX_VALUE, EquivalentDoseUnit.SI);
49  
50      /** Constant with value -MAX_VALUE. */
51      public static final FloatEquivalentDose NEG_MAXVALUE = new FloatEquivalentDose(-Float.MAX_VALUE, EquivalentDoseUnit.SI);
52  
53      /**
54       * Construct FloatEquivalentDose scalar.
55       * @param value float; the float value
56       * @param unit unit for the float value
57       */
58      public FloatEquivalentDose(final float value, final EquivalentDoseUnit unit)
59      {
60          super(value, unit);
61      }
62  
63      /**
64       * Construct FloatEquivalentDose scalar.
65       * @param value Scalar from which to construct this instance
66       */
67      public FloatEquivalentDose(final FloatEquivalentDose value)
68      {
69          super(value);
70      }
71  
72      /**
73       * Construct FloatEquivalentDose scalar using a double value.
74       * @param value double; the double value
75       * @param unit unit for the resulting float value
76       */
77      public FloatEquivalentDose(final double value, final EquivalentDoseUnit unit)
78      {
79          super((float) value, unit);
80      }
81  
82      @Override
83      public final FloatEquivalentDose instantiateRel(final float value, final EquivalentDoseUnit unit)
84      {
85          return new FloatEquivalentDose(value, unit);
86      }
87  
88      /**
89       * Construct FloatEquivalentDose 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 FloatEquivalentDose instantiateSI(final float value)
94      {
95          return new FloatEquivalentDose(value, EquivalentDoseUnit.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 FloatEquivalentDose interpolate(final FloatEquivalentDose zero, final FloatEquivalentDose one,
106             final float ratio)
107     {
108         return new FloatEquivalentDose(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 FloatEquivalentDose max(final FloatEquivalentDose r1, final FloatEquivalentDose 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 FloatEquivalentDose max(final FloatEquivalentDose r1, final FloatEquivalentDose r2,
131             final FloatEquivalentDose... rn)
132     {
133         FloatEquivalentDose maxr = r1.gt(r2) ? r1 : r2;
134         for (FloatEquivalentDose r : rn)
135         {
136             if (r.gt(maxr))
137             {
138                 maxr = r;
139             }
140         }
141         return maxr;
142     }
143 
144     /**
145      * Return the minimum value of two relative scalars.
146      * @param r1 the first scalar
147      * @param r2 the second scalar
148      * @return the minimum value of two relative scalars
149      */
150     public static FloatEquivalentDose min(final FloatEquivalentDose r1, final FloatEquivalentDose r2)
151     {
152         return r1.lt(r2) ? r1 : r2;
153     }
154 
155     /**
156      * Return the minimum value of more than two relative scalars.
157      * @param r1 the first scalar
158      * @param r2 the second scalar
159      * @param rn the other scalars
160      * @return the minimum value of more than two relative scalars
161      */
162     public static FloatEquivalentDose min(final FloatEquivalentDose r1, final FloatEquivalentDose r2,
163             final FloatEquivalentDose... rn)
164     {
165         FloatEquivalentDose minr = r1.lt(r2) ? r1 : r2;
166         for (FloatEquivalentDose r : rn)
167         {
168             if (r.lt(minr))
169             {
170                 minr = r;
171             }
172         }
173         return minr;
174     }
175 
176     /**
177      * Returns a FloatEquivalentDose representation of a textual representation of a value with a unit. The String
178      * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
179      * unit. Spaces are allowed, but not required, between the value and the unit.
180      * @param text String; the textual representation to parse into a FloatEquivalentDose
181      * @return FloatEquivalentDose; the Scalar representation of the value in its unit
182      * @throws IllegalArgumentException when the text cannot be parsed
183      * @throws NullPointerException when the text argument is null
184      */
185     public static FloatEquivalentDose valueOf(final String text)
186     {
187         Throw.whenNull(text, "Error parsing FloatEquivalentDose: text to parse is null");
188         Throw.when(text.length() == 0, IllegalArgumentException.class,
189                 "Error parsing FloatEquivalentDose: empty text to parse");
190         try
191         {
192             NumberParser numberParser = new NumberParser().lenient().trailing();
193             float f = numberParser.parseFloat(text);
194             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
195             EquivalentDoseUnit unit = EquivalentDoseUnit.BASE.getUnitByAbbreviation(unitString);
196             if (unit == null)
197                 throw new IllegalArgumentException("Unit " + unitString + " not found");
198             return new FloatEquivalentDose(f, unit);
199         }
200         catch (Exception exception)
201         {
202             throw new IllegalArgumentException("Error parsing FloatEquivalentDose from " + text + " using Locale "
203                     + Locale.getDefault(Locale.Category.FORMAT), exception);
204         }
205     }
206 
207     /**
208      * Returns a FloatEquivalentDose based on a value and the textual representation of the unit, which can be localized.
209      * @param value double; the value to use
210      * @param unitString String; the textual representation of the unit
211      * @return FloatEquivalentDose; the Scalar representation of the value in its unit
212      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
213      * @throws NullPointerException when the unitString argument is null
214      */
215     public static FloatEquivalentDose of(final float value, final String unitString)
216     {
217         Throw.whenNull(unitString, "Error parsing FloatEquivalentDose: unitString is null");
218         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
219                 "Error parsing FloatEquivalentDose: empty unitString");
220         EquivalentDoseUnit unit = EquivalentDoseUnit.BASE.getUnitByAbbreviation(unitString);
221         if (unit != null)
222         {
223             return new FloatEquivalentDose(value, unit);
224         }
225         throw new IllegalArgumentException("Error parsing FloatEquivalentDose with unit " + unitString);
226     }
227 
228     /**
229      * Calculate the division of FloatEquivalentDose and FloatEquivalentDose, which results in a FloatDimensionless scalar.
230      * @param v FloatEquivalentDose; scalar
231      * @return FloatDimensionless; scalar as a division of FloatEquivalentDose and FloatEquivalentDose
232      */
233     public final FloatDimensionless divide(final FloatEquivalentDose v)
234     {
235         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
236     }
237 
238     @Override
239     public FloatSIScalar reciprocal()
240     {
241         return FloatScalar.divide(FloatDimensionless.ONE, this);
242     }
243 
244 }