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