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