1 package org.djunits.value.vfloat.scalar;
2
3 import org.djunits.unit.DimensionlessUnit;
4 import org.djunits.unit.ForceUnit;
5 import org.djunits.unit.FrequencyUnit;
6 import org.djunits.unit.LengthUnit;
7 import org.djunits.unit.LinearDensityUnit;
8 import org.djunits.unit.MoneyPerLengthUnit;
9
10 /**
11 * Easy access methods for the LinearDensity FloatScalar, which is relative by definition. An example is Speed. Instead of:
12 *
13 * <pre>
14 * FloatScalar.Rel<LinearDensityUnit> value = new FloatScalar.Rel<LinearDensityUnit>(100.0, LinearDensityUnit.SI);
15 * </pre>
16 *
17 * we can now write:
18 *
19 * <pre>
20 * FloatLinearDensity value = new FloatLinearDensity(100.0, LinearDensityUnit.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 FloatLinearDensity extends AbstractFloatScalarRel<LinearDensityUnit, FloatLinearDensity>
35 {
36 /** */
37 private static final long serialVersionUID = 20150901L;
38
39 /** constant with value zero. */
40 public static final FloatLinearDensity ZERO = new FloatLinearDensity(0.0f, LinearDensityUnit.SI);
41
42 /** constant with value NaN. */
43 @SuppressWarnings("checkstyle:constantname")
44 public static final FloatLinearDensity NaN = new FloatLinearDensity(Float.NaN, LinearDensityUnit.SI);
45
46 /** constant with value POSITIVE_INFINITY. */
47 public static final FloatLinearDensity POSITIVE_INFINITY =
48 new FloatLinearDensity(Float.POSITIVE_INFINITY, LinearDensityUnit.SI);
49
50 /** constant with value NEGATIVE_INFINITY. */
51 public static final FloatLinearDensity NEGATIVE_INFINITY =
52 new FloatLinearDensity(Float.NEGATIVE_INFINITY, LinearDensityUnit.SI);
53
54 /** constant with value MAX_VALUE. */
55 public static final FloatLinearDensity POS_MAXVALUE = new FloatLinearDensity(Float.MAX_VALUE, LinearDensityUnit.SI);
56
57 /** constant with value -MAX_VALUE. */
58 public static final FloatLinearDensity NEG_MAXVALUE = new FloatLinearDensity(-Float.MAX_VALUE, LinearDensityUnit.SI);
59
60 /**
61 * Construct FloatLinearDensity scalar.
62 * @param value float value
63 * @param unit unit for the float value
64 */
65 public FloatLinearDensity(final float value, final LinearDensityUnit unit)
66 {
67 super(value, unit);
68 }
69
70 /**
71 * Construct FloatLinearDensity scalar.
72 * @param value Scalar from which to construct this instance
73 */
74 public FloatLinearDensity(final FloatLinearDensity value)
75 {
76 super(value);
77 }
78
79 /**
80 * Construct FloatLinearDensity scalar using a double value.
81 * @param value double value
82 * @param unit unit for the resulting float value
83 */
84 public FloatLinearDensity(final double value, final LinearDensityUnit unit)
85 {
86 super((float) value, unit);
87 }
88
89 /** {@inheritDoc} */
90 @Override
91 public final FloatLinearDensity instantiateRel(final float value, final LinearDensityUnit unit)
92 {
93 return new FloatLinearDensity(value, unit);
94 }
95
96 /**
97 * Construct FloatLinearDensity scalar.
98 * @param value float value in SI units
99 * @return the new scalar with the SI value
100 */
101 public static final FloatLinearDensity createSI(final float value)
102 {
103 return new FloatLinearDensity(value, LinearDensityUnit.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 FloatLinearDensity interpolate(final FloatLinearDensity zero, final FloatLinearDensity one, final float ratio)
114 {
115 return new FloatLinearDensity(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 FloatLinearDensity max(final FloatLinearDensity r1, final FloatLinearDensity 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 FloatLinearDensity max(final FloatLinearDensity r1, final FloatLinearDensity r2,
137 final FloatLinearDensity... rn)
138 {
139 FloatLinearDensity maxr = (r1.gt(r2)) ? r1 : r2;
140 for (FloatLinearDensity r : rn)
141 {
142 if (r.gt(maxr))
143 {
144 maxr = r;
145 }
146 }
147 return maxr;
148 }
149
150 /**
151 * Return the minimum value of two relative scalars.
152 * @param r1 the first scalar
153 * @param r2 the second scalar
154 * @return the minimum value of two relative scalars
155 */
156 public static FloatLinearDensity min(final FloatLinearDensity r1, final FloatLinearDensity r2)
157 {
158 return (r1.lt(r2)) ? r1 : r2;
159 }
160
161 /**
162 * Return the minimum value of more than two relative scalars.
163 * @param r1 the first scalar
164 * @param r2 the second scalar
165 * @param rn the other scalars
166 * @return the minimum value of more than two relative scalars
167 */
168 public static FloatLinearDensity min(final FloatLinearDensity r1, final FloatLinearDensity r2,
169 final FloatLinearDensity... rn)
170 {
171 FloatLinearDensity minr = (r1.lt(r2)) ? r1 : r2;
172 for (FloatLinearDensity r : rn)
173 {
174 if (r.lt(minr))
175 {
176 minr = r;
177 }
178 }
179 return minr;
180 }
181
182 /**
183 * Calculate the division of FloatLinearDensity and FloatLinearDensity, which results in a FloatDimensionless scalar.
184 * @param v FloatLinearDensity scalar
185 * @return FloatDimensionless scalar as a division of FloatLinearDensity and FloatLinearDensity
186 */
187 public final FloatDimensionless divideBy(final FloatLinearDensity v)
188 {
189 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
190 }
191
192 /**
193 * Calculate the multiplication of FloatLinearDensity and FloatArea, which results in a FloatLength scalar.
194 * @param v FloatLinearDensity scalar
195 * @return FloatLength scalar as a multiplication of FloatLinearDensity and FloatArea
196 */
197 public final FloatLength multiplyBy(final FloatArea v)
198 {
199 return new FloatLength(this.si * v.si, LengthUnit.SI);
200 }
201
202 /**
203 * Calculate the multiplication of FloatLinearDensity and FloatEnergy, which results in a FloatForce scalar.
204 * @param v FloatLinearDensity scalar
205 * @return FloatForce scalar as a multiplication of FloatLinearDensity and FloatEnergy
206 */
207 public final FloatForce multiplyBy(final FloatEnergy v)
208 {
209 return new FloatForce(this.si * v.si, ForceUnit.SI);
210 }
211
212 /**
213 * Calculate the multiplication of FloatLinearDensity and FloatSpeed, which results in a FloatFrequency scalar.
214 * @param v FloatLinearDensity scalar
215 * @return FloatFrequency scalar as a multiplication of FloatLinearDensity and FloatSpeed
216 */
217 public final FloatFrequency multiplyBy(final FloatSpeed v)
218 {
219 return new FloatFrequency(this.si * v.si, FrequencyUnit.SI);
220 }
221
222 /**
223 * Calculate the multiplication of FloatLinearDensity and FloatMoney, which results in a FloatMoneyPerLength scalar.
224 * @param v FloatLinearDensity scalar
225 * @return FloatMoneyPerLength scalar as a multiplication of FloatLinearDensity and FloatMoney
226 */
227 public final FloatMoneyPerLength multiplyBy(final FloatMoney v)
228 {
229 return new FloatMoneyPerLength(this.si * v.si, MoneyPerLengthUnit.getStandardMoneyPerLengthUnit());
230 }
231
232 }