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.FloatScalarRel;
8   import org.djutils.base.NumberParser;
9   import org.djutils.exceptions.Throw;
10  
11  import jakarta.annotation.Generated;
12  
13  /**
14   * Easy access methods for the FloatRadioActivity FloatScalar, which is relative by definition.
15   * <p>
16   * Copyright (c) 2013-2025 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 = "2025-09-06T15:16:28.380798Z")
23  public class FloatRadioActivity extends FloatScalarRel<RadioActivityUnit, FloatRadioActivity>
24  {
25      /** */
26      private static final long serialVersionUID = 20150901L;
27  
28      /** Constant with value zero. */
29      public static final FloatRadioActivity ZERO = new FloatRadioActivity(0.0f, RadioActivityUnit.SI);
30  
31      /** Constant with value one. */
32      public static final FloatRadioActivity ONE = new FloatRadioActivity(1.0f, RadioActivityUnit.SI);
33  
34      /** Constant with value NaN. */
35      @SuppressWarnings("checkstyle:constantname")
36      public static final FloatRadioActivity NaN = new FloatRadioActivity(Float.NaN, RadioActivityUnit.SI);
37  
38      /** Constant with value POSITIVE_INFINITY. */
39      public static final FloatRadioActivity POSITIVE_INFINITY =
40              new FloatRadioActivity(Float.POSITIVE_INFINITY, RadioActivityUnit.SI);
41  
42      /** Constant with value NEGATIVE_INFINITY. */
43      public static final FloatRadioActivity NEGATIVE_INFINITY =
44              new FloatRadioActivity(Float.NEGATIVE_INFINITY, RadioActivityUnit.SI);
45  
46      /** Constant with value MAX_VALUE. */
47      public static final FloatRadioActivity POS_MAXVALUE = new FloatRadioActivity(Float.MAX_VALUE, RadioActivityUnit.SI);
48  
49      /** Constant with value -MAX_VALUE. */
50      public static final FloatRadioActivity NEG_MAXVALUE = new FloatRadioActivity(-Float.MAX_VALUE, RadioActivityUnit.SI);
51  
52      /**
53       * Construct FloatRadioActivity scalar with a unit.
54       * @param value the float value, expressed in the given unit
55       * @param unit unit for the float value
56       */
57      public FloatRadioActivity(final float value, final RadioActivityUnit unit)
58      {
59          super(value, unit);
60      }
61  
62      /**
63       * Construct FloatRadioActivity scalar.
64       * @param value Scalar from which to construct this instance
65       */
66      public FloatRadioActivity(final FloatRadioActivity value)
67      {
68          super(value);
69      }
70  
71      /**
72       * Construct FloatRadioActivity scalar with a unit using a double value.
73       * @param value the double value, expressed in the given unit
74       * @param unit unit for the resulting float value
75       */
76      public FloatRadioActivity(final double value, final RadioActivityUnit unit)
77      {
78          super((float) value, unit);
79      }
80  
81      @Override
82      public final FloatRadioActivity instantiateRel(final float value, final RadioActivityUnit unit)
83      {
84          return new FloatRadioActivity(value, unit);
85      }
86  
87      /**
88       * Construct FloatRadioActivity scalar based on an SI value.
89       * @param value the float value in SI units
90       * @return the new scalar with the SI value
91       */
92      public static final FloatRadioActivity ofSI(final float value)
93      {
94          return new FloatRadioActivity(value, RadioActivityUnit.SI);
95      }
96  
97      /**
98       * Interpolate between two values. Note that the first value does not have to be smaller than the second.
99       * @param zero the value at a ratio of zero
100      * @param one the value at a ratio of one
101      * @param ratio the ratio between 0 and 1, inclusive
102      * @return a FloatRadioActivity at the given ratio between 0 and 1
103      */
104     public static FloatRadioActivity interpolate(final FloatRadioActivity zero, final FloatRadioActivity one, final float ratio)
105     {
106         Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
107                 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
108         return new FloatRadioActivity(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 FloatRadioActivity max(final FloatRadioActivity r1, final FloatRadioActivity 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 FloatRadioActivity max(final FloatRadioActivity r1, final FloatRadioActivity r2,
131             final FloatRadioActivity... rn)
132     {
133         FloatRadioActivity maxr = r1.gt(r2) ? r1 : r2;
134         for (FloatRadioActivity 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 FloatRadioActivity min(final FloatRadioActivity r1, final FloatRadioActivity 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 FloatRadioActivity min(final FloatRadioActivity r1, final FloatRadioActivity r2,
163             final FloatRadioActivity... rn)
164     {
165         FloatRadioActivity minr = r1.lt(r2) ? r1 : r2;
166         for (FloatRadioActivity r : rn)
167         {
168             if (r.lt(minr))
169             {
170                 minr = r;
171             }
172         }
173         return minr;
174     }
175 
176     /**
177      * Returns a FloatRadioActivity representation of a textual representation of a value with a unit. The String representation
178      * that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces
179      * are allowed, but not required, between the value and the unit.
180      * @param text the textual representation to parse into a FloatRadioActivity
181      * @return 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 FloatRadioActivity valueOf(final String text)
186     {
187         Throw.whenNull(text, "Error parsing FloatRadioActivity: text to parse is null");
188         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatRadioActivity: empty text to parse");
189         try
190         {
191             NumberParser numberParser = new NumberParser().lenient().trailing();
192             float f = numberParser.parseFloat(text);
193             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
194             RadioActivityUnit unit = RadioActivityUnit.BASE.getUnitByAbbreviation(unitString);
195             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity RadioActivity",
196                     unitString);
197             return new FloatRadioActivity(f, unit);
198         }
199         catch (Exception exception)
200         {
201             throw new IllegalArgumentException("Error parsing FloatRadioActivity from " + text + " using Locale "
202                     + Locale.getDefault(Locale.Category.FORMAT), exception);
203         }
204     }
205 
206     /**
207      * Returns a FloatRadioActivity based on a value and the textual representation of the unit, which can be localized.
208      * @param value the value to use
209      * @param unitString the textual representation of the unit
210      * @return the Scalar representation of the value in its unit
211      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
212      * @throws NullPointerException when the unitString argument is null
213      */
214     public static FloatRadioActivity of(final float value, final String unitString)
215     {
216         Throw.whenNull(unitString, "Error parsing FloatRadioActivity: unitString is null");
217         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
218                 "Error parsing FloatRadioActivity: empty unitString");
219         RadioActivityUnit unit = RadioActivityUnit.BASE.getUnitByAbbreviation(unitString);
220         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FloatRadioActivity with unit %s", unitString);
221         return new FloatRadioActivity(value, unit);
222     }
223 
224     /**
225      * Calculate the division of FloatRadioActivity and FloatRadioActivity, which results in a FloatDimensionless scalar.
226      * @param v scalar
227      * @return scalar as a division of FloatRadioActivity and FloatRadioActivity
228      */
229     public final FloatDimensionless divide(final FloatRadioActivity v)
230     {
231         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
232     }
233 
234     @Override
235     public FloatSIScalar reciprocal()
236     {
237         return FloatSIScalar.divide(FloatDimensionless.ONE, this);
238     }
239 
240     /**
241      * Multiply two scalars that result in a scalar of type FloatRadioActivity.
242      * @param scalar1 the first scalar
243      * @param scalar2 the second scalar
244      * @return the multiplication of both scalars as an instance of FloatRadioActivity
245      */
246     public static FloatRadioActivity multiply(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
247     {
248         Throw.whenNull(scalar1, "scalar1 cannot be null");
249         Throw.whenNull(scalar2, "scalar2 cannot be null");
250         Throw.when(
251                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
252                         .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
253                         .equals(RadioActivityUnit.BASE.getSiDimensions()),
254                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type FloatRadioActivity",
255                 scalar1.toDisplayString(), scalar2.toDisplayString());
256         return new FloatRadioActivity(scalar1.si * scalar2.si, RadioActivityUnit.SI);
257     }
258 
259     /**
260      * Divide two scalars that result in a scalar of type FloatRadioActivity.
261      * @param scalar1 the first scalar
262      * @param scalar2 the second scalar
263      * @return the division of scalar1 by scalar2 as an instance of FloatRadioActivity
264      */
265     public static FloatRadioActivity divide(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
266     {
267         Throw.whenNull(scalar1, "scalar1 cannot be null");
268         Throw.whenNull(scalar2, "scalar2 cannot be null");
269         Throw.when(
270                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
271                         .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
272                         .equals(RadioActivityUnit.BASE.getSiDimensions()),
273                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type FloatRadioActivity",
274                 scalar1.toDisplayString(), scalar2.toDisplayString());
275         return new FloatRadioActivity(scalar1.si / scalar2.si, RadioActivityUnit.SI);
276     }
277 
278 }