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