View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.AccelerationUnit;
6   import org.djunits.unit.AngularAccelerationUnit;
7   import org.djunits.unit.AngularVelocityUnit;
8   import org.djunits.unit.DimensionlessUnit;
9   import org.djunits.unit.FrequencyUnit;
10  import org.djunits.unit.PowerUnit;
11  import org.djunits.unit.SpeedUnit;
12  import org.djunits.value.vfloat.scalar.base.AbstractFloatScalarRel;
13  import org.djutils.base.NumberParser;
14  import org.djutils.exceptions.Throw;
15  
16  import jakarta.annotation.Generated;
17  
18  /**
19   * Easy access methods for the FloatFrequency FloatScalar, which is relative by definition.
20   * <p>
21   * Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. 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 = "2023-04-30T13:59:27.633664900Z")
28  public class FloatFrequency extends AbstractFloatScalarRel<FrequencyUnit, FloatFrequency>
29  {
30      /** */
31      private static final long serialVersionUID = 20150901L;
32  
33      /** Constant with value zero. */
34      public static final FloatFrequency ZERO = new FloatFrequency(0.0f, FrequencyUnit.SI);
35  
36      /** Constant with value one. */
37      public static final FloatFrequency ONE = new FloatFrequency(1.0f, FrequencyUnit.SI);
38  
39      /** Constant with value NaN. */
40      @SuppressWarnings("checkstyle:constantname")
41      public static final FloatFrequency NaN = new FloatFrequency(Float.NaN, FrequencyUnit.SI);
42  
43      /** Constant with value POSITIVE_INFINITY. */
44      public static final FloatFrequency POSITIVE_INFINITY = new FloatFrequency(Float.POSITIVE_INFINITY, FrequencyUnit.SI);
45  
46      /** Constant with value NEGATIVE_INFINITY. */
47      public static final FloatFrequency NEGATIVE_INFINITY = new FloatFrequency(Float.NEGATIVE_INFINITY, FrequencyUnit.SI);
48  
49      /** Constant with value MAX_VALUE. */
50      public static final FloatFrequency POS_MAXVALUE = new FloatFrequency(Float.MAX_VALUE, FrequencyUnit.SI);
51  
52      /** Constant with value -MAX_VALUE. */
53      public static final FloatFrequency NEG_MAXVALUE = new FloatFrequency(-Float.MAX_VALUE, FrequencyUnit.SI);
54  
55      /**
56       * Construct FloatFrequency scalar.
57       * @param value float; the float value
58       * @param unit unit for the float value
59       */
60      public FloatFrequency(final float value, final FrequencyUnit unit)
61      {
62          super(value, unit);
63      }
64  
65      /**
66       * Construct FloatFrequency scalar.
67       * @param value Scalar from which to construct this instance
68       */
69      public FloatFrequency(final FloatFrequency value)
70      {
71          super(value);
72      }
73  
74      /**
75       * Construct FloatFrequency scalar using a double value.
76       * @param value double; the double value
77       * @param unit unit for the resulting float value
78       */
79      public FloatFrequency(final double value, final FrequencyUnit unit)
80      {
81          super((float) value, unit);
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public final FloatFrequency instantiateRel(final float value, final FrequencyUnit unit)
87      {
88          return new FloatFrequency(value, unit);
89      }
90  
91      /**
92       * Construct FloatFrequency scalar.
93       * @param value float; the float value in SI units
94       * @return the new scalar with the SI value
95       */
96      public static final FloatFrequency instantiateSI(final float value)
97      {
98          return new FloatFrequency(value, FrequencyUnit.SI);
99      }
100 
101     /**
102      * Interpolate between two values.
103      * @param zero the low value
104      * @param one the high value
105      * @param ratio double; the ratio between 0 and 1, inclusive
106      * @return a Scalar at the ratio between
107      */
108     public static FloatFrequency interpolate(final FloatFrequency zero, final FloatFrequency one, final float ratio)
109     {
110         return new FloatFrequency(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
111                 zero.getDisplayUnit());
112     }
113 
114     /**
115      * Return the maximum value of two relative scalars.
116      * @param r1 the first scalar
117      * @param r2 the second scalar
118      * @return the maximum value of two relative scalars
119      */
120     public static FloatFrequency max(final FloatFrequency r1, final FloatFrequency r2)
121     {
122         return r1.gt(r2) ? r1 : r2;
123     }
124 
125     /**
126      * Return the maximum value of more than two relative scalars.
127      * @param r1 the first scalar
128      * @param r2 the second scalar
129      * @param rn the other scalars
130      * @return the maximum value of more than two relative scalars
131      */
132     public static FloatFrequency max(final FloatFrequency r1, final FloatFrequency r2, final FloatFrequency... rn)
133     {
134         FloatFrequency maxr = r1.gt(r2) ? r1 : r2;
135         for (FloatFrequency r : rn)
136         {
137             if (r.gt(maxr))
138             {
139                 maxr = r;
140             }
141         }
142         return maxr;
143     }
144 
145     /**
146      * Return the minimum value of two relative scalars.
147      * @param r1 the first scalar
148      * @param r2 the second scalar
149      * @return the minimum value of two relative scalars
150      */
151     public static FloatFrequency min(final FloatFrequency r1, final FloatFrequency r2)
152     {
153         return r1.lt(r2) ? r1 : r2;
154     }
155 
156     /**
157      * Return the minimum value of more than two relative scalars.
158      * @param r1 the first scalar
159      * @param r2 the second scalar
160      * @param rn the other scalars
161      * @return the minimum value of more than two relative scalars
162      */
163     public static FloatFrequency min(final FloatFrequency r1, final FloatFrequency r2, final FloatFrequency... rn)
164     {
165         FloatFrequency minr = r1.lt(r2) ? r1 : r2;
166         for (FloatFrequency r : rn)
167         {
168             if (r.lt(minr))
169             {
170                 minr = r;
171             }
172         }
173         return minr;
174     }
175 
176     /**
177      * Returns a FloatFrequency representation of a textual representation of a value with a unit. The String representation
178      * that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces
179      * are allowed, but not required, between the value and the unit.
180      * @param text String; the textual representation to parse into a FloatFrequency
181      * @return FloatFrequency; the Scalar representation of the value in its unit
182      * @throws IllegalArgumentException when the text cannot be parsed
183      * @throws NullPointerException when the text argument is null
184      */
185     public static FloatFrequency valueOf(final String text)
186     {
187         Throw.whenNull(text, "Error parsing FloatFrequency: text to parse is null");
188         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatFrequency: empty text to parse");
189         try
190         {
191             NumberParser numberParser = new NumberParser().lenient().trailing();
192             float f = numberParser.parseFloat(text);
193             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
194             FrequencyUnit unit = FrequencyUnit.BASE.getUnitByAbbreviation(unitString);
195             if (unit == null)
196                 throw new IllegalArgumentException("Unit " + unitString + " not found");
197             return new FloatFrequency(f, unit);
198         }
199         catch (Exception exception)
200         {
201             throw new IllegalArgumentException(
202                     "Error parsing FloatFrequency from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
203                     exception);
204         }
205     }
206 
207     /**
208      * Returns a FloatFrequency based on a value and the textual representation of the unit, which can be localized.
209      * @param value double; the value to use
210      * @param unitString String; the textual representation of the unit
211      * @return FloatFrequency; the Scalar representation of the value in its unit
212      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
213      * @throws NullPointerException when the unitString argument is null
214      */
215     public static FloatFrequency of(final float value, final String unitString)
216     {
217         Throw.whenNull(unitString, "Error parsing FloatFrequency: unitString is null");
218         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatFrequency: empty unitString");
219         FrequencyUnit unit = FrequencyUnit.BASE.getUnitByAbbreviation(unitString);
220         if (unit != null)
221         {
222             return new FloatFrequency(value, unit);
223         }
224         throw new IllegalArgumentException("Error parsing FloatFrequency with unit " + unitString);
225     }
226 
227     /**
228      * Calculate the division of FloatFrequency and FloatFrequency, which results in a FloatDimensionless scalar.
229      * @param v FloatFrequency; scalar
230      * @return FloatDimensionless; scalar as a division of FloatFrequency and FloatFrequency
231      */
232     public final FloatDimensionless divide(final FloatFrequency v)
233     {
234         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
235     }
236 
237     /**
238      * Calculate the multiplication of FloatFrequency and FloatDuration, which results in a FloatDimensionless scalar.
239      * @param v FloatFrequency; scalar
240      * @return FloatDimensionless; scalar as a multiplication of FloatFrequency and FloatDuration
241      */
242     public final FloatDimensionless times(final FloatDuration v)
243     {
244         return new FloatDimensionless(this.si * v.si, DimensionlessUnit.SI);
245     }
246 
247     /**
248      * Calculate the multiplication of FloatFrequency and FloatLength, which results in a FloatSpeed scalar.
249      * @param v FloatFrequency; scalar
250      * @return FloatSpeed; scalar as a multiplication of FloatFrequency and FloatLength
251      */
252     public final FloatSpeed times(final FloatLength v)
253     {
254         return new FloatSpeed(this.si * v.si, SpeedUnit.SI);
255     }
256 
257     /**
258      * Calculate the multiplication of FloatFrequency and FloatSpeed, which results in a FloatAcceleration scalar.
259      * @param v FloatFrequency; scalar
260      * @return FloatAcceleration; scalar as a multiplication of FloatFrequency and FloatSpeed
261      */
262     public final FloatAcceleration times(final FloatSpeed v)
263     {
264         return new FloatAcceleration(this.si * v.si, AccelerationUnit.SI);
265     }
266 
267     /**
268      * Calculate the multiplication of FloatFrequency and FloatEnergy, which results in a FloatPower scalar.
269      * @param v FloatFrequency; scalar
270      * @return FloatPower; scalar as a multiplication of FloatFrequency and FloatEnergy
271      */
272     public final FloatPower times(final FloatEnergy v)
273     {
274         return new FloatPower(this.si * v.si, PowerUnit.SI);
275     }
276 
277     /**
278      * Calculate the multiplication of FloatFrequency and FloatAngle, which results in a FloatAngularVelocity scalar.
279      * @param v FloatFrequency; scalar
280      * @return FloatAngularVelocity; scalar as a multiplication of FloatFrequency and FloatAngle
281      */
282     public final FloatAngularVelocity times(final FloatAngle v)
283     {
284         return new FloatAngularVelocity(this.si * v.si, AngularVelocityUnit.SI);
285     }
286 
287     /**
288      * Calculate the multiplication of FloatFrequency and FloatAngularVelocity, which results in a FloatAngularAcceleration
289      * scalar.
290      * @param v FloatFrequency; scalar
291      * @return FloatAngularAcceleration; scalar as a multiplication of FloatFrequency and FloatAngularVelocity
292      */
293     public final FloatAngularAcceleration times(final FloatAngularVelocity v)
294     {
295         return new FloatAngularAcceleration(this.si * v.si, AngularAccelerationUnit.SI);
296     }
297 
298     /** {@inheritDoc} */
299     @Override
300     public FloatDuration reciprocal()
301     {
302         return FloatDuration.instantiateSI(1.0f / this.si);
303     }
304 
305 }