View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import org.djunits.unit.AccelerationUnit;
4   import org.djunits.unit.AreaUnit;
5   import org.djunits.unit.DimensionlessUnit;
6   import org.djunits.unit.EnergyUnit;
7   import org.djunits.unit.ForceUnit;
8   import org.djunits.unit.LinearDensityUnit;
9   import org.djunits.unit.MassUnit;
10  import org.djunits.unit.PowerUnit;
11  import org.djunits.unit.PressureUnit;
12  
13  /**
14   * Easy access methods for the Force FloatScalar, which is relative by definition. An example is Speed. Instead of:
15   * 
16   * <pre>
17   * FloatScalar.Rel&lt;ForceUnit&gt; value = new FloatScalar.Rel&lt;ForceUnit&gt;(100.0, ForceUnit.SI);
18   * </pre>
19   * 
20   * we can now write:
21   * 
22   * <pre>
23   * FloatForce value = new FloatForce(100.0, ForceUnit.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 FloatForce extends AbstractFloatScalarRel<ForceUnit, FloatForce>
38  {
39      /** */
40      private static final long serialVersionUID = 20150901L;
41  
42      /** constant with value zero. */
43      public static final FloatForce ZERO = new FloatForce(0.0f, ForceUnit.SI);
44  
45      /** constant with value NaN. */
46      @SuppressWarnings("checkstyle:constantname")
47      public static final FloatForce NaN = new FloatForce(Float.NaN, ForceUnit.SI);
48  
49      /** constant with value POSITIVE_INFINITY. */
50      public static final FloatForce POSITIVE_INFINITY = new FloatForce(Float.POSITIVE_INFINITY, ForceUnit.SI);
51  
52      /** constant with value NEGATIVE_INFINITY. */
53      public static final FloatForce NEGATIVE_INFINITY = new FloatForce(Float.NEGATIVE_INFINITY, ForceUnit.SI);
54  
55      /** constant with value MAX_VALUE. */
56      public static final FloatForce POS_MAXVALUE = new FloatForce(Float.MAX_VALUE, ForceUnit.SI);
57  
58      /** constant with value -MAX_VALUE. */
59      public static final FloatForce NEG_MAXVALUE = new FloatForce(-Float.MAX_VALUE, ForceUnit.SI);
60  
61      /**
62       * Construct FloatForce scalar.
63       * @param value float value
64       * @param unit unit for the float value
65       */
66      public FloatForce(final float value, final ForceUnit unit)
67      {
68          super(value, unit);
69      }
70  
71      /**
72       * Construct FloatForce scalar.
73       * @param value Scalar from which to construct this instance
74       */
75      public FloatForce(final FloatForce value)
76      {
77          super(value);
78      }
79  
80      /**
81       * Construct FloatForce scalar using a double value.
82       * @param value double value
83       * @param unit unit for the resulting float value
84       */
85      public FloatForce(final double value, final ForceUnit unit)
86      {
87          super((float) value, unit);
88      }
89  
90      /** {@inheritDoc} */
91      @Override
92      public final FloatForce instantiateRel(final float value, final ForceUnit unit)
93      {
94          return new FloatForce(value, unit);
95      }
96  
97      /**
98       * Construct FloatForce scalar.
99       * @param value float value in SI units
100      * @return the new scalar with the SI value
101      */
102     public static final FloatForce createSI(final float value)
103     {
104         return new FloatForce(value, ForceUnit.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 FloatForce interpolate(final FloatForce zero, final FloatForce one, final float ratio)
115     {
116         return new FloatForce(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 FloatForce max(final FloatForce r1, final FloatForce 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 FloatForce max(final FloatForce r1, final FloatForce r2, final FloatForce... rn)
138     {
139         FloatForce maxr = (r1.gt(r2)) ? r1 : r2;
140         for (FloatForce 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 FloatForce min(final FloatForce r1, final FloatForce 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 FloatForce min(final FloatForce r1, final FloatForce r2, final FloatForce... rn)
169     {
170         FloatForce minr = (r1.lt(r2)) ? r1 : r2;
171         for (FloatForce 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 FloatForce and FloatForce, which results in a FloatDimensionless scalar.
183      * @param v FloatForce scalar
184      * @return FloatDimensionless scalar as a division of FloatForce and FloatForce
185      */
186     public final FloatDimensionless divideBy(final FloatForce v)
187     {
188         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
189     }
190 
191     /**
192      * Calculate the multiplication of FloatForce and FloatLength, which results in a FloatEnergy scalar.
193      * @param v FloatForce scalar
194      * @return FloatEnergy scalar as a multiplication of FloatForce and FloatLength
195      */
196     public final FloatEnergy multiplyBy(final FloatLength v)
197     {
198         return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
199     }
200 
201     /**
202      * Calculate the division of FloatForce and FloatLinearDensity, which results in a FloatEnergy scalar.
203      * @param v FloatForce scalar
204      * @return FloatEnergy scalar as a division of FloatForce and FloatLinearDensity
205      */
206     public final FloatEnergy divideBy(final FloatLinearDensity v)
207     {
208         return new FloatEnergy(this.si / v.si, EnergyUnit.SI);
209     }
210 
211     /**
212      * Calculate the division of FloatForce and FloatEnergy, which results in a FloatLinearDensity scalar.
213      * @param v FloatForce scalar
214      * @return FloatLinearDensity scalar as a division of FloatForce and FloatEnergy
215      */
216     public final FloatLinearDensity divideBy(final FloatEnergy v)
217     {
218         return new FloatLinearDensity(this.si / v.si, LinearDensityUnit.SI);
219     }
220 
221     /**
222      * Calculate the multiplication of FloatForce and FloatSpeed, which results in a FloatPower scalar.
223      * @param v FloatForce scalar
224      * @return FloatPower scalar as a multiplication of FloatForce and FloatSpeed
225      */
226     public final FloatPower multiplyBy(final FloatSpeed v)
227     {
228         return new FloatPower(this.si * v.si, PowerUnit.SI);
229     }
230 
231     /**
232      * Calculate the division of FloatForce and FloatMass, which results in a FloatAcceleration scalar.
233      * @param v FloatForce scalar
234      * @return FloatAcceleration scalar as a division of FloatForce and FloatMass
235      */
236     public final FloatAcceleration divideBy(final FloatMass v)
237     {
238         return new FloatAcceleration(this.si / v.si, AccelerationUnit.SI);
239     }
240 
241     /**
242      * Calculate the division of FloatForce and FloatAcceleration, which results in a FloatMass scalar.
243      * @param v FloatForce scalar
244      * @return FloatMass scalar as a division of FloatForce and FloatAcceleration
245      */
246     public final FloatMass divideBy(final FloatAcceleration v)
247     {
248         return new FloatMass(this.si / v.si, MassUnit.SI);
249     }
250 
251     /**
252      * Calculate the division of FloatForce and FloatArea, which results in a FloatPressure scalar.
253      * @param v FloatForce scalar
254      * @return FloatPressure scalar as a division of FloatForce and FloatArea
255      */
256     public final FloatPressure divideBy(final FloatArea v)
257     {
258         return new FloatPressure(this.si / v.si, PressureUnit.SI);
259     }
260 
261     /**
262      * Calculate the division of FloatForce and FloatPressure, which results in a FloatArea scalar.
263      * @param v FloatForce scalar
264      * @return FloatArea scalar as a division of FloatForce and FloatPressure
265      */
266     public final FloatArea divideBy(final FloatPressure v)
267     {
268         return new FloatArea(this.si / v.si, AreaUnit.SI);
269     }
270 
271 }