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.LuminousFluxUnit;
7   import org.djunits.unit.LuminousIntensityUnit;
8   import org.djunits.value.vdouble.scalar.base.DoubleScalar;
9   import org.djunits.value.vdouble.scalar.base.DoubleScalarRel;
10  import org.djutils.base.NumberParser;
11  import org.djutils.exceptions.Throw;
12  
13  import jakarta.annotation.Generated;
14  
15  /**
16   * Easy access methods for the LuminousIntensity DoubleScalar, which is relative by definition.
17   * <p>
18   * Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
19   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
20   * </p>
21   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
23   */
24  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
25  public class LuminousIntensity extends DoubleScalarRel<LuminousIntensityUnit, LuminousIntensity>
26  {
27      /** */
28      private static final long serialVersionUID = 20150905L;
29  
30      /** Constant with value zero. */
31      public static final LuminousIntensity ZERO = new LuminousIntensity(0.0, LuminousIntensityUnit.SI);
32  
33      /** Constant with value one. */
34      public static final LuminousIntensity ONE = new LuminousIntensity(1.0, LuminousIntensityUnit.SI);
35  
36      /** Constant with value NaN. */
37      @SuppressWarnings("checkstyle:constantname")
38      public static final LuminousIntensity NaN = new LuminousIntensity(Double.NaN, LuminousIntensityUnit.SI);
39  
40      /** Constant with value POSITIVE_INFINITY. */
41      public static final LuminousIntensity POSITIVE_INFINITY =
42              new LuminousIntensity(Double.POSITIVE_INFINITY, LuminousIntensityUnit.SI);
43  
44      /** Constant with value NEGATIVE_INFINITY. */
45      public static final LuminousIntensity NEGATIVE_INFINITY =
46              new LuminousIntensity(Double.NEGATIVE_INFINITY, LuminousIntensityUnit.SI);
47  
48      /** Constant with value MAX_VALUE. */
49      public static final LuminousIntensity POS_MAXVALUE = new LuminousIntensity(Double.MAX_VALUE, LuminousIntensityUnit.SI);
50  
51      /** Constant with value -MAX_VALUE. */
52      public static final LuminousIntensity NEG_MAXVALUE = new LuminousIntensity(-Double.MAX_VALUE, LuminousIntensityUnit.SI);
53  
54      /**
55       * Construct LuminousIntensity scalar.
56       * @param value double; the double value
57       * @param unit LuminousIntensityUnit; unit for the double value
58       */
59      public LuminousIntensity(final double value, final LuminousIntensityUnit unit)
60      {
61          super(value, unit);
62      }
63  
64      /**
65       * Construct LuminousIntensity scalar.
66       * @param value LuminousIntensity; Scalar from which to construct this instance
67       */
68      public LuminousIntensity(final LuminousIntensity value)
69      {
70          super(value);
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public final LuminousIntensity instantiateRel(final double value, final LuminousIntensityUnit unit)
76      {
77          return new LuminousIntensity(value, unit);
78      }
79  
80      /**
81       * Construct LuminousIntensity scalar.
82       * @param value double; the double value in SI units
83       * @return LuminousIntensity; the new scalar with the SI value
84       */
85      public static final LuminousIntensity instantiateSI(final double value)
86      {
87          return new LuminousIntensity(value, LuminousIntensityUnit.SI);
88      }
89  
90      /**
91       * Interpolate between two values.
92       * @param zero LuminousIntensity; the low value
93       * @param one LuminousIntensity; the high value
94       * @param ratio double; the ratio between 0 and 1, inclusive
95       * @return LuminousIntensity; a Scalar at the ratio between
96       */
97      public static LuminousIntensity interpolate(final LuminousIntensity zero, final LuminousIntensity one, final double ratio)
98      {
99          return new LuminousIntensity(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
100                 zero.getDisplayUnit());
101     }
102 
103     /**
104      * Return the maximum value of two relative scalars.
105      * @param r1 LuminousIntensity; the first scalar
106      * @param r2 LuminousIntensity; the second scalar
107      * @return LuminousIntensity; the maximum value of two relative scalars
108      */
109     public static LuminousIntensity max(final LuminousIntensity r1, final LuminousIntensity r2)
110     {
111         return r1.gt(r2) ? r1 : r2;
112     }
113 
114     /**
115      * Return the maximum value of more than two relative scalars.
116      * @param r1 LuminousIntensity; the first scalar
117      * @param r2 LuminousIntensity; the second scalar
118      * @param rn LuminousIntensity...; the other scalars
119      * @return LuminousIntensity; the maximum value of more than two relative scalars
120      */
121     public static LuminousIntensity max(final LuminousIntensity r1, final LuminousIntensity r2, final LuminousIntensity... rn)
122     {
123         LuminousIntensity maxr = r1.gt(r2) ? r1 : r2;
124         for (LuminousIntensity r : rn)
125         {
126             if (r.gt(maxr))
127             {
128                 maxr = r;
129             }
130         }
131         return maxr;
132     }
133 
134     /**
135      * Return the minimum value of two relative scalars.
136      * @param r1 LuminousIntensity; the first scalar
137      * @param r2 LuminousIntensity; the second scalar
138      * @return LuminousIntensity; the minimum value of two relative scalars
139      */
140     public static LuminousIntensity min(final LuminousIntensity r1, final LuminousIntensity r2)
141     {
142         return r1.lt(r2) ? r1 : r2;
143     }
144 
145     /**
146      * Return the minimum value of more than two relative scalars.
147      * @param r1 LuminousIntensity; the first scalar
148      * @param r2 LuminousIntensity; the second scalar
149      * @param rn LuminousIntensity...; the other scalars
150      * @return LuminousIntensity; the minimum value of more than two relative scalars
151      */
152     public static LuminousIntensity min(final LuminousIntensity r1, final LuminousIntensity r2, final LuminousIntensity... rn)
153     {
154         LuminousIntensity minr = r1.lt(r2) ? r1 : r2;
155         for (LuminousIntensity r : rn)
156         {
157             if (r.lt(minr))
158             {
159                 minr = r;
160             }
161         }
162         return minr;
163     }
164 
165     /**
166      * Returns a LuminousIntensity representation of a textual representation of a value with a unit. The String representation
167      * that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces
168      * are allowed, but not required, between the value and the unit.
169      * @param text String; the textual representation to parse into a LuminousIntensity
170      * @return LuminousIntensity; the Scalar representation of the value in its unit
171      * @throws IllegalArgumentException when the text cannot be parsed
172      * @throws NullPointerException when the text argument is null
173      */
174     public static LuminousIntensity valueOf(final String text)
175     {
176         Throw.whenNull(text, "Error parsing LuminousIntensity: text to parse is null");
177         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing LuminousIntensity: empty text to parse");
178         try
179         {
180             NumberParser numberParser = new NumberParser().lenient().trailing();
181             double d = numberParser.parseDouble(text);
182             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
183             LuminousIntensityUnit unit = LuminousIntensityUnit.BASE.getUnitByAbbreviation(unitString);
184             if (unit == null)
185                 throw new IllegalArgumentException("Unit " + unitString + " not found");
186             return new LuminousIntensity(d, unit);
187         }
188         catch (Exception exception)
189         {
190             throw new IllegalArgumentException("Error parsing LuminousIntensity from " + text + " using Locale "
191                     + Locale.getDefault(Locale.Category.FORMAT), exception);
192         }
193     }
194 
195     /**
196      * Returns a LuminousIntensity based on a value and the textual representation of the unit, which can be localized.
197      * @param value double; the value to use
198      * @param unitString String; the textual representation of the unit
199      * @return LuminousIntensity; the Scalar representation of the value in its unit
200      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
201      * @throws NullPointerException when the unitString argument is null
202      */
203     public static LuminousIntensity of(final double value, final String unitString)
204     {
205         Throw.whenNull(unitString, "Error parsing LuminousIntensity: unitString is null");
206         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
207                 "Error parsing LuminousIntensity: empty unitString");
208         LuminousIntensityUnit unit = LuminousIntensityUnit.BASE.getUnitByAbbreviation(unitString);
209         if (unit != null)
210         {
211             return new LuminousIntensity(value, unit);
212         }
213         throw new IllegalArgumentException("Error parsing LuminousIntensity with unit " + unitString);
214     }
215 
216     /**
217      * Calculate the division of LuminousIntensity and LuminousIntensity, which results in a Dimensionless scalar.
218      * @param v LuminousIntensity; scalar
219      * @return Dimensionless; scalar as a division of LuminousIntensity and LuminousIntensity
220      */
221     public final Dimensionless divide(final LuminousIntensity v)
222     {
223         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
224     }
225 
226     /**
227      * Calculate the multiplication of LuminousIntensity and SolidAngle, which results in a LuminousFlux scalar.
228      * @param v LuminousIntensity; scalar
229      * @return LuminousFlux; scalar as a multiplication of LuminousIntensity and SolidAngle
230      */
231     public final LuminousFlux times(final SolidAngle v)
232     {
233         return new LuminousFlux(this.si * v.si, LuminousFluxUnit.SI);
234     }
235 
236     /** {@inheritDoc} */
237     @Override
238     public SIScalar reciprocal()
239     {
240         return DoubleScalar.divide(Dimensionless.ONE, this);
241     }
242 
243 }