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