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