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