View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import org.djunits.unit.AccelerationUnit;
4   import org.djunits.unit.DimensionlessUnit;
5   import org.djunits.unit.FrequencyUnit;
6   import org.djunits.unit.MoneyPerDurationUnit;
7   import org.djunits.unit.PowerUnit;
8   import org.djunits.unit.SpeedUnit;
9   
10  /**
11   * Easy access methods for the Frequency FloatScalar, which is relative by definition. An example is Speed. Instead of:
12   * 
13   * <pre>
14   * FloatScalar.Rel&lt;FrequencyUnit&gt; value = new FloatScalar.Rel&lt;FrequencyUnit&gt;(100.0, FrequencyUnit.SI);
15   * </pre>
16   * 
17   * we can now write:
18   * 
19   * <pre>
20   * FloatFrequency value = new FloatFrequency(100.0, FrequencyUnit.SI);
21   * </pre>
22   * 
23   * The compiler will automatically recognize which units belong to which quantity, and whether the quantity type and the unit
24   * used are compatible.
25   * <p>
26   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
27   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
28   * <p>
29   * $LastChangedDate: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, by $Author: averbraeck $,
30   * initial version Sep 5, 2015 <br>
31   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
32   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
33   */
34  public class FloatFrequency extends AbstractFloatScalarRel<FrequencyUnit, FloatFrequency>
35  {
36      /** */
37      private static final long serialVersionUID = 20150901L;
38  
39      /** constant with value zero. */
40      public static final FloatFrequency ZERO = new FloatFrequency(0.0f, FrequencyUnit.SI);
41  
42      /** constant with value NaN. */
43      @SuppressWarnings("checkstyle:constantname")
44      public static final FloatFrequency NaN = new FloatFrequency(Float.NaN, FrequencyUnit.SI);
45  
46      /** constant with value POSITIVE_INFINITY. */
47      public static final FloatFrequency POSITIVE_INFINITY = new FloatFrequency(Float.POSITIVE_INFINITY, FrequencyUnit.SI);
48  
49      /** constant with value NEGATIVE_INFINITY. */
50      public static final FloatFrequency NEGATIVE_INFINITY = new FloatFrequency(Float.NEGATIVE_INFINITY, FrequencyUnit.SI);
51  
52      /** constant with value MAX_VALUE. */
53      public static final FloatFrequency POS_MAXVALUE = new FloatFrequency(Float.MAX_VALUE, FrequencyUnit.SI);
54  
55      /** constant with value -MAX_VALUE. */
56      public static final FloatFrequency NEG_MAXVALUE = new FloatFrequency(-Float.MAX_VALUE, FrequencyUnit.SI);
57  
58      /**
59       * Construct FloatFrequency scalar.
60       * @param value float value
61       * @param unit unit for the float value
62       */
63      public FloatFrequency(final float value, final FrequencyUnit unit)
64      {
65          super(value, unit);
66      }
67  
68      /**
69       * Construct FloatFrequency scalar.
70       * @param value Scalar from which to construct this instance
71       */
72      public FloatFrequency(final FloatFrequency value)
73      {
74          super(value);
75      }
76  
77      /**
78       * Construct FloatFrequency scalar using a double value.
79       * @param value double value
80       * @param unit unit for the resulting float value
81       */
82      public FloatFrequency(final double value, final FrequencyUnit unit)
83      {
84          super((float) value, unit);
85      }
86  
87      /** {@inheritDoc} */
88      @Override
89      public final FloatFrequency instantiateRel(final float value, final FrequencyUnit unit)
90      {
91          return new FloatFrequency(value, unit);
92      }
93  
94      /**
95       * Construct FloatFrequency scalar.
96       * @param value float value in SI units
97       * @return the new scalar with the SI value
98       */
99      public static final FloatFrequency createSI(final float value)
100     {
101         return new FloatFrequency(value, FrequencyUnit.SI);
102     }
103 
104     /**
105      * Interpolate between two values.
106      * @param zero the low value
107      * @param one the high value
108      * @param ratio the ratio between 0 and 1, inclusive
109      * @return a Scalar at the ratio between
110      */
111     public static FloatFrequency interpolate(final FloatFrequency zero, final FloatFrequency one, final float ratio)
112     {
113         return new FloatFrequency(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
114     }
115 
116     /**
117      * Return the maximum value of two relative scalars.
118      * @param r1 the first scalar
119      * @param r2 the second scalar
120      * @return the maximum value of two relative scalars
121      */
122     public static FloatFrequency max(final FloatFrequency r1, final FloatFrequency r2)
123     {
124         return (r1.gt(r2)) ? r1 : r2;
125     }
126 
127     /**
128      * Return the maximum value of more than two relative scalars.
129      * @param r1 the first scalar
130      * @param r2 the second scalar
131      * @param rn the other scalars
132      * @return the maximum value of more than two relative scalars
133      */
134     public static FloatFrequency max(final FloatFrequency r1, final FloatFrequency r2, final FloatFrequency... rn)
135     {
136         FloatFrequency maxr = (r1.gt(r2)) ? r1 : r2;
137         for (FloatFrequency r : rn)
138         {
139             if (r.gt(maxr))
140             {
141                 maxr = r;
142             }
143         }
144         return maxr;
145     }
146 
147     /**
148      * Return the minimum value of two relative scalars.
149      * @param r1 the first scalar
150      * @param r2 the second scalar
151      * @return the minimum value of two relative scalars
152      */
153     public static FloatFrequency min(final FloatFrequency r1, final FloatFrequency r2)
154     {
155         return (r1.lt(r2)) ? r1 : r2;
156     }
157 
158     /**
159      * Return the minimum value of more than two relative scalars.
160      * @param r1 the first scalar
161      * @param r2 the second scalar
162      * @param rn the other scalars
163      * @return the minimum value of more than two relative scalars
164      */
165     public static FloatFrequency min(final FloatFrequency r1, final FloatFrequency r2, final FloatFrequency... rn)
166     {
167         FloatFrequency minr = (r1.lt(r2)) ? r1 : r2;
168         for (FloatFrequency r : rn)
169         {
170             if (r.lt(minr))
171             {
172                 minr = r;
173             }
174         }
175         return minr;
176     }
177 
178     /**
179      * Calculate the division of FloatFrequency and FloatFrequency, which results in a FloatDimensionless scalar.
180      * @param v FloatFrequency scalar
181      * @return FloatDimensionless scalar as a division of FloatFrequency and FloatFrequency
182      */
183     public final FloatDimensionless divideBy(final FloatFrequency v)
184     {
185         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
186     }
187 
188     /**
189      * Calculate the multiplication of FloatFrequency and FloatDuration, which results in a FloatDimensionless scalar.
190      * @param v FloatFrequency scalar
191      * @return FloatDimensionless scalar as a multiplication of FloatFrequency and FloatDuration
192      */
193     public final FloatDimensionless multiplyBy(final FloatDuration v)
194     {
195         return new FloatDimensionless(this.si * v.si, DimensionlessUnit.SI);
196     }
197 
198     /**
199      * Calculate the multiplication of FloatFrequency and FloatLength, which results in a FloatSpeed scalar.
200      * @param v FloatFrequency scalar
201      * @return FloatSpeed scalar as a multiplication of FloatFrequency and FloatLength
202      */
203     public final FloatSpeed multiplyBy(final FloatLength v)
204     {
205         return new FloatSpeed(this.si * v.si, SpeedUnit.SI);
206     }
207 
208     /**
209      * Calculate the multiplication of FloatFrequency and FloatSpeed, which results in a FloatAcceleration scalar.
210      * @param v FloatFrequency scalar
211      * @return FloatAcceleration scalar as a multiplication of FloatFrequency and FloatSpeed
212      */
213     public final FloatAcceleration multiplyBy(final FloatSpeed v)
214     {
215         return new FloatAcceleration(this.si * v.si, AccelerationUnit.SI);
216     }
217 
218     /**
219      * Calculate the multiplication of FloatFrequency and FloatEnergy, which results in a FloatPower scalar.
220      * @param v FloatFrequency scalar
221      * @return FloatPower scalar as a multiplication of FloatFrequency and FloatEnergy
222      */
223     public final FloatPower multiplyBy(final FloatEnergy v)
224     {
225         return new FloatPower(this.si * v.si, PowerUnit.SI);
226     }
227 
228     /**
229      * Calculate the multiplication of FloatFrequency and FloatMoney, which results in a FloatMoneyPerDuration scalar.
230      * @param v FloatFrequency scalar
231      * @return FloatMoneyPerDuration scalar as a multiplication of FloatFrequency and FloatMoney
232      */
233     public final FloatMoneyPerDuration multiplyBy(final FloatMoney v)
234     {
235         return new FloatMoneyPerDuration(this.si * v.si, MoneyPerDurationUnit.getStandardMoneyPerDurationUnit());
236     }
237 
238 }