View Javadoc
1   package org.djunits.value.vdouble.scalar;
2   
3   import java.util.regex.Matcher;
4   
5   import javax.annotation.Generated;
6   
7   import org.djunits.Throw;
8   import org.djunits.unit.DimensionlessUnit;
9   import org.djunits.unit.IlluminanceUnit;
10  import org.djunits.unit.LuminousFluxUnit;
11  import org.djunits.value.util.ValueUtil;
12  import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRel;
13  
14  /**
15   * Easy access methods for the Illuminance DoubleScalar, which is relative by definition.
16   * <p>
17   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
19   * </p>
20   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
21   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
22   */
23  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2020-01-19T15:21:24.964166400Z")
24  public class Illuminance extends AbstractDoubleScalarRel<IlluminanceUnit, Illuminance>
25  {
26      /** */
27      private static final long serialVersionUID = 20150905L;
28  
29      /** Constant with value zero. */
30      public static final Illuminancealar/Illuminance.html#Illuminance">Illuminance ZERO = new Illuminance(0.0, IlluminanceUnit.SI);
31  
32      /** Constant with value one. */
33      public static final Illuminancecalar/Illuminance.html#Illuminance">Illuminance ONE = new Illuminance(1.0, IlluminanceUnit.SI);
34  
35      /** Constant with value NaN. */
36      @SuppressWarnings("checkstyle:constantname")
37      public static final Illuminancecalar/Illuminance.html#Illuminance">Illuminance NaN = new Illuminance(Double.NaN, IlluminanceUnit.SI);
38  
39      /** Constant with value POSITIVE_INFINITY. */
40      public static final Illuminancence.html#Illuminance">Illuminance POSITIVE_INFINITY = new Illuminance(Double.POSITIVE_INFINITY, IlluminanceUnit.SI);
41  
42      /** Constant with value NEGATIVE_INFINITY. */
43      public static final Illuminancence.html#Illuminance">Illuminance NEGATIVE_INFINITY = new Illuminance(Double.NEGATIVE_INFINITY, IlluminanceUnit.SI);
44  
45      /** Constant with value MAX_VALUE. */
46      public static final Illuminanceuminance.html#Illuminance">Illuminance POS_MAXVALUE = new Illuminance(Double.MAX_VALUE, IlluminanceUnit.SI);
47  
48      /** Constant with value -MAX_VALUE. */
49      public static final Illuminanceuminance.html#Illuminance">Illuminance NEG_MAXVALUE = new Illuminance(-Double.MAX_VALUE, IlluminanceUnit.SI);
50  
51      /**
52       * Construct Illuminance scalar.
53       * @param value double; the double value
54       * @param unit IlluminanceUnit; unit for the double value
55       */
56      public Illuminance(final double value, final IlluminanceUnit unit)
57      {
58          super(value, unit);
59      }
60  
61      /**
62       * Construct Illuminance scalar.
63       * @param value Illuminance; Scalar from which to construct this instance
64       */
65      public Illuminancele/scalar/Illuminance.html#Illuminance">Illuminance(final Illuminance value)
66      {
67          super(value);
68      }
69  
70      /** {@inheritDoc} */
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 Illuminancelar/Illuminance.html#Illuminance">Illuminanceluminance.html#Illuminance">Illuminance interpolate(final Illuminancelar/Illuminance.html#Illuminance">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 Illuminancecalar/Illuminance.html#Illuminance">Illuminancecalar/Illuminance.html#Illuminance">Illuminance max(final Illuminancecalar/Illuminance.html#Illuminance">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 Illuminancecalar/Illuminance.html#Illuminance">Illuminancecalar/Illuminance.html#Illuminance">Illuminance max(final Illuminancecalar/Illuminance.html#Illuminance">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 Illuminancecalar/Illuminance.html#Illuminance">Illuminancecalar/Illuminance.html#Illuminance">Illuminance min(final Illuminancecalar/Illuminance.html#Illuminance">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 Illuminancecalar/Illuminance.html#Illuminance">Illuminancecalar/Illuminance.html#Illuminance">Illuminance min(final Illuminancecalar/Illuminance.html#Illuminance">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 the official abbreviation of the unit. Spaces are allowed, but
165      * 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         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
176         if (matcher.find())
177         {
178             int index = matcher.end();
179             String unitString = text.substring(index).trim();
180             String valueString = text.substring(0, index).trim();
181             IlluminanceUnit unit = IlluminanceUnit.BASE.getUnitByAbbreviation(unitString);
182             if (unit != null)
183             {
184                 double d = Double.parseDouble(valueString);
185                 return new Illuminance(d, unit);
186             }
187         }
188         throw new IllegalArgumentException("Error parsing Illuminance from " + text);
189     }
190 
191     /**
192      * Returns a Illuminance based on a value and the textual representation of the unit.
193      * @param value double; the value to use
194      * @param unitString String; the textual representation of the unit
195      * @return Illuminance; the Scalar representation of the value in its unit
196      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
197      * @throws NullPointerException when the unitString argument is null
198      */
199     public static Illuminance of(final double value, final String unitString)
200     {
201         Throw.whenNull(unitString, "Error parsing Illuminance: unitString is null");
202         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Illuminance: empty unitString");
203         IlluminanceUnit unit = IlluminanceUnit.BASE.getUnitByAbbreviation(unitString);
204         if (unit != null)
205         {
206             return new Illuminance(value, unit);
207         }
208         throw new IllegalArgumentException("Error parsing Illuminance with unit " + unitString);
209     }
210 
211     /**
212      * Calculate the division of Illuminance and Illuminance, which results in a Dimensionless scalar.
213      * @param v Illuminance scalar
214      * @return Dimensionless scalar as a division of Illuminance and Illuminance
215      */
216     public final Dimensionless divide(final Illuminance v)
217     {
218         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
219     }
220 
221     /**
222      * Calculate the multiplication of Illuminance and Area, which results in a LuminousFlux scalar.
223      * @param v Illuminance scalar
224      * @return LuminousFlux scalar as a multiplication of Illuminance and Area
225      */
226     public final LuminousFlux times(final Area v)
227     {
228         return new LuminousFlux(this.si * v.si, LuminousFluxUnit.SI);
229     }
230 
231 }