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