1 package org.djunits.value.vdouble.scalar;
2
3 import org.djunits.unit.DimensionlessUnit;
4 import org.djunits.unit.MoneyPerVolumeUnit;
5 import org.djunits.unit.MoneyUnit;
6
7 /**
8 * Easy access methods for the MoneyPerVolume DoubleScalar, which is relative by definition. Instead of:
9 *
10 * <pre>
11 * DoubleScalar.Rel<MoneyPerVolumeUnit> value = new DoubleScalar.Rel<MoneyPerVolumeUnit>(100.0, MoneyPerVolumeUnit.SI);
12 * </pre>
13 *
14 * we can now write:
15 *
16 * <pre>
17 * MoneyPerVolume value = new MoneyPerVolume(100.0, MoneyPerVolumeUnit.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: 2015-10-16 02:04:00 +0200 (Fri, 16 Oct 2015) $, @version $Revision: 113 $, 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 MoneyPerVolume extends AbstractDoubleScalarRel<MoneyPerVolumeUnit, MoneyPerVolume>
32 {
33 /** */
34 private static final long serialVersionUID = 20150905L;
35
36 /**
37 * Construct MoneyPerVolume scalar.
38 * @param value double value
39 * @param unit unit for the double value
40 */
41 public MoneyPerVolume(final double value, final MoneyPerVolumeUnit unit)
42 {
43 super(value, unit);
44 }
45
46 /**
47 * Construct MoneyPerVolume scalar.
48 * @param value Scalar from which to construct this instance
49 */
50 public MoneyPerVolume(final MoneyPerVolume value)
51 {
52 super(value);
53 }
54
55 /** {@inheritDoc} */
56 @Override
57 public final MoneyPerVolume instantiateRel(final double value, final MoneyPerVolumeUnit unit)
58 {
59 return new MoneyPerVolume(value, unit);
60 }
61
62 /**
63 * Interpolate between two values.
64 * @param zero the low value
65 * @param one the high value
66 * @param ratio the ratio between 0 and 1, inclusive
67 * @return a Scalar at the ratio between
68 */
69 public static MoneyPerVolume interpolate(final MoneyPerVolume zero, final MoneyPerVolume one, final double ratio)
70 {
71 return new MoneyPerVolume(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
72 }
73
74 /**
75 * Return the maximum value of two monetary scalars.
76 * @param r1 the first scalar
77 * @param r2 the second scalar
78 * @return the maximum value of two monetary scalars
79 */
80 public static MoneyPerVolume max(final MoneyPerVolume r1, final MoneyPerVolume r2)
81 {
82 return (r1.gt(r2)) ? r1 : r2;
83 }
84
85 /**
86 * Return the maximum value of more than two monetary scalars.
87 * @param r1 the first scalar
88 * @param r2 the second scalar
89 * @param rn the other scalars
90 * @return the maximum value of more than two monetary scalars
91 */
92 public static MoneyPerVolume max(final MoneyPerVolume r1, final MoneyPerVolume r2, final MoneyPerVolume... rn)
93 {
94 MoneyPerVolume maxr = (r1.gt(r2)) ? r1 : r2;
95 for (MoneyPerVolume r : rn)
96 {
97 if (r.gt(maxr))
98 {
99 maxr = r;
100 }
101 }
102 return maxr;
103 }
104
105 /**
106 * Return the minimum value of two monetary scalars.
107 * @param r1 the first scalar
108 * @param r2 the second scalar
109 * @return the minimum value of two monetary scalars
110 */
111 public static MoneyPerVolume min(final MoneyPerVolume r1, final MoneyPerVolume r2)
112 {
113 return (r1.lt(r2)) ? r1 : r2;
114 }
115
116 /**
117 * Return the minimum value of more than two monetary scalars.
118 * @param r1 the first scalar
119 * @param r2 the second scalar
120 * @param rn the other scalars
121 * @return the minimum value of more than two monetary scalars
122 */
123 public static MoneyPerVolume min(final MoneyPerVolume r1, final MoneyPerVolume r2, final MoneyPerVolume... rn)
124 {
125 MoneyPerVolume minr = (r1.lt(r2)) ? r1 : r2;
126 for (MoneyPerVolume r : rn)
127 {
128 if (r.lt(minr))
129 {
130 minr = r;
131 }
132 }
133 return minr;
134 }
135
136 /**
137 * Calculate the division of MoneyPerVolume and MoneyPerVolume, which results in a Dimensionless scalar.
138 * @param v MoneyPerVolume scalar
139 * @return Dimensionless scalar as a division of MoneyPerVolume and MoneyPerVolume
140 */
141 public final Dimensionless divideBy(final MoneyPerVolume v)
142 {
143 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
144 }
145
146 /**
147 * Calculate the multiplication of MoneyPerVolume and Volume, which results in a Money scalar.
148 * @param v MoneyPerVolume scalar
149 * @return Money scalar as a multiplication of MoneyPerVolume and Volume
150 */
151 public final Money multiplyBy(final Volume v)
152 {
153 return new Money(this.si * v.si, MoneyUnit.getStandardMoneyUnit());
154 }
155
156 }