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