You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Try to find a constructor that takes the element's class
113
+
java.lang.reflect.Constructor<?> matched = null;
114
+
for (java.lang.reflect.Constructor<?> c : clazz.getConstructors()) {
115
+
Class<?>[] params = c.getParameterTypes();
116
+
if (params.length == 1 && params[0].isAssignableFrom(elem.getClass())) {
117
+
matched = c;
118
+
break;
119
+
}
120
+
}
121
+
if (matched != null) {
122
+
try {
123
+
array[i] = (T) matched.newInstance(elem);
124
+
} catch (Exceptione) {
125
+
thrownewZarrException("Failed to convert element at index " + i + " to type " + clazz.getName(), e);
126
+
}
127
+
} else {
128
+
thrownewIllegalArgumentException("Element at index " + i + " is not of type " + clazz.getName() + " and no suitable constructor found for conversion of type " + elem.getClass().getName());
129
+
}
130
+
}
131
+
}
132
+
returnarray;
133
+
}
134
+
thrownewIllegalArgumentException("Value for key " + key + " is not a List or array of type " + clazz.getName());
135
+
}
136
+
137
+
publicint[] getIntArray(Stringkey) {
138
+
Objectvalue = this.get(key);
139
+
if (valueinstanceofint[]) {
140
+
return (int[]) value;
141
+
}
142
+
if (valueinstanceofList) {
143
+
List<?> list = (List<?>) value;
144
+
int[] array = newint[list.size()];
145
+
for (inti = 0; i < list.size(); i++) {
146
+
Objectelem = list.get(i);
147
+
if (eleminstanceofNumber) {
148
+
array[i] = ((Number) elem).intValue();
149
+
} else {
150
+
thrownewIllegalArgumentException("Element at index " + i + " is not a Number");
151
+
}
152
+
}
153
+
returnarray;
154
+
}
155
+
thrownewIllegalArgumentException("Value for key " + key + " is not an int array or List");
156
+
}
157
+
158
+
publiclong[] getLongArray(Stringkey) {
159
+
Objectvalue = this.get(key);
160
+
if (valueinstanceoflong[]) {
161
+
return (long[]) value;
162
+
}
163
+
if (valueinstanceofList) {
164
+
List<?> list = (List<?>) value;
165
+
long[] array = newlong[list.size()];
166
+
for (inti = 0; i < list.size(); i++) {
167
+
Objectelem = list.get(i);
168
+
if (eleminstanceofNumber) {
169
+
array[i] = ((Number) elem).longValue();
170
+
} else {
171
+
thrownewIllegalArgumentException("Element at index " + i + " is not a Number");
172
+
}
173
+
}
174
+
returnarray;
175
+
}
176
+
thrownewIllegalArgumentException("Value for key " + key + " is not a long array or List");
177
+
}
178
+
179
+
publicdouble[] getDoubleArray(Stringkey) {
180
+
Objectvalue = this.get(key);
181
+
if (valueinstanceofdouble[]) {
182
+
return (double[]) value;
183
+
}
184
+
if (valueinstanceofList) {
185
+
List<?> list = (List<?>) value;
186
+
double[] array = newdouble[list.size()];
187
+
for (inti = 0; i < list.size(); i++) {
188
+
Objectelem = list.get(i);
189
+
if (eleminstanceofNumber) {
190
+
array[i] = ((Number) elem).doubleValue();
191
+
} else {
192
+
thrownewIllegalArgumentException("Element at index " + i + " is not a Number");
193
+
}
194
+
}
195
+
returnarray;
196
+
}
197
+
thrownewIllegalArgumentException("Value for key " + key + " is not a double array or List");
198
+
}
199
+
200
+
publicfloat[] getFloatArray(Stringkey) {
201
+
Objectvalue = this.get(key);
202
+
if (valueinstanceoffloat[]) {
203
+
return (float[]) value;
204
+
}
205
+
if (valueinstanceofList) {
206
+
List<?> list = (List<?>) value;
207
+
float[] array = newfloat[list.size()];
208
+
for (inti = 0; i < list.size(); i++) {
209
+
Objectelem = list.get(i);
210
+
if (eleminstanceofNumber) {
211
+
array[i] = ((Number) elem).floatValue();
212
+
} else {
213
+
thrownewIllegalArgumentException("Element at index " + i + " is not a Number");
214
+
}
215
+
}
216
+
returnarray;
217
+
}
218
+
thrownewIllegalArgumentException("Value for key " + key + " is not a float array or List");
219
+
}
220
+
221
+
publicboolean[] getBooleanArray(Stringkey) {
222
+
Objectvalue = this.get(key);
223
+
if (valueinstanceofboolean[]) {
224
+
return (boolean[]) value;
225
+
}
226
+
if (valueinstanceofList) {
227
+
List<?> list = (List<?>) value;
228
+
boolean[] array = newboolean[list.size()];
229
+
for (inti = 0; i < list.size(); i++) {
230
+
Objectelem = list.get(i);
231
+
if (eleminstanceofBoolean) {
232
+
array[i] = (Boolean) elem;
233
+
} else {
234
+
thrownewIllegalArgumentException("Element at index " + i + " is not a Boolean");
235
+
}
236
+
}
237
+
returnarray;
238
+
}
239
+
thrownewIllegalArgumentException("Value for key " + key + " is not a boolean array or List");
0 commit comments