View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import org.djunits.unit.DimensionlessUnit;
4   import org.djunits.unit.MoneyPerLengthUnit;
5   import org.djunits.unit.MoneyUnit;
6   
7   /**
8    * Easy access methods for the MoneyPerLength FloatScalar, which is relative by definition. An example is Speed. Instead of:
9    * 
10   * <pre>
11   * FloatScalar.Rel&lt;MoneyPerLengthUnit&gt; value = new FloatScalar.Rel&lt;MoneyPerLengthUnit&gt;(100.0, MoneyPerLengthUnit.SI);
12   * </pre>
13   * 
14   * we can now write:
15   * 
16   * <pre>
17   * FloatMoneyPerLength value = new FloatMoneyPerLength(100.0, MoneyPerLengthUnit.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 FloatMoneyPerLength extends AbstractFloatScalarRel<MoneyPerLengthUnit, FloatMoneyPerLength>
32  {
33      /** */
34      private static final long serialVersionUID = 20150901L;
35  
36      /**
37       * Construct FloatMoneyPerLength scalar.
38       * @param value float value
39       * @param unit unit for the float value
40       */
41      public FloatMoneyPerLength(final float value, final MoneyPerLengthUnit unit)
42      {
43          super(value, unit);
44      }
45  
46      /**
47       * Construct FloatMoneyPerLength scalar.
48       * @param value Scalar from which to construct this instance
49       */
50      public FloatMoneyPerLength(final FloatMoneyPerLength value)
51      {
52          super(value);
53      }
54  
55      /**
56       * Construct FloatMoneyPerLength scalar using a double value.
57       * @param value double value
58       * @param unit unit for the resulting float value
59       */
60      public FloatMoneyPerLength(final double value, final MoneyPerLengthUnit unit)
61      {
62          super((float) value, unit);
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public final FloatMoneyPerLength instantiateRel(final float value, final MoneyPerLengthUnit unit)
68      {
69          return new FloatMoneyPerLength(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 FloatMoneyPerLength interpolate(final FloatMoneyPerLength zero, final FloatMoneyPerLength one,
80              final float ratio)
81      {
82          return new FloatMoneyPerLength(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
83      }
84  
85      /**
86       * Return the maximum value of two monetary scalars.
87       * @param r1 the first scalar
88       * @param r2 the second scalar
89       * @return the maximum value of two monetary scalars
90       */
91      public static FloatMoneyPerLength max(final FloatMoneyPerLength r1, final FloatMoneyPerLength r2)
92      {
93          return (r1.gt(r2)) ? r1 : r2;
94      }
95  
96      /**
97       * Return the maximum value of more than two monetary scalars.
98       * @param r1 the first scalar
99       * @param r2 the second scalar
100      * @param rn the other scalars
101      * @return the maximum value of more than two monetary scalars
102      */
103     public static FloatMoneyPerLength max(final FloatMoneyPerLength r1, final FloatMoneyPerLength r2,
104             final FloatMoneyPerLength... rn)
105     {
106         FloatMoneyPerLength maxr = (r1.gt(r2)) ? r1 : r2;
107         for (FloatMoneyPerLength r : rn)
108         {
109             if (r.gt(maxr))
110             {
111                 maxr = r;
112             }
113         }
114         return maxr;
115     }
116 
117     /**
118      * Return the minimum value of two monetary scalars.
119      * @param r1 the first scalar
120      * @param r2 the second scalar
121      * @return the minimum value of two monetary scalars
122      */
123     public static FloatMoneyPerLength min(final FloatMoneyPerLength r1, final FloatMoneyPerLength r2)
124     {
125         return (r1.lt(r2)) ? r1 : r2;
126     }
127 
128     /**
129      * Return the minimum value of more than two monetary scalars.
130      * @param r1 the first scalar
131      * @param r2 the second scalar
132      * @param rn the other scalars
133      * @return the minimum value of more than two monetary scalars
134      */
135     public static FloatMoneyPerLength min(final FloatMoneyPerLength r1, final FloatMoneyPerLength r2,
136             final FloatMoneyPerLength... rn)
137     {
138         FloatMoneyPerLength minr = (r1.lt(r2)) ? r1 : r2;
139         for (FloatMoneyPerLength r : rn)
140         {
141             if (r.lt(minr))
142             {
143                 minr = r;
144             }
145         }
146         return minr;
147     }
148 
149     /**
150      * Calculate the division of FloatMoneyPerLength and FloatMoneyPerLength, which results in a FloatDimensionless scalar.
151      * @param v FloatMoneyPerLength scalar
152      * @return FloatDimensionless scalar as a division of FloatMoneyPerLength and FloatMoneyPerLength
153      */
154     public final FloatDimensionless divideBy(final FloatMoneyPerLength v)
155     {
156         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
157     }
158 
159     /**
160      * Calculate the multiplication of FloatMoneyPerLength and FloatLength, which results in a FloatMoney scalar.
161      * @param v FloatMoneyPerLength scalar
162      * @return FloatMoney scalar as a multiplication of FloatMoneyPerLength and FloatLength
163      */
164     public final FloatMoney multiplyBy(final FloatLength v)
165     {
166         return new FloatMoney(this.si * v.si, MoneyUnit.getStandardMoneyUnit());
167     }
168 
169     /**
170      * Calculate the division of FloatMoneyPerLength and FloatLinearDensity, which results in a FloatMoney scalar.
171      * @param v FloatMoneyPerLength scalar
172      * @return FloatMoney scalar as a division of FloatMoneyPerLength and FloatLinearDensity
173      */
174     public final FloatMoney divideBy(final FloatLinearDensity v)
175     {
176         return new FloatMoney(this.si / v.si, MoneyUnit.getStandardMoneyUnit());
177     }
178 
179 }