1 package org.djunits.value.vdouble.scalar;
2
3 import java.util.regex.Matcher;
4
5 import javax.annotation.Generated;
6
7 import org.djunits.Throw;
8 import org.djunits.unit.AmountOfSubstanceUnit;
9 import org.djunits.unit.CatalyticActivityUnit;
10 import org.djunits.unit.DimensionlessUnit;
11 import org.djunits.unit.DurationUnit;
12 import org.djunits.value.util.ValueUtil;
13 import org.djunits.value.vdouble.scalar.base.AbstractDoubleScalarRel;
14
15
16
17
18
19
20
21
22
23
24 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2020-01-19T15:21:24.964166400Z")
25 public class AmountOfSubstance extends AbstractDoubleScalarRel<AmountOfSubstanceUnit, AmountOfSubstance>
26 {
27
28 private static final long serialVersionUID = 20150905L;
29
30
31 public static final AmountOfSubstancemountOfSubstance.html#AmountOfSubstance">AmountOfSubstance ZERO = new AmountOfSubstance(0.0, AmountOfSubstanceUnit.SI);
32
33
34 public static final AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance ONE = new AmountOfSubstance(1.0, AmountOfSubstanceUnit.SI);
35
36
37 @SuppressWarnings("checkstyle:constantname")
38 public static final AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance NaN = new AmountOfSubstance(Double.NaN, AmountOfSubstanceUnit.SI);
39
40
41 public static final AmountOfSubstance POSITIVE_INFINITY =
42 new AmountOfSubstance(Double.POSITIVE_INFINITY, AmountOfSubstanceUnit.SI);
43
44
45 public static final AmountOfSubstance NEGATIVE_INFINITY =
46 new AmountOfSubstance(Double.NEGATIVE_INFINITY, AmountOfSubstanceUnit.SI);
47
48
49 public static final AmountOfSubstanceubstance.html#AmountOfSubstance">AmountOfSubstance POS_MAXVALUE = new AmountOfSubstance(Double.MAX_VALUE, AmountOfSubstanceUnit.SI);
50
51
52 public static final AmountOfSubstanceubstance.html#AmountOfSubstance">AmountOfSubstance NEG_MAXVALUE = new AmountOfSubstance(-Double.MAX_VALUE, AmountOfSubstanceUnit.SI);
53
54
55
56
57
58
59 public AmountOfSubstance(final double value, final AmountOfSubstanceUnit unit)
60 {
61 super(value, unit);
62 }
63
64
65
66
67
68 public AmountOfSubstancelar/AmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance(final AmountOfSubstance value)
69 {
70 super(value);
71 }
72
73
74 @Override
75 public final AmountOfSubstance instantiateRel(final double value, final AmountOfSubstanceUnit unit)
76 {
77 return new AmountOfSubstance(value, unit);
78 }
79
80
81
82
83
84
85 public static final AmountOfSubstance instantiateSI(final double value)
86 {
87 return new AmountOfSubstance(value, AmountOfSubstanceUnit.SI);
88 }
89
90
91
92
93
94
95
96
97 public static AmountOfSubstanceountOfSubstance.html#AmountOfSubstance">AmountOfSubstanceSubstance.html#AmountOfSubstance">AmountOfSubstance interpolate(final AmountOfSubstanceountOfSubstance.html#AmountOfSubstance">AmountOfSubstance zero, final AmountOfSubstance one, final double ratio)
98 {
99 return new AmountOfSubstance(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
100 zero.getDisplayUnit());
101 }
102
103
104
105
106
107
108
109 public static AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance max(final AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance r1, final AmountOfSubstance r2)
110 {
111 return r1.gt(r2) ? r1 : r2;
112 }
113
114
115
116
117
118
119
120
121 public static AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance max(final AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance r1, final AmountOfSubstance r2, final AmountOfSubstance... rn)
122 {
123 AmountOfSubstance maxr = r1.gt(r2) ? r1 : r2;
124 for (AmountOfSubstance 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 AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance min(final AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance r1, final AmountOfSubstance r2)
141 {
142 return r1.lt(r2) ? r1 : r2;
143 }
144
145
146
147
148
149
150
151
152 public static AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance min(final AmountOfSubstanceAmountOfSubstance.html#AmountOfSubstance">AmountOfSubstance r1, final AmountOfSubstance r2, final AmountOfSubstance... rn)
153 {
154 AmountOfSubstance minr = r1.lt(r2) ? r1 : r2;
155 for (AmountOfSubstance 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 AmountOfSubstance valueOf(final String text)
175 {
176 Throw.whenNull(text, "Error parsing AmountOfSubstance: text to parse is null");
177 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing AmountOfSubstance: empty text to parse");
178 Matcher matcher = ValueUtil.NUMBER_PATTERN.matcher(text);
179 if (matcher.find())
180 {
181 int index = matcher.end();
182 String unitString = text.substring(index).trim();
183 String valueString = text.substring(0, index).trim();
184 AmountOfSubstanceUnit unit = AmountOfSubstanceUnit.BASE.getUnitByAbbreviation(unitString);
185 if (unit != null)
186 {
187 double d = Double.parseDouble(valueString);
188 return new AmountOfSubstance(d, unit);
189 }
190 }
191 throw new IllegalArgumentException("Error parsing AmountOfSubstance from " + text);
192 }
193
194
195
196
197
198
199
200
201
202 public static AmountOfSubstance of(final double value, final String unitString)
203 {
204 Throw.whenNull(unitString, "Error parsing AmountOfSubstance: unitString is null");
205 Throw.when(unitString.length() == 0, IllegalArgumentException.class,
206 "Error parsing AmountOfSubstance: empty unitString");
207 AmountOfSubstanceUnit unit = AmountOfSubstanceUnit.BASE.getUnitByAbbreviation(unitString);
208 if (unit != null)
209 {
210 return new AmountOfSubstance(value, unit);
211 }
212 throw new IllegalArgumentException("Error parsing AmountOfSubstance with unit " + unitString);
213 }
214
215
216
217
218
219
220 public final Dimensionless divide(final AmountOfSubstance v)
221 {
222 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
223 }
224
225
226
227
228
229
230 public final Duration divide(final CatalyticActivity v)
231 {
232 return new Duration(this.si / v.si, DurationUnit.SI);
233 }
234
235
236
237
238
239
240 public final CatalyticActivity divide(final Duration v)
241 {
242 return new CatalyticActivity(this.si / v.si, CatalyticActivityUnit.SI);
243 }
244
245 }