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