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