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