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.DoubleScalar;
8 import org.djunits.value.vdouble.scalar.base.DoubleScalarRel;
9 import org.djutils.base.NumberParser;
10 import org.djutils.exceptions.Throw;
11
12 import jakarta.annotation.Generated;
13
14
15
16
17
18
19
20
21
22
23 @Generated(value = "org.djunits.generator.GenerateDJUNIT", date = "2023-07-23T14:06:38.224104100Z")
24 public class AbsorbedDose extends DoubleScalarRel<AbsorbedDoseUnit, AbsorbedDose>
25 {
26
27 private static final long serialVersionUID = 20150905L;
28
29
30 public static final AbsorbedDose ZERO = new AbsorbedDose(0.0, AbsorbedDoseUnit.SI);
31
32
33 public static final AbsorbedDose ONE = new AbsorbedDose(1.0, AbsorbedDoseUnit.SI);
34
35
36 @SuppressWarnings("checkstyle:constantname")
37 public static final AbsorbedDose NaN = new AbsorbedDose(Double.NaN, AbsorbedDoseUnit.SI);
38
39
40 public static final AbsorbedDose POSITIVE_INFINITY = new AbsorbedDose(Double.POSITIVE_INFINITY, AbsorbedDoseUnit.SI);
41
42
43 public static final AbsorbedDose NEGATIVE_INFINITY = new AbsorbedDose(Double.NEGATIVE_INFINITY, AbsorbedDoseUnit.SI);
44
45
46 public static final AbsorbedDose POS_MAXVALUE = new AbsorbedDose(Double.MAX_VALUE, AbsorbedDoseUnit.SI);
47
48
49 public static final AbsorbedDose NEG_MAXVALUE = new AbsorbedDose(-Double.MAX_VALUE, AbsorbedDoseUnit.SI);
50
51
52
53
54
55
56 public AbsorbedDose(final double value, final AbsorbedDoseUnit unit)
57 {
58 super(value, unit);
59 }
60
61
62
63
64
65 public AbsorbedDose(final AbsorbedDose value)
66 {
67 super(value);
68 }
69
70
71 @Override
72 public final AbsorbedDose instantiateRel(final double value, final AbsorbedDoseUnit unit)
73 {
74 return new AbsorbedDose(value, unit);
75 }
76
77
78
79
80
81
82 public static final AbsorbedDose instantiateSI(final double value)
83 {
84 return new AbsorbedDose(value, AbsorbedDoseUnit.SI);
85 }
86
87
88
89
90
91
92
93
94 public static AbsorbedDose interpolate(final AbsorbedDose zero, final AbsorbedDose one, final double ratio)
95 {
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 if (unit == null)
182 throw new IllegalArgumentException("Unit " + unitString + " not found");
183 return new AbsorbedDose(d, unit);
184 }
185 catch (Exception exception)
186 {
187 throw new IllegalArgumentException(
188 "Error parsing AbsorbedDose from " + text + " using Locale " + Locale.getDefault(Locale.Category.FORMAT),
189 exception);
190 }
191 }
192
193
194
195
196
197
198
199
200
201 public static AbsorbedDose of(final double value, final String unitString)
202 {
203 Throw.whenNull(unitString, "Error parsing AbsorbedDose: unitString is null");
204 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing AbsorbedDose: empty unitString");
205 AbsorbedDoseUnit unit = AbsorbedDoseUnit.BASE.getUnitByAbbreviation(unitString);
206 if (unit != null)
207 {
208 return new AbsorbedDose(value, unit);
209 }
210 throw new IllegalArgumentException("Error parsing AbsorbedDose with unit " + unitString);
211 }
212
213
214
215
216
217
218 public final Dimensionless divide(final AbsorbedDose v)
219 {
220 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
221 }
222
223
224 @Override
225 public SIScalar reciprocal()
226 {
227 return DoubleScalar.divide(Dimensionless.ONE, this);
228 }
229
230 }