1 package org.djunits.value.vdouble.scalar;
2
3 import java.util.Locale;
4
5 import org.djunits.unit.DimensionlessUnit;
6 import org.djunits.unit.EquivalentDoseUnit;
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 EquivalentDose extends DoubleScalarRel<EquivalentDoseUnit, EquivalentDose>
25 {
26
27 private static final long serialVersionUID = 20150905L;
28
29
30 public static final EquivalentDose ZERO = new EquivalentDose(0.0, EquivalentDoseUnit.SI);
31
32
33 public static final EquivalentDose ONE = new EquivalentDose(1.0, EquivalentDoseUnit.SI);
34
35
36 @SuppressWarnings("checkstyle:constantname")
37 public static final EquivalentDose NaN = new EquivalentDose(Double.NaN, EquivalentDoseUnit.SI);
38
39
40 public static final EquivalentDose POSITIVE_INFINITY = new EquivalentDose(Double.POSITIVE_INFINITY, EquivalentDoseUnit.SI);
41
42
43 public static final EquivalentDose NEGATIVE_INFINITY = new EquivalentDose(Double.NEGATIVE_INFINITY, EquivalentDoseUnit.SI);
44
45
46 public static final EquivalentDose POS_MAXVALUE = new EquivalentDose(Double.MAX_VALUE, EquivalentDoseUnit.SI);
47
48
49 public static final EquivalentDose NEG_MAXVALUE = new EquivalentDose(-Double.MAX_VALUE, EquivalentDoseUnit.SI);
50
51
52
53
54
55
56 public EquivalentDose(final double value, final EquivalentDoseUnit unit)
57 {
58 super(value, unit);
59 }
60
61
62
63
64
65 public EquivalentDose(final EquivalentDose value)
66 {
67 super(value);
68 }
69
70 @Override
71 public final EquivalentDose instantiateRel(final double value, final EquivalentDoseUnit unit)
72 {
73 return new EquivalentDose(value, unit);
74 }
75
76
77
78
79
80
81 public static final EquivalentDose instantiateSI(final double value)
82 {
83 return new EquivalentDose(value, EquivalentDoseUnit.SI);
84 }
85
86
87
88
89
90
91
92
93 public static EquivalentDose interpolate(final EquivalentDose zero, final EquivalentDose one, final double ratio)
94 {
95 return new EquivalentDose(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getDisplayUnit()) * ratio,
96 zero.getDisplayUnit());
97 }
98
99
100
101
102
103
104
105 public static EquivalentDose max(final EquivalentDose r1, final EquivalentDose r2)
106 {
107 return r1.gt(r2) ? r1 : r2;
108 }
109
110
111
112
113
114
115
116
117 public static EquivalentDose max(final EquivalentDose r1, final EquivalentDose r2, final EquivalentDose... rn)
118 {
119 EquivalentDose maxr = r1.gt(r2) ? r1 : r2;
120 for (EquivalentDose r : rn)
121 {
122 if (r.gt(maxr))
123 {
124 maxr = r;
125 }
126 }
127 return maxr;
128 }
129
130
131
132
133
134
135
136 public static EquivalentDose min(final EquivalentDose r1, final EquivalentDose r2)
137 {
138 return r1.lt(r2) ? r1 : r2;
139 }
140
141
142
143
144
145
146
147
148 public static EquivalentDose min(final EquivalentDose r1, final EquivalentDose r2, final EquivalentDose... rn)
149 {
150 EquivalentDose minr = r1.lt(r2) ? r1 : r2;
151 for (EquivalentDose r : rn)
152 {
153 if (r.lt(minr))
154 {
155 minr = r;
156 }
157 }
158 return minr;
159 }
160
161
162
163
164
165
166
167
168
169
170 public static EquivalentDose valueOf(final String text)
171 {
172 Throw.whenNull(text, "Error parsing EquivalentDose: text to parse is null");
173 Throw.when(text.length() == 0, IllegalArgumentException.class, "Error parsing EquivalentDose: empty text to parse");
174 try
175 {
176 NumberParser numberParser = new NumberParser().lenient().trailing();
177 double d = numberParser.parseDouble(text);
178 String unitString = text.substring(numberParser.getTrailingPosition()).trim();
179 EquivalentDoseUnit unit = EquivalentDoseUnit.BASE.getUnitByAbbreviation(unitString);
180 if (unit == null)
181 throw new IllegalArgumentException("Unit " + unitString + " not found");
182 return new EquivalentDose(d, unit);
183 }
184 catch (Exception exception)
185 {
186 throw new IllegalArgumentException(
187 "Error parsing EquivalentDose 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 EquivalentDose of(final double value, final String unitString)
201 {
202 Throw.whenNull(unitString, "Error parsing EquivalentDose: unitString is null");
203 Throw.when(unitString.length() == 0, IllegalArgumentException.class, "Error parsing EquivalentDose: empty unitString");
204 EquivalentDoseUnit unit = EquivalentDoseUnit.BASE.getUnitByAbbreviation(unitString);
205 if (unit != null)
206 {
207 return new EquivalentDose(value, unit);
208 }
209 throw new IllegalArgumentException("Error parsing EquivalentDose with unit " + unitString);
210 }
211
212
213
214
215
216
217 public final Dimensionless divide(final EquivalentDose v)
218 {
219 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
220 }
221
222 @Override
223 public SIScalar reciprocal()
224 {
225 return DoubleScalar.divide(Dimensionless.ONE, this);
226 }
227
228 }