View Javadoc
1   package org.djunits.value.vdouble.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.vdouble.scalar.base.DoubleScalarRel;
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 RadioActivity DoubleScalar, 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 RadioActivity extends DoubleScalarRel<RadioActivityUnit, RadioActivity>
24  {
25      /** */
26      private static final long serialVersionUID = 20150905L;
27  
28      /** Constant with value zero. */
29      public static final RadioActivity ZERO = new RadioActivity(0.0, RadioActivityUnit.SI);
30  
31      /** Constant with value one. */
32      public static final RadioActivity ONE = new RadioActivity(1.0, RadioActivityUnit.SI);
33  
34      /** Constant with value NaN. */
35      @SuppressWarnings("checkstyle:constantname")
36      public static final RadioActivity NaN = new RadioActivity(Double.NaN, RadioActivityUnit.SI);
37  
38      /** Constant with value POSITIVE_INFINITY. */
39      public static final RadioActivity POSITIVE_INFINITY = new RadioActivity(Double.POSITIVE_INFINITY, RadioActivityUnit.SI);
40  
41      /** Constant with value NEGATIVE_INFINITY. */
42      public static final RadioActivity NEGATIVE_INFINITY = new RadioActivity(Double.NEGATIVE_INFINITY, RadioActivityUnit.SI);
43  
44      /** Constant with value MAX_VALUE. */
45      public static final RadioActivity POS_MAXVALUE = new RadioActivity(Double.MAX_VALUE, RadioActivityUnit.SI);
46  
47      /** Constant with value -MAX_VALUE. */
48      public static final RadioActivity NEG_MAXVALUE = new RadioActivity(-Double.MAX_VALUE, RadioActivityUnit.SI);
49  
50      /**
51       * Construct RadioActivity scalar with a unit.
52       * @param value the double value, expressed in the given unit
53       * @param unit unit for the double value
54       */
55      public RadioActivity(final double value, final RadioActivityUnit unit)
56      {
57          super(value, unit);
58      }
59  
60      /**
61       * Construct RadioActivity scalar.
62       * @param value Scalar from which to construct this instance
63       */
64      public RadioActivity(final RadioActivity value)
65      {
66          super(value);
67      }
68  
69      @Override
70      public final RadioActivity instantiateRel(final double value, final RadioActivityUnit unit)
71      {
72          return new RadioActivity(value, unit);
73      }
74  
75      /**
76       * Construct RadioActivity scalar based on an SI value.
77       * @param value the double value in SI units
78       * @return the new scalar with the SI value
79       */
80      public static final RadioActivity ofSI(final double value)
81      {
82          return new RadioActivity(value, RadioActivityUnit.SI);
83      }
84  
85      /**
86       * Interpolate between two values. Note that the first value does not have to be smaller than the second.
87       * @param zero the value at a ratio of zero
88       * @param one the value at a ratio of one
89       * @param ratio the ratio between 0 and 1, inclusive
90       * @return a RadioActivity at the given ratio between 0 and 1
91       */
92      public static RadioActivity interpolate(final RadioActivity zero, final RadioActivity one, final double ratio)
93      {
94          Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
95                  "ratio for interpolation should be between 0 and 1, but is %f", ratio);
96          return new RadioActivity(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
97                  zero.getDisplayUnit());
98      }
99  
100     /**
101      * Return the maximum value of two relative scalars.
102      * @param r1 the first scalar
103      * @param r2 the second scalar
104      * @return the maximum value of two relative scalars
105      */
106     public static RadioActivity max(final RadioActivity r1, final RadioActivity r2)
107     {
108         return r1.gt(r2) ? r1 : r2;
109     }
110 
111     /**
112      * Return the maximum value of more than two relative scalars.
113      * @param r1 the first scalar
114      * @param r2 the second scalar
115      * @param rn the other scalars
116      * @return the maximum value of more than two relative scalars
117      */
118     public static RadioActivity max(final RadioActivity r1, final RadioActivity r2, final RadioActivity... rn)
119     {
120         RadioActivity maxr = r1.gt(r2) ? r1 : r2;
121         for (RadioActivity r : rn)
122         {
123             if (r.gt(maxr))
124             {
125                 maxr = r;
126             }
127         }
128         return maxr;
129     }
130 
131     /**
132      * Return the minimum value of two relative scalars.
133      * @param r1 the first scalar
134      * @param r2 the second scalar
135      * @return the minimum value of two relative scalars
136      */
137     public static RadioActivity min(final RadioActivity r1, final RadioActivity r2)
138     {
139         return r1.lt(r2) ? r1 : r2;
140     }
141 
142     /**
143      * Return the minimum value of more than two relative scalars.
144      * @param r1 the first scalar
145      * @param r2 the second scalar
146      * @param rn the other scalars
147      * @return the minimum value of more than two relative scalars
148      */
149     public static RadioActivity min(final RadioActivity r1, final RadioActivity r2, final RadioActivity... rn)
150     {
151         RadioActivity minr = r1.lt(r2) ? r1 : r2;
152         for (RadioActivity r : rn)
153         {
154             if (r.lt(minr))
155             {
156                 minr = r;
157             }
158         }
159         return minr;
160     }
161 
162     /**
163      * Returns a RadioActivity representation of a textual representation of a value with a unit. The String representation that
164      * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
165      * allowed, but not required, between the value and the unit.
166      * @param text the textual representation to parse into a RadioActivity
167      * @return the Scalar representation of the value in its unit
168      * @throws IllegalArgumentException when the text cannot be parsed
169      * @throws NullPointerException when the text argument is null
170      */
171     public static RadioActivity valueOf(final String text)
172     {
173         Throw.whenNull(text, "Error parsing RadioActivity: text to parse is null");
174         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing RadioActivity: empty text to parse");
175         try
176         {
177             NumberParser numberParser = new NumberParser().lenient().trailing();
178             double d = numberParser.parseDouble(text);
179             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
180             RadioActivityUnit unit = RadioActivityUnit.BASE.getUnitByAbbreviation(unitString);
181             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity RadioActivity",
182                     unitString);
183             return new RadioActivity(d, unit);
184         }
185         catch (Exception exception)
186         {
187             throw new IllegalArgumentException(
188                     "Error parsing RadioActivity from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
189                     exception);
190         }
191     }
192 
193     /**
194      * Returns a RadioActivity based on a value and the textual representation of the unit, which can be localized.
195      * @param value the value to use
196      * @param unitString the textual representation of the unit
197      * @return the Scalar representation of the value in its unit
198      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
199      * @throws NullPointerException when the unitString argument is null
200      */
201     public static RadioActivity of(final double value, final String unitString)
202     {
203         Throw.whenNull(unitString, "Error parsing RadioActivity: unitString is null");
204         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing RadioActivity: empty unitString");
205         RadioActivityUnit unit = RadioActivityUnit.BASE.getUnitByAbbreviation(unitString);
206         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing RadioActivity with unit %s", unitString);
207         return new RadioActivity(value, unit);
208     }
209 
210     /**
211      * Calculate the division of RadioActivity and RadioActivity, which results in a Dimensionless scalar.
212      * @param v scalar
213      * @return scalar as a division of RadioActivity and RadioActivity
214      */
215     public final Dimensionless divide(final RadioActivity v)
216     {
217         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
218     }
219 
220     @Override
221     public SIScalar reciprocal()
222     {
223         return SIScalar.divide(Dimensionless.ONE, this);
224     }
225 
226     /**
227      * Multiply two scalars that result in a scalar of type RadioActivity.
228      * @param scalar1 the first scalar
229      * @param scalar2 the second scalar
230      * @return the multiplication of both scalars as an instance of RadioActivity
231      */
232     public static RadioActivity multiply(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
233     {
234         Throw.whenNull(scalar1, "scalar1 cannot be null");
235         Throw.whenNull(scalar2, "scalar2 cannot be null");
236         Throw.when(
237                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
238                         .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
239                         .equals(RadioActivityUnit.BASE.getSiDimensions()),
240                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type RadioActivity",
241                 scalar1.toDisplayString(), scalar2.toDisplayString());
242         return new RadioActivity(scalar1.si * scalar2.si, RadioActivityUnit.SI);
243     }
244 
245     /**
246      * Divide two scalars that result in a scalar of type RadioActivity.
247      * @param scalar1 the first scalar
248      * @param scalar2 the second scalar
249      * @return the division of scalar1 by scalar2 as an instance of RadioActivity
250      */
251     public static RadioActivity divide(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
252     {
253         Throw.whenNull(scalar1, "scalar1 cannot be null");
254         Throw.whenNull(scalar2, "scalar2 cannot be null");
255         Throw.when(
256                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
257                         .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
258                         .equals(RadioActivityUnit.BASE.getSiDimensions()),
259                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type RadioActivity",
260                 scalar1.toDisplayString(), scalar2.toDisplayString());
261         return new RadioActivity(scalar1.si / scalar2.si, RadioActivityUnit.SI);
262     }
263 
264 }