1 package org.djunits.value.vdouble.scalar;
2
3 import java.util.Locale;
4
5 import org.djunits.unit.AccelerationUnit;
6 import org.djunits.unit.DimensionlessUnit;
7 import org.djunits.unit.ForceUnit;
8 import org.djunits.unit.FrequencyUnit;
9 import org.djunits.unit.PowerUnit;
10 import org.djunits.unit.SpeedUnit;
11 import org.djunits.value.vdouble.scalar.base.DoubleScalar;
12 import org.djunits.value.vdouble.scalar.base.DoubleScalarRel;
13 import org.djutils.base.NumberParser;
14 import org.djutils.exceptions.Throw;
15
16 import jakarta.annotation.Generated;
17
18
19
20
21
22
23
24
25
26
27 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
28 public class Acceleration extends DoubleScalarRel<AccelerationUnit, Acceleration>
29 {
30
31 private static final long serialVersionUID = 20150905L;
32
33
34 public static final Acceleration ZERO = new Acceleration(0.0, AccelerationUnit.SI);
35
36
37 public static final Acceleration ONE = new Acceleration(1.0, AccelerationUnit.SI);
38
39
40 @SuppressWarnings("checkstyle:constantname")
41 public static final Acceleration NaN = new Acceleration(Double.NaN, AccelerationUnit.SI);
42
43
44 public static final Acceleration POSITIVE_INFINITY = new Acceleration(Double.POSITIVE_INFINITY, AccelerationUnit.SI);
45
46
47 public static final Acceleration NEGATIVE_INFINITY = new Acceleration(Double.NEGATIVE_INFINITY, AccelerationUnit.SI);
48
49
50 public static final Acceleration POS_MAXVALUE = new Acceleration(Double.MAX_VALUE, AccelerationUnit.SI);
51
52
53 public static final Acceleration NEG_MAXVALUE = new Acceleration(-Double.MAX_VALUE, AccelerationUnit.SI);
54
55
56
57
58
59
60 public Acceleration(final double value, final AccelerationUnit unit)
61 {
62 super(value, unit);
63 }
64
65
66
67
68
69 public Acceleration(final Acceleration value)
70 {
71 super(value);
72 }
73
74 @Override
75 public final Acceleration instantiateRel(final double value, final AccelerationUnit unit)
76 {
77 return new Acceleration(value, unit);
78 }
79
80
81
82
83
84
85 public static final Acceleration instantiateSI(final double value)
86 {
87 return new Acceleration(value, AccelerationUnit.SI);
88 }
89
90
91
92
93
94
95
96
97 public static Acceleration interpolate(final Acceleration zero, final Acceleration one, final double ratio)
98 {
99 return new Acceleration(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
100 zero.getDisplayUnit());
101 }
102
103
104
105
106
107
108
109 public static Acceleration max(final Acceleration r1, final Acceleration r2)
110 {
111 return r1.gt(r2) ? r1 : r2;
112 }
113
114
115
116
117
118
119
120
121 public static Acceleration max(final Acceleration r1, final Acceleration r2, final Acceleration... rn)
122 {
123 Acceleration maxr = r1.gt(r2) ? r1 : r2;
124 for (Acceleration r : rn)
125 {
126 if (r.gt(maxr))
127 {
128 maxr = r;
129 }
130 }
131 return maxr;
132 }
133
134
135
136
137
138
139
140 public static Acceleration min(final Acceleration r1, final Acceleration r2)
141 {
142 return r1.lt(r2) ? r1 : r2;
143 }
144
145
146
147
148
149
150
151
152 public static Acceleration min(final Acceleration r1, final Acceleration r2, final Acceleration... rn)
153 {
154 Acceleration minr = r1.lt(r2) ? r1 : r2;
155 for (Acceleration r : rn)
156 {
157 if (r.lt(minr))
158 {
159 minr = r;
160 }
161 }
162 return minr;
163 }
164
165
166
167
168
169
170
171
172
173
174 public static Acceleration valueOf(final String text)
175 {
176 Throw.whenNull(text, "Error parsing Acceleration: text to parse is null");
177 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing Acceleration: empty text to parse");
178 try
179 {
180 NumberParser numberParser = new NumberParser().lenient().trailing();
181 double d = numberParser.parseDouble(text);
182 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
183 AccelerationUnit unit = AccelerationUnit.BASE.getUnitByAbbreviation(unitString);
184 if (unit == null)
185 throw new IllegalArgumentException("Unit " + unitString + " not found");
186 return new Acceleration(d, unit);
187 }
188 catch (Exception exception)
189 {
190 throw new IllegalArgumentException(
191 "Error parsing Acceleration from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
192 exception);
193 }
194 }
195
196
197
198
199
200
201
202
203
204 public static Acceleration of(final double value, final String unitString)
205 {
206 Throw.whenNull(unitString, "Error parsing Acceleration: unitString is null");
207 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing Acceleration: empty unitString");
208 AccelerationUnit unit = AccelerationUnit.BASE.getUnitByAbbreviation(unitString);
209 if (unit != null)
210 {
211 return new Acceleration(value, unit);
212 }
213 throw new IllegalArgumentException("Error parsing Acceleration with unit " + unitString);
214 }
215
216
217
218
219
220
221 public final Dimensionless divide(final Acceleration v)
222 {
223 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
224 }
225
226
227
228
229
230
231 public final Force times(final Mass v)
232 {
233 return new Force(this.si * v.si, ForceUnit.SI);
234 }
235
236
237
238
239
240
241 public final Speed times(final Duration v)
242 {
243 return new Speed(this.si * v.si, SpeedUnit.SI);
244 }
245
246
247
248
249
250
251 public final Speed divide(final Frequency v)
252 {
253 return new Speed(this.si / v.si, SpeedUnit.SI);
254 }
255
256
257
258
259
260
261 public final Frequency divide(final Speed v)
262 {
263 return new Frequency(this.si / v.si, FrequencyUnit.SI);
264 }
265
266
267
268
269
270
271 public final Power times(final Momentum v)
272 {
273 return new Power(this.si * v.si, PowerUnit.SI);
274 }
275
276 @Override
277 public SIScalar reciprocal()
278 {
279 return DoubleScalar.divide(Dimensionless.ONE, this);
280 }
281
282 }