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