1 |
|
package org.json; |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
import java.io.IOException; |
28 |
|
import java.io.StringWriter; |
29 |
|
import java.io.Writer; |
30 |
|
import java.lang.reflect.Array; |
31 |
|
import java.math.BigDecimal; |
32 |
|
import java.math.BigInteger; |
33 |
|
import java.util.ArrayList; |
34 |
|
import java.util.Collection; |
35 |
|
import java.util.Iterator; |
36 |
|
import java.util.List; |
37 |
|
import java.util.Map; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
@author |
82 |
|
@version |
83 |
|
|
|
|
| 7.1% |
Uncovered Elements: 524 (564) |
Complexity: 197 |
Complexity Density: 0.6 |
|
84 |
|
public class JSONArray implements Iterable<Object> { |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
private final ArrayList<Object> myArrayList; |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
94 |
0 |
public JSONArray() {... |
95 |
0 |
this.myArrayList = new ArrayList<Object>(); |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
@param |
102 |
|
|
103 |
|
@throws |
104 |
|
|
105 |
|
|
|
|
| 0% |
Uncovered Elements: 41 (41) |
Complexity: 10 |
Complexity Density: 0.34 |
|
106 |
0 |
public JSONArray(JSONTokener x) throws JSONException {... |
107 |
0 |
this(); |
108 |
0 |
if (x.nextClean() != '[') { |
109 |
0 |
throw x.syntaxError("A JSONArray text must start with '['"); |
110 |
|
} |
111 |
|
|
112 |
0 |
char nextChar = x.nextClean(); |
113 |
0 |
if (nextChar == 0) { |
114 |
|
|
115 |
0 |
throw x.syntaxError("Expected a ',' or ']'"); |
116 |
|
} |
117 |
0 |
if (nextChar != ']') { |
118 |
0 |
x.back(); |
119 |
0 |
for (;;) { |
120 |
0 |
if (x.nextClean() == ',') { |
121 |
0 |
x.back(); |
122 |
0 |
this.myArrayList.add(JSONObject.NULL); |
123 |
|
} else { |
124 |
0 |
x.back(); |
125 |
0 |
this.myArrayList.add(x.nextValue()); |
126 |
|
} |
127 |
0 |
switch (x.nextClean()) { |
128 |
0 |
case 0: |
129 |
|
|
130 |
0 |
throw x.syntaxError("Expected a ',' or ']'"); |
131 |
0 |
case ',': |
132 |
0 |
nextChar = x.nextClean(); |
133 |
0 |
if (nextChar == 0) { |
134 |
|
|
135 |
0 |
throw x.syntaxError("Expected a ',' or ']'"); |
136 |
|
} |
137 |
0 |
if (nextChar == ']') { |
138 |
0 |
return; |
139 |
|
} |
140 |
0 |
x.back(); |
141 |
0 |
break; |
142 |
0 |
case ']': |
143 |
0 |
return; |
144 |
0 |
default: |
145 |
0 |
throw x.syntaxError("Expected a ',' or ']'"); |
146 |
|
} |
147 |
|
} |
148 |
|
} |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
@param |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
@throws |
159 |
|
|
160 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
161 |
0 |
public JSONArray(String source) throws JSONException {... |
162 |
0 |
this(new JSONTokener(source)); |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
@param |
169 |
|
|
170 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
171 |
25 |
public JSONArray(Collection<?> collection) {... |
172 |
25 |
if (collection == null) { |
173 |
0 |
this.myArrayList = new ArrayList<Object>(); |
174 |
|
} else { |
175 |
25 |
this.myArrayList = new ArrayList<Object>(collection.size()); |
176 |
25 |
for (Object o: collection){ |
177 |
144 |
this.myArrayList.add(JSONObject.wrap(o)); |
178 |
|
} |
179 |
|
} |
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
@throws |
186 |
|
|
187 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
188 |
0 |
public JSONArray(Object array) throws JSONException {... |
189 |
0 |
this(); |
190 |
0 |
if (array.getClass().isArray()) { |
191 |
0 |
int length = Array.getLength(array); |
192 |
0 |
this.myArrayList.ensureCapacity(length); |
193 |
0 |
for (int i = 0; i < length; i += 1) { |
194 |
0 |
this.put(JSONObject.wrap(Array.get(array, i))); |
195 |
|
} |
196 |
|
} else { |
197 |
0 |
throw new JSONException( |
198 |
|
"JSONArray initial value should be a string or collection or array."); |
199 |
|
} |
200 |
|
} |
201 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
202 |
0 |
@Override... |
203 |
|
public Iterator<Object> iterator() { |
204 |
0 |
return this.myArrayList.iterator(); |
205 |
|
} |
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
@param |
211 |
|
|
212 |
|
@return |
213 |
|
@throws |
214 |
|
|
215 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
216 |
0 |
public Object get(int index) throws JSONException {... |
217 |
0 |
Object object = this.opt(index); |
218 |
0 |
if (object == null) { |
219 |
0 |
throw new JSONException("JSONArray[" + index + "] not found."); |
220 |
|
} |
221 |
0 |
return object; |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
@param |
229 |
|
|
230 |
|
@return |
231 |
|
@throws |
232 |
|
|
233 |
|
|
234 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 7 |
Complexity Density: 1.17 |
|
235 |
0 |
public boolean getBoolean(int index) throws JSONException {... |
236 |
0 |
Object object = this.get(index); |
237 |
0 |
if (object.equals(Boolean.FALSE) |
238 |
|
|| (object instanceof String && ((String) object) |
239 |
|
.equalsIgnoreCase("false"))) { |
240 |
0 |
return false; |
241 |
0 |
} else if (object.equals(Boolean.TRUE) |
242 |
|
|| (object instanceof String && ((String) object) |
243 |
|
.equalsIgnoreCase("true"))) { |
244 |
0 |
return true; |
245 |
|
} |
246 |
0 |
throw new JSONException("JSONArray[" + index + "] is not a boolean."); |
247 |
|
} |
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
@param |
253 |
|
|
254 |
|
@return |
255 |
|
@throws |
256 |
|
|
257 |
|
|
258 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
259 |
0 |
public double getDouble(int index) throws JSONException {... |
260 |
0 |
Object object = this.get(index); |
261 |
0 |
try { |
262 |
0 |
return object instanceof Number ? ((Number) object).doubleValue() |
263 |
|
: Double.parseDouble((String) object); |
264 |
|
} catch (Exception e) { |
265 |
0 |
throw new JSONException("JSONArray[" + index + "] is not a number.", e); |
266 |
|
} |
267 |
|
} |
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
@param |
273 |
|
|
274 |
|
@return |
275 |
|
@throws |
276 |
|
|
277 |
|
|
278 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
279 |
0 |
public float getFloat(int index) throws JSONException {... |
280 |
0 |
Object object = this.get(index); |
281 |
0 |
try { |
282 |
0 |
return object instanceof Number ? ((Number) object).floatValue() |
283 |
|
: Float.parseFloat(object.toString()); |
284 |
|
} catch (Exception e) { |
285 |
0 |
throw new JSONException("JSONArray[" + index |
286 |
|
+ "] is not a number.", e); |
287 |
|
} |
288 |
|
} |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
@param |
294 |
|
|
295 |
|
@return |
296 |
|
@throws |
297 |
|
|
298 |
|
|
299 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
300 |
0 |
public Number getNumber(int index) throws JSONException {... |
301 |
0 |
Object object = this.get(index); |
302 |
0 |
try { |
303 |
0 |
if (object instanceof Number) { |
304 |
0 |
return (Number)object; |
305 |
|
} |
306 |
0 |
return JSONObject.stringToNumber(object.toString()); |
307 |
|
} catch (Exception e) { |
308 |
0 |
throw new JSONException("JSONArray[" + index + "] is not a number.", e); |
309 |
|
} |
310 |
|
} |
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
@param |
316 |
|
|
317 |
|
@param |
318 |
|
|
319 |
|
@return |
320 |
|
@throws |
321 |
|
|
322 |
|
|
323 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
324 |
0 |
public <E extends Enum<E>> E getEnum(Class<E> clazz, int index) throws JSONException {... |
325 |
0 |
E val = optEnum(clazz, index); |
326 |
0 |
if(val==null) { |
327 |
|
|
328 |
|
|
329 |
|
|
330 |
0 |
throw new JSONException("JSONArray[" + index + "] is not an enum of type " |
331 |
|
+ JSONObject.quote(clazz.getSimpleName()) + "."); |
332 |
|
} |
333 |
0 |
return val; |
334 |
|
} |
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
@param |
340 |
|
|
341 |
|
@return |
342 |
|
@throws |
343 |
|
|
344 |
|
|
345 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
346 |
0 |
public BigDecimal getBigDecimal (int index) throws JSONException {... |
347 |
0 |
Object object = this.get(index); |
348 |
0 |
try { |
349 |
0 |
return new BigDecimal(object.toString()); |
350 |
|
} catch (Exception e) { |
351 |
0 |
throw new JSONException("JSONArray[" + index + |
352 |
|
"] could not convert to BigDecimal.", e); |
353 |
|
} |
354 |
|
} |
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
@param |
360 |
|
|
361 |
|
@return |
362 |
|
@throws |
363 |
|
|
364 |
|
|
365 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
366 |
0 |
public BigInteger getBigInteger (int index) throws JSONException {... |
367 |
0 |
Object object = this.get(index); |
368 |
0 |
try { |
369 |
0 |
return new BigInteger(object.toString()); |
370 |
|
} catch (Exception e) { |
371 |
0 |
throw new JSONException("JSONArray[" + index + |
372 |
|
"] could not convert to BigInteger.", e); |
373 |
|
} |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
@param |
380 |
|
|
381 |
|
@return |
382 |
|
@throws |
383 |
|
|
384 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
385 |
0 |
public int getInt(int index) throws JSONException {... |
386 |
0 |
Object object = this.get(index); |
387 |
0 |
try { |
388 |
0 |
return object instanceof Number ? ((Number) object).intValue() |
389 |
|
: Integer.parseInt((String) object); |
390 |
|
} catch (Exception e) { |
391 |
0 |
throw new JSONException("JSONArray[" + index + "] is not a number.", e); |
392 |
|
} |
393 |
|
} |
394 |
|
|
395 |
|
|
396 |
|
|
397 |
|
|
398 |
|
@param |
399 |
|
|
400 |
|
@return |
401 |
|
@throws |
402 |
|
|
403 |
|
|
404 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
405 |
0 |
public JSONArray getJSONArray(int index) throws JSONException {... |
406 |
0 |
Object object = this.get(index); |
407 |
0 |
if (object instanceof JSONArray) { |
408 |
0 |
return (JSONArray) object; |
409 |
|
} |
410 |
0 |
throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); |
411 |
|
} |
412 |
|
|
413 |
|
|
414 |
|
|
415 |
|
|
416 |
|
@param |
417 |
|
|
418 |
|
@return |
419 |
|
@throws |
420 |
|
|
421 |
|
|
422 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
423 |
0 |
public JSONObject getJSONObject(int index) throws JSONException {... |
424 |
0 |
Object object = this.get(index); |
425 |
0 |
if (object instanceof JSONObject) { |
426 |
0 |
return (JSONObject) object; |
427 |
|
} |
428 |
0 |
throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); |
429 |
|
} |
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
@param |
435 |
|
|
436 |
|
@return |
437 |
|
@throws |
438 |
|
|
439 |
|
|
440 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
441 |
0 |
public long getLong(int index) throws JSONException {... |
442 |
0 |
Object object = this.get(index); |
443 |
0 |
try { |
444 |
0 |
return object instanceof Number ? ((Number) object).longValue() |
445 |
|
: Long.parseLong((String) object); |
446 |
|
} catch (Exception e) { |
447 |
0 |
throw new JSONException("JSONArray[" + index + "] is not a number.", e); |
448 |
|
} |
449 |
|
} |
450 |
|
|
451 |
|
|
452 |
|
|
453 |
|
|
454 |
|
@param |
455 |
|
|
456 |
|
@return |
457 |
|
@throws |
458 |
|
|
459 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
460 |
0 |
public String getString(int index) throws JSONException {... |
461 |
0 |
Object object = this.get(index); |
462 |
0 |
if (object instanceof String) { |
463 |
0 |
return (String) object; |
464 |
|
} |
465 |
0 |
throw new JSONException("JSONArray[" + index + "] not a string."); |
466 |
|
} |
467 |
|
|
468 |
|
|
469 |
|
|
470 |
|
|
471 |
|
@param |
472 |
|
|
473 |
|
@return |
474 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
475 |
0 |
public boolean isNull(int index) {... |
476 |
0 |
return JSONObject.NULL.equals(this.opt(index)); |
477 |
|
} |
478 |
|
|
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
|
483 |
|
|
484 |
|
@param |
485 |
|
|
486 |
|
@return |
487 |
|
@throws |
488 |
|
|
489 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
490 |
0 |
public String join(String separator) throws JSONException {... |
491 |
0 |
int len = this.length(); |
492 |
0 |
StringBuilder sb = new StringBuilder(); |
493 |
|
|
494 |
0 |
for (int i = 0; i < len; i += 1) { |
495 |
0 |
if (i > 0) { |
496 |
0 |
sb.append(separator); |
497 |
|
} |
498 |
0 |
sb.append(JSONObject.valueToString(this.myArrayList.get(i))); |
499 |
|
} |
500 |
0 |
return sb.toString(); |
501 |
|
} |
502 |
|
|
503 |
|
|
504 |
|
|
505 |
|
|
506 |
|
@return |
507 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
508 |
25 |
public int length() {... |
509 |
25 |
return this.myArrayList.size(); |
510 |
|
} |
511 |
|
|
512 |
|
|
513 |
|
|
514 |
|
|
515 |
|
@param |
516 |
|
|
517 |
|
@return |
518 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
519 |
0 |
public Object opt(int index) {... |
520 |
0 |
return (index < 0 || index >= this.length()) ? null : this.myArrayList |
521 |
|
.get(index); |
522 |
|
} |
523 |
|
|
524 |
|
|
525 |
|
|
526 |
|
|
527 |
|
|
528 |
|
|
529 |
|
@param |
530 |
|
|
531 |
|
@return |
532 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
533 |
0 |
public boolean optBoolean(int index) {... |
534 |
0 |
return this.optBoolean(index, false); |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
|
|
539 |
|
|
540 |
|
|
541 |
|
|
542 |
|
@param |
543 |
|
|
544 |
|
@param |
545 |
|
|
546 |
|
@return |
547 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
548 |
0 |
public boolean optBoolean(int index, boolean defaultValue) {... |
549 |
0 |
try { |
550 |
0 |
return this.getBoolean(index); |
551 |
|
} catch (Exception e) { |
552 |
0 |
return defaultValue; |
553 |
|
} |
554 |
|
} |
555 |
|
|
556 |
|
|
557 |
|
|
558 |
|
|
559 |
|
|
560 |
|
|
561 |
|
@param |
562 |
|
|
563 |
|
@return |
564 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
565 |
0 |
public double optDouble(int index) {... |
566 |
0 |
return this.optDouble(index, Double.NaN); |
567 |
|
} |
568 |
|
|
569 |
|
|
570 |
|
|
571 |
|
|
572 |
|
|
573 |
|
|
574 |
|
@param |
575 |
|
|
576 |
|
@param |
577 |
|
|
578 |
|
@return |
579 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
580 |
0 |
public double optDouble(int index, double defaultValue) {... |
581 |
0 |
Object val = this.opt(index); |
582 |
0 |
if (JSONObject.NULL.equals(val)) { |
583 |
0 |
return defaultValue; |
584 |
|
} |
585 |
0 |
if (val instanceof Number){ |
586 |
0 |
return ((Number) val).doubleValue(); |
587 |
|
} |
588 |
0 |
if (val instanceof String) { |
589 |
0 |
try { |
590 |
0 |
return Double.parseDouble((String) val); |
591 |
|
} catch (Exception e) { |
592 |
0 |
return defaultValue; |
593 |
|
} |
594 |
|
} |
595 |
0 |
return defaultValue; |
596 |
|
} |
597 |
|
|
598 |
|
|
599 |
|
|
600 |
|
|
601 |
|
|
602 |
|
|
603 |
|
@param |
604 |
|
|
605 |
|
@return |
606 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
607 |
0 |
public float optFloat(int index) {... |
608 |
0 |
return this.optFloat(index, Float.NaN); |
609 |
|
} |
610 |
|
|
611 |
|
|
612 |
|
|
613 |
|
|
614 |
|
|
615 |
|
|
616 |
|
@param |
617 |
|
|
618 |
|
@param |
619 |
|
|
620 |
|
@return |
621 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
622 |
0 |
public float optFloat(int index, float defaultValue) {... |
623 |
0 |
Object val = this.opt(index); |
624 |
0 |
if (JSONObject.NULL.equals(val)) { |
625 |
0 |
return defaultValue; |
626 |
|
} |
627 |
0 |
if (val instanceof Number){ |
628 |
0 |
return ((Number) val).floatValue(); |
629 |
|
} |
630 |
0 |
if (val instanceof String) { |
631 |
0 |
try { |
632 |
0 |
return Float.parseFloat((String) val); |
633 |
|
} catch (Exception e) { |
634 |
0 |
return defaultValue; |
635 |
|
} |
636 |
|
} |
637 |
0 |
return defaultValue; |
638 |
|
} |
639 |
|
|
640 |
|
|
641 |
|
|
642 |
|
|
643 |
|
|
644 |
|
|
645 |
|
@param |
646 |
|
|
647 |
|
@return |
648 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
649 |
0 |
public int optInt(int index) {... |
650 |
0 |
return this.optInt(index, 0); |
651 |
|
} |
652 |
|
|
653 |
|
|
654 |
|
|
655 |
|
|
656 |
|
|
657 |
|
|
658 |
|
@param |
659 |
|
|
660 |
|
@param |
661 |
|
|
662 |
|
@return |
663 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
664 |
0 |
public int optInt(int index, int defaultValue) {... |
665 |
0 |
Object val = this.opt(index); |
666 |
0 |
if (JSONObject.NULL.equals(val)) { |
667 |
0 |
return defaultValue; |
668 |
|
} |
669 |
0 |
if (val instanceof Number){ |
670 |
0 |
return ((Number) val).intValue(); |
671 |
|
} |
672 |
|
|
673 |
0 |
if (val instanceof String) { |
674 |
0 |
try { |
675 |
0 |
return new BigDecimal(val.toString()).intValue(); |
676 |
|
} catch (Exception e) { |
677 |
0 |
return defaultValue; |
678 |
|
} |
679 |
|
} |
680 |
0 |
return defaultValue; |
681 |
|
} |
682 |
|
|
683 |
|
|
684 |
|
|
685 |
|
|
686 |
|
@param |
687 |
|
|
688 |
|
@param |
689 |
|
|
690 |
|
@return |
691 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
692 |
0 |
public <E extends Enum<E>> E optEnum(Class<E> clazz, int index) {... |
693 |
0 |
return this.optEnum(clazz, index, null); |
694 |
|
} |
695 |
|
|
696 |
|
|
697 |
|
|
698 |
|
|
699 |
|
@param |
700 |
|
|
701 |
|
@param |
702 |
|
|
703 |
|
@param |
704 |
|
|
705 |
|
@return |
706 |
|
|
707 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.5 |
|
708 |
0 |
public <E extends Enum<E>> E optEnum(Class<E> clazz, int index, E defaultValue) {... |
709 |
0 |
try { |
710 |
0 |
Object val = this.opt(index); |
711 |
0 |
if (JSONObject.NULL.equals(val)) { |
712 |
0 |
return defaultValue; |
713 |
|
} |
714 |
0 |
if (clazz.isAssignableFrom(val.getClass())) { |
715 |
|
|
716 |
0 |
@SuppressWarnings("unchecked") |
717 |
|
E myE = (E) val; |
718 |
0 |
return myE; |
719 |
|
} |
720 |
0 |
return Enum.valueOf(clazz, val.toString()); |
721 |
|
} catch (IllegalArgumentException e) { |
722 |
0 |
return defaultValue; |
723 |
|
} catch (NullPointerException e) { |
724 |
0 |
return defaultValue; |
725 |
|
} |
726 |
|
} |
727 |
|
|
728 |
|
|
729 |
|
|
730 |
|
|
731 |
|
|
732 |
|
|
733 |
|
|
734 |
|
@param |
735 |
|
|
736 |
|
@param |
737 |
|
|
738 |
|
@return |
739 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 12 |
Complexity Density: 0.71 |
|
740 |
0 |
public BigInteger optBigInteger(int index, BigInteger defaultValue) {... |
741 |
0 |
Object val = this.opt(index); |
742 |
0 |
if (JSONObject.NULL.equals(val)) { |
743 |
0 |
return defaultValue; |
744 |
|
} |
745 |
0 |
if (val instanceof BigInteger){ |
746 |
0 |
return (BigInteger) val; |
747 |
|
} |
748 |
0 |
if (val instanceof BigDecimal){ |
749 |
0 |
return ((BigDecimal) val).toBigInteger(); |
750 |
|
} |
751 |
0 |
if (val instanceof Double || val instanceof Float){ |
752 |
0 |
return new BigDecimal(((Number) val).doubleValue()).toBigInteger(); |
753 |
|
} |
754 |
0 |
if (val instanceof Long || val instanceof Integer |
755 |
|
|| val instanceof Short || val instanceof Byte){ |
756 |
0 |
return BigInteger.valueOf(((Number) val).longValue()); |
757 |
|
} |
758 |
0 |
try { |
759 |
0 |
final String valStr = val.toString(); |
760 |
0 |
if(JSONObject.isDecimalNotation(valStr)) { |
761 |
0 |
return new BigDecimal(valStr).toBigInteger(); |
762 |
|
} |
763 |
0 |
return new BigInteger(valStr); |
764 |
|
} catch (Exception e) { |
765 |
0 |
return defaultValue; |
766 |
|
} |
767 |
|
} |
768 |
|
|
769 |
|
|
770 |
|
|
771 |
|
|
772 |
|
|
773 |
|
|
774 |
|
@param |
775 |
|
|
776 |
|
@param |
777 |
|
|
778 |
|
@return |
779 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 11 |
Complexity Density: 0.79 |
|
780 |
0 |
public BigDecimal optBigDecimal(int index, BigDecimal defaultValue) {... |
781 |
0 |
Object val = this.opt(index); |
782 |
0 |
if (JSONObject.NULL.equals(val)) { |
783 |
0 |
return defaultValue; |
784 |
|
} |
785 |
0 |
if (val instanceof BigDecimal){ |
786 |
0 |
return (BigDecimal) val; |
787 |
|
} |
788 |
0 |
if (val instanceof BigInteger){ |
789 |
0 |
return new BigDecimal((BigInteger) val); |
790 |
|
} |
791 |
0 |
if (val instanceof Double || val instanceof Float){ |
792 |
0 |
return new BigDecimal(((Number) val).doubleValue()); |
793 |
|
} |
794 |
0 |
if (val instanceof Long || val instanceof Integer |
795 |
|
|| val instanceof Short || val instanceof Byte){ |
796 |
0 |
return new BigDecimal(((Number) val).longValue()); |
797 |
|
} |
798 |
0 |
try { |
799 |
0 |
return new BigDecimal(val.toString()); |
800 |
|
} catch (Exception e) { |
801 |
0 |
return defaultValue; |
802 |
|
} |
803 |
|
} |
804 |
|
|
805 |
|
|
806 |
|
|
807 |
|
|
808 |
|
@param |
809 |
|
|
810 |
|
@return |
811 |
|
|
812 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
813 |
0 |
public JSONArray optJSONArray(int index) {... |
814 |
0 |
Object o = this.opt(index); |
815 |
0 |
return o instanceof JSONArray ? (JSONArray) o : null; |
816 |
|
} |
817 |
|
|
818 |
|
|
819 |
|
|
820 |
|
|
821 |
|
|
822 |
|
|
823 |
|
@param |
824 |
|
|
825 |
|
@return |
826 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
827 |
0 |
public JSONObject optJSONObject(int index) {... |
828 |
0 |
Object o = this.opt(index); |
829 |
0 |
return o instanceof JSONObject ? (JSONObject) o : null; |
830 |
|
} |
831 |
|
|
832 |
|
|
833 |
|
|
834 |
|
|
835 |
|
|
836 |
|
|
837 |
|
@param |
838 |
|
|
839 |
|
@return |
840 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
841 |
0 |
public long optLong(int index) {... |
842 |
0 |
return this.optLong(index, 0); |
843 |
|
} |
844 |
|
|
845 |
|
|
846 |
|
|
847 |
|
|
848 |
|
|
849 |
|
|
850 |
|
@param |
851 |
|
|
852 |
|
@param |
853 |
|
|
854 |
|
@return |
855 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
856 |
0 |
public long optLong(int index, long defaultValue) {... |
857 |
0 |
Object val = this.opt(index); |
858 |
0 |
if (JSONObject.NULL.equals(val)) { |
859 |
0 |
return defaultValue; |
860 |
|
} |
861 |
0 |
if (val instanceof Number){ |
862 |
0 |
return ((Number) val).longValue(); |
863 |
|
} |
864 |
|
|
865 |
0 |
if (val instanceof String) { |
866 |
0 |
try { |
867 |
0 |
return new BigDecimal(val.toString()).longValue(); |
868 |
|
} catch (Exception e) { |
869 |
0 |
return defaultValue; |
870 |
|
} |
871 |
|
} |
872 |
0 |
return defaultValue; |
873 |
|
} |
874 |
|
|
875 |
|
|
876 |
|
@link |
877 |
|
|
878 |
|
@link |
879 |
|
|
880 |
|
|
881 |
|
@param |
882 |
|
|
883 |
|
@return |
884 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
885 |
0 |
public Number optNumber(int index) {... |
886 |
0 |
return this.optNumber(index, null); |
887 |
|
} |
888 |
|
|
889 |
|
|
890 |
|
@link |
891 |
|
|
892 |
|
@link |
893 |
|
|
894 |
|
|
895 |
|
@param |
896 |
|
|
897 |
|
@param |
898 |
|
|
899 |
|
@return |
900 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
901 |
0 |
public Number optNumber(int index, Number defaultValue) {... |
902 |
0 |
Object val = this.opt(index); |
903 |
0 |
if (JSONObject.NULL.equals(val)) { |
904 |
0 |
return defaultValue; |
905 |
|
} |
906 |
0 |
if (val instanceof Number){ |
907 |
0 |
return (Number) val; |
908 |
|
} |
909 |
|
|
910 |
0 |
if (val instanceof String) { |
911 |
0 |
try { |
912 |
0 |
return JSONObject.stringToNumber((String) val); |
913 |
|
} catch (Exception e) { |
914 |
0 |
return defaultValue; |
915 |
|
} |
916 |
|
} |
917 |
0 |
return defaultValue; |
918 |
|
} |
919 |
|
|
920 |
|
|
921 |
|
|
922 |
|
|
923 |
|
|
924 |
|
|
925 |
|
@param |
926 |
|
|
927 |
|
@return |
928 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
929 |
0 |
public String optString(int index) {... |
930 |
0 |
return this.optString(index, ""); |
931 |
|
} |
932 |
|
|
933 |
|
|
934 |
|
|
935 |
|
|
936 |
|
|
937 |
|
@param |
938 |
|
|
939 |
|
@param |
940 |
|
|
941 |
|
@return |
942 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
943 |
0 |
public String optString(int index, String defaultValue) {... |
944 |
0 |
Object object = this.opt(index); |
945 |
0 |
return JSONObject.NULL.equals(object) ? defaultValue : object |
946 |
|
.toString(); |
947 |
|
} |
948 |
|
|
949 |
|
|
950 |
|
|
951 |
|
|
952 |
|
@param |
953 |
|
|
954 |
|
@return |
955 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
956 |
0 |
public JSONArray put(boolean value) {... |
957 |
0 |
return this.put(value ? Boolean.TRUE : Boolean.FALSE); |
958 |
|
} |
959 |
|
|
960 |
|
|
961 |
|
|
962 |
|
|
963 |
|
|
964 |
|
@param |
965 |
|
|
966 |
|
@return |
967 |
|
@throws |
968 |
|
|
969 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
970 |
0 |
public JSONArray put(Collection<?> value) {... |
971 |
0 |
return this.put(new JSONArray(value)); |
972 |
|
} |
973 |
|
|
974 |
|
|
975 |
|
|
976 |
|
|
977 |
|
@param |
978 |
|
|
979 |
|
@return |
980 |
|
@throws |
981 |
|
|
982 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
983 |
0 |
public JSONArray put(double value) throws JSONException {... |
984 |
0 |
return this.put(Double.valueOf(value)); |
985 |
|
} |
986 |
|
|
987 |
|
|
988 |
|
|
989 |
|
|
990 |
|
@param |
991 |
|
|
992 |
|
@return |
993 |
|
@throws |
994 |
|
|
995 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
996 |
0 |
public JSONArray put(float value) throws JSONException {... |
997 |
0 |
return this.put(Float.valueOf(value)); |
998 |
|
} |
999 |
|
|
1000 |
|
|
1001 |
|
|
1002 |
|
|
1003 |
|
@param |
1004 |
|
|
1005 |
|
@return |
1006 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1007 |
0 |
public JSONArray put(int value) {... |
1008 |
0 |
return this.put(Integer.valueOf(value)); |
1009 |
|
} |
1010 |
|
|
1011 |
|
|
1012 |
|
|
1013 |
|
|
1014 |
|
@param |
1015 |
|
|
1016 |
|
@return |
1017 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1018 |
0 |
public JSONArray put(long value) {... |
1019 |
0 |
return this.put(Long.valueOf(value)); |
1020 |
|
} |
1021 |
|
|
1022 |
|
|
1023 |
|
|
1024 |
|
|
1025 |
|
|
1026 |
|
@param |
1027 |
|
|
1028 |
|
@return |
1029 |
|
@throws |
1030 |
|
|
1031 |
|
@throws |
1032 |
|
|
1033 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1034 |
0 |
public JSONArray put(Map<?, ?> value) {... |
1035 |
0 |
return this.put(new JSONObject(value)); |
1036 |
|
} |
1037 |
|
|
1038 |
|
|
1039 |
|
|
1040 |
|
|
1041 |
|
@param |
1042 |
|
|
1043 |
|
|
1044 |
|
|
1045 |
|
@return |
1046 |
|
@throws |
1047 |
|
|
1048 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
1049 |
0 |
public JSONArray put(Object value) {... |
1050 |
0 |
JSONObject.testValidity(value); |
1051 |
0 |
this.myArrayList.add(value); |
1052 |
0 |
return this; |
1053 |
|
} |
1054 |
|
|
1055 |
|
|
1056 |
|
|
1057 |
|
|
1058 |
|
|
1059 |
|
|
1060 |
|
@param |
1061 |
|
|
1062 |
|
@param |
1063 |
|
|
1064 |
|
@return |
1065 |
|
@throws |
1066 |
|
|
1067 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
1068 |
0 |
public JSONArray put(int index, boolean value) throws JSONException {... |
1069 |
0 |
return this.put(index, value ? Boolean.TRUE : Boolean.FALSE); |
1070 |
|
} |
1071 |
|
|
1072 |
|
|
1073 |
|
|
1074 |
|
|
1075 |
|
|
1076 |
|
@param |
1077 |
|
|
1078 |
|
@param |
1079 |
|
|
1080 |
|
@return |
1081 |
|
@throws |
1082 |
|
|
1083 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1084 |
0 |
public JSONArray put(int index, Collection<?> value) throws JSONException {... |
1085 |
0 |
return this.put(index, new JSONArray(value)); |
1086 |
|
} |
1087 |
|
|
1088 |
|
|
1089 |
|
|
1090 |
|
|
1091 |
|
|
1092 |
|
|
1093 |
|
@param |
1094 |
|
|
1095 |
|
@param |
1096 |
|
|
1097 |
|
@return |
1098 |
|
@throws |
1099 |
|
|
1100 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1101 |
0 |
public JSONArray put(int index, double value) throws JSONException {... |
1102 |
0 |
return this.put(index, Double.valueOf(value)); |
1103 |
|
} |
1104 |
|
|
1105 |
|
|
1106 |
|
|
1107 |
|
|
1108 |
|
|
1109 |
|
|
1110 |
|
@param |
1111 |
|
|
1112 |
|
@param |
1113 |
|
|
1114 |
|
@return |
1115 |
|
@throws |
1116 |
|
|
1117 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1118 |
0 |
public JSONArray put(int index, float value) throws JSONException {... |
1119 |
0 |
return this.put(index, Float.valueOf(value)); |
1120 |
|
} |
1121 |
|
|
1122 |
|
|
1123 |
|
|
1124 |
|
|
1125 |
|
|
1126 |
|
|
1127 |
|
@param |
1128 |
|
|
1129 |
|
@param |
1130 |
|
|
1131 |
|
@return |
1132 |
|
@throws |
1133 |
|
|
1134 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1135 |
0 |
public JSONArray put(int index, int value) throws JSONException {... |
1136 |
0 |
return this.put(index, Integer.valueOf(value)); |
1137 |
|
} |
1138 |
|
|
1139 |
|
|
1140 |
|
|
1141 |
|
|
1142 |
|
|
1143 |
|
|
1144 |
|
@param |
1145 |
|
|
1146 |
|
@param |
1147 |
|
|
1148 |
|
@return |
1149 |
|
@throws |
1150 |
|
|
1151 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1152 |
0 |
public JSONArray put(int index, long value) throws JSONException {... |
1153 |
0 |
return this.put(index, Long.valueOf(value)); |
1154 |
|
} |
1155 |
|
|
1156 |
|
|
1157 |
|
|
1158 |
|
|
1159 |
|
|
1160 |
|
@param |
1161 |
|
|
1162 |
|
@param |
1163 |
|
|
1164 |
|
@return |
1165 |
|
@throws |
1166 |
|
|
1167 |
|
|
1168 |
|
@throws |
1169 |
|
|
1170 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
1171 |
0 |
public JSONArray put(int index, Map<?, ?> value) throws JSONException {... |
1172 |
0 |
this.put(index, new JSONObject(value)); |
1173 |
0 |
return this; |
1174 |
|
} |
1175 |
|
|
1176 |
|
|
1177 |
|
|
1178 |
|
|
1179 |
|
|
1180 |
|
|
1181 |
|
@param |
1182 |
|
|
1183 |
|
@param |
1184 |
|
|
1185 |
|
|
1186 |
|
|
1187 |
|
@return |
1188 |
|
@throws |
1189 |
|
|
1190 |
|
|
1191 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
|
1192 |
0 |
public JSONArray put(int index, Object value) throws JSONException {... |
1193 |
0 |
if (index < 0) { |
1194 |
0 |
throw new JSONException("JSONArray[" + index + "] not found."); |
1195 |
|
} |
1196 |
0 |
if (index < this.length()) { |
1197 |
0 |
JSONObject.testValidity(value); |
1198 |
0 |
this.myArrayList.set(index, value); |
1199 |
0 |
return this; |
1200 |
|
} |
1201 |
0 |
if(index == this.length()){ |
1202 |
|
|
1203 |
0 |
return this.put(value); |
1204 |
|
} |
1205 |
|
|
1206 |
|
|
1207 |
0 |
this.myArrayList.ensureCapacity(index + 1); |
1208 |
0 |
while (index != this.length()) { |
1209 |
|
|
1210 |
0 |
this.myArrayList.add(JSONObject.NULL); |
1211 |
|
} |
1212 |
0 |
return this.put(value); |
1213 |
|
} |
1214 |
|
|
1215 |
|
|
1216 |
|
|
1217 |
|
|
1218 |
|
|
1219 |
|
|
1220 |
|
|
1221 |
|
|
1222 |
|
|
1223 |
|
|
1224 |
|
|
1225 |
|
|
1226 |
|
|
1227 |
|
|
1228 |
|
|
1229 |
|
|
1230 |
|
|
1231 |
|
@param |
1232 |
|
@return |
1233 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1234 |
0 |
public Object query(String jsonPointer) {... |
1235 |
0 |
return query(new JSONPointer(jsonPointer)); |
1236 |
|
} |
1237 |
|
|
1238 |
|
|
1239 |
|
|
1240 |
|
|
1241 |
|
|
1242 |
|
|
1243 |
|
|
1244 |
|
|
1245 |
|
|
1246 |
|
|
1247 |
|
|
1248 |
|
|
1249 |
|
|
1250 |
|
|
1251 |
|
|
1252 |
|
|
1253 |
|
|
1254 |
|
@param |
1255 |
|
@return |
1256 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1257 |
0 |
public Object query(JSONPointer jsonPointer) {... |
1258 |
0 |
return jsonPointer.queryFrom(this); |
1259 |
|
} |
1260 |
|
|
1261 |
|
|
1262 |
|
|
1263 |
|
|
1264 |
|
|
1265 |
|
@param |
1266 |
|
@return |
1267 |
|
@throws |
1268 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1269 |
0 |
public Object optQuery(String jsonPointer) {... |
1270 |
0 |
return optQuery(new JSONPointer(jsonPointer)); |
1271 |
|
} |
1272 |
|
|
1273 |
|
|
1274 |
|
|
1275 |
|
|
1276 |
|
|
1277 |
|
@param |
1278 |
|
@return |
1279 |
|
@throws |
1280 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
1281 |
0 |
public Object optQuery(JSONPointer jsonPointer) {... |
1282 |
0 |
try { |
1283 |
0 |
return jsonPointer.queryFrom(this); |
1284 |
|
} catch (JSONPointerException e) { |
1285 |
0 |
return null; |
1286 |
|
} |
1287 |
|
} |
1288 |
|
|
1289 |
|
|
1290 |
|
|
1291 |
|
|
1292 |
|
@param |
1293 |
|
|
1294 |
|
@return |
1295 |
|
|
1296 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: 3 |
|
1297 |
0 |
public Object remove(int index) {... |
1298 |
0 |
return index >= 0 && index < this.length() |
1299 |
|
? this.myArrayList.remove(index) |
1300 |
|
: null; |
1301 |
|
} |
1302 |
|
|
1303 |
|
|
1304 |
|
|
1305 |
|
|
1306 |
|
|
1307 |
|
@param |
1308 |
|
@return |
1309 |
|
|
|
|
| 0% |
Uncovered Elements: 41 (41) |
Complexity: 11 |
Complexity Density: 0.52 |
|
1310 |
0 |
public boolean similar(Object other) {... |
1311 |
0 |
if (!(other instanceof JSONArray)) { |
1312 |
0 |
return false; |
1313 |
|
} |
1314 |
0 |
int len = this.length(); |
1315 |
0 |
if (len != ((JSONArray)other).length()) { |
1316 |
0 |
return false; |
1317 |
|
} |
1318 |
0 |
for (int i = 0; i < len; i += 1) { |
1319 |
0 |
Object valueThis = this.myArrayList.get(i); |
1320 |
0 |
Object valueOther = ((JSONArray)other).myArrayList.get(i); |
1321 |
0 |
if(valueThis == valueOther) { |
1322 |
0 |
continue; |
1323 |
|
} |
1324 |
0 |
if(valueThis == null) { |
1325 |
0 |
return false; |
1326 |
|
} |
1327 |
0 |
if (valueThis instanceof JSONObject) { |
1328 |
0 |
if (!((JSONObject)valueThis).similar(valueOther)) { |
1329 |
0 |
return false; |
1330 |
|
} |
1331 |
0 |
} else if (valueThis instanceof JSONArray) { |
1332 |
0 |
if (!((JSONArray)valueThis).similar(valueOther)) { |
1333 |
0 |
return false; |
1334 |
|
} |
1335 |
0 |
} else if (!valueThis.equals(valueOther)) { |
1336 |
0 |
return false; |
1337 |
|
} |
1338 |
|
} |
1339 |
0 |
return true; |
1340 |
|
} |
1341 |
|
|
1342 |
|
|
1343 |
|
|
1344 |
|
|
1345 |
|
|
1346 |
|
@param |
1347 |
|
|
1348 |
|
|
1349 |
|
@return |
1350 |
|
|
1351 |
|
@throws |
1352 |
|
|
1353 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 5 |
Complexity Density: 0.83 |
|
1354 |
0 |
public JSONObject toJSONObject(JSONArray names) throws JSONException {... |
1355 |
0 |
if (names == null || names.isEmpty() || this.isEmpty()) { |
1356 |
0 |
return null; |
1357 |
|
} |
1358 |
0 |
JSONObject jo = new JSONObject(names.length()); |
1359 |
0 |
for (int i = 0; i < names.length(); i += 1) { |
1360 |
0 |
jo.put(names.getString(i), this.opt(i)); |
1361 |
|
} |
1362 |
0 |
return jo; |
1363 |
|
} |
1364 |
|
|
1365 |
|
|
1366 |
|
|
1367 |
|
|
1368 |
|
|
1369 |
|
|
1370 |
|
|
1371 |
|
|
1372 |
|
|
1373 |
|
|
1374 |
|
@return |
1375 |
|
|
1376 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
1377 |
0 |
@Override... |
1378 |
|
public String toString() { |
1379 |
0 |
try { |
1380 |
0 |
return this.toString(0); |
1381 |
|
} catch (Exception e) { |
1382 |
0 |
return null; |
1383 |
|
} |
1384 |
|
} |
1385 |
|
|
1386 |
|
|
1387 |
|
|
1388 |
|
|
1389 |
|
@link |
1390 |
|
|
1391 |
|
|
1392 |
|
|
1393 |
|
|
1394 |
|
|
1395 |
|
|
1396 |
|
|
1397 |
|
|
1398 |
|
|
1399 |
|
|
1400 |
|
|
1401 |
|
|
1402 |
|
|
1403 |
|
|
1404 |
|
|
1405 |
|
@param |
1406 |
|
|
1407 |
|
@return |
1408 |
|
|
1409 |
|
|
1410 |
|
|
1411 |
|
@throws |
1412 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
1413 |
0 |
public String toString(int indentFactor) throws JSONException {... |
1414 |
0 |
StringWriter sw = new StringWriter(); |
1415 |
0 |
synchronized (sw.getBuffer()) { |
1416 |
0 |
return this.write(sw, indentFactor, 0).toString(); |
1417 |
|
} |
1418 |
|
} |
1419 |
|
|
1420 |
|
|
1421 |
|
|
1422 |
|
|
1423 |
|
|
1424 |
|
|
1425 |
|
|
1426 |
|
|
1427 |
|
@return |
1428 |
|
@throws |
1429 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1430 |
0 |
public Writer write(Writer writer) throws JSONException {... |
1431 |
0 |
return this.write(writer, 0, 0); |
1432 |
|
} |
1433 |
|
|
1434 |
|
|
1435 |
|
|
1436 |
|
|
1437 |
|
@link |
1438 |
|
|
1439 |
|
|
1440 |
|
|
1441 |
|
|
1442 |
|
|
1443 |
|
|
1444 |
|
|
1445 |
|
|
1446 |
|
|
1447 |
|
|
1448 |
|
|
1449 |
|
|
1450 |
|
|
1451 |
|
|
1452 |
|
|
1453 |
|
@param |
1454 |
|
|
1455 |
|
@param |
1456 |
|
|
1457 |
|
@param |
1458 |
|
|
1459 |
|
@return |
1460 |
|
@throws |
1461 |
|
|
|
|
| 81.6% |
Uncovered Elements: 7 (38) |
Complexity: 10 |
Complexity Density: 0.38 |
|
1462 |
25 |
public Writer write(Writer writer, int indentFactor, int indent)... |
1463 |
|
throws JSONException { |
1464 |
25 |
try { |
1465 |
25 |
boolean commanate = false; |
1466 |
25 |
int length = this.length(); |
1467 |
25 |
writer.write('['); |
1468 |
|
|
1469 |
25 |
if (length == 1) { |
1470 |
5 |
try { |
1471 |
5 |
JSONObject.writeValue(writer, this.myArrayList.get(0), |
1472 |
|
indentFactor, indent); |
1473 |
|
} catch (Exception e) { |
1474 |
0 |
throw new JSONException("Unable to write JSONArray value at index: 0", e); |
1475 |
|
} |
1476 |
20 |
} else if (length != 0) { |
1477 |
13 |
final int newindent = indent + indentFactor; |
1478 |
|
|
1479 |
152 |
for (int i = 0; i < length; i += 1) { |
1480 |
139 |
if (commanate) { |
1481 |
126 |
writer.write(','); |
1482 |
|
} |
1483 |
139 |
if (indentFactor > 0) { |
1484 |
0 |
writer.write('\n'); |
1485 |
|
} |
1486 |
139 |
JSONObject.indent(writer, newindent); |
1487 |
139 |
try { |
1488 |
139 |
JSONObject.writeValue(writer, this.myArrayList.get(i), |
1489 |
|
indentFactor, newindent); |
1490 |
|
} catch (Exception e) { |
1491 |
0 |
throw new JSONException("Unable to write JSONArray value at index: " + i, e); |
1492 |
|
} |
1493 |
139 |
commanate = true; |
1494 |
|
} |
1495 |
13 |
if (indentFactor > 0) { |
1496 |
0 |
writer.write('\n'); |
1497 |
|
} |
1498 |
13 |
JSONObject.indent(writer, indent); |
1499 |
|
} |
1500 |
25 |
writer.write(']'); |
1501 |
25 |
return writer; |
1502 |
|
} catch (IOException e) { |
1503 |
0 |
throw new JSONException(e); |
1504 |
|
} |
1505 |
|
} |
1506 |
|
|
1507 |
|
|
1508 |
|
|
1509 |
|
|
1510 |
|
|
1511 |
|
|
1512 |
|
|
1513 |
|
|
1514 |
|
@return |
1515 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
1516 |
0 |
public List<Object> toList() {... |
1517 |
0 |
List<Object> results = new ArrayList<Object>(this.myArrayList.size()); |
1518 |
0 |
for (Object element : this.myArrayList) { |
1519 |
0 |
if (element == null || JSONObject.NULL.equals(element)) { |
1520 |
0 |
results.add(null); |
1521 |
0 |
} else if (element instanceof JSONArray) { |
1522 |
0 |
results.add(((JSONArray) element).toList()); |
1523 |
0 |
} else if (element instanceof JSONObject) { |
1524 |
0 |
results.add(((JSONObject) element).toMap()); |
1525 |
|
} else { |
1526 |
0 |
results.add(element); |
1527 |
|
} |
1528 |
|
} |
1529 |
0 |
return results; |
1530 |
|
} |
1531 |
|
|
1532 |
|
|
1533 |
|
|
1534 |
|
|
1535 |
|
@return |
1536 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1537 |
0 |
public boolean isEmpty() {... |
1538 |
0 |
return myArrayList.isEmpty(); |
1539 |
|
} |
1540 |
|
|
1541 |
|
} |