View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import org.djunits.unit.AbsoluteLinearUnit;
4   import org.djunits.unit.SICoefficients;
5   import org.djunits.unit.SIUnit;
6   import org.djunits.unit.Unit;
7   
8   /**
9    * Immutable FloatScalar.
10   * <p>
11   * This file was generated by the djunits value classes generator, 26 jun, 2015
12   * <p>
13   * Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
15   * <p>
16   * $LastChangedDate: 2019-01-18 00:35:01 +0100 (Fri, 18 Jan 2019) $, @version $Revision: 324 $, by $Author: averbraeck $,
17   * initial version 26 jun, 2015 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
20   */
21  public abstract class FloatScalar
22  {
23      /**
24       * Absolute Immutable FloatScalar.
25       * @param <AU> Absolute unit
26       * @param <RU> Relative unit
27       */
28      public static class Abs<AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>>
29              extends AbstractFloatScalarAbs<AU, FloatScalar.Abs<AU, RU>, RU, FloatScalar.Rel<RU>>
30      {
31          /**  */
32          private static final long serialVersionUID = 20150626L;
33  
34          /**
35           * Construct a new Absolute Immutable FloatScalar.
36           * @param value float; the value of the new Absolute Immutable FloatScalar
37           * @param unit AU; the unit of the new Absolute Immutable FloatScalar
38           */
39          public Abs(final float value, final AU unit)
40          {
41              super(value, unit);
42          }
43  
44          /**
45           * Construct a new Absolute Immutable FloatScalar from an existing Absolute Immutable FloatScalar.
46           * @param value FloatScalar.Abs&lt;AU, RU&gt;; the reference
47           */
48          public Abs(final FloatScalar.Abs<AU, RU> value)
49          {
50              super(value);
51          }
52  
53          /** {@inheritDoc} */
54          @Override
55          public final FloatScalar.Abs<AU, RU> instantiateAbs(final float value, final AU unit)
56          {
57              return new FloatScalar.Abs<>(value, unit);
58          }
59  
60          /** {@inheritDoc} */
61          @Override
62          public final FloatScalar.Rel<RU> instantiateRel(final float value, final RU unit)
63          {
64              return new FloatScalar.Rel<>(value, unit);
65          }
66  
67      }
68  
69      /**
70       * Relative Immutable FloatScalar.
71       * @param <U> Unit
72       */
73      public static class Rel<U extends Unit<U>> extends AbstractFloatScalarRel<U, FloatScalar.Rel<U>>
74      {
75          /**  */
76          private static final long serialVersionUID = 20150626L;
77  
78          /**
79           * Construct a new Relative Immutable FloatScalar.
80           * @param value float; the value of the new Relative Immutable FloatScalar
81           * @param unit U; the unit of the new Relative Immutable FloatScalar
82           */
83          public Rel(final float value, final U unit)
84          {
85              super(value, unit);
86          }
87  
88          /**
89           * Construct a new Relative Immutable FloatScalar from an existing Relative Immutable FloatScalar.
90           * @param value FloatScalar.Rel&lt;U&gt;; the reference
91           */
92          public Rel(final FloatScalar.Rel<U> value)
93          {
94              super(value);
95          }
96  
97          /** {@inheritDoc} */
98          @Override
99          public final FloatScalar.Rel<U> instantiateRel(final float value, final U unit)
100         {
101             return new FloatScalar.Rel<>(value, unit);
102         }
103 
104     }
105 
106     /**********************************************************************************/
107     /********************************* STATIC METHODS *********************************/
108     /**********************************************************************************/
109 
110     /**
111      * Add a Relative value to an Absolute value. Return a new instance of the value. The unit of the return value will be the
112      * unit of the left argument.
113      * @param left A, an absolute typed FloatScalar; the left argument
114      * @param right R, a relative typed FloatScalar; the right argument
115      * @param <AU> Unit; the absolute unit of the parameter and the result
116      * @param <RU> Unit; the relative unit of the parameter
117      * @param <R> the relative type
118      * @param <A> the corresponding absolute type
119      * @return A, an absolute typed FloatScalar; the sum of the values as an Absolute value
120      */
121     public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends AbstractFloatScalarRel<RU, R>,
122             A extends AbstractFloatScalarAbs<AU, A, RU, R>> A plus(final A left, final R right)
123     {
124         return left.plus(right);
125     }
126 
127     /**
128      * Add an Absolute value to a Relative value. Return a new instance of the value. The unit of the return value will be the
129      * unit of the left argument.
130      * @param left A, an absolute typed FloatScalar; the left argument
131      * @param right R, a relative typed FloatScalar; the right argument
132      * @param <AU> Unit; the absolute unit of the parameter and the result
133      * @param <RU> Unit; the relative unit of the parameter
134      * @param <R> the relative type
135      * @param <A> the corresponding absolute type
136      * @return A, an absolute typed FloatScalar; the sum of the values as an Absolute value
137      */
138     public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends AbstractFloatScalarRel<RU, R>,
139             A extends AbstractFloatScalarAbs<AU, A, RU, R>> A plus(final R left, final A right)
140     {
141         return right.plus(left);
142     }
143 
144     /**
145      * Add a Relative value to a Relative value. Return a new instance of the value. The unit of the return value will be the
146      * unit of the left argument.
147      * @param left R, a relative typed FloatScalar; the left argument
148      * @param right R, a relative typed FloatScalar; the right argument
149      * @param <U> Unit; the unit of the parameters and the result
150      * @param <R> the relative type
151      * @return R, a relative typed FloatScalar; the sum of the values as a Relative value
152      */
153     public static <U extends Unit<U>, R extends AbstractFloatScalarRel<U, R>> R plus(final R left, final R right)
154     {
155         return left.plus(right);
156     }
157 
158     /**
159      * Subtract a Relative value from an absolute value. Return a new instance of the value. The unit of the return value will
160      * be the unit of the left argument.
161      * @param left A, an absolute typed FloatScalar; the left value
162      * @param right R, a relative typed FloatScalar; the right value
163      * @param <AU> Unit; the absolute unit of the parameter and the result
164      * @param <RU> Unit; the relative unit of the parameter
165      * @param <R> the relative type
166      * @param <A> the corresponding absolute type
167      * @return A, an absolute typed FloatScalar; the resulting value as an absolute value
168      */
169     public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends AbstractFloatScalarRel<RU, R>,
170             A extends AbstractFloatScalarAbs<AU, A, RU, R>> A minus(final A left, final R right)
171     {
172         return left.minus(right);
173     }
174 
175     /**
176      * Subtract a relative value from a relative value. Return a new instance of the value. The unit of the value will be the
177      * unit of the first argument.
178      * @param left R, a relative typed FloatScalar; the left value
179      * @param right R, a relative typed FloatScalar; the right value
180      * @param <U> Unit; the unit of the parameters and the result
181      * @param <R> the relative type
182      * @return R, a relative typed FloatScalar; the resulting value as a relative value
183      */
184     public static <U extends Unit<U>, R extends AbstractFloatScalarRel<U, R>> R minus(final R left, final R right)
185     {
186         return left.minus(right);
187     }
188 
189     /**
190      * Subtract two absolute values. Return a new instance of a relative value of the difference. The unit of the value will be
191      * the unit of the first argument.
192      * @param left A, an absolute typed FloatScalar; value 1
193      * @param right A, an absolute typed FloatScalar; value 2
194      * @param <AU> Unit; the absolute unit of the parameter
195      * @param <RU> Unit; the relative unit of the parameter and the result
196      * @param <R> the relative type
197      * @param <A> the corresponding absolute type
198      * @return R, a relative typed FloatScalar; the difference of the two absolute values as a relative value
199      */
200     public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends AbstractFloatScalarRel<RU, R>,
201             A extends AbstractFloatScalarAbs<AU, A, RU, R>> R minus(final A left, final A right)
202     {
203         return left.minus(right);
204     }
205 
206     /**
207      * Interpolate between or extrapolate over two values.
208      * @param zero A, an absolute typed FloatScalar; zero reference (returned when ratio == 0)
209      * @param one A, an absolute typed FloatScalar; one reference (returned when ratio == 1)
210      * @param ratio float; the ratio that determines where between (or outside) zero and one the result lies
211      * @param <AU> Unit; the absolute unit of the parameter and the result
212      * @param <RU> Unit; the relative unit belonging to the absolute unit
213      * @param <R> the relative type
214      * @param <A> the corresponding absolute type
215      * @return Absolute FloatScalar
216      */
217     public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>, R extends AbstractFloatScalarRel<RU, R>,
218             A extends AbstractFloatScalarAbs<AU, A, RU, R>> A interpolate(final A zero, final A one, final float ratio)
219     {
220         return zero.instantiateAbs(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
221     }
222 
223     /**
224      * Interpolate between or extrapolate over two values.
225      * @param zero R, a relative typed FloatScalar; zero reference (returned when ratio == 0)
226      * @param one R, a relative typed FloatScalar; one reference (returned when ratio == 1)
227      * @param ratio float; the ratio that determines where between (or outside) zero and one the result lies
228      * @param <U> Unit; the unit of the parameters and the result
229      * @param <R> the relative type
230      * @return Relative FloatScalar
231      */
232     public static <U extends Unit<U>, R extends AbstractFloatScalarRel<U, R>> R interpolate(final R zero, final R one,
233             final float ratio)
234     {
235         return zero.instantiateRel(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
236     }
237 
238     /**
239      * Multiply two values; the result is a new instance with a different (existing or generated) SI unit.
240      * @param left AbstractFloatScalarRel&lt;?, ?&gt;; the left operand
241      * @param right AbstractFloatScalarRel&lt;?, ?&gt;; the right operand
242      * @return FloatScalar.Rel&lt;SIUnit&gt;; the product of the two values
243      */
244     public static FloatScalar.Rel<SIUnit> multiply(final AbstractFloatScalarRel<?, ?> left,
245             final AbstractFloatScalarRel<?, ?> right)
246     {
247         SIUnit targetUnit = Unit.lookupOrCreateSIUnitWithSICoefficients(
248                 SICoefficients.multiply(left.getUnit().getSICoefficients(), right.getUnit().getSICoefficients()).toString());
249         return new FloatScalar.Rel<SIUnit>(left.getSI() * right.getSI(), targetUnit);
250     }
251 
252     /**
253      * Divide two values; the result is a new instance with a different (existing or generated) SI unit.
254      * @param left AbstractFloatScalarRel&lt;?, ?&gt;; the left operand
255      * @param right AbstractFloatScalarRel&lt;?, ?&gt;; the right operand
256      * @return FloatScalar.Rel&lt;SIUnit&gt;; the ratio of the two values
257      */
258     public static FloatScalar.Rel<SIUnit> divide(final AbstractFloatScalarRel<?, ?> left,
259             final AbstractFloatScalarRel<?, ?> right)
260     {
261         SIUnit targetUnit = Unit.lookupOrCreateSIUnitWithSICoefficients(
262                 SICoefficients.divide(left.getUnit().getSICoefficients(), right.getUnit().getSICoefficients()).toString());
263         return new FloatScalar.Rel<SIUnit>(left.getSI() / right.getSI(), targetUnit);
264     }
265 
266     /**
267      * Interpolate between or extrapolate over two values.
268      * @param zero FloatScalar.Abs&lt;AU, RU&gt;; zero reference (returned when ratio == 0)
269      * @param one FloatScalar.Abs&lt;AU, RU&gt;; one reference (returned when ratio == 1)
270      * @param ratio float; the ratio that determines where between (or outside) zero and one the result lies
271      * @param <AU> Unit; the absolute unit of the parameter and the result
272      * @param <RU> Unit; the relative unit belonging to the absolute unit
273      * @return FloatScalar.Abs&lt;U&gt;
274      */
275     public static <AU extends AbsoluteLinearUnit<AU, RU>, RU extends Unit<RU>> FloatScalar.Abs<AU, RU> interpolate(
276             final FloatScalar.Abs<AU, RU> zero, final FloatScalar.Abs<AU, RU> one, final float ratio)
277     {
278         return new FloatScalar.Abs<AU, RU>(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio,
279                 zero.getUnit());
280     }
281 
282     /**
283      * Interpolate between or extrapolate over two values.
284      * @param zero FloatScalar.Rel&lt;U&gt;; zero reference (returned when ratio == 0)
285      * @param one FloatScalar.Rel&lt;U&gt;; one reference (returned when ratio == 1)
286      * @param ratio float; the ratio that determines where between (or outside) zero and one the result lies
287      * @param <U> Unit; the unit of the parameters and the result
288      * @return FloatScalar.Rel&lt;U&gt;
289      */
290     public static <U extends Unit<U>> FloatScalar.Rel<U> interpolate(final FloatScalar.Rel<U> zero,
291             final FloatScalar.Rel<U> one, final float ratio)
292     {
293         return new FloatScalar.Rel<U>(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
294     }
295 
296 }