View Javadoc
1   package org.djunits.value.vfloat.scalar;
2   
3   import java.util.regex.Matcher;
4   
5   import javax.annotation.Generated;
6   
7   import org.djunits.Throw;
8   import org.djunits.unit.AreaUnit;
9   import org.djunits.unit.DimensionlessUnit;
10  import org.djunits.unit.DurationUnit;
11  import org.djunits.unit.EnergyUnit;
12  import org.djunits.unit.LengthUnit;
13  import org.djunits.unit.LinearDensityUnit;
14  import org.djunits.unit.MomentumUnit;
15  import org.djunits.unit.PositionUnit;
16  import org.djunits.unit.SpeedUnit;
17  import org.djunits.unit.VolumeUnit;
18  import org.djunits.value.util.ValueUtil;
19  import org.djunits.value.vfloat.scalar.base.AbstractFloatScalarRelWithAbs;
20  
21  /**
22   * Easy access methods for the FloatLength FloatScalar.
23   * <p>
24   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. <br>
25   * All rights reserved. <br>
26   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
27   * </p>
28   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
29   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
30   */
31  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2020-01-19T15:21:24.964166400Z")
32  public class FloatLength extends AbstractFloatScalarRelWithAbs<PositionUnit, FloatPosition, LengthUnit, FloatLength>
33  {
34      /** */
35      private static final long serialVersionUID = 20150901L;
36  
37      /** Constant with value zero. */
38      public static final FloatLengthlar/FloatLength.html#FloatLength">FloatLength ZERO = new FloatLength(0.0f, LengthUnit.SI);
39  
40      /** Constant with value one. */
41      public static final FloatLengthalar/FloatLength.html#FloatLength">FloatLength ONE = new FloatLength(1.0f, LengthUnit.SI);
42  
43      /** Constant with value NaN. */
44      @SuppressWarnings("checkstyle:constantname")
45      public static final FloatLengthalar/FloatLength.html#FloatLength">FloatLength NaN = new FloatLength(Float.NaN, LengthUnit.SI);
46  
47      /** Constant with value POSITIVE_INFINITY. */
48      public static final FloatLengthth.html#FloatLength">FloatLength POSITIVE_INFINITY = new FloatLength(Float.POSITIVE_INFINITY, LengthUnit.SI);
49  
50      /** Constant with value NEGATIVE_INFINITY. */
51      public static final FloatLengthth.html#FloatLength">FloatLength NEGATIVE_INFINITY = new FloatLength(Float.NEGATIVE_INFINITY, LengthUnit.SI);
52  
53      /** Constant with value MAX_VALUE. */
54      public static final FloatLengthtLength.html#FloatLength">FloatLength POS_MAXVALUE = new FloatLength(Float.MAX_VALUE, LengthUnit.SI);
55  
56      /** Constant with value -MAX_VALUE. */
57      public static final FloatLengthtLength.html#FloatLength">FloatLength NEG_MAXVALUE = new FloatLength(-Float.MAX_VALUE, LengthUnit.SI);
58  
59      /**
60       * Construct FloatLength scalar.
61       * @param value float; the float value
62       * @param unit LengthUnit; unit for the float value
63       */
64      public FloatLength(final float value, final LengthUnit unit)
65      {
66          super(value, unit);
67      }
68  
69      /**
70       * Construct FloatLength scalar.
71       * @param value FloatLength; Scalar from which to construct this instance
72       */
73      public FloatLengtht/scalar/FloatLength.html#FloatLength">FloatLength(final FloatLength value)
74      {
75          super(value);
76      }
77  
78      /**
79       * Construct FloatLength scalar using a double value.
80       * @param value double; the double value
81       * @param unit LengthUnit; unit for the resulting float value
82       */
83      public FloatLength(final double value, final LengthUnit unit)
84      {
85          super((float) value, unit);
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      public final FloatLength instantiateRel(final float value, final LengthUnit unit)
91      {
92          return new FloatLength(value, unit);
93      }
94  
95      /**
96       * Construct FloatLength scalar.
97       * @param value float; the float value in SI units
98       * @return FloatLength; the new scalar with the SI value
99       */
100     public static final FloatLength instantiateSI(final float value)
101     {
102         return new FloatLength(value, LengthUnit.SI);
103     }
104 
105     /** {@inheritDoc} */
106     @Override
107     public final FloatPosition instantiateAbs(final float value, final PositionUnit unit)
108     {
109         return new FloatPosition(value, unit);
110     }
111 
112     /**
113      * Interpolate between two values.
114      * @param zero FloatLength; the low value
115      * @param one FloatLength; the high value
116      * @param ratio double; the ratio between 0 and 1, inclusive
117      * @return FloatLength; a Scalar at the ratio between
118      */
119     public static FloatLengthar/FloatLength.html#FloatLength">FloatLengthatLength.html#FloatLength">FloatLength interpolate(final FloatLengthar/FloatLength.html#FloatLength">FloatLength zero, final FloatLength one, final float ratio)
120     {
121         return new FloatLength(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
122                 zero.getDisplayUnit());
123     }
124 
125     /**
126      * Return the maximum value of two relative scalars.
127      * @param r1 FloatLength; the first scalar
128      * @param r2 FloatLength; the second scalar
129      * @return FloatLength; the maximum value of two relative scalars
130      */
131     public static FloatLengthalar/FloatLength.html#FloatLength">FloatLengthalar/FloatLength.html#FloatLength">FloatLength max(final FloatLengthalar/FloatLength.html#FloatLength">FloatLength r1, final FloatLength r2)
132     {
133         return r1.gt(r2) ? r1 : r2;
134     }
135 
136     /**
137      * Return the maximum value of more than two relative scalars.
138      * @param r1 FloatLength; the first scalar
139      * @param r2 FloatLength; the second scalar
140      * @param rn FloatLength...; the other scalars
141      * @return FloatLength; the maximum value of more than two relative scalars
142      */
143     public static FloatLengthalar/FloatLength.html#FloatLength">FloatLengthalar/FloatLength.html#FloatLength">FloatLength max(final FloatLengthalar/FloatLength.html#FloatLength">FloatLength r1, final FloatLength r2, final FloatLength... rn)
144     {
145         FloatLength maxr = r1.gt(r2) ? r1 : r2;
146         for (FloatLength r : rn)
147         {
148             if (r.gt(maxr))
149             {
150                 maxr = r;
151             }
152         }
153         return maxr;
154     }
155 
156     /**
157      * Return the minimum value of two relative scalars.
158      * @param r1 FloatLength; the first scalar
159      * @param r2 FloatLength; the second scalar
160      * @return FloatLength; the minimum value of two relative scalars
161      */
162     public static FloatLengthalar/FloatLength.html#FloatLength">FloatLengthalar/FloatLength.html#FloatLength">FloatLength min(final FloatLengthalar/FloatLength.html#FloatLength">FloatLength r1, final FloatLength r2)
163     {
164         return r1.lt(r2) ? r1 : r2;
165     }
166 
167     /**
168      * Return the minimum value of more than two relative scalars.
169      * @param r1 FloatLength; the first scalar
170      * @param r2 FloatLength; the second scalar
171      * @param rn FloatLength...; the other scalars
172      * @return FloatLength; the minimum value of more than two relative scalars
173      */
174     public static FloatLengthalar/FloatLength.html#FloatLength">FloatLengthalar/FloatLength.html#FloatLength">FloatLength min(final FloatLengthalar/FloatLength.html#FloatLength">FloatLength r1, final FloatLength r2, final FloatLength... rn)
175     {
176         FloatLength minr = r1.lt(r2) ? r1 : r2;
177         for (FloatLength r : rn)
178         {
179             if (r.lt(minr))
180             {
181                 minr = r;
182             }
183         }
184         return minr;
185     }
186 
187     /**
188      * Returns a FloatLength representation of a textual representation of a value with a unit. The String representation that
189      * can be parsed is the double value in the unit, followed by the official abbreviation of the unit. Spaces are allowed, but
190      * not required, between the value and the unit.
191      * @param text String; the textual representation to parse into a FloatLength
192      * @return FloatLength; the Scalar representation of the value in its unit
193      * @throws IllegalArgumentException when the text cannot be parsed
194      * @throws NullPointerException when the text argument is null
195      */
196     public static FloatLength valueOf(final String text)
197     {
198         Throw.whenNull(text, "Error parsing FloatLength: text to parse is null");
199         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatLength: empty text to parse");
200         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
201         if (matcher.find())
202         {
203             int index = matcher.end();
204             String unitString = text.substring(index).trim();
205             String valueString = text.substring(0, index).trim();
206             LengthUnit unit = LengthUnit.BASE.getUnitByAbbreviation(unitString);
207             if (unit != null)
208             {
209                 float f = Float.parseFloat(valueString);
210                 return new FloatLength(f, unit);
211             }
212         }
213         throw new IllegalArgumentException("Error parsing FloatLength from " + text);
214     }
215 
216     /**
217      * Returns a FloatLength based on a value and the textual representation of the unit.
218      * @param value double; the value to use
219      * @param unitString String; the textual representation of the unit
220      * @return FloatLength; the Scalar representation of the value in its unit
221      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
222      * @throws NullPointerException when the unitString argument is null
223      */
224     public static FloatLength of(final float value, final String unitString)
225     {
226         Throw.whenNull(unitString, "Error parsing FloatLength: unitString is null");
227         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatLength: empty unitString");
228         LengthUnit unit = LengthUnit.BASE.getUnitByAbbreviation(unitString);
229         if (unit != null)
230         {
231             return new FloatLength(value, unit);
232         }
233         throw new IllegalArgumentException("Error parsing FloatLength with unit " + unitString);
234     }
235 
236     /**
237      * Calculate the division of FloatLength and FloatLength, which results in a FloatDimensionless scalar.
238      * @param v FloatLength scalar
239      * @return FloatDimensionless scalar as a division of FloatLength and FloatLength
240      */
241     public final FloatDimensionless divide(final FloatLength v)
242     {
243         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
244     }
245 
246     /**
247      * Calculate the multiplication of FloatLength and FloatLength, which results in a FloatArea scalar.
248      * @param v FloatLength scalar
249      * @return FloatArea scalar as a multiplication of FloatLength and FloatLength
250      */
251     public final FloatArea times(final FloatLength v)
252     {
253         return new FloatArea(this.si * v.si, AreaUnit.SI);
254     }
255 
256     /**
257      * Calculate the division of FloatLength and FloatLinearDensity, which results in a FloatArea scalar.
258      * @param v FloatLength scalar
259      * @return FloatArea scalar as a division of FloatLength and FloatLinearDensity
260      */
261     public final FloatArea divide(final FloatLinearDensity v)
262     {
263         return new FloatArea(this.si / v.si, AreaUnit.SI);
264     }
265 
266     /**
267      * Calculate the division of FloatLength and FloatArea, which results in a FloatLinearDensity scalar.
268      * @param v FloatLength scalar
269      * @return FloatLinearDensity scalar as a division of FloatLength and FloatArea
270      */
271     public final FloatLinearDensity divide(final FloatArea v)
272     {
273         return new FloatLinearDensity(this.si / v.si, LinearDensityUnit.SI);
274     }
275 
276     /**
277      * Calculate the multiplication of FloatLength and FloatArea, which results in a FloatVolume scalar.
278      * @param v FloatLength scalar
279      * @return FloatVolume scalar as a multiplication of FloatLength and FloatArea
280      */
281     public final FloatVolume times(final FloatArea v)
282     {
283         return new FloatVolume(this.si * v.si, VolumeUnit.SI);
284     }
285 
286     /**
287      * Calculate the multiplication of FloatLength and FloatForce, which results in a FloatEnergy scalar.
288      * @param v FloatLength scalar
289      * @return FloatEnergy scalar as a multiplication of FloatLength and FloatForce
290      */
291     public final FloatEnergy times(final FloatForce v)
292     {
293         return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
294     }
295 
296     /**
297      * Calculate the multiplication of FloatLength and FloatFrequency, which results in a FloatSpeed scalar.
298      * @param v FloatLength scalar
299      * @return FloatSpeed scalar as a multiplication of FloatLength and FloatFrequency
300      */
301     public final FloatSpeed times(final FloatFrequency v)
302     {
303         return new FloatSpeed(this.si * v.si, SpeedUnit.SI);
304     }
305 
306     /**
307      * Calculate the division of FloatLength and FloatDuration, which results in a FloatSpeed scalar.
308      * @param v FloatLength scalar
309      * @return FloatSpeed scalar as a division of FloatLength and FloatDuration
310      */
311     public final FloatSpeed divide(final FloatDuration v)
312     {
313         return new FloatSpeed(this.si / v.si, SpeedUnit.SI);
314     }
315 
316     /**
317      * Calculate the division of FloatLength and FloatSpeed, which results in a FloatDuration scalar.
318      * @param v FloatLength scalar
319      * @return FloatDuration scalar as a division of FloatLength and FloatSpeed
320      */
321     public final FloatDuration divide(final FloatSpeed v)
322     {
323         return new FloatDuration(this.si / v.si, DurationUnit.SI);
324     }
325 
326     /**
327      * Calculate the multiplication of FloatLength and FloatFlowMass, which results in a FloatMomentum scalar.
328      * @param v FloatLength scalar
329      * @return FloatMomentum scalar as a multiplication of FloatLength and FloatFlowMass
330      */
331     public final FloatMomentum times(final FloatFlowMass v)
332     {
333         return new FloatMomentum(this.si * v.si, MomentumUnit.SI);
334     }
335 
336 }