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