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.DoubleScalar;
8   import org.djunits.value.vdouble.scalar.base.DoubleScalarRel;
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 RadioActivity DoubleScalar, 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 RadioActivity extends DoubleScalarRel<RadioActivityUnit, RadioActivity>
25  {
26      /** */
27      private static final long serialVersionUID = 20150905L;
28  
29      /** Constant with value zero. */
30      public static final RadioActivity ZERO = new RadioActivity(0.0, RadioActivityUnit.SI);
31  
32      /** Constant with value one. */
33      public static final RadioActivity ONE = new RadioActivity(1.0, RadioActivityUnit.SI);
34  
35      /** Constant with value NaN. */
36      @SuppressWarnings("checkstyle:constantname")
37      public static final RadioActivity NaN = new RadioActivity(Double.NaN, RadioActivityUnit.SI);
38  
39      /** Constant with value POSITIVE_INFINITY. */
40      public static final RadioActivity POSITIVE_INFINITY = new RadioActivity(Double.POSITIVE_INFINITY, RadioActivityUnit.SI);
41  
42      /** Constant with value NEGATIVE_INFINITY. */
43      public static final RadioActivity NEGATIVE_INFINITY = new RadioActivity(Double.NEGATIVE_INFINITY, RadioActivityUnit.SI);
44  
45      /** Constant with value MAX_VALUE. */
46      public static final RadioActivity POS_MAXVALUE = new RadioActivity(Double.MAX_VALUE, RadioActivityUnit.SI);
47  
48      /** Constant with value -MAX_VALUE. */
49      public static final RadioActivity NEG_MAXVALUE = new RadioActivity(-Double.MAX_VALUE, RadioActivityUnit.SI);
50  
51      /**
52       * Construct RadioActivity scalar.
53       * @param value double; the double value
54       * @param unit RadioActivityUnit; unit for the double value
55       */
56      public RadioActivity(final double value, final RadioActivityUnit unit)
57      {
58          super(value, unit);
59      }
60  
61      /**
62       * Construct RadioActivity scalar.
63       * @param value RadioActivity; Scalar from which to construct this instance
64       */
65      public RadioActivity(final RadioActivity value)
66      {
67          super(value);
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public final RadioActivity instantiateRel(final double value, final RadioActivityUnit unit)
73      {
74          return new RadioActivity(value, unit);
75      }
76  
77      /**
78       * Construct RadioActivity scalar.
79       * @param value double; the double value in SI units
80       * @return RadioActivity; the new scalar with the SI value
81       */
82      public static final RadioActivity instantiateSI(final double value)
83      {
84          return new RadioActivity(value, RadioActivityUnit.SI);
85      }
86  
87      /**
88       * Interpolate between two values.
89       * @param zero RadioActivity; the low value
90       * @param one RadioActivity; the high value
91       * @param ratio double; the ratio between 0 and 1, inclusive
92       * @return RadioActivity; a Scalar at the ratio between
93       */
94      public static RadioActivity interpolate(final RadioActivity zero, final RadioActivity one, final double ratio)
95      {
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 RadioActivity; the first scalar
103      * @param r2 RadioActivity; the second scalar
104      * @return RadioActivity; 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 RadioActivity; the first scalar
114      * @param r2 RadioActivity; the second scalar
115      * @param rn RadioActivity...; the other scalars
116      * @return RadioActivity; 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 RadioActivity; the first scalar
134      * @param r2 RadioActivity; the second scalar
135      * @return RadioActivity; 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 RadioActivity; the first scalar
145      * @param r2 RadioActivity; the second scalar
146      * @param rn RadioActivity...; the other scalars
147      * @return RadioActivity; 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 String; the textual representation to parse into a RadioActivity
167      * @return RadioActivity; 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             if (unit == null)
182                 throw new IllegalArgumentException("Unit " + unitString + " not found");
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 double; the value to use
196      * @param unitString String; the textual representation of the unit
197      * @return RadioActivity; 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         if (unit != null)
207         {
208             return new RadioActivity(value, unit);
209         }
210         throw new IllegalArgumentException("Error parsing RadioActivity with unit " + unitString);
211     }
212 
213     /**
214      * Calculate the division of RadioActivity and RadioActivity, which results in a Dimensionless scalar.
215      * @param v RadioActivity; scalar
216      * @return Dimensionless; scalar as a division of RadioActivity and RadioActivity
217      */
218     public final Dimensionless divide(final RadioActivity v)
219     {
220         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
221     }
222 
223     /** {@inheritDoc} */
224     @Override
225     public SIScalar reciprocal()
226     {
227         return DoubleScalar.divide(Dimensionless.ONE, this);
228     }
229 
230 }