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