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