1 package org.djunits.value.vdouble.scalar;
2
3 import org.djunits.unit.DimensionlessUnit;
4 import org.djunits.unit.ElectricalChargeUnit;
5 import org.djunits.unit.ElectricalCurrentUnit;
6 import org.djunits.unit.ElectricalPotentialUnit;
7 import org.djunits.unit.PowerUnit;
8
9 /**
10 * Easy access methods for the ElectricalCurrent DoubleScalar, which is relative by definition. Instead of:
11 *
12 * <pre>
13 * DoubleScalar.Rel<ElectricalCurrentUnit> value = new DoubleScalar.Rel<ElectricalCurrentUnit>(100.0, ElectricalCurrentUnit.SI);
14 * </pre>
15 *
16 * we can now write:
17 *
18 * <pre>
19 * ElectricalCurrent value = new ElectricalCurrent(100.0, ElectricalCurrentUnit.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 ElectricalCurrent extends AbstractDoubleScalarRel<ElectricalCurrentUnit, ElectricalCurrent>
34 {
35 /** */
36 private static final long serialVersionUID = 20150905L;
37
38 /** constant with value zero. */
39 public static final ElectricalCurrent ZERO = new ElectricalCurrent(0.0, ElectricalCurrentUnit.SI);
40
41 /** constant with value NaN. */
42 @SuppressWarnings("checkstyle:constantname")
43 public static final ElectricalCurrent NaN = new ElectricalCurrent(Double.NaN, ElectricalCurrentUnit.SI);
44
45 /** constant with value POSITIVE_INFINITY. */
46 public static final ElectricalCurrent POSITIVE_INFINITY =
47 new ElectricalCurrent(Double.POSITIVE_INFINITY, ElectricalCurrentUnit.SI);
48
49 /** constant with value NEGATIVE_INFINITY. */
50 public static final ElectricalCurrent NEGATIVE_INFINITY =
51 new ElectricalCurrent(Double.NEGATIVE_INFINITY, ElectricalCurrentUnit.SI);
52
53 /** constant with value MAX_VALUE. */
54 public static final ElectricalCurrent POS_MAXVALUE = new ElectricalCurrent(Double.MAX_VALUE, ElectricalCurrentUnit.SI);
55
56 /** constant with value -MAX_VALUE. */
57 public static final ElectricalCurrent NEG_MAXVALUE = new ElectricalCurrent(-Double.MAX_VALUE, ElectricalCurrentUnit.SI);
58
59 /**
60 * Construct ElectricalCurrent scalar.
61 * @param value double value
62 * @param unit unit for the double value
63 */
64 public ElectricalCurrent(final double value, final ElectricalCurrentUnit unit)
65 {
66 super(value, unit);
67 }
68
69 /**
70 * Construct ElectricalCurrent scalar.
71 * @param value Scalar from which to construct this instance
72 */
73 public ElectricalCurrent(final ElectricalCurrent value)
74 {
75 super(value);
76 }
77
78 /** {@inheritDoc} */
79 @Override
80 public final ElectricalCurrent instantiateRel(final double value, final ElectricalCurrentUnit unit)
81 {
82 return new ElectricalCurrent(value, unit);
83 }
84
85 /**
86 * Construct ElectricalCurrent scalar.
87 * @param value double value in SI units
88 * @return the new scalar with the SI value
89 */
90 public static final ElectricalCurrent createSI(final double value)
91 {
92 return new ElectricalCurrent(value, ElectricalCurrentUnit.SI);
93 }
94
95 /**
96 * Interpolate between two values.
97 * @param zero the low value
98 * @param one the high value
99 * @param ratio the ratio between 0 and 1, inclusive
100 * @return a Scalar at the ratio between
101 */
102 public static ElectricalCurrent interpolate(final ElectricalCurrent zero, final ElectricalCurrent one, final double ratio)
103 {
104 return new ElectricalCurrent(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
105 }
106
107 /**
108 * Return the maximum value of two relative scalars.
109 * @param r1 the first scalar
110 * @param r2 the second scalar
111 * @return the maximum value of two relative scalars
112 */
113 public static ElectricalCurrent max(final ElectricalCurrent r1, final ElectricalCurrent r2)
114 {
115 return (r1.gt(r2)) ? r1 : r2;
116 }
117
118 /**
119 * Return the maximum value of more than two relative scalars.
120 * @param r1 the first scalar
121 * @param r2 the second scalar
122 * @param rn the other scalars
123 * @return the maximum value of more than two relative scalars
124 */
125 public static ElectricalCurrent max(final ElectricalCurrent r1, final ElectricalCurrent r2, final ElectricalCurrent... rn)
126 {
127 ElectricalCurrent maxr = (r1.gt(r2)) ? r1 : r2;
128 for (ElectricalCurrent r : rn)
129 {
130 if (r.gt(maxr))
131 {
132 maxr = r;
133 }
134 }
135 return maxr;
136 }
137
138 /**
139 * Return the minimum value of two relative scalars.
140 * @param r1 the first scalar
141 * @param r2 the second scalar
142 * @return the minimum value of two relative scalars
143 */
144 public static ElectricalCurrent min(final ElectricalCurrent r1, final ElectricalCurrent r2)
145 {
146 return (r1.lt(r2)) ? r1 : r2;
147 }
148
149 /**
150 * Return the minimum value of more than two relative scalars.
151 * @param r1 the first scalar
152 * @param r2 the second scalar
153 * @param rn the other scalars
154 * @return the minimum value of more than two relative scalars
155 */
156 public static ElectricalCurrent min(final ElectricalCurrent r1, final ElectricalCurrent r2, final ElectricalCurrent... rn)
157 {
158 ElectricalCurrent minr = (r1.lt(r2)) ? r1 : r2;
159 for (ElectricalCurrent r : rn)
160 {
161 if (r.lt(minr))
162 {
163 minr = r;
164 }
165 }
166 return minr;
167 }
168
169 /**
170 * Calculate the division of ElectricalCurrent and ElectricalCurrent, which results in a Dimensionless scalar.
171 * @param v ElectricalCurrent scalar
172 * @return Dimensionless scalar as a division of ElectricalCurrent and ElectricalCurrent
173 */
174 public final Dimensionless divideBy(final ElectricalCurrent v)
175 {
176 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
177 }
178
179 /**
180 * Calculate the multiplication of ElectricalCurrent and ElectricalPotential, which results in a Power scalar.
181 * @param v ElectricalCurrent scalar
182 * @return Power scalar as a multiplication of ElectricalCurrent and ElectricalPotential
183 */
184 public final Power multiplyBy(final ElectricalPotential v)
185 {
186 return new Power(this.si * v.si, PowerUnit.SI);
187 }
188
189 /**
190 * Calculate the multiplication of ElectricalCurrent and Duration, which results in a ElectricalCharge scalar.
191 * @param v ElectricalCurrent scalar
192 * @return ElectricalCharge scalar as a multiplication of ElectricalCurrent and Duration
193 */
194 public final ElectricalCharge multiplyBy(final Duration v)
195 {
196 return new ElectricalCharge(this.si * v.si, ElectricalChargeUnit.SI);
197 }
198
199 /**
200 * Calculate the multiplication of ElectricalCurrent and ElectricalResistance, which results in a ElectricalPotential
201 * scalar.
202 * @param v ElectricalCurrent scalar
203 * @return ElectricalPotential scalar as a multiplication of ElectricalCurrent and ElectricalResistance
204 */
205 public final ElectricalPotential multiplyBy(final ElectricalResistance v)
206 {
207 return new ElectricalPotential(this.si * v.si, ElectricalPotentialUnit.SI);
208 }
209
210 }