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.AbstractDoubleScalarRel;
10 import org.djunits.value.vdouble.scalar.base.DoubleScalar;
11 import org.djutils.base.NumberParser;
12 import org.djutils.exceptions.Throw;
13
14 import jakarta.annotation.Generated;
15
16
17
18
19
20
21
22
23
24
25 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-04-30T13:59:27.633664900Z")
26 public class Pressure extends AbstractDoubleScalarRel<PressureUnit, Pressure>
27 {
28
29 private static final long serialVersionUID = 20150905L;
30
31
32 public static final Pressure ZERO = new Pressure(0.0, PressureUnit.SI);
33
34
35 public static final Pressure ONE = new Pressure(1.0, PressureUnit.SI);
36
37
38 @SuppressWarnings("checkstyle:constantname")
39 public static final Pressure NaN = new Pressure(Double.NaN, PressureUnit.SI);
40
41
42 public static final Pressure POSITIVE_INFINITY = new Pressure(Double.POSITIVE_INFINITY, PressureUnit.SI);
43
44
45 public static final Pressure NEGATIVE_INFINITY = new Pressure(Double.NEGATIVE_INFINITY, PressureUnit.SI);
46
47
48 public static final Pressure POS_MAXVALUE = new Pressure(Double.MAX_VALUE, PressureUnit.SI);
49
50
51 public static final Pressure NEG_MAXVALUE = new Pressure(-Double.MAX_VALUE, PressureUnit.SI);
52
53
54
55
56
57
58 public Pressure(final double value, final PressureUnit unit)
59 {
60 super(value, unit);
61 }
62
63
64
65
66
67 public Pressure(final Pressure value)
68 {
69 super(value);
70 }
71
72
73 @Override
74 public final Pressure instantiateRel(final double value, final PressureUnit unit)
75 {
76 return new Pressure(value, unit);
77 }
78
79
80
81
82
83
84 public static final Pressure instantiateSI(final double value)
85 {
86 return new Pressure(value, PressureUnit.SI);
87 }
88
89
90
91
92
93
94
95
96 public static Pressure interpolate(final Pressure zero, final Pressure one, final double ratio)
97 {
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 if (unit == null)
184 throw new IllegalArgumentException("Unit " + unitString + " not found");
185 return new Pressure(d, unit);
186 }
187 catch (Exception exception)
188 {
189 throw new IllegalArgumentException(
190 "Error parsing Pressure from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
191 exception);
192 }
193 }
194
195
196
197
198
199
200
201
202
203 public static Pressure of(final double value, final String unitString)
204 {
205 Throw.whenNull(unitString, "Error parsing Pressure: unitString is null");
206 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Pressure: empty unitString");
207 PressureUnit unit = PressureUnit.BASE.getUnitByAbbreviation(unitString);
208 if (unit != null)
209 {
210 return new Pressure(value, unit);
211 }
212 throw new IllegalArgumentException("Error parsing Pressure with unit " + unitString);
213 }
214
215
216
217
218
219
220 public final Dimensionless divide(final Pressure v)
221 {
222 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
223 }
224
225
226
227
228
229
230 public final Force times(final Area v)
231 {
232 return new Force(this.si * v.si, ForceUnit.SI);
233 }
234
235
236
237
238
239
240 public final Energy times(final Volume v)
241 {
242 return new Energy(this.si * v.si, EnergyUnit.SI);
243 }
244
245
246 @Override
247 public SIScalar reciprocal()
248 {
249 return DoubleScalar.divide(Dimensionless.ONE, this);
250 }
251
252 }