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