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