/** * Matches $ne constraints. */ private static boolean matchesNotEqualConstraint(Object constraint, Object value) { return !matchesEqualConstraint(constraint, value); }
/** * Matches $in constraints. * $in returns true if the intersection of value and constraint is not an empty set. */ private static boolean matchesInConstraint(Object constraint, Object value) { if (constraint instanceof Collection) { for (Object requiredItem : (Collection<?>) constraint) { if (matchesEqualConstraint(requiredItem, value)) { return true; } } return false; } throw new IllegalArgumentException("Constraint type not supported for $in queries."); }
/** * 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."); }