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