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.FrequencyUnit;
11  import org.djunits.unit.PowerUnit;
12  import org.djunits.unit.SpeedUnit;
13  import org.djunits.value.util.ValueUtil;
14  import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRel;
15  
16  /**
17   * Easy access methods for the Frequency DoubleScalar, 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 Frequency extends AbstractDoubleScalarRel<FrequencyUnit, Frequency>
27  {
28      /** */
29      private static final long serialVersionUID = 20150905L;
30  
31      /** Constant with value zero. */
32      public static final Frequencyscalar/Frequency.html#Frequency">Frequency ZERO = new Frequency(0.0, FrequencyUnit.SI);
33  
34      /** Constant with value one. */
35      public static final Frequency/scalar/Frequency.html#Frequency">Frequency ONE = new Frequency(1.0, FrequencyUnit.SI);
36  
37      /** Constant with value NaN. */
38      @SuppressWarnings("checkstyle:constantname")
39      public static final Frequency/scalar/Frequency.html#Frequency">Frequency NaN = new Frequency(Double.NaN, FrequencyUnit.SI);
40  
41      /** Constant with value POSITIVE_INFINITY. */
42      public static final Frequencyncy.html#Frequency">Frequency POSITIVE_INFINITY = new Frequency(Double.POSITIVE_INFINITY, FrequencyUnit.SI);
43  
44      /** Constant with value NEGATIVE_INFINITY. */
45      public static final Frequencyncy.html#Frequency">Frequency NEGATIVE_INFINITY = new Frequency(Double.NEGATIVE_INFINITY, FrequencyUnit.SI);
46  
47      /** Constant with value MAX_VALUE. */
48      public static final Frequencyrequency.html#Frequency">Frequency POS_MAXVALUE = new Frequency(Double.MAX_VALUE, FrequencyUnit.SI);
49  
50      /** Constant with value -MAX_VALUE. */
51      public static final Frequencyrequency.html#Frequency">Frequency NEG_MAXVALUE = new Frequency(-Double.MAX_VALUE, FrequencyUnit.SI);
52  
53      /**
54       * Construct Frequency scalar.
55       * @param value double; the double value
56       * @param unit FrequencyUnit; unit for the double value
57       */
58      public Frequency(final double value, final FrequencyUnit unit)
59      {
60          super(value, unit);
61      }
62  
63      /**
64       * Construct Frequency scalar.
65       * @param value Frequency; Scalar from which to construct this instance
66       */
67      public Frequencyuble/scalar/Frequency.html#Frequency">Frequency(final Frequency value)
68      {
69          super(value);
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      public final Frequency instantiateRel(final double value, final FrequencyUnit unit)
75      {
76          return new Frequency(value, unit);
77      }
78  
79      /**
80       * Construct Frequency scalar.
81       * @param value double; the double value in SI units
82       * @return Frequency; the new scalar with the SI value
83       */
84      public static final Frequency instantiateSI(final double value)
85      {
86          return new Frequency(value, FrequencyUnit.SI);
87      }
88  
89      /**
90       * Interpolate between two values.
91       * @param zero Frequency; the low value
92       * @param one Frequency; the high value
93       * @param ratio double; the ratio between 0 and 1, inclusive
94       * @return Frequency; a Scalar at the ratio between
95       */
96      public static Frequencycalar/Frequency.html#Frequency">FrequencyFrequency.html#Frequency">Frequency interpolate(final Frequencycalar/Frequency.html#Frequency">Frequency zero, final Frequency one, final double ratio)
97      {
98          return new Frequency(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 Frequency; the first scalar
105      * @param r2 Frequency; the second scalar
106      * @return Frequency; the maximum value of two relative scalars
107      */
108     public static Frequency/scalar/Frequency.html#Frequency">Frequency/scalar/Frequency.html#Frequency">Frequency max(final Frequency/scalar/Frequency.html#Frequency">Frequency r1, final Frequency 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 Frequency; the first scalar
116      * @param r2 Frequency; the second scalar
117      * @param rn Frequency...; the other scalars
118      * @return Frequency; the maximum value of more than two relative scalars
119      */
120     public static Frequency/scalar/Frequency.html#Frequency">Frequency/scalar/Frequency.html#Frequency">Frequency max(final Frequency/scalar/Frequency.html#Frequency">Frequency r1, final Frequency r2, final Frequency... rn)
121     {
122         Frequency maxr = (r1.gt(r2)) ? r1 : r2;
123         for (Frequency 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 Frequency; the first scalar
136      * @param r2 Frequency; the second scalar
137      * @return Frequency; the minimum value of two relative scalars
138      */
139     public static Frequency/scalar/Frequency.html#Frequency">Frequency/scalar/Frequency.html#Frequency">Frequency min(final Frequency/scalar/Frequency.html#Frequency">Frequency r1, final Frequency 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 Frequency; the first scalar
147      * @param r2 Frequency; the second scalar
148      * @param rn Frequency...; the other scalars
149      * @return Frequency; the minimum value of more than two relative scalars
150      */
151     public static Frequency/scalar/Frequency.html#Frequency">Frequency/scalar/Frequency.html#Frequency">Frequency min(final Frequency/scalar/Frequency.html#Frequency">Frequency r1, final Frequency r2, final Frequency... rn)
152     {
153         Frequency minr = (r1.lt(r2)) ? r1 : r2;
154         for (Frequency r : rn)
155         {
156             if (r.lt(minr))
157             {
158                 minr = r;
159             }
160         }
161         return minr;
162     }
163 
164     /**
165      * Returns a Frequency representation of a textual representation of a value with a unit. The String representation that can
166      * be parsed is the double value in the unit, followed by the official abbreviation of the unit. Spaces are allowed, but not
167      * required, between the value and the unit.
168      * @param text String; the textual representation to parse into a Frequency
169      * @return Frequency; 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 Frequency valueOf(final String text)
174     {
175         Throw.whenNull(text, "Error parsing Frequency: text to parse is null");
176         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Frequency: empty text to parse");
177         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
178         if (matcher.find())
179         {
180             int index = matcher.end();
181             String unitString = text.substring(index).trim();
182             String valueString = text.substring(0, index).trim();
183             FrequencyUnit unit = FrequencyUnit.BASE.getUnitByAbbreviation(unitString);
184             if (unit != null)
185             {
186                 double d = Double.parseDouble(valueString);
187                 return new Frequency(d, unit);
188             }
189         }
190         throw new IllegalArgumentException("Error parsing Frequency from " + text);
191     }
192 
193     /**
194      * Returns a Frequency based on a value and the textual representation of the unit.
195      * @param value double; the value to use
196      * @param unitString String; the textual representation of the unit
197      * @return Frequency; the Scalar representation of the value in its unit
198      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
199      * @throws NullPointerException when the unitString argument is null
200      */
201     public static Frequency of(final double value, final String unitString)
202     {
203         Throw.whenNull(unitString, "Error parsing Frequency: unitString is null");
204         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Frequency: empty unitString");
205         FrequencyUnit unit = FrequencyUnit.BASE.getUnitByAbbreviation(unitString);
206         if (unit != null)
207         {
208             return new Frequency(value, unit);
209         }
210         throw new IllegalArgumentException("Error parsing Frequency with unit " + unitString);
211     }
212 
213     /**
214      * Calculate the division of Frequency and Frequency, which results in a Dimensionless scalar.
215      * @param v Frequency scalar
216      * @return Dimensionless scalar as a division of Frequency and Frequency
217      */
218     public final Dimensionless divide(final Frequency v)
219     {
220         return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
221     }
222 
223     /**
224      * Calculate the multiplication of Frequency and Duration, which results in a Dimensionless scalar.
225      * @param v Frequency scalar
226      * @return Dimensionless scalar as a multiplication of Frequency and Duration
227      */
228     public final Dimensionless times(final Duration v)
229     {
230         return new Dimensionless(this.si * v.si, DimensionlessUnit.SI);
231     }
232 
233     /**
234      * Calculate the multiplication of Frequency and Length, which results in a Speed scalar.
235      * @param v Frequency scalar
236      * @return Speed scalar as a multiplication of Frequency and Length
237      */
238     public final Speed times(final Length v)
239     {
240         return new Speed(this.si * v.si, SpeedUnit.SI);
241     }
242 
243     /**
244      * Calculate the multiplication of Frequency and Speed, which results in a Acceleration scalar.
245      * @param v Frequency scalar
246      * @return Acceleration scalar as a multiplication of Frequency and Speed
247      */
248     public final Acceleration times(final Speed v)
249     {
250         return new Acceleration(this.si * v.si, AccelerationUnit.SI);
251     }
252 
253     /**
254      * Calculate the multiplication of Frequency and Energy, which results in a Power scalar.
255      * @param v Frequency scalar
256      * @return Power scalar as a multiplication of Frequency and Energy
257      */
258     public final Power times(final Energy v)
259     {
260         return new Power(this.si * v.si, PowerUnit.SI);
261     }
262 
263 }