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