View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import org.djunits.unit.DimensionlessUnit;
4   import org.djunits.unit.MoneyPerEnergyUnit;
5   import org.djunits.unit.MoneyUnit;
6   
7   /**
8    * Easy access methods for the MoneyPerEnergy FloatScalar, which is relative by definition. An example is Speed. Instead of:
9    * 
10   * <pre>
11   * FloatScalar.Rel&lt;MoneyPerEnergyUnit&gt; value = new FloatScalar.Rel&lt;MoneyPerEnergyUnit&gt;(100.0, MoneyPerEnergyUnit.SI);
12   * </pre>
13   * 
14   * we can now write:
15   * 
16   * <pre>
17   * FloatMoneyPerEnergy value = new FloatMoneyPerEnergy(100.0, MoneyPerEnergyUnit.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 FloatMoneyPerEnergy extends AbstractFloatScalarRel<MoneyPerEnergyUnit, FloatMoneyPerEnergy>
32  {
33      /** */
34      private static final long serialVersionUID = 20150901L;
35  
36      /**
37       * Construct FloatMoneyPerEnergy scalar.
38       * @param value float value
39       * @param unit unit for the float value
40       */
41      public FloatMoneyPerEnergy(final float value, final MoneyPerEnergyUnit unit)
42      {
43          super(value, unit);
44      }
45  
46      /**
47       * Construct FloatMoneyPerEnergy scalar.
48       * @param value Scalar from which to construct this instance
49       */
50      public FloatMoneyPerEnergy(final FloatMoneyPerEnergy value)
51      {
52          super(value);
53      }
54  
55      /**
56       * Construct FloatMoneyPerEnergy scalar using a double value.
57       * @param value double value
58       * @param unit unit for the resulting float value
59       */
60      public FloatMoneyPerEnergy(final double value, final MoneyPerEnergyUnit unit)
61      {
62          super((float) value, unit);
63      }
64  
65      /** {@inheritDoc} */
66      @Override
67      public final FloatMoneyPerEnergy instantiateRel(final float value, final MoneyPerEnergyUnit unit)
68      {
69          return new FloatMoneyPerEnergy(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 FloatMoneyPerEnergy interpolate(final FloatMoneyPerEnergy zero, final FloatMoneyPerEnergy one,
80              final float ratio)
81      {
82          return new FloatMoneyPerEnergy(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 FloatMoneyPerEnergy max(final FloatMoneyPerEnergy r1, final FloatMoneyPerEnergy 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 FloatMoneyPerEnergy max(final FloatMoneyPerEnergy r1, final FloatMoneyPerEnergy r2,
104             final FloatMoneyPerEnergy... rn)
105     {
106         FloatMoneyPerEnergy maxr = (r1.gt(r2)) ? r1 : r2;
107         for (FloatMoneyPerEnergy 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 FloatMoneyPerEnergy min(final FloatMoneyPerEnergy r1, final FloatMoneyPerEnergy 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 FloatMoneyPerEnergy min(final FloatMoneyPerEnergy r1, final FloatMoneyPerEnergy r2,
136             final FloatMoneyPerEnergy... rn)
137     {
138         FloatMoneyPerEnergy minr = (r1.lt(r2)) ? r1 : r2;
139         for (FloatMoneyPerEnergy 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 FloatMoneyPerEnergy and FloatMoneyPerEnergy, which results in a FloatDimensionless scalar.
151      * @param v FloatMoneyPerEnergy scalar
152      * @return FloatDimensionless scalar as a division of FloatMoneyPerEnergy and FloatMoneyPerEnergy
153      */
154     public final FloatDimensionless divideBy(final FloatMoneyPerEnergy v)
155     {
156         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
157     }
158 
159     /**
160      * Calculate the multiplication of FloatMoneyPerEnergy and FloatEnergy, which results in a FloatMoney scalar.
161      * @param v FloatMoneyPerEnergy scalar
162      * @return FloatMoney scalar as a multiplication of FloatMoneyPerEnergy and FloatEnergy
163      */
164     public final FloatMoney multiplyBy(final FloatEnergy v)
165     {
166         return new FloatMoney(this.si * v.si, MoneyUnit.getStandardMoneyUnit());
167     }
168 
169 }