View Javadoc
1   package org.djunits.value.vfloat.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.DimensionlessUnit;
9   import org.djunits.unit.EnergyUnit;
10  import org.djunits.unit.ForceUnit;
11  import org.djunits.unit.PressureUnit;
12  import org.djunits.value.util.ValueUtil;
13  import org.djunits.value.vfloat.scalar.base.AbstractFloatScalarRel;
14  import org.djunits.value.vfloat.scalar.base.FloatScalar;
15  
16  /**
17   * Easy access methods for the FloatPressure FloatScalar, which is relative by definition.
18   * <p>
19   * Copyright (c) 2013-2022 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 = "2022-03-14T11:14:15.180987200Z")
26  public class FloatPressure extends AbstractFloatScalarRel<PressureUnit, FloatPressure>
27  {
28      /** */
29      private static final long serialVersionUID = 20150901L;
30  
31      /** Constant with value zero. */
32      public static final FloatPressurer/FloatPressure.html#FloatPressure">FloatPressure ZERO = new FloatPressure(0.0f, PressureUnit.SI);
33  
34      /** Constant with value one. */
35      public static final FloatPressurear/FloatPressure.html#FloatPressure">FloatPressure ONE = new FloatPressure(1.0f, PressureUnit.SI);
36  
37      /** Constant with value NaN. */
38      @SuppressWarnings("checkstyle:constantname")
39      public static final FloatPressurear/FloatPressure.html#FloatPressure">FloatPressure NaN = new FloatPressure(Float.NaN, PressureUnit.SI);
40  
41      /** Constant with value POSITIVE_INFINITY. */
42      public static final FloatPressurere.html#FloatPressure">FloatPressure POSITIVE_INFINITY = new FloatPressure(Float.POSITIVE_INFINITY, PressureUnit.SI);
43  
44      /** Constant with value NEGATIVE_INFINITY. */
45      public static final FloatPressurere.html#FloatPressure">FloatPressure NEGATIVE_INFINITY = new FloatPressure(Float.NEGATIVE_INFINITY, PressureUnit.SI);
46  
47      /** Constant with value MAX_VALUE. */
48      public static final FloatPressureressure.html#FloatPressure">FloatPressure POS_MAXVALUE = new FloatPressure(Float.MAX_VALUE, PressureUnit.SI);
49  
50      /** Constant with value -MAX_VALUE. */
51      public static final FloatPressureressure.html#FloatPressure">FloatPressure NEG_MAXVALUE = new FloatPressure(-Float.MAX_VALUE, PressureUnit.SI);
52  
53      /**
54       * Construct FloatPressure scalar.
55       * @param value float; the float value
56       * @param unit unit for the float value
57       */
58      public FloatPressure(final float value, final PressureUnit unit)
59      {
60          super(value, unit);
61      }
62  
63      /**
64       * Construct FloatPressure scalar.
65       * @param value Scalar from which to construct this instance
66       */
67      public FloatPressurescalar/FloatPressure.html#FloatPressure">FloatPressure(final FloatPressure value)
68      {
69          super(value);
70      }
71  
72      /**
73       * Construct FloatPressure scalar using a double value.
74       * @param value double; the double value
75       * @param unit unit for the resulting float value
76       */
77      public FloatPressure(final double value, final PressureUnit unit)
78      {
79          super((float) value, unit);
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public final FloatPressure instantiateRel(final float value, final PressureUnit unit)
85      {
86          return new FloatPressure(value, unit);
87      }
88  
89      /**
90       * Construct FloatPressure scalar.
91       * @param value float; the float value in SI units
92       * @return the new scalar with the SI value
93       */
94      public static final FloatPressure instantiateSI(final float value)
95      {
96          return new FloatPressure(value, PressureUnit.SI);
97      }
98  
99      /**
100      * Interpolate between two values.
101      * @param zero the low value
102      * @param one the high value
103      * @param ratio double; the ratio between 0 and 1, inclusive
104      * @return a Scalar at the ratio between
105      */
106     public static FloatPressure/FloatPressure.html#FloatPressure">FloatPressurePressure.html#FloatPressure">FloatPressure interpolate(final FloatPressure/FloatPressure.html#FloatPressure">FloatPressure zero, final FloatPressure one, final float ratio)
107     {
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 FloatPressurear/FloatPressure.html#FloatPressure">FloatPressurear/FloatPressure.html#FloatPressure">FloatPressure max(final FloatPressurear/FloatPressure.html#FloatPressure">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 FloatPressurear/FloatPressure.html#FloatPressure">FloatPressurear/FloatPressure.html#FloatPressure">FloatPressure max(final FloatPressurear/FloatPressure.html#FloatPressure">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 FloatPressurear/FloatPressure.html#FloatPressure">FloatPressurear/FloatPressure.html#FloatPressure">FloatPressure min(final FloatPressurear/FloatPressure.html#FloatPressure">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 FloatPressurear/FloatPressure.html#FloatPressure">FloatPressurear/FloatPressure.html#FloatPressure">FloatPressure min(final FloatPressurear/FloatPressure.html#FloatPressure">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 the official abbreviation of the unit. Spaces are allowed, but
177      * not required, between the value and the unit.
178      * @param text String; the textual representation to parse into a FloatPressure
179      * @return FloatPressure; 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         Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
188         if (matcher.find())
189         {
190             int index = matcher.end();
191             String unitString = text.substring(index).trim();
192             String valueString = text.substring(0, index).trim();
193             PressureUnit unit = PressureUnit.BASE.getUnitByAbbreviation(unitString);
194             if (unit != null)
195             {
196                 float f = Float.parseFloat(valueString);
197                 return new FloatPressure(f, unit);
198             }
199         }
200         throw new IllegalArgumentException("Error parsing FloatPressure from " + text);
201     }
202 
203     /**
204      * Returns a FloatPressure based on a value and the textual representation of the unit.
205      * @param value double; the value to use
206      * @param unitString String; the textual representation of the unit
207      * @return FloatPressure; the Scalar representation of the value in its unit
208      * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
209      * @throws NullPointerException when the unitString argument is null
210      */
211     public static FloatPressure of(final float value, final String unitString)
212     {
213         Throw.whenNull(unitString, "Error parsing FloatPressure: unitString is null");
214         Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatPressure: empty unitString");
215         PressureUnit unit = PressureUnit.BASE.getUnitByAbbreviation(unitString);
216         if (unit != null)
217         {
218             return new FloatPressure(value, unit);
219         }
220         throw new IllegalArgumentException("Error parsing FloatPressure with unit " + unitString);
221     }
222 
223     /**
224      * Calculate the division of FloatPressure and FloatPressure, which results in a FloatDimensionless scalar.
225      * @param v FloatPressure; scalar
226      * @return FloatDimensionless; scalar as a division of FloatPressure and FloatPressure
227      */
228     public final FloatDimensionless divide(final FloatPressure v)
229     {
230         return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
231     }
232 
233     /**
234      * Calculate the multiplication of FloatPressure and FloatArea, which results in a FloatForce scalar.
235      * @param v FloatPressure; scalar
236      * @return FloatForce; scalar as a multiplication of FloatPressure and FloatArea
237      */
238     public final FloatForce times(final FloatArea v)
239     {
240         return new FloatForce(this.si * v.si, ForceUnit.SI);
241     }
242 
243     /**
244      * Calculate the multiplication of FloatPressure and FloatVolume, which results in a FloatEnergy scalar.
245      * @param v FloatPressure; scalar
246      * @return FloatEnergy; scalar as a multiplication of FloatPressure and FloatVolume
247      */
248     public final FloatEnergy times(final FloatVolume v)
249     {
250         return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
251     }
252 
253     /** {@inheritDoc} */
254     @Override
255     public FloatSIScalar reciprocal()
256     {
257         return FloatScalar.divide(FloatDimensionless.ONE, this);
258     }
259 
260 }