View Javadoc
1   package org.djunits.value.vdouble.scalar;
2   
3   import java.util.Locale;
4   
5   import org.djunits.unit.DimensionlessUnit;
6   import org.djunits.unit.ForceUnit;
7   import org.djunits.unit.FrequencyUnit;
8   import org.djunits.unit.LengthUnit;
9   import org.djunits.unit.LinearDensityUnit;
10  import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRel;
11  import org.djutils.base.NumberParser;
12  import org.djutils.exceptions.Throw;
13  
14  import jakarta.annotation.Generated;
15  
16  /**
17   * Easy access methods for the LinearDensity DoubleScalar, which is relative by definition.
18   * <p>
19   * Copyright (c) 2013-2023 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 = "2023-04-30T13:59:27.633664900Z")
26  public class LinearDensity extends AbstractDoubleScalarRel<LinearDensityUnit, LinearDensity>
27  {
28      /** */
29      private static final long serialVersionUID = 20150905L;
30  
31      /** Constant with value zero. */
32      public static final LinearDensity ZERO = new LinearDensity(0.0, LinearDensityUnit.SI);
33  
34      /** Constant with value one. */
35      public static final LinearDensity ONE = new LinearDensity(1.0, LinearDensityUnit.SI);
36  
37      /** Constant with value NaN. */
38      @SuppressWarnings("checkstyle:constantname")
39      public static final LinearDensity NaN = new LinearDensity(Double.NaN, LinearDensityUnit.SI);
40  
41      /** Constant with value POSITIVE_INFINITY. */
42      public static final LinearDensity POSITIVE_INFINITY = new LinearDensity(Double.POSITIVE_INFINITY, LinearDensityUnit.SI);
43  
44      /** Constant with value NEGATIVE_INFINITY. */
45      public static final LinearDensity NEGATIVE_INFINITY = new LinearDensity(Double.NEGATIVE_INFINITY, LinearDensityUnit.SI);
46  
47      /** Constant with value MAX_VALUE. */
48      public static final LinearDensity POS_MAXVALUE = new LinearDensity(Double.MAX_VALUE, LinearDensityUnit.SI);
49  
50      /** Constant with value -MAX_VALUE. */
51      public static final LinearDensity NEG_MAXVALUE = new LinearDensity(-Double.MAX_VALUE, LinearDensityUnit.SI);
52  
53      /**
54       * Construct LinearDensity scalar.
55       * @param value double; the double value
56       * @param unit LinearDensityUnit; unit for the double value
57       */
58      public LinearDensity(final double value, final LinearDensityUnit unit)
59      {
60          super(value, unit);
61      }
62  
63      /**
64       * Construct LinearDensity scalar.
65       * @param value LinearDensity; Scalar from which to construct this instance
66       */
67      public LinearDensity(final LinearDensity value)
68      {
69          super(value);
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      public final LinearDensity instantiateRel(final double value, final LinearDensityUnit unit)
75      {
76          return new LinearDensity(value, unit);
77      }
78  
79      /**
80       * Construct LinearDensity scalar.
81       * @param value double; the double value in SI units
82       * @return LinearDensity; the new scalar with the SI value
83       */
84      public static final LinearDensity instantiateSI(final double value)
85      {
86          return new LinearDensity(value, LinearDensityUnit.SI);
87      }
88  
89      /**
90       * Interpolate between two values.
91       * @param zero LinearDensity; the low value
92       * @param one LinearDensity; the high value
93       * @param ratio double; the ratio between 0 and 1, inclusive
94       * @return LinearDensity; a Scalar at the ratio between
95       */
96      public static LinearDensity interpolate(final LinearDensity zero, final LinearDensity one, final double ratio)
97      {
98          return new LinearDensity(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
99                  zero.getDisplayUnit());
100     }
101 
102     /**
103      * Return the maximum value of two relative scalars.
104      * @param r1 LinearDensity; the first scalar
105      * @param r2 LinearDensity; the second scalar
106      * @return LinearDensity; the maximum value of two relative scalars
107      */
108     public static LinearDensity max(final LinearDensity r1, final LinearDensity r2)
109     {
110         return r1.gt(r2) ? r1 : r2;
111     }
112 
113     /**
114      * Return the maximum value of more than two relative scalars.
115      * @param r1 LinearDensity; the first scalar
116      * @param r2 LinearDensity; the second scalar
117      * @param rn LinearDensity...; the other scalars
118      * @return LinearDensity; the maximum value of more than two relative scalars
119      */
120     public static LinearDensity max(final LinearDensity r1, final LinearDensity r2, final LinearDensity... rn)
121     {
122         LinearDensity maxr = r1.gt(r2) ? r1 : r2;
123         for (LinearDensity r : rn)
124         {
125             if (r.gt(maxr))
126             {
127                 maxr = r;
128             }
129         }
130         return maxr;
131     }
132 
133     /**
134      * Return the minimum value of two relative scalars.
135      * @param r1 LinearDensity; the first scalar
136      * @param r2 LinearDensity; the second scalar
137      * @return LinearDensity; the minimum value of two relative scalars
138      */
139     public static LinearDensity min(final LinearDensity r1, final LinearDensity r2)
140     {
141         return r1.lt(r2) ? r1 : r2;
142     }
143 
144     /**
145      * Return the minimum value of more than two relative scalars.
146      * @param r1 LinearDensity; the first scalar
147      * @param r2 LinearDensity; the second scalar
148      * @param rn LinearDensity...; the other scalars
149      * @return LinearDensity; the minimum value of more than two relative scalars
150      */
151     public static LinearDensity min(final LinearDensity r1, final LinearDensity r2, final LinearDensity... rn)
152     {
153         LinearDensity minr = r1.lt(r2) ? r1 : r2;
154         for (LinearDensity r : rn)
155         {
156             if (r.lt(minr))
157             {
158                 minr = r;
159             }
160         }
161         return minr;
162     }
163 
164     /**
165      * Returns a LinearDensity representation of a textual representation of a value with a unit. The String representation that
166      * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
167      * allowed, but not required, between the value and the unit.
168      * @param text String; the textual representation to parse into a LinearDensity
169      * @return LinearDensity; the Scalar representation of the value in its unit
170      * @throws IllegalArgumentException when the text cannot be parsed
171      * @throws NullPointerException when the text argument is null
172      */
173     public static LinearDensity valueOf(final String text)
174     {
175         Throw.whenNull(text, "Error parsing LinearDensity: text to parse is null");
176         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing LinearDensity: empty text to parse");
177         try
178         {
179             NumberParser numberParser = new NumberParser().lenient().trailing();
180             double d = numberParser.parseDouble(text);
181             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
182             LinearDensityUnit unit = LinearDensityUnit.BASE.getUnitByAbbreviation(unitString);
183             if (unit == null)
184                 throw new IllegalArgumentException("Unit " + unitString + " not found");
185             return new LinearDensity(d, unit);
186         }
187         catch (Exception exception)
188         {
189             throw new IllegalArgumentException(
190                     "Error parsing LinearDensity from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
191                     exception);
192         }
193     }
194 
195     /**
196      * Returns a LinearDensity based on a value and the textual representation of the unit, which can be localized.
197      * @param value double; the value to use
198      * @param unitString String; the textual representation of the unit
199      * @return LinearDensity; the Scalar representation of the value in its unit
200      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
201      * @throws NullPointerException when the unitString argument is null
202      */
203     public static LinearDensity of(final double value, final String unitString)
204     {
205         Throw.whenNull(unitString, "Error parsing LinearDensity: unitString is null");
206         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing LinearDensity: empty unitString");
207         LinearDensityUnit unit = LinearDensityUnit.BASE.getUnitByAbbreviation(unitString);
208         if (unit != null)
209         {
210             return new LinearDensity(value, unit);
211         }
212         throw new IllegalArgumentException("Error parsing LinearDensity with unit " + unitString);
213     }
214 
215     /**
216      * Calculate the division of LinearDensity and LinearDensity, which results in a Dimensionless scalar.
217      * @param v LinearDensity; scalar
218      * @return Dimensionless; scalar as a division of LinearDensity and LinearDensity
219      */
220     public final Dimensionless divide(final LinearDensity v)
221     {
222         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
223     }
224 
225     /**
226      * Calculate the multiplication of LinearDensity and Length, which results in a Dimensionless scalar.
227      * @param v LinearDensity; scalar
228      * @return Dimensionless; scalar as a multiplication of LinearDensity and Length
229      */
230     public final Dimensionless times(final Length v)
231     {
232         return new Dimensionless(this.si * v.si, DimensionlessUnit.SI);
233     }
234 
235     /**
236      * Calculate the multiplication of LinearDensity and Area, which results in a Length scalar.
237      * @param v LinearDensity; scalar
238      * @return Length; scalar as a multiplication of LinearDensity and Area
239      */
240     public final Length times(final Area v)
241     {
242         return new Length(this.si * v.si, LengthUnit.SI);
243     }
244 
245     /**
246      * Calculate the multiplication of LinearDensity and Energy, which results in a Force scalar.
247      * @param v LinearDensity; scalar
248      * @return Force; scalar as a multiplication of LinearDensity and Energy
249      */
250     public final Force times(final Energy v)
251     {
252         return new Force(this.si * v.si, ForceUnit.SI);
253     }
254 
255     /**
256      * Calculate the multiplication of LinearDensity and Speed, which results in a Frequency scalar.
257      * @param v LinearDensity; scalar
258      * @return Frequency; scalar as a multiplication of LinearDensity and Speed
259      */
260     public final Frequency times(final Speed v)
261     {
262         return new Frequency(this.si * v.si, FrequencyUnit.SI);
263     }
264 
265     /** {@inheritDoc} */
266     @Override
267     public Length reciprocal()
268     {
269         return Length.instantiateSI(1.0 / this.si);
270     }
271 
272 }