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.DoubleScalarRel;
10 import org.djutils.base.NumberParser;
11 import org.djutils.exceptions.Throw;
12
13 import jakarta.annotation.Generated;
14
15
16
17
18
19
20
21
22
23
24 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2025-09-06T15:16:28.380798Z")
25 public class Pressure extends DoubleScalarRel<PressureUnit, Pressure>
26 {
27
28 private static final long serialVersionUID = 20150905L;
29
30
31 public static final Pressure ZERO = new Pressure(0.0, PressureUnit.SI);
32
33
34 public static final Pressure ONE = new Pressure(1.0, PressureUnit.SI);
35
36
37 @SuppressWarnings("checkstyle:constantname")
38 public static final Pressure NaN = new Pressure(Double.NaN, PressureUnit.SI);
39
40
41 public static final Pressure POSITIVE_INFINITY = new Pressure(Double.POSITIVE_INFINITY, PressureUnit.SI);
42
43
44 public static final Pressure NEGATIVE_INFINITY = new Pressure(Double.NEGATIVE_INFINITY, PressureUnit.SI);
45
46
47 public static final Pressure POS_MAXVALUE = new Pressure(Double.MAX_VALUE, PressureUnit.SI);
48
49
50 public static final Pressure NEG_MAXVALUE = new Pressure(-Double.MAX_VALUE, PressureUnit.SI);
51
52
53
54
55
56
57 public Pressure(final double value, final PressureUnit unit)
58 {
59 super(value, unit);
60 }
61
62
63
64
65
66 public Pressure(final Pressure value)
67 {
68 super(value);
69 }
70
71 @Override
72 public final Pressure instantiateRel(final double value, final PressureUnit unit)
73 {
74 return new Pressure(value, unit);
75 }
76
77
78
79
80
81
82 public static final Pressure ofSI(final double value)
83 {
84 return new Pressure(value, PressureUnit.SI);
85 }
86
87
88
89
90
91
92
93
94 public static Pressure interpolate(final Pressure zero, final Pressure one, final double ratio)
95 {
96 Throw.when(ratio < 0.0 || ratio > 1.0, IllegalArgumentException.class,
97 "ratio for interpolation should be between 0 and 1, but is %f", ratio);
98 return new Pressure(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
99 zero.getDisplayUnit());
100 }
101
102
103
104
105
106
107
108 public static Pressure max(final Pressure r1, final Pressure r2)
109 {
110 return r1.gt(r2) ? r1 : r2;
111 }
112
113
114
115
116
117
118
119
120 public static Pressure max(final Pressure r1, final Pressure r2, final Pressure... rn)
121 {
122 Pressure maxr = r1.gt(r2) ? r1 : r2;
123 for (Pressure r : rn)
124 {
125 if (r.gt(maxr))
126 {
127 maxr = r;
128 }
129 }
130 return maxr;
131 }
132
133
134
135
136
137
138
139 public static Pressure min(final Pressure r1, final Pressure r2)
140 {
141 return r1.lt(r2) ? r1 : r2;
142 }
143
144
145
146
147
148
149
150
151 public static Pressure min(final Pressure r1, final Pressure r2, final Pressure... rn)
152 {
153 Pressure minr = r1.lt(r2) ? r1 : r2;
154 for (Pressure r : rn)
155 {
156 if (r.lt(minr))
157 {
158 minr = r;
159 }
160 }
161 return minr;
162 }
163
164
165
166
167
168
169
170
171
172
173 public static Pressure valueOf(final String text)
174 {
175 Throw.whenNull(text, "Error parsing Pressure: text to parse is null");
176 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Pressure: empty text to parse");
177 try
178 {
179 NumberParser numberParser = new NumberParser().lenient().trailing();
180 double d = numberParser.parseDouble(text);
181 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
182 PressureUnit unit = PressureUnit.BASE.getUnitByAbbreviation(unitString);
183 Throw.when(unit == null, IllegalArgumentException.class, "Unit %s not found for quantity Pressure", unitString);
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
196
197
198
199
200
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 Throw.when(unit == null, IllegalArgumentException.class, "Error parsing Pressure with unit %s", unitString);
208 return new Pressure(value, unit);
209 }
210
211
212
213
214
215
216 public final Dimensionless divide(final Pressure v)
217 {
218 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
219 }
220
221
222
223
224
225
226 public final Force times(final Area v)
227 {
228 return new Force(this.si * v.si, ForceUnit.SI);
229 }
230
231
232
233
234
235
236 public final Energy times(final Volume v)
237 {
238 return new Energy(this.si * v.si, EnergyUnit.SI);
239 }
240
241 @Override
242 public SIScalar reciprocal()
243 {
244 return SIScalar.divide(Dimensionless.ONE, this);
245 }
246
247
248
249
250
251
252
253 public static Pressure multiply(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
254 {
255 Throw.whenNull(scalar1, "scalar1 cannot be null");
256 Throw.whenNull(scalar2, "scalar2 cannot be null");
257 Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
258 .plus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(PressureUnit.BASE.getSiDimensions()),
259 IllegalArgumentException.class, "Multiplying %s by %s does not result in instance of type Pressure",
260 scalar1.toDisplayString(), scalar2.toDisplayString());
261 return new Pressure(scalar1.si * scalar2.si, PressureUnit.SI);
262 }
263
264
265
266
267
268
269
270 public static Pressure divide(final DoubleScalarRel<?, ?> scalar1, final DoubleScalarRel<?, ?> scalar2)
271 {
272 Throw.whenNull(scalar1, "scalar1 cannot be null");
273 Throw.whenNull(scalar2, "scalar2 cannot be null");
274 Throw.when(!scalar1.getDisplayUnit().getQuantity().getSiDimensions()
275 .minus(scalar2.getDisplayUnit().getQuantity().getSiDimensions()).equals(PressureUnit.BASE.getSiDimensions()),
276 IllegalArgumentException.class, "Dividing %s by %s does not result in an instance of type Pressure",
277 scalar1.toDisplayString(), scalar2.toDisplayString());
278 return new Pressure(scalar1.si / scalar2.si, PressureUnit.SI);
279 }
280
281 }