View Javadoc
1   package org.djunits.value.vdouble.scalar;
2   
3   import org.djunits.unit.DimensionlessUnit;
4   import org.djunits.unit.ElectricalCurrentUnit;
5   import org.djunits.unit.ElectricalPotentialUnit;
6   import org.djunits.unit.EnergyUnit;
7   import org.djunits.unit.ForceUnit;
8   import org.djunits.unit.FrequencyUnit;
9   import org.djunits.unit.PowerUnit;
10  import org.djunits.unit.SpeedUnit;
11  
12  /**
13   * Easy access methods for the Power DoubleScalar, which is relative by definition. Instead of:
14   * 
15   * <pre>
16   * DoubleScalar.Rel&lt;PowerUnit&gt; value = new DoubleScalar.Rel&lt;PowerUnit&gt;(100.0, PowerUnit.SI);
17   * </pre>
18   * 
19   * we can now write:
20   * 
21   * <pre>
22   * Power value = new Power(100.0, PowerUnit.SI);
23   * </pre>
24   * 
25   * The compiler will automatically recognize which units belong to which quantity, and whether the quantity type and the unit
26   * used are compatible.
27   * <p>
28   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
29   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
30   * <p>
31   * $LastChangedDate: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, by $Author: averbraeck $,
32   * initial version Sep 5, 2015 <br>
33   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
34   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
35   */
36  public class Power extends AbstractDoubleScalarRel<PowerUnit, Power>
37  {
38      /** */
39      private static final long serialVersionUID = 20150905L;
40  
41      /** constant with value zero. */
42      public static final Power ZERO = new Power(0.0, PowerUnit.SI);
43  
44      /** constant with value NaN. */
45      @SuppressWarnings("checkstyle:constantname")
46      public static final Power NaN = new Power(Double.NaN, PowerUnit.SI);
47  
48      /** constant with value POSITIVE_INFINITY. */
49      public static final Power POSITIVE_INFINITY = new Power(Double.POSITIVE_INFINITY, PowerUnit.SI);
50  
51      /** constant with value NEGATIVE_INFINITY. */
52      public static final Power NEGATIVE_INFINITY = new Power(Double.NEGATIVE_INFINITY, PowerUnit.SI);
53  
54      /** constant with value MAX_VALUE. */
55      public static final Power POS_MAXVALUE = new Power(Double.MAX_VALUE, PowerUnit.SI);
56  
57      /** constant with value -MAX_VALUE. */
58      public static final Power NEG_MAXVALUE = new Power(-Double.MAX_VALUE, PowerUnit.SI);
59  
60      /**
61       * Construct Power scalar.
62       * @param value double value
63       * @param unit unit for the double value
64       */
65      public Power(final double value, final PowerUnit unit)
66      {
67          super(value, unit);
68      }
69  
70      /**
71       * Construct Power scalar.
72       * @param value Scalar from which to construct this instance
73       */
74      public Power(final Power value)
75      {
76          super(value);
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public final Power instantiateRel(final double value, final PowerUnit unit)
82      {
83          return new Power(value, unit);
84      }
85  
86      /**
87       * Construct Power scalar.
88       * @param value double value in SI units
89       * @return the new scalar with the SI value
90       */
91      public static final Power createSI(final double value)
92      {
93          return new Power(value, PowerUnit.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 Power interpolate(final Power zero, final Power one, final double ratio)
104     {
105         return new Power(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
106     }
107 
108     /**
109      * Return the maximum value of two relative scalars.
110      * @param r1 the first scalar
111      * @param r2 the second scalar
112      * @return the maximum value of two relative scalars
113      */
114     public static Power max(final Power r1, final Power r2)
115     {
116         return (r1.gt(r2)) ? r1 : r2;
117     }
118 
119     /**
120      * Return the maximum value of more than two relative scalars.
121      * @param r1 the first scalar
122      * @param r2 the second scalar
123      * @param rn the other scalars
124      * @return the maximum value of more than two relative scalars
125      */
126     public static Power max(final Power r1, final Power r2, final Power... rn)
127     {
128         Power maxr = (r1.gt(r2)) ? r1 : r2;
129         for (Power r : rn)
130         {
131             if (r.gt(maxr))
132             {
133                 maxr = r;
134             }
135         }
136         return maxr;
137     }
138 
139     /**
140      * Return the minimum value of two relative scalars.
141      * @param r1 the first scalar
142      * @param r2 the second scalar
143      * @return the minimum value of two relative scalars
144      */
145     public static Power min(final Power r1, final Power r2)
146     {
147         return (r1.lt(r2)) ? r1 : r2;
148     }
149 
150     /**
151      * Return the minimum value of more than two relative scalars.
152      * @param r1 the first scalar
153      * @param r2 the second scalar
154      * @param rn the other scalars
155      * @return the minimum value of more than two relative scalars
156      */
157     public static Power min(final Power r1, final Power r2, final Power... rn)
158     {
159         Power minr = (r1.lt(r2)) ? r1 : r2;
160         for (Power r : rn)
161         {
162             if (r.lt(minr))
163             {
164                 minr = r;
165             }
166         }
167         return minr;
168     }
169 
170     /**
171      * Calculate the division of Power and Power, which results in a Dimensionless scalar.
172      * @param v Power scalar
173      * @return Dimensionless scalar as a division of Power and Power
174      */
175     public final Dimensionless divideBy(final Power v)
176     {
177         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
178     }
179 
180     /**
181      * Calculate the multiplication of Power and Duration, which results in a Energy scalar.
182      * @param v Power scalar
183      * @return Energy scalar as a multiplication of Power and Duration
184      */
185     public final Energy multiplyBy(final Duration v)
186     {
187         return new Energy(this.si * v.si, EnergyUnit.SI);
188     }
189 
190     /**
191      * Calculate the division of Power and Frequency, which results in a Energy scalar.
192      * @param v Power scalar
193      * @return Energy scalar as a division of Power and Frequency
194      */
195     public final Energy divideBy(final Frequency v)
196     {
197         return new Energy(this.si / v.si, EnergyUnit.SI);
198     }
199 
200     /**
201      * Calculate the division of Power and Energy, which results in a Frequency scalar.
202      * @param v Power scalar
203      * @return Frequency scalar as a division of Power and Energy
204      */
205     public final Frequency divideBy(final Energy v)
206     {
207         return new Frequency(this.si / v.si, FrequencyUnit.SI);
208     }
209 
210     /**
211      * Calculate the division of Power and Speed, which results in a Force scalar.
212      * @param v Power scalar
213      * @return Force scalar as a division of Power and Speed
214      */
215     public final Force divideBy(final Speed v)
216     {
217         return new Force(this.si / v.si, ForceUnit.SI);
218     }
219 
220     /**
221      * Calculate the division of Power and Force, which results in a Speed scalar.
222      * @param v Power scalar
223      * @return Speed scalar as a division of Power and Force
224      */
225     public final Speed divideBy(final Force v)
226     {
227         return new Speed(this.si / v.si, SpeedUnit.SI);
228     }
229 
230     /**
231      * Calculate the division of Power and ElectricalPotential, which results in a ElectricalCurrent scalar.
232      * @param v Power scalar
233      * @return ElectricalCurrent scalar as a division of Power and ElectricalPotential
234      */
235     public final ElectricalCurrent divideBy(final ElectricalPotential v)
236     {
237         return new ElectricalCurrent(this.si / v.si, ElectricalCurrentUnit.SI);
238     }
239 
240     /**
241      * Calculate the division of Power and ElectricalCurrent, which results in a ElectricalPotential scalar.
242      * @param v Power scalar
243      * @return ElectricalPotential scalar as a division of Power and ElectricalCurrent
244      */
245     public final ElectricalPotential divideBy(final ElectricalCurrent v)
246     {
247         return new ElectricalPotential(this.si / v.si, ElectricalPotentialUnit.SI);
248     }
249 
250 }