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