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.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 LuminousIntensity DoubleScalar, which is relative by definition.
16   * <p>
17   * Copyright (c) 2013-2025 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 = "2025-09-06T15:16:28.380798Z")
24  public class LuminousIntensity extends DoubleScalarRel<LuminousIntensityUnit, LuminousIntensity>
25  {
26      /** */
27      private static final long serialVersionUID = 20150905L;
28  
29      /** Constant with value zero. */
30      public static final LuminousIntensity ZERO = new LuminousIntensity(0.0, LuminousIntensityUnit.SI);
31  
32      /** Constant with value one. */
33      public static final LuminousIntensity ONE = new LuminousIntensity(1.0, LuminousIntensityUnit.SI);
34  
35      /** Constant with value NaN. */
36      @SuppressWarnings("checkstyle:constantname")
37      public static final LuminousIntensity NaN = new LuminousIntensity(Double.NaN, LuminousIntensityUnit.SI);
38  
39      /** Constant with value POSITIVE_INFINITY. */
40      public static final LuminousIntensity POSITIVE_INFINITY =
41              new LuminousIntensity(Double.POSITIVE_INFINITY, LuminousIntensityUnit.SI);
42  
43      /** Constant with value NEGATIVE_INFINITY. */
44      public static final LuminousIntensity NEGATIVE_INFINITY =
45              new LuminousIntensity(Double.NEGATIVE_INFINITY, LuminousIntensityUnit.SI);
46  
47      /** Constant with value MAX_VALUE. */
48      public static final LuminousIntensity POS_MAXVALUE = new LuminousIntensity(Double.MAX_VALUE, LuminousIntensityUnit.SI);
49  
50      /** Constant with value -MAX_VALUE. */
51      public static final LuminousIntensity NEG_MAXVALUE = new LuminousIntensity(-Double.MAX_VALUE, LuminousIntensityUnit.SI);
52  
53      /**
54       * Construct LuminousIntensity scalar with a unit.
55       * @param value the double value, expressed in the given unit
56       * @param unit unit for the double value
57       */
58      public LuminousIntensity(final double value, final LuminousIntensityUnit unit)
59      {
60          super(value, unit);
61      }
62  
63      /**
64       * Construct LuminousIntensity scalar.
65       * @param value Scalar from which to construct this instance
66       */
67      public LuminousIntensity(final LuminousIntensity value)
68      {
69          super(value);
70      }
71  
72      @Override
73      public final LuminousIntensity instantiateRel(final double value, final LuminousIntensityUnit unit)
74      {
75          return new LuminousIntensity(value, unit);
76      }
77  
78      /**
79       * Construct LuminousIntensity scalar based on an SI value.
80       * @param value the double value in SI units
81       * @return the new scalar with the SI value
82       */
83      public static final LuminousIntensity ofSI(final double value)
84      {
85          return new LuminousIntensity(value, LuminousIntensityUnit.SI);
86      }
87  
88      /**
89       * Interpolate between two values. Note that the first value does not have to be smaller than the second.
90       * @param zero the value at a ratio of zero
91       * @param one the value at a ratio of one
92       * @param ratio the ratio between 0 and 1, inclusive
93       * @return a LuminousIntensity at the given ratio between 0 and 1
94       */
95      public static LuminousIntensity interpolate(final LuminousIntensity zero, final LuminousIntensity one, final double ratio)
96      {
97          Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
98                  "ratio for interpolation should be between 0 and 1, but is %f", ratio);
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 the first scalar
106      * @param r2 the second scalar
107      * @return 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 the first scalar
117      * @param r2 the second scalar
118      * @param rn the other scalars
119      * @return 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 the first scalar
137      * @param r2 the second scalar
138      * @return 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 the first scalar
148      * @param r2 the second scalar
149      * @param rn the other scalars
150      * @return 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 the textual representation to parse into a LuminousIntensity
170      * @return 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             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity LuminousIntensity",
185                     unitString);
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 the value to use
198      * @param unitString the textual representation of the unit
199      * @return 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         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing LuminousIntensity with unit %s", unitString);
210         return new LuminousIntensity(value, unit);
211     }
212 
213     /**
214      * Calculate the division of LuminousIntensity and LuminousIntensity, which results in a Dimensionless scalar.
215      * @param v scalar
216      * @return scalar as a division of LuminousIntensity and LuminousIntensity
217      */
218     public final Dimensionless divide(final LuminousIntensity v)
219     {
220         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
221     }
222 
223     /**
224      * Calculate the multiplication of LuminousIntensity and SolidAngle, which results in a LuminousFlux scalar.
225      * @param v scalar
226      * @return scalar as a multiplication of LuminousIntensity and SolidAngle
227      */
228     public final LuminousFlux times(final SolidAngle v)
229     {
230         return new LuminousFlux(this.si * v.si, LuminousFluxUnit.SI);
231     }
232 
233     @Override
234     public SIScalar reciprocal()
235     {
236         return SIScalar.divide(Dimensionless.ONE, this);
237     }
238 
239     /**
240      * Multiply two scalars that result in a scalar of type LuminousIntensity.
241      * @param scalar1 the first scalar
242      * @param scalar2 the second scalar
243      * @return the multiplication of both scalars as an instance of LuminousIntensity
244      */
245     public static LuminousIntensity multiply(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
246     {
247         Throw.whenNull(scalar1, "scalar1 cannot be null");
248         Throw.whenNull(scalar2, "scalar2 cannot be null");
249         Throw.when(
250                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
251                         .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
252                         .equals(LuminousIntensityUnit.BASE.getSiDimensions()),
253                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type LuminousIntensity",
254                 scalar1.toDisplayString(), scalar2.toDisplayString());
255         return new LuminousIntensity(scalar1.si * scalar2.si, LuminousIntensityUnit.SI);
256     }
257 
258     /**
259      * Divide two scalars that result in a scalar of type LuminousIntensity.
260      * @param scalar1 the first scalar
261      * @param scalar2 the second scalar
262      * @return the division of scalar1 by scalar2 as an instance of LuminousIntensity
263      */
264     public static LuminousIntensity divide(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
265     {
266         Throw.whenNull(scalar1, "scalar1 cannot be null");
267         Throw.whenNull(scalar2, "scalar2 cannot be null");
268         Throw.when(
269                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
270                         .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
271                         .equals(LuminousIntensityUnit.BASE.getSiDimensions()),
272                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type LuminousIntensity",
273                 scalar1.toDisplayString(), scalar2.toDisplayString());
274         return new LuminousIntensity(scalar1.si / scalar2.si, LuminousIntensityUnit.SI);
275     }
276 
277 }