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