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