View Javadoc
1   package org.djunits.value.vdouble.scalar;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.AreaUnit;
6   import org.djunits.unit.DimensionlessUnit;
7   import org.djunits.unit.IlluminanceUnit;
8   import org.djunits.unit.LuminousFluxUnit;
9   import org.djunits.unit.LuminousIntensityUnit;
10  import org.djunits.unit.SolidAngleUnit;
11  import org.djunits.value.vdouble.scalar.base.DoubleScalarRel;
12  import org.djutils.base.NumberParser;
13  import org.djutils.exceptions.Throw;
14  
15  import jakarta.annotation.Generated;
16  
17  /**
18   * Easy access methods for the LuminousFlux DoubleScalar, which is relative by definition.
19   * <p>
20   * Copyright (c) 2013-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
22   * </p>
23   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
24   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
25   */
26  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2025-09-06T15:16:28.380798Z")
27  public class LuminousFlux extends DoubleScalarRel<LuminousFluxUnit, LuminousFlux>
28  {
29      /** */
30      private static final long serialVersionUID = 20150905L;
31  
32      /** Constant with value zero. */
33      public static final LuminousFlux ZERO = new LuminousFlux(0.0, LuminousFluxUnit.SI);
34  
35      /** Constant with value one. */
36      public static final LuminousFlux ONE = new LuminousFlux(1.0, LuminousFluxUnit.SI);
37  
38      /** Constant with value NaN. */
39      @SuppressWarnings("checkstyle:constantname")
40      public static final LuminousFlux NaN = new LuminousFlux(Double.NaN, LuminousFluxUnit.SI);
41  
42      /** Constant with value POSITIVE_INFINITY. */
43      public static final LuminousFlux POSITIVE_INFINITY = new LuminousFlux(Double.POSITIVE_INFINITY, LuminousFluxUnit.SI);
44  
45      /** Constant with value NEGATIVE_INFINITY. */
46      public static final LuminousFlux NEGATIVE_INFINITY = new LuminousFlux(Double.NEGATIVE_INFINITY, LuminousFluxUnit.SI);
47  
48      /** Constant with value MAX_VALUE. */
49      public static final LuminousFlux POS_MAXVALUE = new LuminousFlux(Double.MAX_VALUE, LuminousFluxUnit.SI);
50  
51      /** Constant with value -MAX_VALUE. */
52      public static final LuminousFlux NEG_MAXVALUE = new LuminousFlux(-Double.MAX_VALUE, LuminousFluxUnit.SI);
53  
54      /**
55       * Construct LuminousFlux scalar with a unit.
56       * @param value the double value, expressed in the given unit
57       * @param unit unit for the double value
58       */
59      public LuminousFlux(final double value, final LuminousFluxUnit unit)
60      {
61          super(value, unit);
62      }
63  
64      /**
65       * Construct LuminousFlux scalar.
66       * @param value Scalar from which to construct this instance
67       */
68      public LuminousFlux(final LuminousFlux value)
69      {
70          super(value);
71      }
72  
73      @Override
74      public final LuminousFlux instantiateRel(final double value, final LuminousFluxUnit unit)
75      {
76          return new LuminousFlux(value, unit);
77      }
78  
79      /**
80       * Construct LuminousFlux scalar based on an SI value.
81       * @param value the double value in SI units
82       * @return the new scalar with the SI value
83       */
84      public static final LuminousFlux ofSI(final double value)
85      {
86          return new LuminousFlux(value, LuminousFluxUnit.SI);
87      }
88  
89      /**
90       * Interpolate between two values. Note that the first value does not have to be smaller than the second.
91       * @param zero the value at a ratio of zero
92       * @param one the value at a ratio of one
93       * @param ratio the ratio between 0 and 1, inclusive
94       * @return a LuminousFlux at the given ratio between 0 and 1
95       */
96      public static LuminousFlux interpolate(final LuminousFlux zero, final LuminousFlux one, final double ratio)
97      {
98          Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
99                  "ratio for interpolation should be between 0 and 1, but is %f", ratio);
100         return new LuminousFlux(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
101                 zero.getDisplayUnit());
102     }
103 
104     /**
105      * Return the maximum value of two relative scalars.
106      * @param r1 the first scalar
107      * @param r2 the second scalar
108      * @return the maximum value of two relative scalars
109      */
110     public static LuminousFlux max(final LuminousFlux r1, final LuminousFlux r2)
111     {
112         return r1.gt(r2) ? r1 : r2;
113     }
114 
115     /**
116      * Return the maximum value of more than two relative scalars.
117      * @param r1 the first scalar
118      * @param r2 the second scalar
119      * @param rn the other scalars
120      * @return the maximum value of more than two relative scalars
121      */
122     public static LuminousFlux max(final LuminousFlux r1, final LuminousFlux r2, final LuminousFlux... rn)
123     {
124         LuminousFlux maxr = r1.gt(r2) ? r1 : r2;
125         for (LuminousFlux r : rn)
126         {
127             if (r.gt(maxr))
128             {
129                 maxr = r;
130             }
131         }
132         return maxr;
133     }
134 
135     /**
136      * Return the minimum value of two relative scalars.
137      * @param r1 the first scalar
138      * @param r2 the second scalar
139      * @return the minimum value of two relative scalars
140      */
141     public static LuminousFlux min(final LuminousFlux r1, final LuminousFlux r2)
142     {
143         return r1.lt(r2) ? r1 : r2;
144     }
145 
146     /**
147      * Return the minimum value of more than two relative scalars.
148      * @param r1 the first scalar
149      * @param r2 the second scalar
150      * @param rn the other scalars
151      * @return the minimum value of more than two relative scalars
152      */
153     public static LuminousFlux min(final LuminousFlux r1, final LuminousFlux r2, final LuminousFlux... rn)
154     {
155         LuminousFlux minr = r1.lt(r2) ? r1 : r2;
156         for (LuminousFlux r : rn)
157         {
158             if (r.lt(minr))
159             {
160                 minr = r;
161             }
162         }
163         return minr;
164     }
165 
166     /**
167      * Returns a LuminousFlux representation of a textual representation of a value with a unit. The String representation that
168      * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
169      * allowed, but not required, between the value and the unit.
170      * @param text the textual representation to parse into a LuminousFlux
171      * @return the Scalar representation of the value in its unit
172      * @throws IllegalArgumentException when the text cannot be parsed
173      * @throws NullPointerException when the text argument is null
174      */
175     public static LuminousFlux valueOf(final String text)
176     {
177         Throw.whenNull(text, "Error parsing LuminousFlux: text to parse is null");
178         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing LuminousFlux: empty text to parse");
179         try
180         {
181             NumberParser numberParser = new NumberParser().lenient().trailing();
182             double d = numberParser.parseDouble(text);
183             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
184             LuminousFluxUnit unit = LuminousFluxUnit.BASE.getUnitByAbbreviation(unitString);
185             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity LuminousFlux", unitString);
186             return new LuminousFlux(d, unit);
187         }
188         catch (Exception exception)
189         {
190             throw new IllegalArgumentException(
191                     "Error parsing LuminousFlux from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
192                     exception);
193         }
194     }
195 
196     /**
197      * Returns a LuminousFlux based on a value and the textual representation of the unit, which can be localized.
198      * @param value the value to use
199      * @param unitString the textual representation of the unit
200      * @return the Scalar representation of the value in its unit
201      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
202      * @throws NullPointerException when the unitString argument is null
203      */
204     public static LuminousFlux of(final double value, final String unitString)
205     {
206         Throw.whenNull(unitString, "Error parsing LuminousFlux: unitString is null");
207         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing LuminousFlux: empty unitString");
208         LuminousFluxUnit unit = LuminousFluxUnit.BASE.getUnitByAbbreviation(unitString);
209         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing LuminousFlux with unit %s", unitString);
210         return new LuminousFlux(value, unit);
211     }
212 
213     /**
214      * Calculate the division of LuminousFlux and LuminousFlux, which results in a Dimensionless scalar.
215      * @param v scalar
216      * @return scalar as a division of LuminousFlux and LuminousFlux
217      */
218     public final Dimensionless divide(final LuminousFlux v)
219     {
220         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
221     }
222 
223     /**
224      * Calculate the division of LuminousFlux and Area, which results in a Illuminance scalar.
225      * @param v scalar
226      * @return scalar as a division of LuminousFlux and Area
227      */
228     public final Illuminance divide(final Area v)
229     {
230         return new Illuminance(this.si / v.si, IlluminanceUnit.SI);
231     }
232 
233     /**
234      * Calculate the division of LuminousFlux and Illuminance, which results in a Area scalar.
235      * @param v scalar
236      * @return scalar as a division of LuminousFlux and Illuminance
237      */
238     public final Area divide(final Illuminance v)
239     {
240         return new Area(this.si / v.si, AreaUnit.SI);
241     }
242 
243     /**
244      * Calculate the division of LuminousFlux and LuminousIntensity, which results in a SolidAngle scalar.
245      * @param v scalar
246      * @return scalar as a division of LuminousFlux and LuminousIntensity
247      */
248     public final SolidAngle divide(final LuminousIntensity v)
249     {
250         return new SolidAngle(this.si / v.si, SolidAngleUnit.SI);
251     }
252 
253     /**
254      * Calculate the division of LuminousFlux and SolidAngle, which results in a LuminousIntensity scalar.
255      * @param v scalar
256      * @return scalar as a division of LuminousFlux and SolidAngle
257      */
258     public final LuminousIntensity divide(final SolidAngle v)
259     {
260         return new LuminousIntensity(this.si / v.si, LuminousIntensityUnit.SI);
261     }
262 
263     @Override
264     public SIScalar reciprocal()
265     {
266         return SIScalar.divide(Dimensionless.ONE, this);
267     }
268 
269     /**
270      * Multiply two scalars that result in a scalar of type LuminousFlux.
271      * @param scalar1 the first scalar
272      * @param scalar2 the second scalar
273      * @return the multiplication of both scalars as an instance of LuminousFlux
274      */
275     public static LuminousFlux multiply(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
276     {
277         Throw.whenNull(scalar1, "scalar1 cannot be null");
278         Throw.whenNull(scalar2, "scalar2 cannot be null");
279         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
280                 .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(LuminousFluxUnit.BASE.getSiDimensions()),
281                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type LuminousFlux",
282                 scalar1.toDisplayString(), scalar2.toDisplayString());
283         return new LuminousFlux(scalar1.si * scalar2.si, LuminousFluxUnit.SI);
284     }
285 
286     /**
287      * Divide two scalars that result in a scalar of type LuminousFlux.
288      * @param scalar1 the first scalar
289      * @param scalar2 the second scalar
290      * @return the division of scalar1 by scalar2 as an instance of LuminousFlux
291      */
292     public static LuminousFlux divide(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
293     {
294         Throw.whenNull(scalar1, "scalar1 cannot be null");
295         Throw.whenNull(scalar2, "scalar2 cannot be null");
296         Throw.when(
297                 !scalar1.getDisplayUnit().getQuantity().getSiDimensions()
298                         .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions())
299                         .equals(LuminousFluxUnit.BASE.getSiDimensions()),
300                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type LuminousFlux",
301                 scalar1.toDisplayString(), scalar2.toDisplayString());
302         return new LuminousFlux(scalar1.si / scalar2.si, LuminousFluxUnit.SI);
303     }
304 
305 }