1 package org.djunits.value.vdouble.scalar;
2
3 import java.util.regex.Matcher;
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.unit.Unit;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public class Pressure extends AbstractDoubleScalarRel<PressureUnit, Pressure>
36 {
37
38 private static final long serialVersionUID = 20150905L;
39
40
41 public static final Pressure ZERO = new Pressure(0.0, PressureUnit.SI);
42
43
44 @SuppressWarnings("checkstyle:constantname")
45 public static final Pressure NaN = new Pressure(Double.NaN, PressureUnit.SI);
46
47
48 public static final Pressure POSITIVE_INFINITY = new Pressure(Double.POSITIVE_INFINITY, PressureUnit.SI);
49
50
51 public static final Pressure NEGATIVE_INFINITY = new Pressure(Double.NEGATIVE_INFINITY, PressureUnit.SI);
52
53
54 public static final Pressure POS_MAXVALUE = new Pressure(Double.MAX_VALUE, PressureUnit.SI);
55
56
57 public static final Pressure NEG_MAXVALUE = new Pressure(-Double.MAX_VALUE, PressureUnit.SI);
58
59
60
61
62
63
64 public Pressure(final double value, final PressureUnit unit)
65 {
66 super(value, unit);
67 }
68
69
70
71
72
73 public Pressure(final Pressure value)
74 {
75 super(value);
76 }
77
78
79 @Override
80 public final Pressure instantiateRel(final double value, final PressureUnit unit)
81 {
82 return new Pressure(value, unit);
83 }
84
85
86
87
88
89
90 public static final Pressure createSI(final double value)
91 {
92 return new Pressure(value, PressureUnit.SI);
93 }
94
95
96
97
98
99
100
101
102 public static Pressure interpolate(final Pressure zero, final Pressure one, final double ratio)
103 {
104 return new Pressure(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
105 }
106
107
108
109
110
111
112
113 public static Pressure max(final Pressure r1, final Pressure r2)
114 {
115 return (r1.gt(r2)) ? r1 : r2;
116 }
117
118
119
120
121
122
123
124
125 public static Pressure max(final Pressure r1, final Pressure r2, final Pressure... rn)
126 {
127 Pressure maxr = (r1.gt(r2)) ? r1 : r2;
128 for (Pressure r : rn)
129 {
130 if (r.gt(maxr))
131 {
132 maxr = r;
133 }
134 }
135 return maxr;
136 }
137
138
139
140
141
142
143
144 public static Pressure min(final Pressure r1, final Pressure r2)
145 {
146 return (r1.lt(r2)) ? r1 : r2;
147 }
148
149
150
151
152
153
154
155
156 public static Pressure min(final Pressure r1, final Pressure r2, final Pressure... rn)
157 {
158 Pressure minr = (r1.lt(r2)) ? r1 : r2;
159 for (Pressure r : rn)
160 {
161 if (r.lt(minr))
162 {
163 minr = r;
164 }
165 }
166 return minr;
167 }
168
169
170
171
172
173
174
175
176
177 public static Pressure valueOf(final String text) throws IllegalArgumentException
178 {
179 if (text == null || text.length() == 0)
180 {
181 throw new IllegalArgumentException("Error parsing Pressure -- null or empty argument");
182 }
183 Matcher matcher = NUMBER_PATTERN.matcher(text);
184 if (matcher.find())
185 {
186 int index = matcher.end();
187 try
188 {
189 String unitString = text.substring(index).trim();
190 String valueString = text.substring(0, index).trim();
191 for (PressureUnit unit : Unit.getUnits(PressureUnit.class))
192 {
193 if (unit.getDefaultLocaleTextualRepresentations().contains(unitString))
194 {
195 double d = Double.parseDouble(valueString);
196 return new Pressure(d, unit);
197 }
198 }
199 }
200 catch (Exception exception)
201 {
202 throw new IllegalArgumentException("Error parsing Pressure from " + text, exception);
203 }
204 }
205 throw new IllegalArgumentException("Error parsing Pressure from " + text);
206 }
207
208
209
210
211
212
213 public final Dimensionless divideBy(final Pressure v)
214 {
215 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
216 }
217
218
219
220
221
222
223 public final Force multiplyBy(final Area v)
224 {
225 return new Force(this.si * v.si, ForceUnit.SI);
226 }
227
228
229
230
231
232
233 public final Energy multiplyBy(final Volume v)
234 {
235 return new Energy(this.si * v.si, EnergyUnit.SI);
236 }
237
238 }