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