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