View Javadoc
1   package org.djunits.value.vdouble.scalar;
2   
3   import org.djunits.unit.DimensionlessUnit;
4   import org.djunits.unit.ForceUnit;
5   import org.djunits.unit.FrequencyUnit;
6   import org.djunits.unit.LengthUnit;
7   import org.djunits.unit.LinearDensityUnit;
8   import org.djunits.unit.MoneyPerLengthUnit;
9   
10  /**
11   * Easy access methods for the LinearDensity DoubleScalar, which is relative by definition. Instead of:
12   * 
13   * <pre>
14   * DoubleScalar.Rel&lt;LinearDensityUnit&gt; value = new DoubleScalar.Rel&lt;LinearDensityUnit&gt;(100.0, LinearDensityUnit.SI);
15   * </pre>
16   * 
17   * we can now write:
18   * 
19   * <pre>
20   * LinearDensity value = new LinearDensity(100.0, LinearDensityUnit.SI);
21   * </pre>
22   * 
23   * The compiler will automatically recognize which units belong to which quantity, and whether the quantity type and the unit
24   * used are compatible.
25   * <p>
26   * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
27   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
28   * <p>
29   * $LastChangedDate: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, by $Author: averbraeck $,
30   * initial version Sep 5, 2015 <br>
31   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
32   * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
33   */
34  public class LinearDensity extends AbstractDoubleScalarRel<LinearDensityUnit, LinearDensity>
35  {
36      /** */
37      private static final long serialVersionUID = 20150905L;
38  
39      /** constant with value zero. */
40      public static final LinearDensity ZERO = new LinearDensity(0.0, LinearDensityUnit.SI);
41  
42      /** constant with value NaN. */
43      @SuppressWarnings("checkstyle:constantname")
44      public static final LinearDensity NaN = new LinearDensity(Double.NaN, LinearDensityUnit.SI);
45  
46      /** constant with value POSITIVE_INFINITY. */
47      public static final LinearDensity POSITIVE_INFINITY = new LinearDensity(Double.POSITIVE_INFINITY, LinearDensityUnit.SI);
48  
49      /** constant with value NEGATIVE_INFINITY. */
50      public static final LinearDensity NEGATIVE_INFINITY = new LinearDensity(Double.NEGATIVE_INFINITY, LinearDensityUnit.SI);
51  
52      /** constant with value MAX_VALUE. */
53      public static final LinearDensity POS_MAXVALUE = new LinearDensity(Double.MAX_VALUE, LinearDensityUnit.SI);
54  
55      /** constant with value -MAX_VALUE. */
56      public static final LinearDensity NEG_MAXVALUE = new LinearDensity(-Double.MAX_VALUE, LinearDensityUnit.SI);
57  
58      /**
59       * Construct LinearDensity scalar.
60       * @param value double value
61       * @param unit unit for the double value
62       */
63      public LinearDensity(final double value, final LinearDensityUnit unit)
64      {
65          super(value, unit);
66      }
67  
68      /**
69       * Construct LinearDensity scalar.
70       * @param value Scalar from which to construct this instance
71       */
72      public LinearDensity(final LinearDensity value)
73      {
74          super(value);
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public final LinearDensity instantiateRel(final double value, final LinearDensityUnit unit)
80      {
81          return new LinearDensity(value, unit);
82      }
83  
84      /**
85       * Construct LinearDensity scalar.
86       * @param value double value in SI units
87       * @return the new scalar with the SI value
88       */
89      public static final LinearDensity createSI(final double value)
90      {
91          return new LinearDensity(value, LinearDensityUnit.SI);
92      }
93  
94      /**
95       * Interpolate between two values.
96       * @param zero the low value
97       * @param one the high value
98       * @param ratio the ratio between 0 and 1, inclusive
99       * @return a Scalar at the ratio between
100      */
101     public static LinearDensity interpolate(final LinearDensity zero, final LinearDensity one, final double ratio)
102     {
103         return new LinearDensity(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
104     }
105 
106     /**
107      * Return the maximum value of two relative scalars.
108      * @param r1 the first scalar
109      * @param r2 the second scalar
110      * @return the maximum value of two relative scalars
111      */
112     public static LinearDensity max(final LinearDensity r1, final LinearDensity r2)
113     {
114         return (r1.gt(r2)) ? r1 : r2;
115     }
116 
117     /**
118      * Return the maximum value of more than two relative scalars.
119      * @param r1 the first scalar
120      * @param r2 the second scalar
121      * @param rn the other scalars
122      * @return the maximum value of more than two relative scalars
123      */
124     public static LinearDensity max(final LinearDensity r1, final LinearDensity r2, final LinearDensity... rn)
125     {
126         LinearDensity maxr = (r1.gt(r2)) ? r1 : r2;
127         for (LinearDensity r : rn)
128         {
129             if (r.gt(maxr))
130             {
131                 maxr = r;
132             }
133         }
134         return maxr;
135     }
136 
137     /**
138      * Return the minimum value of two relative scalars.
139      * @param r1 the first scalar
140      * @param r2 the second scalar
141      * @return the minimum value of two relative scalars
142      */
143     public static LinearDensity min(final LinearDensity r1, final LinearDensity r2)
144     {
145         return (r1.lt(r2)) ? r1 : r2;
146     }
147 
148     /**
149      * Return the minimum value of more than two relative scalars.
150      * @param r1 the first scalar
151      * @param r2 the second scalar
152      * @param rn the other scalars
153      * @return the minimum value of more than two relative scalars
154      */
155     public static LinearDensity min(final LinearDensity r1, final LinearDensity r2, final LinearDensity... rn)
156     {
157         LinearDensity minr = (r1.lt(r2)) ? r1 : r2;
158         for (LinearDensity r : rn)
159         {
160             if (r.lt(minr))
161             {
162                 minr = r;
163             }
164         }
165         return minr;
166     }
167 
168     /**
169      * Calculate the division of LinearDensity and LinearDensity, which results in a Dimensionless scalar.
170      * @param v LinearDensity scalar
171      * @return Dimensionless scalar as a division of LinearDensity and LinearDensity
172      */
173     public final Dimensionless divideBy(final LinearDensity v)
174     {
175         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
176     }
177 
178     /**
179      * Calculate the multiplication of LinearDensity and Area, which results in a Length scalar.
180      * @param v LinearDensity scalar
181      * @return Length scalar as a multiplication of LinearDensity and Area
182      */
183     public final Length multiplyBy(final Area v)
184     {
185         return new Length(this.si * v.si, LengthUnit.SI);
186     }
187 
188     /**
189      * Calculate the multiplication of LinearDensity and Energy, which results in a Force scalar.
190      * @param v LinearDensity scalar
191      * @return Force scalar as a multiplication of LinearDensity and Energy
192      */
193     public final Force multiplyBy(final Energy v)
194     {
195         return new Force(this.si * v.si, ForceUnit.SI);
196     }
197 
198     /**
199      * Calculate the multiplication of LinearDensity and Speed, which results in a Frequency scalar.
200      * @param v LinearDensity scalar
201      * @return Frequency scalar as a multiplication of LinearDensity and Speed
202      */
203     public final Frequency multiplyBy(final Speed v)
204     {
205         return new Frequency(this.si * v.si, FrequencyUnit.SI);
206     }
207 
208     /**
209      * Calculate the multiplication of LinearDensity and Money, which results in a MoneyPerLength scalar.
210      * @param v LinearDensity scalar
211      * @return MoneyPerLength scalar as a multiplication of LinearDensity and Money
212      */
213     public final MoneyPerLength multiplyBy(final Money v)
214     {
215         return new MoneyPerLength(this.si * v.si, MoneyPerLengthUnit.getStandardMoneyPerLengthUnit());
216     }
217 
218 }