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