Browse Source

add filter evaluation on collections

pull/16/head
Jochen Berger 12 years ago
parent
commit
bda35e7056
  1. 17
      json-path/src/main/java/com/jayway/jsonpath/Criteria.java

17
json-path/src/main/java/com/jayway/jsonpath/Criteria.java

@ -103,6 +103,19 @@ public class Criteria {
} }
} }
private static <T> boolean objectOrAnyCollectionItemMatches(final Object singleObjectOrCollection,
final Predicate<T> predicate){
if (singleObjectOrCollection instanceof Collection) {
Iterator it = ((Collection) singleObjectOrCollection).iterator();
while (it.hasNext()) {
if (predicate.accept((T) it.next())) {
return true;
}
}
return false;
}
return predicate.accept((T) singleObjectOrCollection);
}
boolean singleObjectApply(Map<String, Object> map) { boolean singleObjectApply(Map<String, Object> map) {
@ -514,5 +527,9 @@ public class Criteria {
return this; return this;
} }
private interface Predicate<T> {
boolean accept(T value);
}
} }

Loading…
Cancel
Save