View Javadoc
1   package org.djunits.value.vfloat.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.vfloat.scalar.base.FloatScalarRel;
10  import org.djutils.base.NumberParser;
11  import org.djutils.exceptions.Throw;
12  
13  import jakarta.annotation.Generated;
14  
15  /**
16   * Easy access methods for the FloatPressure FloatScalar, which is relative by definition.
17   * <p>
18   * Copyright (c) 2013-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
19   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
20   * </p>
21   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
22   * @author <a href="https://www.tudelft.nl/staff/p.knoppers/">Peter Knoppers</a>
23   */
24  @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2025-09-06T15:16:28.380798Z")
25  public class FloatPressure extends FloatScalarRel<PressureUnit, FloatPressure>
26  {
27      /** */
28      private static final long serialVersionUID = 20150901L;
29  
30      /** Constant with value zero. */
31      public static final FloatPressure ZERO = new FloatPressure(0.0f, PressureUnit.SI);
32  
33      /** Constant with value one. */
34      public static final FloatPressure ONE = new FloatPressure(1.0f, PressureUnit.SI);
35  
36      /** Constant with value NaN. */
37      @SuppressWarnings("checkstyle:constantname")
38      public static final FloatPressure NaN = new FloatPressure(Float.NaN, PressureUnit.SI);
39  
40      /** Constant with value POSITIVE_INFINITY. */
41      public static final FloatPressure POSITIVE_INFINITY = new FloatPressure(Float.POSITIVE_INFINITY, PressureUnit.SI);
42  
43      /** Constant with value NEGATIVE_INFINITY. */
44      public static final FloatPressure NEGATIVE_INFINITY = new FloatPressure(Float.NEGATIVE_INFINITY, PressureUnit.SI);
45  
46      /** Constant with value MAX_VALUE. */
47      public static final FloatPressure POS_MAXVALUE = new FloatPressure(Float.MAX_VALUE, PressureUnit.SI);
48  
49      /** Constant with value -MAX_VALUE. */
50      public static final FloatPressure NEG_MAXVALUE = new FloatPressure(-Float.MAX_VALUE, PressureUnit.SI);
51  
52      /**
53       * Construct FloatPressure scalar with a unit.
54       * @param value the float value, expressed in the given unit
55       * @param unit unit for the float value
56       */
57      public FloatPressure(final float value, final PressureUnit unit)
58      {
59          super(value, unit);
60      }
61  
62      /**
63       * Construct FloatPressure scalar.
64       * @param value Scalar from which to construct this instance
65       */
66      public FloatPressure(final FloatPressure value)
67      {
68          super(value);
69      }
70  
71      /**
72       * Construct FloatPressure scalar with a unit using a double value.
73       * @param value the double value, expressed in the given unit
74       * @param unit unit for the resulting float value
75       */
76      public FloatPressure(final double value, final PressureUnit unit)
77      {
78          super((float) value, unit);
79      }
80  
81      @Override
82      public final FloatPressure instantiateRel(final float value, final PressureUnit unit)
83      {
84          return new FloatPressure(value, unit);
85      }
86  
87      /**
88       * Construct FloatPressure scalar based on an SI value.
89       * @param value the float value in SI units
90       * @return the new scalar with the SI value
91       */
92      public static final FloatPressure ofSI(final float value)
93      {
94          return new FloatPressure(value, PressureUnit.SI);
95      }
96  
97      /**
98       * Interpolate between two values. Note that the first value does not have to be smaller than the second.
99       * @param zero the value at a ratio of zero
100      * @param one the value at a ratio of one
101      * @param ratio the ratio between 0 and 1, inclusive
102      * @return a FloatPressure at the given ratio between 0 and 1
103      */
104     public static FloatPressure interpolate(final FloatPressure zero, final FloatPressure one, final float ratio)
105     {
106         Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
107                 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
108         return new FloatPressure(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
109                 zero.getDisplayUnit());
110     }
111 
112     /**
113      * Return the maximum value of two relative scalars.
114      * @param r1 the first scalar
115      * @param r2 the second scalar
116      * @return the maximum value of two relative scalars
117      */
118     public static FloatPressure max(final FloatPressure r1, final FloatPressure r2)
119     {
120         return r1.gt(r2) ? r1 : r2;
121     }
122 
123     /**
124      * Return the maximum value of more than two relative scalars.
125      * @param r1 the first scalar
126      * @param r2 the second scalar
127      * @param rn the other scalars
128      * @return the maximum value of more than two relative scalars
129      */
130     public static FloatPressure max(final FloatPressure r1, final FloatPressure r2, final FloatPressure... rn)
131     {
132         FloatPressure maxr = r1.gt(r2) ? r1 : r2;
133         for (FloatPressure r : rn)
134         {
135             if (r.gt(maxr))
136             {
137                 maxr = r;
138             }
139         }
140         return maxr;
141     }
142 
143     /**
144      * Return the minimum value of two relative scalars.
145      * @param r1 the first scalar
146      * @param r2 the second scalar
147      * @return the minimum value of two relative scalars
148      */
149     public static FloatPressure min(final FloatPressure r1, final FloatPressure r2)
150     {
151         return r1.lt(r2) ? r1 : r2;
152     }
153 
154     /**
155      * Return the minimum value of more than two relative scalars.
156      * @param r1 the first scalar
157      * @param r2 the second scalar
158      * @param rn the other scalars
159      * @return the minimum value of more than two relative scalars
160      */
161     public static FloatPressure min(final FloatPressure r1, final FloatPressure r2, final FloatPressure... rn)
162     {
163         FloatPressure minr = r1.lt(r2) ? r1 : r2;
164         for (FloatPressure r : rn)
165         {
166             if (r.lt(minr))
167             {
168                 minr = r;
169             }
170         }
171         return minr;
172     }
173 
174     /**
175      * Returns a FloatPressure representation of a textual representation of a value with a unit. The String representation that
176      * can be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
177      * allowed, but not required, between the value and the unit.
178      * @param text the textual representation to parse into a FloatPressure
179      * @return the Scalar representation of the value in its unit
180      * @throws IllegalArgumentException when the text cannot be parsed
181      * @throws NullPointerException when the text argument is null
182      */
183     public static FloatPressure valueOf(final String text)
184     {
185         Throw.whenNull(text, "Error parsing FloatPressure: text to parse is null");
186         Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing FloatPressure: empty text to parse");
187         try
188         {
189             NumberParser numberParser = new NumberParser().lenient().trailing();
190             float f = numberParser.parseFloat(text);
191             String unitString = text.substring(numberParser.getTrailingPosition()).trim();
192             PressureUnit unit = PressureUnit.BASE.getUnitByAbbreviation(unitString);
193             Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity Pressure", unitString);
194             return new FloatPressure(f, unit);
195         }
196         catch (Exception exception)
197         {
198             throw new IllegalArgumentException(
199                     "Error parsing FloatPressure from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
200                     exception);
201         }
202     }
203 
204     /**
205      * Returns a FloatPressure based on a value and the textual representation of the unit, which can be localized.
206      * @param value the value to use
207      * @param unitString the textual representation of the unit
208      * @return the Scalar representation of the value in its unit
209      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
210      * @throws NullPointerException when the unitString argument is null
211      */
212     public static FloatPressure of(final float value, final String unitString)
213     {
214         Throw.whenNull(unitString, "Error parsing FloatPressure: unitString is null");
215         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatPressure: empty unitString");
216         PressureUnit unit = PressureUnit.BASE.getUnitByAbbreviation(unitString);
217         Throw.when(unit == null, IllegalArgumentException.class, "Error parsing FloatPressure with unit %s", unitString);
218         return new FloatPressure(value, unit);
219     }
220 
221     /**
222      * Calculate the division of FloatPressure and FloatPressure, which results in a FloatDimensionless scalar.
223      * @param v scalar
224      * @return scalar as a division of FloatPressure and FloatPressure
225      */
226     public final FloatDimensionless divide(final FloatPressure v)
227     {
228         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
229     }
230 
231     /**
232      * Calculate the multiplication of FloatPressure and FloatArea, which results in a FloatForce scalar.
233      * @param v scalar
234      * @return scalar as a multiplication of FloatPressure and FloatArea
235      */
236     public final FloatForce times(final FloatArea v)
237     {
238         return new FloatForce(this.si * v.si, ForceUnit.SI);
239     }
240 
241     /**
242      * Calculate the multiplication of FloatPressure and FloatVolume, which results in a FloatEnergy scalar.
243      * @param v scalar
244      * @return scalar as a multiplication of FloatPressure and FloatVolume
245      */
246     public final FloatEnergy times(final FloatVolume v)
247     {
248         return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
249     }
250 
251     @Override
252     public FloatSIScalar reciprocal()
253     {
254         return FloatSIScalar.divide(FloatDimensionless.ONE, this);
255     }
256 
257     /**
258      * Multiply two scalars that result in a scalar of type FloatPressure.
259      * @param scalar1 the first scalar
260      * @param scalar2 the second scalar
261      * @return the multiplication of both scalars as an instance of FloatPressure
262      */
263     public static FloatPressure multiply(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
264     {
265         Throw.whenNull(scalar1, "scalar1 cannot be null");
266         Throw.whenNull(scalar2, "scalar2 cannot be null");
267         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
268                 .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(PressureUnit.BASE.getSiDimensions()),
269                 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type FloatPressure",
270                 scalar1.toDisplayString(), scalar2.toDisplayString());
271         return new FloatPressure(scalar1.si * scalar2.si, PressureUnit.SI);
272     }
273 
274     /**
275      * Divide two scalars that result in a scalar of type FloatPressure.
276      * @param scalar1 the first scalar
277      * @param scalar2 the second scalar
278      * @return the division of scalar1 by scalar2 as an instance of FloatPressure
279      */
280     public static FloatPressure divide(final FloatScalarRel<?, ?> scalar1, final FloatScalarRel<?, ?> scalar2)
281     {
282         Throw.whenNull(scalar1, "scalar1 cannot be null");
283         Throw.whenNull(scalar2, "scalar2 cannot be null");
284         Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
285                 .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(PressureUnit.BASE.getSiDimensions()),
286                 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type FloatPressure",
287                 scalar1.toDisplayString(), scalar2.toDisplayString());
288         return new FloatPressure(scalar1.si / scalar2.si, PressureUnit.SI);
289     }
290 
291 }