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