/** * Matches $all constraints. */ private static boolean matchesAllConstraint(Object constraint, Object value) { if (value == null || value == JSONObject.NULL) { return false; } if (!(value instanceof Collection)) { throw new IllegalArgumentException("Value type not supported for $all queries."); } if (constraint instanceof Collection) { if (isAnyValueRegexStartsWith((Collection<?>) constraint)) { constraint = cleanRegexStartsWith((Collection<?>) constraint); if (constraint == null) { throw new IllegalArgumentException("All values in $all queries must be of starting with regex or non regex."); } } for (Object requiredItem : (Collection<?>) constraint) { if (!matchesEqualConstraint(requiredItem, value)) { return false; } } return true; } throw new IllegalArgumentException("Constraint type not supported for $all queries."); }