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