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