1 package org.djunits.value.vdouble.scalar;
2
3 import org.djunits.unit.AreaUnit;
4 import org.djunits.unit.DimensionlessUnit;
5 import org.djunits.unit.DurationUnit;
6 import org.djunits.unit.EnergyUnit;
7 import org.djunits.unit.FlowVolumeUnit;
8 import org.djunits.unit.LengthUnit;
9 import org.djunits.unit.MassUnit;
10 import org.djunits.unit.MoneyUnit;
11 import org.djunits.unit.VolumeUnit;
12
13 /**
14 * Easy access methods for the Volume DoubleScalar, which is relative by definition. Instead of:
15 *
16 * <pre>
17 * DoubleScalar.Rel<VolumeUnit> value = new DoubleScalar.Rel<VolumeUnit>(100.0, VolumeUnit.SI);
18 * </pre>
19 *
20 * we can now write:
21 *
22 * <pre>
23 * Volume value = new Volume(100.0, VolumeUnit.SI);
24 * </pre>
25 *
26 * The compiler will automatically recognize which units belong to which quantity, and whether the quantity type and the unit
27 * used are compatible.
28 * <p>
29 * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
30 * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
31 * <p>
32 * $LastChangedDate: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, by $Author: averbraeck $,
33 * initial version Sep 5, 2015 <br>
34 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
35 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
36 */
37 public class Volume extends AbstractDoubleScalarRel<VolumeUnit, Volume>
38 {
39 /** */
40 private static final long serialVersionUID = 20150905L;
41
42 /** constant with value zero. */
43 public static final Volume ZERO = new Volume(0.0, VolumeUnit.SI);
44
45 /** constant with value NaN. */
46 @SuppressWarnings("checkstyle:constantname")
47 public static final Volume NaN = new Volume(Double.NaN, VolumeUnit.SI);
48
49 /** constant with value POSITIVE_INFINITY. */
50 public static final Volume POSITIVE_INFINITY = new Volume(Double.POSITIVE_INFINITY, VolumeUnit.SI);
51
52 /** constant with value NEGATIVE_INFINITY. */
53 public static final Volume NEGATIVE_INFINITY = new Volume(Double.NEGATIVE_INFINITY, VolumeUnit.SI);
54
55 /** constant with value MAX_VALUE. */
56 public static final Volume POS_MAXVALUE = new Volume(Double.MAX_VALUE, VolumeUnit.SI);
57
58 /** constant with value -MAX_VALUE. */
59 public static final Volume NEG_MAXVALUE = new Volume(-Double.MAX_VALUE, VolumeUnit.SI);
60
61 /**
62 * Construct Volume scalar.
63 * @param value double value
64 * @param unit unit for the double value
65 */
66 public Volume(final double value, final VolumeUnit unit)
67 {
68 super(value, unit);
69 }
70
71 /**
72 * Construct Volume scalar.
73 * @param value Scalar from which to construct this instance
74 */
75 public Volume(final Volume value)
76 {
77 super(value);
78 }
79
80 /** {@inheritDoc} */
81 @Override
82 public final Volume instantiateRel(final double value, final VolumeUnit unit)
83 {
84 return new Volume(value, unit);
85 }
86
87 /**
88 * Construct Volume scalar.
89 * @param value double value in SI units
90 * @return the new scalar with the SI value
91 */
92 public static final Volume createSI(final double value)
93 {
94 return new Volume(value, VolumeUnit.SI);
95 }
96
97 /**
98 * Interpolate between two values.
99 * @param zero the low value
100 * @param one the high value
101 * @param ratio the ratio between 0 and 1, inclusive
102 * @return a Scalar at the ratio between
103 */
104 public static Volume interpolate(final Volume zero, final Volume one, final double ratio)
105 {
106 return new Volume(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
107 }
108
109 /**
110 * Return the maximum value of two relative scalars.
111 * @param r1 the first scalar
112 * @param r2 the second scalar
113 * @return the maximum value of two relative scalars
114 */
115 public static Volume max(final Volume r1, final Volume r2)
116 {
117 return (r1.gt(r2)) ? r1 : r2;
118 }
119
120 /**
121 * Return the maximum value of more than two relative scalars.
122 * @param r1 the first scalar
123 * @param r2 the second scalar
124 * @param rn the other scalars
125 * @return the maximum value of more than two relative scalars
126 */
127 public static Volume max(final Volume r1, final Volume r2, final Volume... rn)
128 {
129 Volume maxr = (r1.gt(r2)) ? r1 : r2;
130 for (Volume r : rn)
131 {
132 if (r.gt(maxr))
133 {
134 maxr = r;
135 }
136 }
137 return maxr;
138 }
139
140 /**
141 * Return the minimum value of two relative scalars.
142 * @param r1 the first scalar
143 * @param r2 the second scalar
144 * @return the minimum value of two relative scalars
145 */
146 public static Volume min(final Volume r1, final Volume r2)
147 {
148 return (r1.lt(r2)) ? r1 : r2;
149 }
150
151 /**
152 * Return the minimum value of more than two relative scalars.
153 * @param r1 the first scalar
154 * @param r2 the second scalar
155 * @param rn the other scalars
156 * @return the minimum value of more than two relative scalars
157 */
158 public static Volume min(final Volume r1, final Volume r2, final Volume... rn)
159 {
160 Volume minr = (r1.lt(r2)) ? r1 : r2;
161 for (Volume r : rn)
162 {
163 if (r.lt(minr))
164 {
165 minr = r;
166 }
167 }
168 return minr;
169 }
170
171 /**
172 * Calculate the division of Volume and Volume, which results in a Dimensionless scalar.
173 * @param v Volume scalar
174 * @return Dimensionless scalar as a division of Volume and Volume
175 */
176 public final Dimensionless divideBy(final Volume v)
177 {
178 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
179 }
180
181 /**
182 * Calculate the multiplication of Volume and Density, which results in a Mass scalar.
183 * @param v Volume scalar
184 * @return Mass scalar as a multiplication of Volume and Density
185 */
186 public final Mass multiplyBy(final Density v)
187 {
188 return new Mass(this.si * v.si, MassUnit.SI);
189 }
190
191 /**
192 * Calculate the multiplication of Volume and Pressure, which results in a Energy scalar.
193 * @param v Volume scalar
194 * @return Energy scalar as a multiplication of Volume and Pressure
195 */
196 public final Energy multiplyBy(final Pressure v)
197 {
198 return new Energy(this.si * v.si, EnergyUnit.SI);
199 }
200
201 /**
202 * Calculate the division of Volume and Length, which results in a Area scalar.
203 * @param v Volume scalar
204 * @return Area scalar as a division of Volume and Length
205 */
206 public final Area divideBy(final Length v)
207 {
208 return new Area(this.si / v.si, AreaUnit.SI);
209 }
210
211 /**
212 * Calculate the division of Volume and Area, which results in a Length scalar.
213 * @param v Volume scalar
214 * @return Length scalar as a division of Volume and Area
215 */
216 public final Length divideBy(final Area v)
217 {
218 return new Length(this.si / v.si, LengthUnit.SI);
219 }
220
221 /**
222 * Calculate the multiplication of Volume and LinearDensity, which results in a Area scalar.
223 * @param v Volume scalar
224 * @return Area scalar as a multiplication of Volume and LinearDensity
225 */
226 public final Area multiplyBy(final LinearDensity v)
227 {
228 return new Area(this.si * v.si, AreaUnit.SI);
229 }
230
231 /**
232 * Calculate the division of Volume and Duration, which results in a FlowVolume scalar.
233 * @param v Volume scalar
234 * @return FlowVolume scalar as a division of Volume and Duration
235 */
236 public final FlowVolume divideBy(final Duration v)
237 {
238 return new FlowVolume(this.si / v.si, FlowVolumeUnit.SI);
239 }
240
241 /**
242 * Calculate the division of Volume and FlowVolume, which results in a Duration scalar.
243 * @param v Volume scalar
244 * @return Duration scalar as a division of Volume and FlowVolume
245 */
246 public final Duration divideBy(final FlowVolume v)
247 {
248 return new Duration(this.si / v.si, DurationUnit.SI);
249 }
250
251 /**
252 * Calculate the multiplication of Volume and MoneyPerVolume, which results in a Money scalar.
253 * @param v Volume scalar
254 * @return Money scalar as a multiplication of Volume and MoneyPerVolume
255 */
256 public final Money multiplyBy(final MoneyPerVolume v)
257 {
258 return new Money(this.si * v.si, MoneyUnit.getStandardMoneyUnit());
259 }
260
261 }