1 |
|
package org.json; |
2 |
|
|
3 |
|
import java.io.Closeable; |
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
import java.io.IOException; |
33 |
|
import java.io.StringWriter; |
34 |
|
import java.io.Writer; |
35 |
|
import java.lang.annotation.Annotation; |
36 |
|
import java.lang.reflect.Field; |
37 |
|
import java.lang.reflect.InvocationTargetException; |
38 |
|
import java.lang.reflect.Method; |
39 |
|
import java.lang.reflect.Modifier; |
40 |
|
import java.math.BigDecimal; |
41 |
|
import java.math.BigInteger; |
42 |
|
import java.util.Collection; |
43 |
|
import java.util.Enumeration; |
44 |
|
import java.util.HashMap; |
45 |
|
import java.util.Iterator; |
46 |
|
import java.util.Locale; |
47 |
|
import java.util.Map; |
48 |
|
import java.util.Map.Entry; |
49 |
|
import java.util.ResourceBundle; |
50 |
|
import java.util.Set; |
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 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
@author |
100 |
|
@version |
101 |
|
|
|
|
| 22.4% |
Uncovered Elements: 816 (1,051) |
Complexity: 368 |
Complexity Density: 0.59 |
|
102 |
|
public class JSONObject |
103 |
|
{ |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
|
|
| 25% |
Uncovered Elements: 6 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
109 |
|
private static final class Null |
110 |
|
{ |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
@return |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
0 |
@Override... |
119 |
|
protected final Object clone() |
120 |
|
{ |
121 |
0 |
return this; |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
@param |
128 |
|
|
129 |
|
@return |
130 |
|
|
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
132 |
1580 |
@Override... |
133 |
|
public boolean equals(Object object) |
134 |
|
{ |
135 |
1580 |
return object == null || object == this; |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
@return |
142 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
143 |
0 |
@Override... |
144 |
|
public int hashCode() |
145 |
|
{ |
146 |
0 |
return 0; |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
@return |
153 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
154 |
0 |
@Override... |
155 |
|
public String toString() |
156 |
|
{ |
157 |
0 |
return "null"; |
158 |
|
} |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
private final Map<String, Object> map; |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
public static final Object NULL = new Null(); |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
283 |
public JSONObject()... |
178 |
|
{ |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
283 |
this.map = new HashMap<String, Object>(); |
186 |
|
} |
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
@param |
194 |
|
|
195 |
|
@param |
196 |
|
|
197 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
198 |
0 |
public JSONObject(JSONObject jo, String[] names)... |
199 |
|
{ |
200 |
0 |
this(names.length); |
201 |
0 |
for (int i = 0; i < names.length; i += 1) |
202 |
|
{ |
203 |
0 |
try |
204 |
|
{ |
205 |
0 |
this.putOnce(names[i], jo.opt(names[i])); |
206 |
|
} catch (Exception ignore) |
207 |
|
{ |
208 |
|
} |
209 |
|
} |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
@param |
216 |
|
|
217 |
|
@throws |
218 |
|
|
219 |
|
|
220 |
|
|
|
|
| 0% |
Uncovered Elements: 47 (47) |
Complexity: 12 |
Complexity Density: 0.34 |
|
221 |
0 |
public JSONObject(JSONTokener x) throws JSONException... |
222 |
|
{ |
223 |
0 |
this(); |
224 |
0 |
char c; |
225 |
0 |
String key; |
226 |
|
|
227 |
0 |
if (x.nextClean() != '{') |
228 |
|
{ |
229 |
0 |
throw x.syntaxError("A JSONObject text must begin with '{'"); |
230 |
|
} |
231 |
0 |
for (;;) |
232 |
|
{ |
233 |
0 |
c = x.nextClean(); |
234 |
0 |
switch (c) |
235 |
|
{ |
236 |
0 |
case 0: |
237 |
0 |
throw x.syntaxError("A JSONObject text must end with '}'"); |
238 |
0 |
case '}': |
239 |
0 |
return; |
240 |
0 |
default: |
241 |
0 |
x.back(); |
242 |
0 |
key = x.nextValue().toString(); |
243 |
|
} |
244 |
|
|
245 |
|
|
246 |
|
|
247 |
0 |
c = x.nextClean(); |
248 |
0 |
if (c != ':') |
249 |
|
{ |
250 |
0 |
throw x.syntaxError("Expected a ':' after a key"); |
251 |
|
} |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
0 |
if (key != null) |
256 |
|
{ |
257 |
|
|
258 |
0 |
if (this.opt(key) != null) |
259 |
|
{ |
260 |
|
|
261 |
0 |
throw x.syntaxError("Duplicate key \"" + key + "\""); |
262 |
|
} |
263 |
|
|
264 |
0 |
Object value = x.nextValue(); |
265 |
0 |
if (value != null) |
266 |
|
{ |
267 |
0 |
this.put(key, value); |
268 |
|
} |
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
|
|
273 |
0 |
switch (x.nextClean()) |
274 |
|
{ |
275 |
0 |
case ';': |
276 |
0 |
case ',': |
277 |
0 |
if (x.nextClean() == '}') |
278 |
|
{ |
279 |
0 |
return; |
280 |
|
} |
281 |
0 |
x.back(); |
282 |
0 |
break; |
283 |
0 |
case '}': |
284 |
0 |
return; |
285 |
0 |
default: |
286 |
0 |
throw x.syntaxError("Expected a ',' or '}'"); |
287 |
|
} |
288 |
|
} |
289 |
|
} |
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
@param |
295 |
|
|
296 |
|
|
297 |
|
@throws |
298 |
|
|
299 |
|
@throws |
300 |
|
|
301 |
|
|
|
|
| 73.3% |
Uncovered Elements: 4 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
302 |
8 |
public JSONObject(Map<?, ?> m)... |
303 |
|
{ |
304 |
8 |
if (m == null) |
305 |
|
{ |
306 |
0 |
this.map = new HashMap<String, Object>(); |
307 |
|
} |
308 |
|
else |
309 |
|
{ |
310 |
8 |
this.map = new HashMap<String, Object>(m.size()); |
311 |
8 |
for (final Entry<?, ?> e : m.entrySet()) |
312 |
|
{ |
313 |
50 |
if (e.getKey() == null) |
314 |
|
{ |
315 |
0 |
throw new NullPointerException("Null key."); |
316 |
|
} |
317 |
50 |
final Object value = e.getValue(); |
318 |
50 |
if (value != null) |
319 |
|
{ |
320 |
42 |
this.map.put(String.valueOf(e.getKey()), wrap(value)); |
321 |
|
} |
322 |
|
} |
323 |
|
} |
324 |
|
} |
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
@link |
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
|
352 |
|
|
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
@link |
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
|
|
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
@link |
377 |
|
@link |
378 |
|
@link |
379 |
|
|
380 |
|
|
381 |
|
@link |
382 |
|
|
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
|
388 |
|
|
389 |
|
|
390 |
|
|
391 |
|
|
392 |
|
|
393 |
|
|
394 |
|
|
395 |
|
@param |
396 |
|
|
397 |
|
|
398 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
399 |
283 |
public JSONObject(Object bean)... |
400 |
|
{ |
401 |
283 |
this(); |
402 |
283 |
this.populateMap(bean); |
403 |
|
} |
404 |
|
|
405 |
|
|
406 |
|
|
407 |
|
|
408 |
|
|
409 |
|
|
410 |
|
|
411 |
|
|
412 |
|
@param |
413 |
|
|
414 |
|
|
415 |
|
@param |
416 |
|
|
417 |
|
|
418 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
419 |
0 |
public JSONObject(Object object, String names[])... |
420 |
|
{ |
421 |
0 |
this(names.length); |
422 |
0 |
Class<?> c = object.getClass(); |
423 |
0 |
for (int i = 0; i < names.length; i += 1) |
424 |
|
{ |
425 |
0 |
String name = names[i]; |
426 |
0 |
try |
427 |
|
{ |
428 |
0 |
this.putOpt(name, c.getField(name).get(object)); |
429 |
|
} catch (Exception ignore) |
430 |
|
{ |
431 |
|
} |
432 |
|
} |
433 |
|
} |
434 |
|
|
435 |
|
|
436 |
|
|
437 |
|
|
438 |
|
|
439 |
|
@param |
440 |
|
|
441 |
|
|
442 |
|
|
443 |
|
@exception |
444 |
|
|
445 |
|
|
446 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
447 |
0 |
public JSONObject(String source) throws JSONException... |
448 |
|
{ |
449 |
0 |
this(new JSONTokener(source)); |
450 |
|
} |
451 |
|
|
452 |
|
|
453 |
|
|
454 |
|
|
455 |
|
@param |
456 |
|
|
457 |
|
@param |
458 |
|
|
459 |
|
@throws |
460 |
|
|
461 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 5 |
Complexity Density: 0.29 |
|
462 |
0 |
public JSONObject(String baseName, Locale locale) throws JSONException... |
463 |
|
{ |
464 |
0 |
this(); |
465 |
0 |
ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, |
466 |
|
Thread.currentThread().getContextClassLoader()); |
467 |
|
|
468 |
|
|
469 |
|
|
470 |
0 |
Enumeration<String> keys = bundle.getKeys(); |
471 |
0 |
while (keys.hasMoreElements()) |
472 |
|
{ |
473 |
0 |
Object key = keys.nextElement(); |
474 |
0 |
if (key != null) |
475 |
|
{ |
476 |
|
|
477 |
|
|
478 |
|
|
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
|
483 |
0 |
String[] path = ((String) key).split("\\."); |
484 |
0 |
int last = path.length - 1; |
485 |
0 |
JSONObject target = this; |
486 |
0 |
for (int i = 0; i < last; i += 1) |
487 |
|
{ |
488 |
0 |
String segment = path[i]; |
489 |
0 |
JSONObject nextTarget = target.optJSONObject(segment); |
490 |
0 |
if (nextTarget == null) |
491 |
|
{ |
492 |
0 |
nextTarget = new JSONObject(); |
493 |
0 |
target.put(segment, nextTarget); |
494 |
|
} |
495 |
0 |
target = nextTarget; |
496 |
|
} |
497 |
0 |
target.put(path[last], bundle.getString((String) key)); |
498 |
|
} |
499 |
|
} |
500 |
|
} |
501 |
|
|
502 |
|
|
503 |
|
|
504 |
|
|
505 |
|
|
506 |
|
|
507 |
|
@param |
508 |
|
|
509 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
510 |
0 |
protected JSONObject(int initialCapacity)... |
511 |
|
{ |
512 |
0 |
this.map = new HashMap<String, Object>(initialCapacity); |
513 |
|
} |
514 |
|
|
515 |
|
|
516 |
|
|
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
|
|
522 |
|
|
523 |
|
|
524 |
|
|
525 |
|
|
526 |
|
@param |
527 |
|
|
528 |
|
@param |
529 |
|
|
530 |
|
@return |
531 |
|
@throws |
532 |
|
|
533 |
|
@throws |
534 |
|
|
535 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
536 |
0 |
public JSONObject accumulate(String key, Object value)... |
537 |
|
throws JSONException |
538 |
|
{ |
539 |
0 |
testValidity(value); |
540 |
0 |
Object object = this.opt(key); |
541 |
0 |
if (object == null) |
542 |
|
{ |
543 |
0 |
this.put(key, value instanceof JSONArray ? new JSONArray().put(value) |
544 |
|
: value); |
545 |
|
} |
546 |
0 |
else if (object instanceof JSONArray) |
547 |
|
{ |
548 |
0 |
((JSONArray) object).put(value); |
549 |
|
} |
550 |
|
else |
551 |
|
{ |
552 |
0 |
this.put(key, new JSONArray().put(object).put(value)); |
553 |
|
} |
554 |
0 |
return this; |
555 |
|
} |
556 |
|
|
557 |
|
|
558 |
|
|
559 |
|
|
560 |
|
|
561 |
|
|
562 |
|
|
563 |
|
@param |
564 |
|
|
565 |
|
@param |
566 |
|
|
567 |
|
@return |
568 |
|
@throws |
569 |
|
|
570 |
|
|
571 |
|
@throws |
572 |
|
|
573 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
574 |
0 |
public JSONObject append(String key, Object value) throws JSONException... |
575 |
|
{ |
576 |
0 |
testValidity(value); |
577 |
0 |
Object object = this.opt(key); |
578 |
0 |
if (object == null) |
579 |
|
{ |
580 |
0 |
this.put(key, new JSONArray().put(value)); |
581 |
|
} |
582 |
0 |
else if (object instanceof JSONArray) |
583 |
|
{ |
584 |
0 |
this.put(key, ((JSONArray) object).put(value)); |
585 |
|
} |
586 |
|
else |
587 |
|
{ |
588 |
0 |
throw new JSONException( |
589 |
|
"JSONObject[" + key + "] is not a JSONArray."); |
590 |
|
} |
591 |
0 |
return this; |
592 |
|
} |
593 |
|
|
594 |
|
|
595 |
|
|
596 |
|
|
597 |
|
|
598 |
|
@param |
599 |
|
|
600 |
|
@return |
601 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 8 |
Complexity Density: 0.89 |
|
602 |
0 |
public static String doubleToString(double d)... |
603 |
|
{ |
604 |
0 |
if (Double.isInfinite(d) || Double.isNaN(d)) |
605 |
|
{ |
606 |
0 |
return "null"; |
607 |
|
} |
608 |
|
|
609 |
|
|
610 |
|
|
611 |
0 |
String string = Double.toString(d); |
612 |
0 |
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 |
613 |
|
&& string.indexOf('E') < 0) |
614 |
|
{ |
615 |
0 |
while (string.endsWith("0")) |
616 |
|
{ |
617 |
0 |
string = string.substring(0, string.length() - 1); |
618 |
|
} |
619 |
0 |
if (string.endsWith(".")) |
620 |
|
{ |
621 |
0 |
string = string.substring(0, string.length() - 1); |
622 |
|
} |
623 |
|
} |
624 |
0 |
return string; |
625 |
|
} |
626 |
|
|
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
@param |
631 |
|
|
632 |
|
@return |
633 |
|
@throws |
634 |
|
|
635 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
636 |
0 |
public Object get(String key) throws JSONException... |
637 |
|
{ |
638 |
0 |
if (key == null) |
639 |
|
{ |
640 |
0 |
throw new JSONException("Null key."); |
641 |
|
} |
642 |
0 |
Object object = this.opt(key); |
643 |
0 |
if (object == null) |
644 |
|
{ |
645 |
0 |
throw new JSONException("JSONObject[" + quote(key) + "] not found."); |
646 |
|
} |
647 |
0 |
return object; |
648 |
|
} |
649 |
|
|
650 |
|
|
651 |
|
|
652 |
|
|
653 |
|
@param |
654 |
|
|
655 |
|
@param |
656 |
|
|
657 |
|
@return |
658 |
|
@throws |
659 |
|
|
660 |
|
|
661 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
662 |
0 |
public <E extends Enum<E>> E getEnum(Class<E> clazz, String key)... |
663 |
|
throws JSONException |
664 |
|
{ |
665 |
0 |
E val = optEnum(clazz, key); |
666 |
0 |
if (val == null) |
667 |
|
{ |
668 |
|
|
669 |
|
|
670 |
|
|
671 |
0 |
throw new JSONException( |
672 |
|
"JSONObject[" + quote(key) + "] is not an enum of type " |
673 |
|
+ quote(clazz.getSimpleName()) + "."); |
674 |
|
} |
675 |
0 |
return val; |
676 |
|
} |
677 |
|
|
678 |
|
|
679 |
|
|
680 |
|
|
681 |
|
@param |
682 |
|
|
683 |
|
@return |
684 |
|
@throws |
685 |
|
|
686 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 7 |
Complexity Density: 1.17 |
|
687 |
0 |
public boolean getBoolean(String key) throws JSONException... |
688 |
|
{ |
689 |
0 |
Object object = this.get(key); |
690 |
0 |
if (object.equals(Boolean.FALSE) || (object instanceof String |
691 |
|
&& ((String) object).equalsIgnoreCase("false"))) |
692 |
|
{ |
693 |
0 |
return false; |
694 |
|
} |
695 |
0 |
else if (object.equals(Boolean.TRUE) || (object instanceof String |
696 |
|
&& ((String) object).equalsIgnoreCase("true"))) |
697 |
|
{ |
698 |
0 |
return true; |
699 |
|
} |
700 |
0 |
throw new JSONException( |
701 |
|
"JSONObject[" + quote(key) + "] is not a Boolean."); |
702 |
|
} |
703 |
|
|
704 |
|
|
705 |
|
|
706 |
|
|
707 |
|
@param |
708 |
|
|
709 |
|
@return |
710 |
|
@throws |
711 |
|
|
712 |
|
|
713 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
714 |
0 |
public BigInteger getBigInteger(String key) throws JSONException... |
715 |
|
{ |
716 |
0 |
Object object = this.get(key); |
717 |
0 |
try |
718 |
|
{ |
719 |
0 |
return new BigInteger(object.toString()); |
720 |
|
} catch (Exception e) |
721 |
|
{ |
722 |
0 |
throw new JSONException("JSONObject[" + quote(key) |
723 |
|
+ "] could not be converted to BigInteger.", e); |
724 |
|
} |
725 |
|
} |
726 |
|
|
727 |
|
|
728 |
|
|
729 |
|
|
730 |
|
@param |
731 |
|
|
732 |
|
@return |
733 |
|
@throws |
734 |
|
|
735 |
|
|
736 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
737 |
0 |
public BigDecimal getBigDecimal(String key) throws JSONException... |
738 |
|
{ |
739 |
0 |
Object object = this.get(key); |
740 |
0 |
if (object instanceof BigDecimal) |
741 |
|
{ |
742 |
0 |
return (BigDecimal) object; |
743 |
|
} |
744 |
0 |
try |
745 |
|
{ |
746 |
0 |
return new BigDecimal(object.toString()); |
747 |
|
} catch (Exception e) |
748 |
|
{ |
749 |
0 |
throw new JSONException("JSONObject[" + quote(key) |
750 |
|
+ "] could not be converted to BigDecimal.", e); |
751 |
|
} |
752 |
|
} |
753 |
|
|
754 |
|
|
755 |
|
|
756 |
|
|
757 |
|
@param |
758 |
|
|
759 |
|
@return |
760 |
|
@throws |
761 |
|
|
762 |
|
|
763 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
764 |
0 |
public double getDouble(String key) throws JSONException... |
765 |
|
{ |
766 |
0 |
Object object = this.get(key); |
767 |
0 |
try |
768 |
|
{ |
769 |
0 |
return object instanceof Number ? ((Number) object).doubleValue() |
770 |
|
: Double.parseDouble(object.toString()); |
771 |
|
} catch (Exception e) |
772 |
|
{ |
773 |
0 |
throw new JSONException( |
774 |
|
"JSONObject[" + quote(key) + "] is not a number.", e); |
775 |
|
} |
776 |
|
} |
777 |
|
|
778 |
|
|
779 |
|
|
780 |
|
|
781 |
|
@param |
782 |
|
|
783 |
|
@return |
784 |
|
@throws |
785 |
|
|
786 |
|
|
787 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
788 |
0 |
public float getFloat(String key) throws JSONException... |
789 |
|
{ |
790 |
0 |
Object object = this.get(key); |
791 |
0 |
try |
792 |
|
{ |
793 |
0 |
return object instanceof Number ? ((Number) object).floatValue() |
794 |
|
: Float.parseFloat(object.toString()); |
795 |
|
} catch (Exception e) |
796 |
|
{ |
797 |
0 |
throw new JSONException( |
798 |
|
"JSONObject[" + quote(key) + "] is not a number.", e); |
799 |
|
} |
800 |
|
} |
801 |
|
|
802 |
|
|
803 |
|
|
804 |
|
|
805 |
|
@param |
806 |
|
|
807 |
|
@return |
808 |
|
@throws |
809 |
|
|
810 |
|
|
811 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
812 |
0 |
public Number getNumber(String key) throws JSONException... |
813 |
|
{ |
814 |
0 |
Object object = this.get(key); |
815 |
0 |
try |
816 |
|
{ |
817 |
0 |
if (object instanceof Number) |
818 |
|
{ |
819 |
0 |
return (Number) object; |
820 |
|
} |
821 |
0 |
return stringToNumber(object.toString()); |
822 |
|
} catch (Exception e) |
823 |
|
{ |
824 |
0 |
throw new JSONException( |
825 |
|
"JSONObject[" + quote(key) + "] is not a number.", e); |
826 |
|
} |
827 |
|
} |
828 |
|
|
829 |
|
|
830 |
|
|
831 |
|
|
832 |
|
@param |
833 |
|
|
834 |
|
@return |
835 |
|
@throws |
836 |
|
|
837 |
|
|
838 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
839 |
0 |
public int getInt(String key) throws JSONException... |
840 |
|
{ |
841 |
0 |
Object object = this.get(key); |
842 |
0 |
try |
843 |
|
{ |
844 |
0 |
return object instanceof Number ? ((Number) object).intValue() |
845 |
|
: Integer.parseInt((String) object); |
846 |
|
} catch (Exception e) |
847 |
|
{ |
848 |
0 |
throw new JSONException( |
849 |
|
"JSONObject[" + quote(key) + "] is not an int.", e); |
850 |
|
} |
851 |
|
} |
852 |
|
|
853 |
|
|
854 |
|
|
855 |
|
|
856 |
|
@param |
857 |
|
|
858 |
|
@return |
859 |
|
@throws |
860 |
|
|
861 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
862 |
0 |
public JSONArray getJSONArray(String key) throws JSONException... |
863 |
|
{ |
864 |
0 |
Object object = this.get(key); |
865 |
0 |
if (object instanceof JSONArray) |
866 |
|
{ |
867 |
0 |
return (JSONArray) object; |
868 |
|
} |
869 |
0 |
throw new JSONException( |
870 |
|
"JSONObject[" + quote(key) + "] is not a JSONArray."); |
871 |
|
} |
872 |
|
|
873 |
|
|
874 |
|
|
875 |
|
|
876 |
|
@param |
877 |
|
|
878 |
|
@return |
879 |
|
@throws |
880 |
|
|
881 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
882 |
0 |
public JSONObject getJSONObject(String key) throws JSONException... |
883 |
|
{ |
884 |
0 |
Object object = this.get(key); |
885 |
0 |
if (object instanceof JSONObject) |
886 |
|
{ |
887 |
0 |
return (JSONObject) object; |
888 |
|
} |
889 |
0 |
throw new JSONException( |
890 |
|
"JSONObject[" + quote(key) + "] is not a JSONObject."); |
891 |
|
} |
892 |
|
|
893 |
|
|
894 |
|
|
895 |
|
|
896 |
|
@param |
897 |
|
|
898 |
|
@return |
899 |
|
@throws |
900 |
|
|
901 |
|
|
902 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
903 |
0 |
public long getLong(String key) throws JSONException... |
904 |
|
{ |
905 |
0 |
Object object = this.get(key); |
906 |
0 |
try |
907 |
|
{ |
908 |
0 |
return object instanceof Number ? ((Number) object).longValue() |
909 |
|
: Long.parseLong((String) object); |
910 |
|
} catch (Exception e) |
911 |
|
{ |
912 |
0 |
throw new JSONException( |
913 |
|
"JSONObject[" + quote(key) + "] is not a long.", e); |
914 |
|
} |
915 |
|
} |
916 |
|
|
917 |
|
|
918 |
|
|
919 |
|
|
920 |
|
@return |
921 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
922 |
0 |
public static String[] getNames(JSONObject jo)... |
923 |
|
{ |
924 |
0 |
if (jo.isEmpty()) |
925 |
|
{ |
926 |
0 |
return null; |
927 |
|
} |
928 |
0 |
return jo.keySet().toArray(new String[jo.length()]); |
929 |
|
} |
930 |
|
|
931 |
|
|
932 |
|
|
933 |
|
|
934 |
|
@return |
935 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
936 |
0 |
public static String[] getNames(Object object)... |
937 |
|
{ |
938 |
0 |
if (object == null) |
939 |
|
{ |
940 |
0 |
return null; |
941 |
|
} |
942 |
0 |
Class<?> klass = object.getClass(); |
943 |
0 |
Field[] fields = klass.getFields(); |
944 |
0 |
int length = fields.length; |
945 |
0 |
if (length == 0) |
946 |
|
{ |
947 |
0 |
return null; |
948 |
|
} |
949 |
0 |
String[] names = new String[length]; |
950 |
0 |
for (int i = 0; i < length; i += 1) |
951 |
|
{ |
952 |
0 |
names[i] = fields[i].getName(); |
953 |
|
} |
954 |
0 |
return names; |
955 |
|
} |
956 |
|
|
957 |
|
|
958 |
|
|
959 |
|
|
960 |
|
@param |
961 |
|
|
962 |
|
@return |
963 |
|
@throws |
964 |
|
|
965 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
966 |
0 |
public String getString(String key) throws JSONException... |
967 |
|
{ |
968 |
0 |
Object object = this.get(key); |
969 |
0 |
if (object instanceof String) |
970 |
|
{ |
971 |
0 |
return (String) object; |
972 |
|
} |
973 |
0 |
throw new JSONException("JSONObject[" + quote(key) + "] not a string."); |
974 |
|
} |
975 |
|
|
976 |
|
|
977 |
|
|
978 |
|
|
979 |
|
@param |
980 |
|
|
981 |
|
@return |
982 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
983 |
0 |
public boolean has(String key)... |
984 |
|
{ |
985 |
0 |
return this.map.containsKey(key); |
986 |
|
} |
987 |
|
|
988 |
|
|
989 |
|
|
990 |
|
|
991 |
|
|
992 |
|
|
993 |
|
@param |
994 |
|
|
995 |
|
@return |
996 |
|
@throws |
997 |
|
|
998 |
|
|
999 |
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 8 |
Complexity Density: 0.47 |
|
1000 |
0 |
public JSONObject increment(String key) throws JSONException... |
1001 |
|
{ |
1002 |
0 |
Object value = this.opt(key); |
1003 |
0 |
if (value == null) |
1004 |
|
{ |
1005 |
0 |
this.put(key, 1); |
1006 |
|
} |
1007 |
0 |
else if (value instanceof BigInteger) |
1008 |
|
{ |
1009 |
0 |
this.put(key, ((BigInteger) value).add(BigInteger.ONE)); |
1010 |
|
} |
1011 |
0 |
else if (value instanceof BigDecimal) |
1012 |
|
{ |
1013 |
0 |
this.put(key, ((BigDecimal) value).add(BigDecimal.ONE)); |
1014 |
|
} |
1015 |
0 |
else if (value instanceof Integer) |
1016 |
|
{ |
1017 |
0 |
this.put(key, ((Integer) value).intValue() + 1); |
1018 |
|
} |
1019 |
0 |
else if (value instanceof Long) |
1020 |
|
{ |
1021 |
0 |
this.put(key, ((Long) value).longValue() + 1L); |
1022 |
|
} |
1023 |
0 |
else if (value instanceof Double) |
1024 |
|
{ |
1025 |
0 |
this.put(key, ((Double) value).doubleValue() + 1.0d); |
1026 |
|
} |
1027 |
0 |
else if (value instanceof Float) |
1028 |
|
{ |
1029 |
0 |
this.put(key, ((Float) value).floatValue() + 1.0f); |
1030 |
|
} |
1031 |
|
else |
1032 |
|
{ |
1033 |
0 |
throw new JSONException("Unable to increment [" + quote(key) + "]."); |
1034 |
|
} |
1035 |
0 |
return this; |
1036 |
|
} |
1037 |
|
|
1038 |
|
|
1039 |
|
|
1040 |
|
|
1041 |
|
|
1042 |
|
@param |
1043 |
|
|
1044 |
|
@return |
1045 |
|
|
1046 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1047 |
0 |
public boolean isNull(String key)... |
1048 |
|
{ |
1049 |
0 |
return JSONObject.NULL.equals(this.opt(key)); |
1050 |
|
} |
1051 |
|
|
1052 |
|
|
1053 |
|
|
1054 |
|
|
1055 |
|
|
1056 |
|
@see |
1057 |
|
|
1058 |
|
@return |
1059 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1060 |
0 |
public Iterator<String> keys()... |
1061 |
|
{ |
1062 |
0 |
return this.keySet().iterator(); |
1063 |
|
} |
1064 |
|
|
1065 |
|
|
1066 |
|
|
1067 |
|
|
1068 |
|
|
1069 |
|
@see |
1070 |
|
|
1071 |
|
@return |
1072 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1073 |
0 |
public Set<String> keySet()... |
1074 |
|
{ |
1075 |
0 |
return this.map.keySet(); |
1076 |
|
} |
1077 |
|
|
1078 |
|
|
1079 |
|
|
1080 |
|
|
1081 |
|
|
1082 |
|
|
1083 |
|
|
1084 |
|
|
1085 |
|
|
1086 |
|
@see |
1087 |
|
|
1088 |
|
@return |
1089 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1090 |
291 |
protected Set<Entry<String, Object>> entrySet()... |
1091 |
|
{ |
1092 |
291 |
return this.map.entrySet(); |
1093 |
|
} |
1094 |
|
|
1095 |
|
|
1096 |
|
|
1097 |
|
|
1098 |
|
@return |
1099 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1100 |
291 |
public int length()... |
1101 |
|
{ |
1102 |
291 |
return this.map.size(); |
1103 |
|
} |
1104 |
|
|
1105 |
|
|
1106 |
|
|
1107 |
|
|
1108 |
|
@return |
1109 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1110 |
0 |
public boolean isEmpty()... |
1111 |
|
{ |
1112 |
0 |
return map.isEmpty(); |
1113 |
|
} |
1114 |
|
|
1115 |
|
|
1116 |
|
|
1117 |
|
|
1118 |
|
|
1119 |
|
@return |
1120 |
|
|
1121 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
1122 |
0 |
public JSONArray names()... |
1123 |
|
{ |
1124 |
0 |
if (this.map.isEmpty()) |
1125 |
|
{ |
1126 |
0 |
return null; |
1127 |
|
} |
1128 |
0 |
return new JSONArray(this.map.keySet()); |
1129 |
|
} |
1130 |
|
|
1131 |
|
|
1132 |
|
|
1133 |
|
|
1134 |
|
@param |
1135 |
|
|
1136 |
|
@return |
1137 |
|
@throws |
1138 |
|
|
1139 |
|
|
|
|
| 83.3% |
Uncovered Elements: 3 (18) |
Complexity: 7 |
Complexity Density: 0.7 |
|
1140 |
449 |
public static String numberToString(Number number) throws JSONException... |
1141 |
|
{ |
1142 |
449 |
if (number == null) |
1143 |
|
{ |
1144 |
0 |
throw new JSONException("Null pointer"); |
1145 |
|
} |
1146 |
449 |
testValidity(number); |
1147 |
|
|
1148 |
|
|
1149 |
|
|
1150 |
449 |
String string = number.toString(); |
1151 |
449 |
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 |
1152 |
|
&& string.indexOf('E') < 0) |
1153 |
|
{ |
1154 |
408 |
while (string.endsWith("0")) |
1155 |
|
{ |
1156 |
204 |
string = string.substring(0, string.length() - 1); |
1157 |
|
} |
1158 |
204 |
if (string.endsWith(".")) |
1159 |
|
{ |
1160 |
204 |
string = string.substring(0, string.length() - 1); |
1161 |
|
} |
1162 |
|
} |
1163 |
449 |
return string; |
1164 |
|
} |
1165 |
|
|
1166 |
|
|
1167 |
|
|
1168 |
|
|
1169 |
|
@param |
1170 |
|
|
1171 |
|
@return |
1172 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
1173 |
0 |
public Object opt(String key)... |
1174 |
|
{ |
1175 |
0 |
return key == null ? null : this.map.get(key); |
1176 |
|
} |
1177 |
|
|
1178 |
|
|
1179 |
|
|
1180 |
|
|
1181 |
|
@param |
1182 |
|
|
1183 |
|
@param |
1184 |
|
|
1185 |
|
@return |
1186 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1187 |
0 |
public <E extends Enum<E>> E optEnum(Class<E> clazz, String key)... |
1188 |
|
{ |
1189 |
0 |
return this.optEnum(clazz, key, null); |
1190 |
|
} |
1191 |
|
|
1192 |
|
|
1193 |
|
|
1194 |
|
|
1195 |
|
@param |
1196 |
|
|
1197 |
|
@param |
1198 |
|
|
1199 |
|
@param |
1200 |
|
|
1201 |
|
@return |
1202 |
|
|
1203 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.5 |
|
1204 |
0 |
public <E extends Enum<E>> E optEnum(Class<E> clazz, String key,... |
1205 |
|
E defaultValue) |
1206 |
|
{ |
1207 |
0 |
try |
1208 |
|
{ |
1209 |
0 |
Object val = this.opt(key); |
1210 |
0 |
if (NULL.equals(val)) |
1211 |
|
{ |
1212 |
0 |
return defaultValue; |
1213 |
|
} |
1214 |
0 |
if (clazz.isAssignableFrom(val.getClass())) |
1215 |
|
{ |
1216 |
|
|
1217 |
0 |
@SuppressWarnings("unchecked") |
1218 |
|
E myE = (E) val; |
1219 |
0 |
return myE; |
1220 |
|
} |
1221 |
0 |
return Enum.valueOf(clazz, val.toString()); |
1222 |
|
} catch (IllegalArgumentException e) |
1223 |
|
{ |
1224 |
0 |
return defaultValue; |
1225 |
|
} catch (NullPointerException e) |
1226 |
|
{ |
1227 |
0 |
return defaultValue; |
1228 |
|
} |
1229 |
|
} |
1230 |
|
|
1231 |
|
|
1232 |
|
|
1233 |
|
|
1234 |
|
|
1235 |
|
@param |
1236 |
|
|
1237 |
|
@return |
1238 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1239 |
0 |
public boolean optBoolean(String key)... |
1240 |
|
{ |
1241 |
0 |
return this.optBoolean(key, false); |
1242 |
|
} |
1243 |
|
|
1244 |
|
|
1245 |
|
|
1246 |
|
|
1247 |
|
|
1248 |
|
|
1249 |
|
@param |
1250 |
|
|
1251 |
|
@param |
1252 |
|
|
1253 |
|
@return |
1254 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
1255 |
0 |
public boolean optBoolean(String key, boolean defaultValue)... |
1256 |
|
{ |
1257 |
0 |
Object val = this.opt(key); |
1258 |
0 |
if (NULL.equals(val)) |
1259 |
|
{ |
1260 |
0 |
return defaultValue; |
1261 |
|
} |
1262 |
0 |
if (val instanceof Boolean) |
1263 |
|
{ |
1264 |
0 |
return ((Boolean) val).booleanValue(); |
1265 |
|
} |
1266 |
0 |
try |
1267 |
|
{ |
1268 |
|
|
1269 |
0 |
return this.getBoolean(key); |
1270 |
|
} catch (Exception e) |
1271 |
|
{ |
1272 |
0 |
return defaultValue; |
1273 |
|
} |
1274 |
|
} |
1275 |
|
|
1276 |
|
|
1277 |
|
|
1278 |
|
|
1279 |
|
|
1280 |
|
|
1281 |
|
@param |
1282 |
|
|
1283 |
|
@param |
1284 |
|
|
1285 |
|
@return |
1286 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 11 |
Complexity Density: 0.79 |
|
1287 |
0 |
public BigDecimal optBigDecimal(String key, BigDecimal defaultValue)... |
1288 |
|
{ |
1289 |
0 |
Object val = this.opt(key); |
1290 |
0 |
if (NULL.equals(val)) |
1291 |
|
{ |
1292 |
0 |
return defaultValue; |
1293 |
|
} |
1294 |
0 |
if (val instanceof BigDecimal) |
1295 |
|
{ |
1296 |
0 |
return (BigDecimal) val; |
1297 |
|
} |
1298 |
0 |
if (val instanceof BigInteger) |
1299 |
|
{ |
1300 |
0 |
return new BigDecimal((BigInteger) val); |
1301 |
|
} |
1302 |
0 |
if (val instanceof Double || val instanceof Float) |
1303 |
|
{ |
1304 |
0 |
return new BigDecimal(((Number) val).doubleValue()); |
1305 |
|
} |
1306 |
0 |
if (val instanceof Long || val instanceof Integer |
1307 |
|
|| val instanceof Short || val instanceof Byte) |
1308 |
|
{ |
1309 |
0 |
return new BigDecimal(((Number) val).longValue()); |
1310 |
|
} |
1311 |
|
|
1312 |
0 |
try |
1313 |
|
{ |
1314 |
0 |
return new BigDecimal(val.toString()); |
1315 |
|
} catch (Exception e) |
1316 |
|
{ |
1317 |
0 |
return defaultValue; |
1318 |
|
} |
1319 |
|
} |
1320 |
|
|
1321 |
|
|
1322 |
|
|
1323 |
|
|
1324 |
|
|
1325 |
|
|
1326 |
|
@param |
1327 |
|
|
1328 |
|
@param |
1329 |
|
|
1330 |
|
@return |
1331 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 12 |
Complexity Density: 0.71 |
|
1332 |
0 |
public BigInteger optBigInteger(String key, BigInteger defaultValue)... |
1333 |
|
{ |
1334 |
0 |
Object val = this.opt(key); |
1335 |
0 |
if (NULL.equals(val)) |
1336 |
|
{ |
1337 |
0 |
return defaultValue; |
1338 |
|
} |
1339 |
0 |
if (val instanceof BigInteger) |
1340 |
|
{ |
1341 |
0 |
return (BigInteger) val; |
1342 |
|
} |
1343 |
0 |
if (val instanceof BigDecimal) |
1344 |
|
{ |
1345 |
0 |
return ((BigDecimal) val).toBigInteger(); |
1346 |
|
} |
1347 |
0 |
if (val instanceof Double || val instanceof Float) |
1348 |
|
{ |
1349 |
0 |
return new BigDecimal(((Number) val).doubleValue()).toBigInteger(); |
1350 |
|
} |
1351 |
0 |
if (val instanceof Long || val instanceof Integer |
1352 |
|
|| val instanceof Short || val instanceof Byte) |
1353 |
|
{ |
1354 |
0 |
return BigInteger.valueOf(((Number) val).longValue()); |
1355 |
|
} |
1356 |
|
|
1357 |
0 |
try |
1358 |
|
{ |
1359 |
|
|
1360 |
|
|
1361 |
|
|
1362 |
|
|
1363 |
|
|
1364 |
0 |
final String valStr = val.toString(); |
1365 |
0 |
if (isDecimalNotation(valStr)) |
1366 |
|
{ |
1367 |
0 |
return new BigDecimal(valStr).toBigInteger(); |
1368 |
|
} |
1369 |
0 |
return new BigInteger(valStr); |
1370 |
|
} catch (Exception e) |
1371 |
|
{ |
1372 |
0 |
return defaultValue; |
1373 |
|
} |
1374 |
|
} |
1375 |
|
|
1376 |
|
|
1377 |
|
|
1378 |
|
|
1379 |
|
|
1380 |
|
|
1381 |
|
@param |
1382 |
|
|
1383 |
|
@return |
1384 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1385 |
0 |
public double optDouble(String key)... |
1386 |
|
{ |
1387 |
0 |
return this.optDouble(key, Double.NaN); |
1388 |
|
} |
1389 |
|
|
1390 |
|
|
1391 |
|
|
1392 |
|
|
1393 |
|
|
1394 |
|
|
1395 |
|
@param |
1396 |
|
|
1397 |
|
@param |
1398 |
|
|
1399 |
|
@return |
1400 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
1401 |
0 |
public double optDouble(String key, double defaultValue)... |
1402 |
|
{ |
1403 |
0 |
Object val = this.opt(key); |
1404 |
0 |
if (NULL.equals(val)) |
1405 |
|
{ |
1406 |
0 |
return defaultValue; |
1407 |
|
} |
1408 |
0 |
if (val instanceof Number) |
1409 |
|
{ |
1410 |
0 |
return ((Number) val).doubleValue(); |
1411 |
|
} |
1412 |
0 |
if (val instanceof String) |
1413 |
|
{ |
1414 |
0 |
try |
1415 |
|
{ |
1416 |
0 |
return Double.parseDouble((String) val); |
1417 |
|
} catch (Exception e) |
1418 |
|
{ |
1419 |
0 |
return defaultValue; |
1420 |
|
} |
1421 |
|
} |
1422 |
0 |
return defaultValue; |
1423 |
|
} |
1424 |
|
|
1425 |
|
|
1426 |
|
|
1427 |
|
|
1428 |
|
|
1429 |
|
|
1430 |
|
@param |
1431 |
|
|
1432 |
|
@return |
1433 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1434 |
0 |
public float optFloat(String key)... |
1435 |
|
{ |
1436 |
0 |
return this.optFloat(key, Float.NaN); |
1437 |
|
} |
1438 |
|
|
1439 |
|
|
1440 |
|
|
1441 |
|
|
1442 |
|
|
1443 |
|
|
1444 |
|
@param |
1445 |
|
|
1446 |
|
@param |
1447 |
|
|
1448 |
|
@return |
1449 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
1450 |
0 |
public float optFloat(String key, float defaultValue)... |
1451 |
|
{ |
1452 |
0 |
Object val = this.opt(key); |
1453 |
0 |
if (JSONObject.NULL.equals(val)) |
1454 |
|
{ |
1455 |
0 |
return defaultValue; |
1456 |
|
} |
1457 |
0 |
if (val instanceof Number) |
1458 |
|
{ |
1459 |
0 |
return ((Number) val).floatValue(); |
1460 |
|
} |
1461 |
0 |
if (val instanceof String) |
1462 |
|
{ |
1463 |
0 |
try |
1464 |
|
{ |
1465 |
0 |
return Float.parseFloat((String) val); |
1466 |
|
} catch (Exception e) |
1467 |
|
{ |
1468 |
0 |
return defaultValue; |
1469 |
|
} |
1470 |
|
} |
1471 |
0 |
return defaultValue; |
1472 |
|
} |
1473 |
|
|
1474 |
|
|
1475 |
|
|
1476 |
|
|
1477 |
|
|
1478 |
|
|
1479 |
|
@param |
1480 |
|
|
1481 |
|
@return |
1482 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1483 |
0 |
public int optInt(String key)... |
1484 |
|
{ |
1485 |
0 |
return this.optInt(key, 0); |
1486 |
|
} |
1487 |
|
|
1488 |
|
|
1489 |
|
|
1490 |
|
|
1491 |
|
|
1492 |
|
|
1493 |
|
@param |
1494 |
|
|
1495 |
|
@param |
1496 |
|
|
1497 |
|
@return |
1498 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
1499 |
0 |
public int optInt(String key, int defaultValue)... |
1500 |
|
{ |
1501 |
0 |
Object val = this.opt(key); |
1502 |
0 |
if (NULL.equals(val)) |
1503 |
|
{ |
1504 |
0 |
return defaultValue; |
1505 |
|
} |
1506 |
0 |
if (val instanceof Number) |
1507 |
|
{ |
1508 |
0 |
return ((Number) val).intValue(); |
1509 |
|
} |
1510 |
|
|
1511 |
0 |
if (val instanceof String) |
1512 |
|
{ |
1513 |
0 |
try |
1514 |
|
{ |
1515 |
0 |
return new BigDecimal((String) val).intValue(); |
1516 |
|
} catch (Exception e) |
1517 |
|
{ |
1518 |
0 |
return defaultValue; |
1519 |
|
} |
1520 |
|
} |
1521 |
0 |
return defaultValue; |
1522 |
|
} |
1523 |
|
|
1524 |
|
|
1525 |
|
|
1526 |
|
|
1527 |
|
|
1528 |
|
@param |
1529 |
|
|
1530 |
|
@return |
1531 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
1532 |
0 |
public JSONArray optJSONArray(String key)... |
1533 |
|
{ |
1534 |
0 |
Object o = this.opt(key); |
1535 |
0 |
return o instanceof JSONArray ? (JSONArray) o : null; |
1536 |
|
} |
1537 |
|
|
1538 |
|
|
1539 |
|
|
1540 |
|
|
1541 |
|
|
1542 |
|
@param |
1543 |
|
|
1544 |
|
@return |
1545 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
1546 |
0 |
public JSONObject optJSONObject(String key)... |
1547 |
|
{ |
1548 |
0 |
Object object = this.opt(key); |
1549 |
0 |
return object instanceof JSONObject ? (JSONObject) object : null; |
1550 |
|
} |
1551 |
|
|
1552 |
|
|
1553 |
|
|
1554 |
|
|
1555 |
|
|
1556 |
|
|
1557 |
|
@param |
1558 |
|
|
1559 |
|
@return |
1560 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1561 |
0 |
public long optLong(String key)... |
1562 |
|
{ |
1563 |
0 |
return this.optLong(key, 0); |
1564 |
|
} |
1565 |
|
|
1566 |
|
|
1567 |
|
|
1568 |
|
|
1569 |
|
|
1570 |
|
|
1571 |
|
@param |
1572 |
|
|
1573 |
|
@param |
1574 |
|
|
1575 |
|
@return |
1576 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
1577 |
0 |
public long optLong(String key, long defaultValue)... |
1578 |
|
{ |
1579 |
0 |
Object val = this.opt(key); |
1580 |
0 |
if (NULL.equals(val)) |
1581 |
|
{ |
1582 |
0 |
return defaultValue; |
1583 |
|
} |
1584 |
0 |
if (val instanceof Number) |
1585 |
|
{ |
1586 |
0 |
return ((Number) val).longValue(); |
1587 |
|
} |
1588 |
|
|
1589 |
0 |
if (val instanceof String) |
1590 |
|
{ |
1591 |
0 |
try |
1592 |
|
{ |
1593 |
0 |
return new BigDecimal((String) val).longValue(); |
1594 |
|
} catch (Exception e) |
1595 |
|
{ |
1596 |
0 |
return defaultValue; |
1597 |
|
} |
1598 |
|
} |
1599 |
0 |
return defaultValue; |
1600 |
|
} |
1601 |
|
|
1602 |
|
|
1603 |
|
@link |
1604 |
|
|
1605 |
|
|
1606 |
|
@link |
1607 |
|
|
1608 |
|
|
1609 |
|
@param |
1610 |
|
|
1611 |
|
@return |
1612 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1613 |
0 |
public Number optNumber(String key)... |
1614 |
|
{ |
1615 |
0 |
return this.optNumber(key, null); |
1616 |
|
} |
1617 |
|
|
1618 |
|
|
1619 |
|
@link |
1620 |
|
|
1621 |
|
|
1622 |
|
|
1623 |
|
|
1624 |
|
@param |
1625 |
|
|
1626 |
|
@param |
1627 |
|
|
1628 |
|
@return |
1629 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
1630 |
0 |
public Number optNumber(String key, Number defaultValue)... |
1631 |
|
{ |
1632 |
0 |
Object val = this.opt(key); |
1633 |
0 |
if (NULL.equals(val)) |
1634 |
|
{ |
1635 |
0 |
return defaultValue; |
1636 |
|
} |
1637 |
0 |
if (val instanceof Number) |
1638 |
|
{ |
1639 |
0 |
return (Number) val; |
1640 |
|
} |
1641 |
|
|
1642 |
0 |
if (val instanceof String) |
1643 |
|
{ |
1644 |
0 |
try |
1645 |
|
{ |
1646 |
0 |
return stringToNumber((String) val); |
1647 |
|
} catch (Exception e) |
1648 |
|
{ |
1649 |
0 |
return defaultValue; |
1650 |
|
} |
1651 |
|
} |
1652 |
0 |
return defaultValue; |
1653 |
|
} |
1654 |
|
|
1655 |
|
|
1656 |
|
|
1657 |
|
|
1658 |
|
|
1659 |
|
|
1660 |
|
@param |
1661 |
|
|
1662 |
|
@return |
1663 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1664 |
0 |
public String optString(String key)... |
1665 |
|
{ |
1666 |
0 |
return this.optString(key, ""); |
1667 |
|
} |
1668 |
|
|
1669 |
|
|
1670 |
|
|
1671 |
|
|
1672 |
|
|
1673 |
|
@param |
1674 |
|
|
1675 |
|
@param |
1676 |
|
|
1677 |
|
@return |
1678 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
1679 |
0 |
public String optString(String key, String defaultValue)... |
1680 |
|
{ |
1681 |
0 |
Object object = this.opt(key); |
1682 |
0 |
return NULL.equals(object) ? defaultValue : object.toString(); |
1683 |
|
} |
1684 |
|
|
1685 |
|
|
1686 |
|
|
1687 |
|
|
1688 |
|
|
1689 |
|
@see |
1690 |
|
|
1691 |
|
@param |
1692 |
|
|
1693 |
|
|
|
|
| 84% |
Uncovered Elements: 4 (25) |
Complexity: 16 |
Complexity Density: 1.07 |
|
1694 |
283 |
private void populateMap(Object bean)... |
1695 |
|
{ |
1696 |
283 |
Class<?> klass = bean.getClass(); |
1697 |
|
|
1698 |
|
|
1699 |
|
|
1700 |
283 |
boolean includeSuperClass = klass.getClassLoader() != null; |
1701 |
|
|
1702 |
283 |
Method[] methods = includeSuperClass ? klass.getMethods() |
1703 |
|
: klass.getDeclaredMethods(); |
1704 |
283 |
for (final Method method : methods) |
1705 |
|
{ |
1706 |
5989 |
final int modifiers = method.getModifiers(); |
1707 |
5989 |
if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers) |
1708 |
|
&& method.getParameterTypes().length == 0 |
1709 |
|
&& !method.isBridge() && method.getReturnType() != Void.TYPE |
1710 |
|
&& isValidMethodName(method.getName())) |
1711 |
|
{ |
1712 |
2287 |
final String key = getKeyNameFromMethod(method); |
1713 |
2287 |
if (key != null && !key.isEmpty()) |
1714 |
|
{ |
1715 |
1721 |
try |
1716 |
|
{ |
1717 |
1721 |
final Object result = method.invoke(bean); |
1718 |
1721 |
if (result != null) |
1719 |
|
{ |
1720 |
1244 |
this.map.put(key, wrap(result)); |
1721 |
|
|
1722 |
|
|
1723 |
|
|
1724 |
1244 |
if (result instanceof Closeable) |
1725 |
|
{ |
1726 |
0 |
try |
1727 |
|
{ |
1728 |
0 |
((Closeable) result).close(); |
1729 |
|
} catch (IOException ignore) |
1730 |
|
{ |
1731 |
|
} |
1732 |
|
} |
1733 |
|
} |
1734 |
|
} catch (IllegalAccessException ignore) |
1735 |
|
{ |
1736 |
|
} catch (IllegalArgumentException ignore) |
1737 |
|
{ |
1738 |
|
} catch (InvocationTargetException ignore) |
1739 |
|
{ |
1740 |
|
} |
1741 |
|
} |
1742 |
|
} |
1743 |
|
} |
1744 |
|
} |
1745 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1746 |
2570 |
private boolean isValidMethodName(String name)... |
1747 |
|
{ |
1748 |
2570 |
return !"getClass".equals(name) && !"getDeclaringClass".equals(name); |
1749 |
|
} |
1750 |
|
|
|
|
| 80% |
Uncovered Elements: 5 (25) |
Complexity: 8 |
Complexity Density: 0.53 |
|
1751 |
2287 |
private String getKeyNameFromMethod(Method method)... |
1752 |
|
{ |
1753 |
2287 |
final int ignoreDepth = -1; |
1754 |
|
|
1755 |
|
|
1756 |
|
|
1757 |
|
|
1758 |
|
|
1759 |
|
|
1760 |
|
|
1761 |
|
|
1762 |
|
|
1763 |
|
|
1764 |
|
|
1765 |
|
|
1766 |
|
|
1767 |
|
|
1768 |
|
|
1769 |
|
|
1770 |
2287 |
String key; |
1771 |
2287 |
final String name = method.getName(); |
1772 |
2287 |
if (name.startsWith("get") && name.length() > 3) |
1773 |
|
{ |
1774 |
1667 |
key = name.substring(3); |
1775 |
|
} |
1776 |
620 |
else if (name.startsWith("is") && name.length() > 2) |
1777 |
|
{ |
1778 |
54 |
key = name.substring(2); |
1779 |
|
} |
1780 |
|
else |
1781 |
|
{ |
1782 |
566 |
return null; |
1783 |
|
} |
1784 |
|
|
1785 |
|
|
1786 |
|
|
1787 |
1721 |
if (Character.isLowerCase(key.charAt(0))) |
1788 |
|
{ |
1789 |
0 |
return null; |
1790 |
|
} |
1791 |
1721 |
if (key.length() == 1) |
1792 |
|
{ |
1793 |
0 |
key = key.toLowerCase(Locale.ROOT); |
1794 |
|
} |
1795 |
1721 |
else if (!Character.isUpperCase(key.charAt(1))) |
1796 |
|
{ |
1797 |
1721 |
key = key.substring(0, 1).toLowerCase(Locale.ROOT) + key.substring(1); |
1798 |
|
} |
1799 |
1721 |
return ( |
1800 |
|
key); |
1801 |
|
} |
1802 |
|
|
1803 |
|
|
1804 |
|
|
1805 |
|
|
1806 |
|
|
1807 |
|
|
1808 |
|
|
1809 |
|
|
1810 |
|
|
1811 |
|
|
1812 |
|
|
1813 |
|
|
1814 |
|
|
1815 |
|
|
1816 |
|
|
1817 |
|
|
1818 |
|
|
1819 |
|
|
1820 |
|
|
1821 |
|
|
1822 |
|
|
1823 |
|
|
1824 |
|
|
1825 |
|
|
1826 |
|
|
1827 |
|
|
1828 |
|
|
1829 |
|
|
1830 |
|
|
1831 |
|
|
1832 |
|
|
1833 |
|
|
1834 |
|
|
1835 |
|
|
1836 |
|
|
1837 |
|
|
1838 |
|
|
1839 |
|
|
1840 |
|
|
1841 |
|
|
1842 |
|
|
1843 |
|
|
1844 |
|
|
1845 |
|
|
1846 |
|
|
1847 |
|
|
1848 |
|
|
1849 |
|
|
1850 |
|
|
1851 |
|
|
1852 |
|
|
1853 |
|
|
1854 |
|
|
1855 |
|
|
1856 |
|
|
1857 |
|
|
1858 |
|
|
1859 |
|
|
1860 |
|
|
1861 |
|
|
1862 |
|
|
1863 |
|
|
1864 |
|
|
1865 |
|
|
1866 |
|
|
1867 |
|
|
1868 |
|
|
1869 |
|
|
1870 |
|
|
1871 |
|
|
1872 |
|
|
1873 |
|
|
1874 |
|
|
1875 |
|
|
1876 |
|
|
1877 |
|
|
1878 |
|
|
1879 |
|
|
1880 |
|
|
1881 |
|
|
1882 |
|
|
1883 |
|
|
1884 |
|
|
1885 |
|
|
1886 |
|
|
1887 |
|
|
1888 |
|
|
1889 |
|
|
1890 |
|
|
1891 |
|
|
1892 |
|
|
1893 |
|
|
1894 |
|
|
1895 |
|
|
1896 |
|
|
1897 |
|
|
1898 |
|
|
1899 |
|
|
1900 |
|
|
1901 |
|
|
1902 |
|
|
1903 |
|
|
1904 |
|
|
1905 |
|
|
1906 |
|
|
1907 |
|
|
1908 |
|
|
1909 |
|
|
1910 |
|
|
1911 |
|
|
1912 |
|
|
1913 |
|
|
1914 |
|
|
1915 |
|
|
1916 |
|
|
1917 |
|
|
1918 |
|
|
1919 |
|
|
1920 |
|
|
1921 |
|
|
1922 |
|
|
1923 |
|
|
1924 |
|
|
1925 |
|
|
1926 |
|
@param |
1927 |
|
|
1928 |
|
@param |
1929 |
|
|
1930 |
|
@return |
1931 |
|
@throws |
1932 |
|
|
1933 |
|
@throws |
1934 |
|
|
1935 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
1936 |
0 |
public JSONObject put(String key, boolean value) throws JSONException... |
1937 |
|
{ |
1938 |
0 |
return this.put(key, value ? Boolean.TRUE : Boolean.FALSE); |
1939 |
|
} |
1940 |
|
|
1941 |
|
|
1942 |
|
|
1943 |
|
|
1944 |
|
|
1945 |
|
@param |
1946 |
|
|
1947 |
|
@param |
1948 |
|
|
1949 |
|
@return |
1950 |
|
@throws |
1951 |
|
|
1952 |
|
@throws |
1953 |
|
|
1954 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1955 |
0 |
public JSONObject put(String key, Collection<?> value)... |
1956 |
|
throws JSONException |
1957 |
|
{ |
1958 |
0 |
return this.put(key, new JSONArray(value)); |
1959 |
|
} |
1960 |
|
|
1961 |
|
|
1962 |
|
|
1963 |
|
|
1964 |
|
@param |
1965 |
|
|
1966 |
|
@param |
1967 |
|
|
1968 |
|
@return |
1969 |
|
@throws |
1970 |
|
|
1971 |
|
@throws |
1972 |
|
|
1973 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1974 |
0 |
public JSONObject put(String key, double value) throws JSONException... |
1975 |
|
{ |
1976 |
0 |
return this.put(key, Double.valueOf(value)); |
1977 |
|
} |
1978 |
|
|
1979 |
|
|
1980 |
|
|
1981 |
|
|
1982 |
|
@param |
1983 |
|
|
1984 |
|
@param |
1985 |
|
|
1986 |
|
@return |
1987 |
|
@throws |
1988 |
|
|
1989 |
|
@throws |
1990 |
|
|
1991 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1992 |
0 |
public JSONObject put(String key, float value) throws JSONException... |
1993 |
|
{ |
1994 |
0 |
return this.put(key, Float.valueOf(value)); |
1995 |
|
} |
1996 |
|
|
1997 |
|
|
1998 |
|
|
1999 |
|
|
2000 |
|
@param |
2001 |
|
|
2002 |
|
@param |
2003 |
|
|
2004 |
|
@return |
2005 |
|
@throws |
2006 |
|
|
2007 |
|
@throws |
2008 |
|
|
2009 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
2010 |
0 |
public JSONObject put(String key, int value) throws JSONException... |
2011 |
|
{ |
2012 |
0 |
return this.put(key, Integer.valueOf(value)); |
2013 |
|
} |
2014 |
|
|
2015 |
|
|
2016 |
|
|
2017 |
|
|
2018 |
|
@param |
2019 |
|
|
2020 |
|
@param |
2021 |
|
|
2022 |
|
@return |
2023 |
|
@throws |
2024 |
|
|
2025 |
|
@throws |
2026 |
|
|
2027 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
2028 |
0 |
public JSONObject put(String key, long value) throws JSONException... |
2029 |
|
{ |
2030 |
0 |
return this.put(key, Long.valueOf(value)); |
2031 |
|
} |
2032 |
|
|
2033 |
|
|
2034 |
|
|
2035 |
|
|
2036 |
|
|
2037 |
|
@param |
2038 |
|
|
2039 |
|
@param |
2040 |
|
|
2041 |
|
@return |
2042 |
|
@throws |
2043 |
|
|
2044 |
|
@throws |
2045 |
|
|
2046 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
2047 |
0 |
public JSONObject put(String key, Map<?, ?> value) throws JSONException... |
2048 |
|
{ |
2049 |
0 |
return this.put(key, new JSONObject(value)); |
2050 |
|
} |
2051 |
|
|
2052 |
|
|
2053 |
|
|
2054 |
|
|
2055 |
|
|
2056 |
|
@param |
2057 |
|
|
2058 |
|
@param |
2059 |
|
|
2060 |
|
|
2061 |
|
|
2062 |
|
@return |
2063 |
|
@throws |
2064 |
|
|
2065 |
|
@throws |
2066 |
|
|
2067 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
2068 |
0 |
public JSONObject put(String key, Object value) throws JSONException... |
2069 |
|
{ |
2070 |
0 |
if (key == null) |
2071 |
|
{ |
2072 |
0 |
throw new NullPointerException("Null key."); |
2073 |
|
} |
2074 |
0 |
if (value != null) |
2075 |
|
{ |
2076 |
0 |
testValidity(value); |
2077 |
0 |
this.map.put(key, value); |
2078 |
|
} |
2079 |
|
else |
2080 |
|
{ |
2081 |
0 |
this.remove(key); |
2082 |
|
} |
2083 |
0 |
return this; |
2084 |
|
} |
2085 |
|
|
2086 |
|
|
2087 |
|
|
2088 |
|
|
2089 |
|
|
2090 |
|
|
2091 |
|
@param |
2092 |
|
|
2093 |
|
@param |
2094 |
|
|
2095 |
|
@return |
2096 |
|
@throws |
2097 |
|
|
2098 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
2099 |
0 |
public JSONObject putOnce(String key, Object value) throws JSONException... |
2100 |
|
{ |
2101 |
0 |
if (key != null && value != null) |
2102 |
|
{ |
2103 |
0 |
if (this.opt(key) != null) |
2104 |
|
{ |
2105 |
0 |
throw new JSONException("Duplicate key \"" + key + "\""); |
2106 |
|
} |
2107 |
0 |
return this.put(key, value); |
2108 |
|
} |
2109 |
0 |
return this; |
2110 |
|
} |
2111 |
|
|
2112 |
|
|
2113 |
|
|
2114 |
|
|
2115 |
|
|
2116 |
|
@param |
2117 |
|
|
2118 |
|
@param |
2119 |
|
|
2120 |
|
|
2121 |
|
|
2122 |
|
@return |
2123 |
|
@throws |
2124 |
|
|
2125 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
2126 |
0 |
public JSONObject putOpt(String key, Object value) throws JSONException... |
2127 |
|
{ |
2128 |
0 |
if (key != null && value != null) |
2129 |
|
{ |
2130 |
0 |
return this.put(key, value); |
2131 |
|
} |
2132 |
0 |
return this; |
2133 |
|
} |
2134 |
|
|
2135 |
|
|
2136 |
|
|
2137 |
|
|
2138 |
|
|
2139 |
|
|
2140 |
|
|
2141 |
|
|
2142 |
|
|
2143 |
|
|
2144 |
|
|
2145 |
|
|
2146 |
|
|
2147 |
|
|
2148 |
|
|
2149 |
|
|
2150 |
|
|
2151 |
|
|
2152 |
|
|
2153 |
|
|
2154 |
|
|
2155 |
|
@param |
2156 |
|
|
2157 |
|
@return |
2158 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
2159 |
0 |
public Object query(String jsonPointer)... |
2160 |
|
{ |
2161 |
0 |
return query(new JSONPointer(jsonPointer)); |
2162 |
|
} |
2163 |
|
|
2164 |
|
|
2165 |
|
|
2166 |
|
|
2167 |
|
|
2168 |
|
|
2169 |
|
|
2170 |
|
|
2171 |
|
|
2172 |
|
|
2173 |
|
|
2174 |
|
|
2175 |
|
|
2176 |
|
|
2177 |
|
|
2178 |
|
|
2179 |
|
|
2180 |
|
|
2181 |
|
|
2182 |
|
|
2183 |
|
|
2184 |
|
@param |
2185 |
|
|
2186 |
|
@return |
2187 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
2188 |
0 |
public Object query(JSONPointer jsonPointer)... |
2189 |
|
{ |
2190 |
0 |
return jsonPointer.queryFrom(this); |
2191 |
|
} |
2192 |
|
|
2193 |
|
|
2194 |
|
|
2195 |
|
|
2196 |
|
|
2197 |
|
@param |
2198 |
|
|
2199 |
|
@return |
2200 |
|
@throws |
2201 |
|
|
2202 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
2203 |
0 |
public Object optQuery(String jsonPointer)... |
2204 |
|
{ |
2205 |
0 |
return optQuery(new JSONPointer(jsonPointer)); |
2206 |
|
} |
2207 |
|
|
2208 |
|
|
2209 |
|
|
2210 |
|
|
2211 |
|
|
2212 |
|
@param |
2213 |
|
|
2214 |
|
@return |
2215 |
|
@throws |
2216 |
|
|
2217 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
2218 |
0 |
public Object optQuery(JSONPointer jsonPointer)... |
2219 |
|
{ |
2220 |
0 |
try |
2221 |
|
{ |
2222 |
0 |
return jsonPointer.queryFrom(this); |
2223 |
|
} catch (JSONPointerException e) |
2224 |
|
{ |
2225 |
0 |
return null; |
2226 |
|
} |
2227 |
|
} |
2228 |
|
|
2229 |
|
|
2230 |
|
|
2231 |
|
|
2232 |
|
|
2233 |
|
|
2234 |
|
|
2235 |
|
@param |
2236 |
|
|
2237 |
|
@return |
2238 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
2239 |
1286 |
public static String quote(String string)... |
2240 |
|
{ |
2241 |
1286 |
StringWriter sw = new StringWriter(); |
2242 |
1286 |
synchronized (sw.getBuffer()) |
2243 |
|
{ |
2244 |
1286 |
try |
2245 |
|
{ |
2246 |
1286 |
return quote(string, sw).toString(); |
2247 |
|
} catch (IOException ignored) |
2248 |
|
{ |
2249 |
|
|
2250 |
0 |
return ""; |
2251 |
|
} |
2252 |
|
} |
2253 |
|
} |
2254 |
|
|
|
|
| 60% |
Uncovered Elements: 22 (55) |
Complexity: 18 |
Complexity Density: 0.38 |
|
2255 |
2037 |
public static Writer quote(String string, Writer w) throws IOException... |
2256 |
|
{ |
2257 |
2037 |
if (string == null || string.isEmpty()) |
2258 |
|
{ |
2259 |
100 |
w.write("\"\""); |
2260 |
100 |
return w; |
2261 |
|
} |
2262 |
|
|
2263 |
1937 |
char b; |
2264 |
1937 |
char c = 0; |
2265 |
1937 |
String hhhh; |
2266 |
1937 |
int i; |
2267 |
1937 |
int len = string.length(); |
2268 |
|
|
2269 |
1937 |
w.write('"'); |
2270 |
23384 |
for (i = 0; i < len; i += 1) |
2271 |
|
{ |
2272 |
21447 |
b = c; |
2273 |
21447 |
c = string.charAt(i); |
2274 |
21447 |
switch (c) |
2275 |
|
{ |
2276 |
0 |
case '\\': |
2277 |
0 |
case '"': |
2278 |
0 |
w.write('\\'); |
2279 |
0 |
w.write(c); |
2280 |
0 |
break; |
2281 |
92 |
case '/': |
2282 |
92 |
if (b == '<') |
2283 |
|
{ |
2284 |
0 |
w.write('\\'); |
2285 |
|
} |
2286 |
92 |
w.write(c); |
2287 |
92 |
break; |
2288 |
0 |
case '\b': |
2289 |
0 |
w.write("\\b"); |
2290 |
0 |
break; |
2291 |
0 |
case '\t': |
2292 |
0 |
w.write("\\t"); |
2293 |
0 |
break; |
2294 |
0 |
case '\n': |
2295 |
0 |
w.write("\\n"); |
2296 |
0 |
break; |
2297 |
0 |
case '\f': |
2298 |
0 |
w.write("\\f"); |
2299 |
0 |
break; |
2300 |
0 |
case '\r': |
2301 |
0 |
w.write("\\r"); |
2302 |
0 |
break; |
2303 |
21355 |
default: |
2304 |
21355 |
if (c < ' ' || (c >= '\u0080' && c < '\u00a0') |
2305 |
|
|| (c >= '\u2000' && c < '\u2100')) |
2306 |
|
{ |
2307 |
95 |
w.write("\\u"); |
2308 |
95 |
hhhh = Integer.toHexString(c); |
2309 |
95 |
w.write("0000", 0, 4 - hhhh.length()); |
2310 |
95 |
w.write(hhhh); |
2311 |
|
} |
2312 |
|
else |
2313 |
|
{ |
2314 |
21260 |
w.write(c); |
2315 |
|
} |
2316 |
|
} |
2317 |
|
} |
2318 |
1937 |
w.write('"'); |
2319 |
1937 |
return w; |
2320 |
|
} |
2321 |
|
|
2322 |
|
|
2323 |
|
|
2324 |
|
|
2325 |
|
@param |
2326 |
|
|
2327 |
|
@return |
2328 |
|
|
2329 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
2330 |
0 |
public Object remove(String key)... |
2331 |
|
{ |
2332 |
0 |
return this.map.remove(key); |
2333 |
|
} |
2334 |
|
|
2335 |
|
|
2336 |
|
|
2337 |
|
|
2338 |
|
|
2339 |
|
@param |
2340 |
|
|
2341 |
|
@return |
2342 |
|
|
|
|
| 0% |
Uncovered Elements: 41 (41) |
Complexity: 11 |
Complexity Density: 0.48 |
|
2343 |
0 |
public boolean similar(Object other)... |
2344 |
|
{ |
2345 |
0 |
try |
2346 |
|
{ |
2347 |
0 |
if (!(other instanceof JSONObject)) |
2348 |
|
{ |
2349 |
0 |
return false; |
2350 |
|
} |
2351 |
0 |
if (!this.keySet().equals(((JSONObject) other).keySet())) |
2352 |
|
{ |
2353 |
0 |
return false; |
2354 |
|
} |
2355 |
0 |
for (final Entry<String, ?> entry : this.entrySet()) |
2356 |
|
{ |
2357 |
0 |
String name = entry.getKey(); |
2358 |
0 |
Object valueThis = entry.getValue(); |
2359 |
0 |
Object valueOther = ((JSONObject) other).get(name); |
2360 |
0 |
if (valueThis == valueOther) |
2361 |
|
{ |
2362 |
0 |
continue; |
2363 |
|
} |
2364 |
0 |
if (valueThis == null) |
2365 |
|
{ |
2366 |
0 |
return false; |
2367 |
|
} |
2368 |
0 |
if (valueThis instanceof JSONObject) |
2369 |
|
{ |
2370 |
0 |
if (!((JSONObject) valueThis).similar(valueOther)) |
2371 |
|
{ |
2372 |
0 |
return false; |
2373 |
|
} |
2374 |
|
} |
2375 |
0 |
else if (valueThis instanceof JSONArray) |
2376 |
|
{ |
2377 |
0 |
if (!((JSONArray) valueThis).similar(valueOther)) |
2378 |
|
{ |
2379 |
0 |
return false; |
2380 |
|
} |
2381 |
|
} |
2382 |
0 |
else if (!valueThis.equals(valueOther)) |
2383 |
|
{ |
2384 |
0 |
return false; |
2385 |
|
} |
2386 |
|
} |
2387 |
0 |
return true; |
2388 |
|
} catch (Throwable exception) |
2389 |
|
{ |
2390 |
0 |
return false; |
2391 |
|
} |
2392 |
|
} |
2393 |
|
|
2394 |
|
|
2395 |
|
|
2396 |
|
|
2397 |
|
|
2398 |
|
@param |
2399 |
|
|
2400 |
|
@return |
2401 |
|
|
2402 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
2403 |
0 |
protected static boolean isDecimalNotation(final String val)... |
2404 |
|
{ |
2405 |
0 |
return val.indexOf('.') > -1 || val.indexOf('e') > -1 |
2406 |
|
|| val.indexOf('E') > -1 || "-0".equals(val); |
2407 |
|
} |
2408 |
|
|
2409 |
|
|
2410 |
|
|
2411 |
|
|
2412 |
|
|
2413 |
|
|
2414 |
|
|
2415 |
|
@param |
2416 |
|
|
2417 |
|
@return |
2418 |
|
@throws |
2419 |
|
|
2420 |
|
@link |
2421 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 10 |
Complexity Density: 0.62 |
|
2422 |
0 |
protected static Number stringToNumber(final String val)... |
2423 |
|
throws NumberFormatException |
2424 |
|
{ |
2425 |
0 |
char initial = val.charAt(0); |
2426 |
0 |
if ((initial >= '0' && initial <= '9') || initial == '-') |
2427 |
|
{ |
2428 |
|
|
2429 |
0 |
if (isDecimalNotation(val)) |
2430 |
|
{ |
2431 |
|
|
2432 |
|
|
2433 |
0 |
if (val.length() > 14) |
2434 |
|
{ |
2435 |
0 |
return new BigDecimal(val); |
2436 |
|
} |
2437 |
0 |
final Double d = Double.valueOf(val); |
2438 |
0 |
if (d.isInfinite() || d.isNaN()) |
2439 |
|
{ |
2440 |
|
|
2441 |
|
|
2442 |
|
|
2443 |
|
|
2444 |
0 |
return new BigDecimal(val); |
2445 |
|
} |
2446 |
0 |
return d; |
2447 |
|
} |
2448 |
|
|
2449 |
|
|
2450 |
|
|
2451 |
|
|
2452 |
|
|
2453 |
|
|
2454 |
|
|
2455 |
|
|
2456 |
|
|
2457 |
|
|
2458 |
|
|
2459 |
|
|
2460 |
|
|
2461 |
|
|
2462 |
|
|
2463 |
|
|
2464 |
|
|
2465 |
|
|
2466 |
|
|
2467 |
|
|
2468 |
|
|
2469 |
|
|
2470 |
|
|
2471 |
|
|
2472 |
0 |
BigInteger bi = new BigInteger(val); |
2473 |
0 |
if (bi.bitLength() <= 31) |
2474 |
|
{ |
2475 |
0 |
return Integer.valueOf(bi.intValue()); |
2476 |
|
} |
2477 |
0 |
if (bi.bitLength() <= 63) |
2478 |
|
{ |
2479 |
0 |
return Long.valueOf(bi.longValue()); |
2480 |
|
} |
2481 |
0 |
return bi; |
2482 |
|
} |
2483 |
0 |
throw new NumberFormatException( |
2484 |
|
"val [" + val + "] is not a valid number."); |
2485 |
|
} |
2486 |
|
|
2487 |
|
|
2488 |
|
|
2489 |
|
|
2490 |
|
|
2491 |
|
@param |
2492 |
|
|
2493 |
|
@return |
2494 |
|
|
2495 |
|
|
2496 |
|
|
|
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 14 |
Complexity Density: 0.67 |
|
2497 |
0 |
public static Object stringToValue(String string)... |
2498 |
|
{ |
2499 |
0 |
if (string.equals("")) |
2500 |
|
{ |
2501 |
0 |
return string; |
2502 |
|
} |
2503 |
0 |
if (string.equalsIgnoreCase("true")) |
2504 |
|
{ |
2505 |
0 |
return Boolean.TRUE; |
2506 |
|
} |
2507 |
0 |
if (string.equalsIgnoreCase("false")) |
2508 |
|
{ |
2509 |
0 |
return Boolean.FALSE; |
2510 |
|
} |
2511 |
0 |
if (string.equalsIgnoreCase("null")) |
2512 |
|
{ |
2513 |
0 |
return JSONObject.NULL; |
2514 |
|
} |
2515 |
|
|
2516 |
|
|
2517 |
|
|
2518 |
|
|
2519 |
|
|
2520 |
|
|
2521 |
0 |
char initial = string.charAt(0); |
2522 |
0 |
if ((initial >= '0' && initial <= '9') || initial == '-') |
2523 |
|
{ |
2524 |
0 |
try |
2525 |
|
{ |
2526 |
|
|
2527 |
|
|
2528 |
0 |
if (isDecimalNotation(string)) |
2529 |
|
{ |
2530 |
0 |
Double d = Double.valueOf(string); |
2531 |
0 |
if (!d.isInfinite() && !d.isNaN()) |
2532 |
|
{ |
2533 |
0 |
return d; |
2534 |
|
} |
2535 |
|
} |
2536 |
|
else |
2537 |
|
{ |
2538 |
0 |
Long myLong = Long.valueOf(string); |
2539 |
0 |
if (string.equals(myLong.toString())) |
2540 |
|
{ |
2541 |
0 |
if (myLong.longValue() == myLong.intValue()) |
2542 |
|
{ |
2543 |
0 |
return Integer.valueOf(myLong.intValue()); |
2544 |
|
} |
2545 |
0 |
return myLong; |
2546 |
|
} |
2547 |
|
} |
2548 |
|
} catch (Exception ignore) |
2549 |
|
{ |
2550 |
|
} |
2551 |
|
} |
2552 |
0 |
return string; |
2553 |
|
} |
2554 |
|
|
2555 |
|
|
2556 |
|
|
2557 |
|
|
2558 |
|
@param |
2559 |
|
|
2560 |
|
@throws |
2561 |
|
|
2562 |
|
|
|
|
| 70.6% |
Uncovered Elements: 5 (17) |
Complexity: 8 |
Complexity Density: 1.14 |
|
2563 |
449 |
public static void testValidity(Object o) throws JSONException... |
2564 |
|
{ |
2565 |
449 |
if (o != null) |
2566 |
|
{ |
2567 |
449 |
if (o instanceof Double) |
2568 |
|
{ |
2569 |
5 |
if (((Double) o).isInfinite() || ((Double) o).isNaN()) |
2570 |
|
{ |
2571 |
0 |
throw new JSONException( |
2572 |
|
"JSON does not allow non-finite numbers."); |
2573 |
|
} |
2574 |
|
} |
2575 |
444 |
else if (o instanceof Float) |
2576 |
|
{ |
2577 |
199 |
if (((Float) o).isInfinite() || ((Float) o).isNaN()) |
2578 |
|
{ |
2579 |
0 |
throw new JSONException( |
2580 |
|
"JSON does not allow non-finite numbers."); |
2581 |
|
} |
2582 |
|
} |
2583 |
|
} |
2584 |
|
} |
2585 |
|
|
2586 |
|
|
2587 |
|
|
2588 |
|
|
2589 |
|
|
2590 |
|
@param |
2591 |
|
|
2592 |
|
|
2593 |
|
@return |
2594 |
|
@throws |
2595 |
|
|
2596 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
2597 |
0 |
public JSONArray toJSONArray(JSONArray names) throws JSONException... |
2598 |
|
{ |
2599 |
0 |
if (names == null || names.isEmpty()) |
2600 |
|
{ |
2601 |
0 |
return null; |
2602 |
|
} |
2603 |
0 |
JSONArray ja = new JSONArray(); |
2604 |
0 |
for (int i = 0; i < names.length(); i += 1) |
2605 |
|
{ |
2606 |
0 |
ja.put(this.opt(names.getString(i))); |
2607 |
|
} |
2608 |
0 |
return ja; |
2609 |
|
} |
2610 |
|
|
2611 |
|
|
2612 |
|
|
2613 |
|
|
2614 |
|
|
2615 |
|
|
2616 |
|
|
2617 |
|
|
2618 |
|
@return |
2619 |
|
|
2620 |
|
|
2621 |
|
|
2622 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
2623 |
8 |
@Override... |
2624 |
|
public String toString() |
2625 |
|
{ |
2626 |
8 |
try |
2627 |
|
{ |
2628 |
8 |
return this.toString(0); |
2629 |
|
} catch (Exception e) |
2630 |
|
{ |
2631 |
0 |
return null; |
2632 |
|
} |
2633 |
|
} |
2634 |
|
|
2635 |
|
|
2636 |
|
|
2637 |
|
|
2638 |
|
|
2639 |
|
@link |
2640 |
|
|
2641 |
|
|
2642 |
|
|
2643 |
|
|
2644 |
|
|
2645 |
|
|
2646 |
|
|
2647 |
|
|
2648 |
|
|
2649 |
|
|
2650 |
|
|
2651 |
|
|
2652 |
|
|
2653 |
|
|
2654 |
|
|
2655 |
|
|
2656 |
|
@param |
2657 |
|
|
2658 |
|
@return |
2659 |
|
|
2660 |
|
|
2661 |
|
|
2662 |
|
@throws |
2663 |
|
|
2664 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
2665 |
8 |
public String toString(int indentFactor) throws JSONException... |
2666 |
|
{ |
2667 |
8 |
StringWriter w = new StringWriter(); |
2668 |
8 |
synchronized (w.getBuffer()) |
2669 |
|
{ |
2670 |
8 |
return this.write(w, indentFactor, 0).toString(); |
2671 |
|
} |
2672 |
|
} |
2673 |
|
|
2674 |
|
|
2675 |
|
|
2676 |
|
|
2677 |
|
|
2678 |
|
|
2679 |
|
|
2680 |
|
|
2681 |
|
|
2682 |
|
|
2683 |
|
|
2684 |
|
|
2685 |
|
|
2686 |
|
|
2687 |
|
|
2688 |
|
|
2689 |
|
@param |
2690 |
|
|
2691 |
|
@return |
2692 |
|
|
2693 |
|
|
2694 |
|
|
2695 |
|
@throws |
2696 |
|
|
2697 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
2698 |
0 |
public static String valueToString(Object value) throws JSONException... |
2699 |
|
{ |
2700 |
|
|
2701 |
|
|
2702 |
|
|
2703 |
|
|
2704 |
|
|
2705 |
|
|
2706 |
|
|
2707 |
0 |
return JSONWriter.valueToString(value); |
2708 |
|
} |
2709 |
|
|
2710 |
|
|
2711 |
|
|
2712 |
|
|
2713 |
|
|
2714 |
|
|
2715 |
|
|
2716 |
|
|
2717 |
|
|
2718 |
|
|
2719 |
|
@param |
2720 |
|
|
2721 |
|
@return |
2722 |
|
|
|
|
| 75.8% |
Uncovered Elements: 8 (33) |
Complexity: 26 |
Complexity Density: 1.37 |
|
2723 |
1580 |
public static Object wrap(Object object)... |
2724 |
|
{ |
2725 |
1580 |
try |
2726 |
|
{ |
2727 |
1580 |
if (object == null) |
2728 |
|
{ |
2729 |
0 |
return NULL; |
2730 |
|
} |
2731 |
1580 |
if (object instanceof JSONObject || object instanceof JSONArray |
2732 |
|
|| NULL.equals(object) || object instanceof JSONString |
2733 |
|
|| object instanceof Byte || object instanceof Character |
2734 |
|
|| object instanceof Short || object instanceof Integer |
2735 |
|
|| object instanceof Long || object instanceof Boolean |
2736 |
|
|| object instanceof Float || object instanceof Double |
2737 |
|
|| object instanceof String || object instanceof BigInteger |
2738 |
|
|| object instanceof BigDecimal || object instanceof Enum) |
2739 |
|
{ |
2740 |
1254 |
return object; |
2741 |
|
} |
2742 |
|
|
2743 |
326 |
if (object instanceof Collection) |
2744 |
|
{ |
2745 |
43 |
Collection<?> coll = (Collection<?>) object; |
2746 |
43 |
return new JSONArray(coll); |
2747 |
|
} |
2748 |
283 |
if (object.getClass().isArray()) |
2749 |
|
{ |
2750 |
0 |
return new JSONArray(object); |
2751 |
|
} |
2752 |
283 |
if (object instanceof Map) |
2753 |
|
{ |
2754 |
8 |
Map<?, ?> map = (Map<?, ?>) object; |
2755 |
8 |
return new JSONObject(map); |
2756 |
|
} |
2757 |
275 |
Package objectPackage = object.getClass().getPackage(); |
2758 |
275 |
String objectPackageName = objectPackage != null |
2759 |
|
? objectPackage.getName() |
2760 |
|
: ""; |
2761 |
275 |
if (objectPackageName.startsWith("java.") |
2762 |
|
|| objectPackageName.startsWith("javax.") |
2763 |
|
|| object.getClass().getClassLoader() == null) |
2764 |
|
{ |
2765 |
0 |
return object.toString(); |
2766 |
|
} |
2767 |
275 |
return new JSONObject(object); |
2768 |
|
} catch (Exception exception) |
2769 |
|
{ |
2770 |
0 |
return null; |
2771 |
|
} |
2772 |
|
} |
2773 |
|
|
2774 |
|
|
2775 |
|
|
2776 |
|
|
2777 |
|
|
2778 |
|
|
2779 |
|
|
2780 |
|
@return |
2781 |
|
@throws |
2782 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
2783 |
0 |
public Writer write(Writer writer) throws JSONException... |
2784 |
|
{ |
2785 |
0 |
return this.write(writer, 0, 0); |
2786 |
|
} |
2787 |
|
|
|
|
| 61.1% |
Uncovered Elements: 21 (54) |
Complexity: 15 |
Complexity Density: 0.47 |
|
2788 |
1580 |
static final Writer writeValue(Writer writer, Object value,... |
2789 |
|
int indentFactor, int indent) throws JSONException, IOException |
2790 |
|
{ |
2791 |
1580 |
if (value == null || value.equals(null)) |
2792 |
|
{ |
2793 |
0 |
writer.write("null"); |
2794 |
|
} |
2795 |
1580 |
else if (value instanceof JSONString) |
2796 |
|
{ |
2797 |
0 |
Object o; |
2798 |
0 |
try |
2799 |
|
{ |
2800 |
0 |
o = ((JSONString) value).toJSONString(); |
2801 |
|
} catch (Exception e) |
2802 |
|
{ |
2803 |
0 |
throw new JSONException(e); |
2804 |
|
} |
2805 |
0 |
writer.write(o != null ? o.toString() : quote(value.toString())); |
2806 |
|
} |
2807 |
1580 |
else if (value instanceof Number) |
2808 |
|
{ |
2809 |
|
|
2810 |
|
|
2811 |
449 |
final String numberAsString = numberToString((Number) value); |
2812 |
449 |
try |
2813 |
|
{ |
2814 |
|
|
2815 |
449 |
@SuppressWarnings("unused") |
2816 |
|
BigDecimal testNum = new BigDecimal(numberAsString); |
2817 |
|
|
2818 |
449 |
writer.write(numberAsString); |
2819 |
|
} catch (NumberFormatException ex) |
2820 |
|
{ |
2821 |
|
|
2822 |
|
|
2823 |
0 |
quote(numberAsString, writer); |
2824 |
|
} |
2825 |
|
} |
2826 |
1131 |
else if (value instanceof Boolean) |
2827 |
|
{ |
2828 |
54 |
writer.write(value.toString()); |
2829 |
|
} |
2830 |
1077 |
else if (value instanceof Enum<?>) |
2831 |
|
{ |
2832 |
0 |
writer.write(quote(((Enum<?>) value).name())); |
2833 |
|
} |
2834 |
1077 |
else if (value instanceof JSONObject) |
2835 |
|
{ |
2836 |
283 |
((JSONObject) value).write(writer, indentFactor, indent); |
2837 |
|
} |
2838 |
794 |
else if (value instanceof JSONArray) |
2839 |
|
{ |
2840 |
43 |
((JSONArray) value).write(writer, indentFactor, indent); |
2841 |
|
} |
2842 |
751 |
else if (value instanceof Map) |
2843 |
|
{ |
2844 |
0 |
Map<?, ?> map = (Map<?, ?>) value; |
2845 |
0 |
new JSONObject(map).write(writer, indentFactor, indent); |
2846 |
|
} |
2847 |
751 |
else if (value instanceof Collection) |
2848 |
|
{ |
2849 |
0 |
Collection<?> coll = (Collection<?>) value; |
2850 |
0 |
new JSONArray(coll).write(writer, indentFactor, indent); |
2851 |
|
} |
2852 |
751 |
else if (value.getClass().isArray()) |
2853 |
|
{ |
2854 |
0 |
new JSONArray(value).write(writer, indentFactor, indent); |
2855 |
|
} |
2856 |
|
else |
2857 |
|
{ |
2858 |
751 |
quote(value.toString(), writer); |
2859 |
|
} |
2860 |
1580 |
return writer; |
2861 |
|
} |
2862 |
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
2863 |
1885 |
static final void indent(Writer writer, int indent) throws IOException... |
2864 |
|
{ |
2865 |
1885 |
for (int i = 0; i < indent; i += 1) |
2866 |
|
{ |
2867 |
0 |
writer.write(' '); |
2868 |
|
} |
2869 |
|
} |
2870 |
|
|
2871 |
|
|
2872 |
|
|
2873 |
|
|
2874 |
|
|
2875 |
|
@link |
2876 |
|
|
2877 |
|
|
2878 |
|
|
2879 |
|
|
2880 |
|
|
2881 |
|
|
2882 |
|
|
2883 |
|
|
2884 |
|
|
2885 |
|
|
2886 |
|
|
2887 |
|
|
2888 |
|
|
2889 |
|
|
2890 |
|
|
2891 |
|
|
2892 |
|
@param |
2893 |
|
|
2894 |
|
@param |
2895 |
|
|
2896 |
|
@param |
2897 |
|
|
2898 |
|
@return |
2899 |
|
@throws |
2900 |
|
|
|
|
| 58.8% |
Uncovered Elements: 21 (51) |
Complexity: 11 |
Complexity Density: 0.3 |
|
2901 |
291 |
public Writer write(Writer writer, int indentFactor, int indent)... |
2902 |
|
throws JSONException |
2903 |
|
{ |
2904 |
291 |
try |
2905 |
|
{ |
2906 |
291 |
boolean commanate = false; |
2907 |
291 |
final int length = this.length(); |
2908 |
291 |
writer.write('{'); |
2909 |
|
|
2910 |
291 |
if (length == 1) |
2911 |
|
{ |
2912 |
0 |
final Entry<String, ?> entry = this.entrySet().iterator().next(); |
2913 |
0 |
final String key = entry.getKey(); |
2914 |
0 |
writer.write(quote(key)); |
2915 |
0 |
writer.write(':'); |
2916 |
0 |
if (indentFactor > 0) |
2917 |
|
{ |
2918 |
0 |
writer.write(' '); |
2919 |
|
} |
2920 |
0 |
try |
2921 |
|
{ |
2922 |
0 |
writeValue(writer, entry.getValue(), indentFactor, indent); |
2923 |
|
} catch (Exception e) |
2924 |
|
{ |
2925 |
0 |
throw new JSONException( |
2926 |
|
"Unable to write JSONObject value for key: " + key, e); |
2927 |
|
} |
2928 |
|
} |
2929 |
291 |
else if (length != 0) |
2930 |
|
{ |
2931 |
291 |
final int newindent = indent + indentFactor; |
2932 |
291 |
for (final Entry<String, ?> entry : this.entrySet()) |
2933 |
|
{ |
2934 |
1286 |
if (commanate) |
2935 |
|
{ |
2936 |
995 |
writer.write(','); |
2937 |
|
} |
2938 |
1286 |
if (indentFactor > 0) |
2939 |
|
{ |
2940 |
0 |
writer.write('\n'); |
2941 |
|
} |
2942 |
1286 |
indent(writer, newindent); |
2943 |
1286 |
final String key = entry.getKey(); |
2944 |
1286 |
writer.write(quote(key)); |
2945 |
1286 |
writer.write(':'); |
2946 |
1286 |
if (indentFactor > 0) |
2947 |
|
{ |
2948 |
0 |
writer.write(' '); |
2949 |
|
} |
2950 |
1286 |
try |
2951 |
|
{ |
2952 |
1286 |
writeValue(writer, entry.getValue(), indentFactor, newindent); |
2953 |
|
} catch (Exception e) |
2954 |
|
{ |
2955 |
0 |
throw new JSONException( |
2956 |
|
"Unable to write JSONObject value for key: " + key, e); |
2957 |
|
} |
2958 |
1286 |
commanate = true; |
2959 |
|
} |
2960 |
291 |
if (indentFactor > 0) |
2961 |
|
{ |
2962 |
0 |
writer.write('\n'); |
2963 |
|
} |
2964 |
291 |
indent(writer, indent); |
2965 |
|
} |
2966 |
291 |
writer.write('}'); |
2967 |
291 |
return writer; |
2968 |
|
} catch (IOException exception) |
2969 |
|
{ |
2970 |
0 |
throw new JSONException(exception); |
2971 |
|
} |
2972 |
|
} |
2973 |
|
|
2974 |
|
|
2975 |
|
|
2976 |
|
|
2977 |
|
|
2978 |
|
|
2979 |
|
|
2980 |
|
@return |
2981 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.42 |
|
2982 |
0 |
public Map<String, Object> toMap()... |
2983 |
|
{ |
2984 |
0 |
Map<String, Object> results = new HashMap<String, Object>(); |
2985 |
0 |
for (Entry<String, Object> entry : this.entrySet()) |
2986 |
|
{ |
2987 |
0 |
Object value; |
2988 |
0 |
if (entry.getValue() == null || NULL.equals(entry.getValue())) |
2989 |
|
{ |
2990 |
0 |
value = null; |
2991 |
|
} |
2992 |
0 |
else if (entry.getValue() instanceof JSONObject) |
2993 |
|
{ |
2994 |
0 |
value = ((JSONObject) entry.getValue()).toMap(); |
2995 |
|
} |
2996 |
0 |
else if (entry.getValue() instanceof JSONArray) |
2997 |
|
{ |
2998 |
0 |
value = ((JSONArray) entry.getValue()).toList(); |
2999 |
|
} |
3000 |
|
else |
3001 |
|
{ |
3002 |
0 |
value = entry.getValue(); |
3003 |
|
} |
3004 |
0 |
results.put(entry.getKey(), value); |
3005 |
|
} |
3006 |
0 |
return results; |
3007 |
|
} |
3008 |
|
} |