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.AbstractFloatScalarRel;
10 import org.djunits.value.vfloat.scalar.base.FloatScalar;
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 FloatPressure extends AbstractFloatScalarRel<PressureUnit, FloatPressure>
27 {
28
29 private static final long serialVersionUID = 20150901L;
30
31
32 public static final FloatPressure ZERO = new FloatPressure(0.0f, PressureUnit.SI);
33
34
35 public static final FloatPressure ONE = new FloatPressure(1.0f, PressureUnit.SI);
36
37
38 @SuppressWarnings("checkstyle:constantname")
39 public static final FloatPressure NaN = new FloatPressure(Float.NaN, PressureUnit.SI);
40
41
42 public static final FloatPressure POSITIVE_INFINITY = new FloatPressure(Float.POSITIVE_INFINITY, PressureUnit.SI);
43
44
45 public static final FloatPressure NEGATIVE_INFINITY = new FloatPressure(Float.NEGATIVE_INFINITY, PressureUnit.SI);
46
47
48 public static final FloatPressure POS_MAXVALUE = new FloatPressure(Float.MAX_VALUE, PressureUnit.SI);
49
50
51 public static final FloatPressure NEG_MAXVALUE = new FloatPressure(-Float.MAX_VALUE, PressureUnit.SI);
52
53
54
55
56
57
58 public FloatPressure(final float value, final PressureUnit unit)
59 {
60 super(value, unit);
61 }
62
63
64
65
66
67 public FloatPressure(final FloatPressure value)
68 {
69 super(value);
70 }
71
72
73
74
75
76
77 public FloatPressure(final double value, final PressureUnit unit)
78 {
79 super((float) value, unit);
80 }
81
82
83 @Override
84 public final FloatPressure instantiateRel(final float value, final PressureUnit unit)
85 {
86 return new FloatPressure(value, unit);
87 }
88
89
90
91
92
93
94 public static final FloatPressure instantiateSI(final float value)
95 {
96 return new FloatPressure(value, PressureUnit.SI);
97 }
98
99
100
101
102
103
104
105
106 public static FloatPressure interpolate(final 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
114
115
116
117
118 public static FloatPressure max(final FloatPressure r1, final FloatPressure r2)
119 {
120 return r1.gt(r2) ? r1 : r2;
121 }
122
123
124
125
126
127
128
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
145
146
147
148
149 public static FloatPressure min(final FloatPressure r1, final FloatPressure r2)
150 {
151 return r1.lt(r2) ? r1 : r2;
152 }
153
154
155
156
157
158
159
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
176
177
178
179
180
181
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 if (unit == null)
194 throw new IllegalArgumentException("Unit " + unitString + " not found");
195 return new FloatPressure(f, unit);
196 }
197 catch (Exception exception)
198 {
199 throw new IllegalArgumentException(
200 "Error parsing FloatPressure from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
201 exception);
202 }
203 }
204
205
206
207
208
209
210
211
212
213 public static FloatPressure of(final float value, final String unitString)
214 {
215 Throw.whenNull(unitString, "Error parsing FloatPressure: unitString is null");
216 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing FloatPressure: empty unitString");
217 PressureUnit unit = PressureUnit.BASE.getUnitByAbbreviation(unitString);
218 if (unit != null)
219 {
220 return new FloatPressure(value, unit);
221 }
222 throw new IllegalArgumentException("Error parsing FloatPressure with unit " + unitString);
223 }
224
225
226
227
228
229
230 public final FloatDimensionless divide(final FloatPressure v)
231 {
232 return new FloatDimensionless(this.si / v.si, DimensionlessUnit.SI);
233 }
234
235
236
237
238
239
240 public final FloatForce times(final FloatArea v)
241 {
242 return new FloatForce(this.si * v.si, ForceUnit.SI);
243 }
244
245
246
247
248
249
250 public final FloatEnergy times(final FloatVolume v)
251 {
252 return new FloatEnergy(this.si * v.si, EnergyUnit.SI);
253 }
254
255
256 @Override
257 public FloatSIScalar reciprocal()
258 {
259 return FloatScalar.divide(FloatDimensionless.ONE, this);
260 }
261
262 }