View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.DimensionlessUnit;
6   import org.djunits.unit.IlluminanceUnit;
7   import org.djunits.unit.LuminousFluxUnit;
8   import org.djunits.value.vfloat.scalar.base.FloatScalar;
9   import org.djunits.value.vfloat.scalar.base.FloatScalarRel;
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 FloatIlluminance FloatScalar, 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 FloatIlluminance extends FloatScalarRel<IlluminanceUnit, FloatIlluminance>
26  {
27      /** */
28      private static final long serialVersionUID = 20150901L;
29  
30      /** Constant with value zero. */
31      public static final FloatIlluminance ZERO = new FloatIlluminance(0.0f, IlluminanceUnit.SI);
32  
33      /** Constant with value one. */
34      public static final FloatIlluminance ONE = new FloatIlluminance(1.0f, IlluminanceUnit.SI);
35  
36      /** Constant with value NaN. */
37      @SuppressWarnings("checkstyle:constantname")
38      public static final FloatIlluminance NaN = new FloatIlluminance(Float.NaN, IlluminanceUnit.SI);
39  
40      /** Constant with value POSITIVE_INFINITY. */
41      public static final FloatIlluminance POSITIVE_INFINITY = new FloatIlluminance(Float.POSITIVE_INFINITY, IlluminanceUnit.SI);
42  
43      /** Constant with value NEGATIVE_INFINITY. */
44      public static final FloatIlluminance NEGATIVE_INFINITY = new FloatIlluminance(Float.NEGATIVE_INFINITY, IlluminanceUnit.SI);
45  
46      /** Constant with value MAX_VALUE. */
47      public static final FloatIlluminance POS_MAXVALUE = new FloatIlluminance(Float.MAX_VALUE, IlluminanceUnit.SI);
48  
49      /** Constant with value -MAX_VALUE. */
50      public static final FloatIlluminance NEG_MAXVALUE = new FloatIlluminance(-Float.MAX_VALUE, IlluminanceUnit.SI);
51  
52      /**
53       * Construct FloatIlluminance scalar.
54       * @param value float; the float value
55       * @param unit unit for the float value
56       */
57      public FloatIlluminance(final float value, final IlluminanceUnit unit)
58      {
59          super(value, unit);
60      }
61  
62      /**
63       * Construct FloatIlluminance scalar.
64       * @param value Scalar from which to construct this instance
65       */
66      public FloatIlluminance(final FloatIlluminance value)
67      {
68          super(value);
69      }
70  
71      /**
72       * Construct FloatIlluminance scalar using a double value.
73       * @param value double; the double value
74       * @param unit unit for the resulting float value
75       */
76      public FloatIlluminance(final double value, final IlluminanceUnit unit)
77      {
78          super((float) value, unit);
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      public final FloatIlluminance instantiateRel(final float value, final IlluminanceUnit unit)
84      {
85          return new FloatIlluminance(value, unit);
86      }
87  
88      /**
89       * Construct FloatIlluminance scalar.
90       * @param value float; the float value in SI units
91       * @return the new scalar with the SI value
92       */
93      public static final FloatIlluminance instantiateSI(final float value)
94      {
95          return new FloatIlluminance(value, IlluminanceUnit.SI);
96      }
97  
98      /**
99       * Interpolate between two values.
100      * @param zero the low value
101      * @param one the high value
102      * @param ratio double; the ratio between 0 and 1, inclusive
103      * @return a Scalar at the ratio between
104      */
105     public static FloatIlluminance interpolate(final FloatIlluminance zero, final FloatIlluminance one, final float ratio)
106     {
107         return new FloatIlluminance(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
108                 zero.getDisplayUnit());
109     }
110 
111     /**
112      * Return the maximum value of two relative scalars.
113      * @param r1 the first scalar
114      * @param r2 the second scalar
115      * @return the maximum value of two relative scalars
116      */
117     public static FloatIlluminance max(final FloatIlluminance r1, final FloatIlluminance r2)
118     {
119         return r1.gt(r2) ? r1 : r2;
120     }
121 
122     /**
123      * Return the maximum value of more than two relative scalars.
124      * @param r1 the first scalar
125      * @param r2 the second scalar
126      * @param rn the other scalars
127      * @return the maximum value of more than two relative scalars
128      */
129     public static FloatIlluminance max(final FloatIlluminance r1, final FloatIlluminance r2, final FloatIlluminance... rn)
130     {
131         FloatIlluminance maxr = r1.gt(r2) ? r1 : r2;
132         for (FloatIlluminance r : rn)
133         {
134             if (r.gt(maxr))
135             {
136                 maxr = r;
137             }
138         }
139         return maxr;
140     }
141 
142     /**
143      * Return the minimum value of two relative scalars.
144      * @param r1 the first scalar
145      * @param r2 the second scalar
146      * @return the minimum value of two relative scalars
147      */
148     public static FloatIlluminance min(final FloatIlluminance r1, final FloatIlluminance r2)
149     {
150         return r1.lt(r2) ? r1 : r2;
151     }
152 
153     /**
154      * Return the minimum value of more than two relative scalars.
155      * @param r1 the first scalar
156      * @param r2 the second scalar
157      * @param rn the other scalars
158      * @return the minimum value of more than two relative scalars
159      */
160     public static FloatIlluminance min(final FloatIlluminance r1, final FloatIlluminance r2, final FloatIlluminance... rn)
161     {
162         FloatIlluminance minr = r1.lt(r2) ? r1 : r2;
163         for (FloatIlluminance r : rn)
164         {
165             if (r.lt(minr))
166             {
167                 minr = r;
168             }
169         }
170         return minr;
171     }
172 
173     /**
174      * Returns a FloatIlluminance representation of a textual representation of a value with a unit. The String representation
175      * that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces
176      * are allowed, but not required, between the value and the unit.
177      * @param text String; the textual representation to parse into a FloatIlluminance
178      * @return FloatIlluminance; the Scalar representation of the value in its unit
179      * @throws IllegalArgumentException when the text cannot be parsed
180      * @throws NullPointerException when the text argument is null
181      */
182     public static FloatIlluminance valueOf(final String text)
183     {
184         Throw.whenNull(text, "Error parsing FloatIlluminance: text to parse is null");
185         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatIlluminance: empty text to parse");
186         try
187         {
188             NumberParser numberParser = new NumberParser().lenient().trailing();
189             float f = numberParser.parseFloat(text);
190             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
191             IlluminanceUnit unit = IlluminanceUnit.BASE.getUnitByAbbreviation(unitString);
192             if (unit == null)
193                 throw new IllegalArgumentException("Unit " + unitString + " not found");
194             return new FloatIlluminance(f, unit);
195         }
196         catch (Exception exception)
197         {
198             throw new IllegalArgumentException("Error parsing FloatIlluminance from " + text + " using Locale "
199                     + Locale.getDefault(Locale.Category.FORMAT), exception);
200         }
201     }
202 
203     /**
204      * Returns a FloatIlluminance based on a value and the textual representation of the unit, which can be localized.
205      * @param value double; the value to use
206      * @param unitString String; the textual representation of the unit
207      * @return FloatIlluminance; the Scalar representation of the value in its unit
208      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
209      * @throws NullPointerException when the unitString argument is null
210      */
211     public static FloatIlluminance of(final float value, final String unitString)
212     {
213         Throw.whenNull(unitString, "Error parsing FloatIlluminance: unitString is null");
214         Throw.when(unitString.length() == 0, IllegalArgumentException.class,
215                 "Error parsing FloatIlluminance: empty unitString");
216         IlluminanceUnit unit = IlluminanceUnit.BASE.getUnitByAbbreviation(unitString);
217         if (unit != null)
218         {
219             return new FloatIlluminance(value, unit);
220         }
221         throw new IllegalArgumentException("Error parsing FloatIlluminance with unit " + unitString);
222     }
223 
224     /**
225      * Calculate the division of FloatIlluminance and FloatIlluminance, which results in a FloatDimensionless scalar.
226      * @param v FloatIlluminance; scalar
227      * @return FloatDimensionless; scalar as a division of FloatIlluminance and FloatIlluminance
228      */
229     public final FloatDimensionless divide(final FloatIlluminance v)
230     {
231         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
232     }
233 
234     /**
235      * Calculate the multiplication of FloatIlluminance and FloatArea, which results in a FloatLuminousFlux scalar.
236      * @param v FloatIlluminance; scalar
237      * @return FloatLuminousFlux; scalar as a multiplication of FloatIlluminance and FloatArea
238      */
239     public final FloatLuminousFlux times(final FloatArea v)
240     {
241         return new FloatLuminousFlux(this.si * v.si, LuminousFluxUnit.SI);
242     }
243 
244     /** {@inheritDoc} */
245     @Override
246     public FloatSIScalar reciprocal()
247     {
248         return FloatScalar.divide(FloatDimensionless.ONE, this);
249     }
250 
251 }