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.MoneyUnit;
6   
7   /**
8    * Easy access methods for the MoneyPerArea FloatScalar, which is relative by definition. An example is Speed. Instead of:
9    * 
10   * <pre>
11   * FloatScalar.Rel&lt;MoneyPerAreaUnit&gt; value = new FloatScalar.Rel&lt;MoneyPerAreaUnit&gt;(100.0, MoneyPerAreaUnit.SI);
12   * </pre>
13   * 
14   * we can now write:
15   * 
16   * <pre>
17   * FloatMoneyPerArea value = new FloatMoneyPerArea(100.0, MoneyPerAreaUnit.SI);
18   * </pre>
19   * 
20   * The compiler will automatically recognize which units belong to which quantity, and whether the quantity type and the unit
21   * used are compatible.
22   * <p>
23   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
24   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
25   * <p>
26   * $LastChangedDate: 2019-02-27 23:44:43 +0100 (Wed, 27 Feb 2019) $, @version $Revision: 333 $, by $Author: averbraeck $,
27   * initial version Sep 5, 2015 <br>
28   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
30   */
31  public class FloatMoneyPerArea extends AbstractFloatScalarRel<MoneyPerAreaUnit, FloatMoneyPerArea>
32  {
33      /** */
34      private static final long serialVersionUID = 20150901L;
35  
36      /**
37       * Construct FloatMoneyPerArea scalar.
38       * @param value float value
39       * @param unit unit for the float value
40       */
41      public FloatMoneyPerArea(final float value, final MoneyPerAreaUnit unit)
42      {
43          super(value, unit);
44      }
45  
46      /**
47       * Construct FloatMoneyPerArea scalar.
48       * @param value Scalar from which to construct this instance
49       */
50      public FloatMoneyPerArea(final FloatMoneyPerArea value)
51      {
52          super(value);
53      }
54  
55      /**
56       * Construct FloatMoneyPerArea scalar using a double value.
57       * @param value double value
58       * @param unit unit for the resulting float value
59       */
60      public FloatMoneyPerArea(final double value, final MoneyPerAreaUnit unit)
61      {
62          super((float) value, unit);
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public final FloatMoneyPerArea instantiateRel(final float value, final MoneyPerAreaUnit unit)
68      {
69          return new FloatMoneyPerArea(value, unit);
70      }
71  
72      /**
73       * Interpolate between two values.
74       * @param zero the low value
75       * @param one the high value
76       * @param ratio the ratio between 0 and 1, inclusive
77       * @return a Scalar at the ratio between
78       */
79      public static FloatMoneyPerArea interpolate(final FloatMoneyPerArea zero, final FloatMoneyPerArea one, final float ratio)
80      {
81          return new FloatMoneyPerArea(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
82      }
83  
84      /**
85       * Return the maximum value of two monetary scalars.
86       * @param r1 the first scalar
87       * @param r2 the second scalar
88       * @return the maximum value of two monetary scalars
89       */
90      public static FloatMoneyPerArea max(final FloatMoneyPerArea r1, final FloatMoneyPerArea r2)
91      {
92          return (r1.gt(r2)) ? r1 : r2;
93      }
94  
95      /**
96       * Return the maximum value of more than two monetary scalars.
97       * @param r1 the first scalar
98       * @param r2 the second scalar
99       * @param rn the other scalars
100      * @return the maximum value of more than two monetary scalars
101      */
102     public static FloatMoneyPerArea max(final FloatMoneyPerArea r1, final FloatMoneyPerArea r2, final FloatMoneyPerArea... rn)
103     {
104         FloatMoneyPerArea maxr = (r1.gt(r2)) ? r1 : r2;
105         for (FloatMoneyPerArea r : rn)
106         {
107             if (r.gt(maxr))
108             {
109                 maxr = r;
110             }
111         }
112         return maxr;
113     }
114 
115     /**
116      * Return the minimum value of two monetary scalars.
117      * @param r1 the first scalar
118      * @param r2 the second scalar
119      * @return the minimum value of two monetary scalars
120      */
121     public static FloatMoneyPerArea min(final FloatMoneyPerArea r1, final FloatMoneyPerArea r2)
122     {
123         return (r1.lt(r2)) ? r1 : r2;
124     }
125 
126     /**
127      * Return the minimum value of more than two monetary scalars.
128      * @param r1 the first scalar
129      * @param r2 the second scalar
130      * @param rn the other scalars
131      * @return the minimum value of more than two monetary scalars
132      */
133     public static FloatMoneyPerArea min(final FloatMoneyPerArea r1, final FloatMoneyPerArea r2, final FloatMoneyPerArea... rn)
134     {
135         FloatMoneyPerArea minr = (r1.lt(r2)) ? r1 : r2;
136         for (FloatMoneyPerArea r : rn)
137         {
138             if (r.lt(minr))
139             {
140                 minr = r;
141             }
142         }
143         return minr;
144     }
145 
146     /**
147      * Calculate the division of FloatMoneyPerArea and FloatMoneyPerArea, which results in a FloatDimensionless scalar.
148      * @param v FloatMoneyPerArea scalar
149      * @return FloatDimensionless scalar as a division of FloatMoneyPerArea and FloatMoneyPerArea
150      */
151     public final FloatDimensionless divideBy(final FloatMoneyPerArea v)
152     {
153         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
154     }
155 
156     /**
157      * Calculate the multiplication of FloatMoneyPerArea and FloatArea, which results in a FloatMoney scalar.
158      * @param v FloatMoneyPerArea scalar
159      * @return FloatMoney scalar as a multiplication of FloatMoneyPerArea and FloatArea
160      */
161     public final FloatMoney multiplyBy(final FloatArea v)
162     {
163         return new FloatMoney(this.si * v.si, MoneyUnit.getStandardMoneyUnit());
164     }
165 
166 }