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