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.FloatScalarRel;
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-2024 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-07-23T14:06:38.224104100Z")
28  public class FloatFrequency extends FloatScalarRel<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      @Override
85      public final FloatFrequency instantiateRel(final float value, final FrequencyUnit unit)
86      {
87          return new FloatFrequency(value, unit);
88      }
89  
90      /**
91       * Construct FloatFrequency scalar.
92       * @param value float; the float value in SI units
93       * @return the new scalar with the SI value
94       */
95      public static final FloatFrequency instantiateSI(final float value)
96      {
97          return new FloatFrequency(value, FrequencyUnit.SI);
98      }
99  
100     /**
101      * Interpolate between two values.
102      * @param zero the low value
103      * @param one the high value
104      * @param ratio double; the ratio between 0 and 1, inclusive
105      * @return a Scalar at the ratio between
106      */
107     public static FloatFrequency interpolate(final FloatFrequency zero, final FloatFrequency one, final float ratio)
108     {
109         return new FloatFrequency(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
110                 zero.getDisplayUnit());
111     }
112 
113     /**
114      * Return the maximum value of two relative scalars.
115      * @param r1 the first scalar
116      * @param r2 the second scalar
117      * @return the maximum value of two relative scalars
118      */
119     public static FloatFrequency max(final FloatFrequency r1, final FloatFrequency r2)
120     {
121         return r1.gt(r2) ? r1 : r2;
122     }
123 
124     /**
125      * Return the maximum value of more than two relative scalars.
126      * @param r1 the first scalar
127      * @param r2 the second scalar
128      * @param rn the other scalars
129      * @return the maximum value of more than two relative scalars
130      */
131     public static FloatFrequency max(final FloatFrequency r1, final FloatFrequency r2, final FloatFrequency... rn)
132     {
133         FloatFrequency maxr = r1.gt(r2) ? r1 : r2;
134         for (FloatFrequency r : rn)
135         {
136             if (r.gt(maxr))
137             {
138                 maxr = r;
139             }
140         }
141         return maxr;
142     }
143 
144     /**
145      * Return the minimum value of two relative scalars.
146      * @param r1 the first scalar
147      * @param r2 the second scalar
148      * @return the minimum value of two relative scalars
149      */
150     public static FloatFrequency min(final FloatFrequency r1, final FloatFrequency r2)
151     {
152         return r1.lt(r2) ? r1 : r2;
153     }
154 
155     /**
156      * Return the minimum value of more than two relative scalars.
157      * @param r1 the first scalar
158      * @param r2 the second scalar
159      * @param rn the other scalars
160      * @return the minimum value of more than two relative scalars
161      */
162     public static FloatFrequency min(final FloatFrequency r1, final FloatFrequency r2, final FloatFrequency... rn)
163     {
164         FloatFrequency minr = r1.lt(r2) ? r1 : r2;
165         for (FloatFrequency r : rn)
166         {
167             if (r.lt(minr))
168             {
169                 minr = r;
170             }
171         }
172         return minr;
173     }
174 
175     /**
176      * Returns a FloatFrequency representation of a textual representation of a value with a unit. The String representation
177      * that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces
178      * are allowed, but not required, between the value and the unit.
179      * @param text String; the textual representation to parse into a FloatFrequency
180      * @return FloatFrequency; the Scalar representation of the value in its unit
181      * @throws IllegalArgumentException when the text cannot be parsed
182      * @throws NullPointerException when the text argument is null
183      */
184     public static FloatFrequency valueOf(final String text)
185     {
186         Throw.whenNull(text, "Error parsing FloatFrequency: text to parse is null");
187         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatFrequency: empty text to parse");
188         try
189         {
190             NumberParser numberParser = new NumberParser().lenient().trailing();
191             float f = numberParser.parseFloat(text);
192             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
193             FrequencyUnit unit = FrequencyUnit.BASE.getUnitByAbbreviation(unitString);
194             if (unit == null)
195                 throw new IllegalArgumentException("Unit " + unitString + " not found");
196             return new FloatFrequency(f, unit);
197         }
198         catch (Exception exception)
199         {
200             throw new IllegalArgumentException(
201                     "Error parsing FloatFrequency from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
202                     exception);
203         }
204     }
205 
206     /**
207      * Returns a FloatFrequency based on a value and the textual representation of the unit, which can be localized.
208      * @param value double; the value to use
209      * @param unitString String; the textual representation of the unit
210      * @return FloatFrequency; the Scalar representation of the value in its unit
211      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
212      * @throws NullPointerException when the unitString argument is null
213      */
214     public static FloatFrequency of(final float value, final String unitString)
215     {
216         Throw.whenNull(unitString, "Error parsing FloatFrequency: unitString is null");
217         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatFrequency: empty unitString");
218         FrequencyUnit unit = FrequencyUnit.BASE.getUnitByAbbreviation(unitString);
219         if (unit != null)
220         {
221             return new FloatFrequency(value, unit);
222         }
223         throw new IllegalArgumentException("Error parsing FloatFrequency with unit " + unitString);
224     }
225 
226     /**
227      * Calculate the division of FloatFrequency and FloatFrequency, which results in a FloatDimensionless scalar.
228      * @param v FloatFrequency; scalar
229      * @return FloatDimensionless; scalar as a division of FloatFrequency and FloatFrequency
230      */
231     public final FloatDimensionless divide(final FloatFrequency v)
232     {
233         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
234     }
235 
236     /**
237      * Calculate the multiplication of FloatFrequency and FloatDuration, which results in a FloatDimensionless scalar.
238      * @param v FloatFrequency; scalar
239      * @return FloatDimensionless; scalar as a multiplication of FloatFrequency and FloatDuration
240      */
241     public final FloatDimensionless times(final FloatDuration v)
242     {
243         return new FloatDimensionless(this.si * v.si, DimensionlessUnit.SI);
244     }
245 
246     /**
247      * Calculate the multiplication of FloatFrequency and FloatLength, which results in a FloatSpeed scalar.
248      * @param v FloatFrequency; scalar
249      * @return FloatSpeed; scalar as a multiplication of FloatFrequency and FloatLength
250      */
251     public final FloatSpeed times(final FloatLength v)
252     {
253         return new FloatSpeed(this.si * v.si, SpeedUnit.SI);
254     }
255 
256     /**
257      * Calculate the multiplication of FloatFrequency and FloatSpeed, which results in a FloatAcceleration scalar.
258      * @param v FloatFrequency; scalar
259      * @return FloatAcceleration; scalar as a multiplication of FloatFrequency and FloatSpeed
260      */
261     public final FloatAcceleration times(final FloatSpeed v)
262     {
263         return new FloatAcceleration(this.si * v.si, AccelerationUnit.SI);
264     }
265 
266     /**
267      * Calculate the multiplication of FloatFrequency and FloatEnergy, which results in a FloatPower scalar.
268      * @param v FloatFrequency; scalar
269      * @return FloatPower; scalar as a multiplication of FloatFrequency and FloatEnergy
270      */
271     public final FloatPower times(final FloatEnergy v)
272     {
273         return new FloatPower(this.si * v.si, PowerUnit.SI);
274     }
275 
276     /**
277      * Calculate the multiplication of FloatFrequency and FloatAngle, which results in a FloatAngularVelocity scalar.
278      * @param v FloatFrequency; scalar
279      * @return FloatAngularVelocity; scalar as a multiplication of FloatFrequency and FloatAngle
280      */
281     public final FloatAngularVelocity times(final FloatAngle v)
282     {
283         return new FloatAngularVelocity(this.si * v.si, AngularVelocityUnit.SI);
284     }
285 
286     /**
287      * Calculate the multiplication of FloatFrequency and FloatAngularVelocity, which results in a FloatAngularAcceleration
288      * scalar.
289      * @param v FloatFrequency; scalar
290      * @return FloatAngularAcceleration; scalar as a multiplication of FloatFrequency and FloatAngularVelocity
291      */
292     public final FloatAngularAcceleration times(final FloatAngularVelocity v)
293     {
294         return new FloatAngularAcceleration(this.si * v.si, AngularAccelerationUnit.SI);
295     }
296 
297     @Override
298     public FloatDuration reciprocal()
299     {
300         return FloatDuration.instantiateSI(1.0f / this.si);
301     }
302 
303 }