You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Does the JSON array contain the specified value? This method will scan the entire array until it finds a value
453
-
* or reaches the end.
452
+
* Returns {@code true} if this JSON Array contains the specified value.
453
+
* More formally, returns {@code true} if and only if this JSON array contains
454
+
* at least one entry {@code entry} such that {@code Objects.equals(value, entry)}.
454
455
*
455
-
* @param value the value
456
+
* @param value the value whose presence in this JSON array is to be tested
456
457
* @return true if it contains the value, false if not
457
458
*/
458
459
publicbooleancontains(Objectvalue) {
459
-
returnlist.contains(value);
460
+
returnindexOf(value) >= 0;
461
+
}
462
+
463
+
/**
464
+
* Returns the index of the last occurrence of the specified value
465
+
* in this JSON array, or -1 if this JSON array does not contain the value.
466
+
* More formally, returns the highest index {@code i} such that
467
+
* {@code Objects.equals(value, get(i))},
468
+
* or -1 if there is no such index.
469
+
*
470
+
* @param value the value whose index in this JSON array is to be returned
471
+
* @return the index of the value in the array, or -1 if the value is not in the array
472
+
*/
473
+
publicintindexOf(Objectvalue) {
474
+
if (value == null) {
475
+
returnlist.indexOf(value);
476
+
} else {
477
+
ObjectunwrappedValue = value;
478
+
479
+
if (valueinstanceofJsonObject) {
480
+
unwrappedValue = ((JsonObject) value).getMap();
481
+
} elseif (valueinstanceofJsonArray) {
482
+
unwrappedValue = ((JsonArray) value).getList();
483
+
}
484
+
485
+
for (inti = 0; i < list.size(); i++) {
486
+
Objectentry = list.get(i);
487
+
// no need to check "entry instanceof Map/List" here, as the first check in unwrappedValue.equals will be "entry instanceof Map/List" anyways, so this would be a redundant check
488
+
if (value.equals(entry) || unwrappedValue.equals(entry)) {
0 commit comments