private static <T> Predicate<T> isNull(String field, RequestScope requestScope) { return (T entity) -> getFieldValue(entity, field, requestScope) == null; }
private static <T> Predicate<T> isNull(String field, RequestScope requestScope) { return (T entity) -> getFieldValue(entity, field, requestScope) == null; }
private static <T> Predicate<T> in(String field, List<Object> values, RequestScope requestScope) { return (T entity) -> { Object val = getFieldValue(entity, field, requestScope); return val != null && values.stream() .map(v -> CoerceUtil.coerce(v, val.getClass())) .anyMatch(val::equals); }; }
private static <T> Predicate<T> in(String field, List<Object> values, RequestScope requestScope) { return (T entity) -> { Object val = getFieldValue(entity, field, requestScope); return val != null && values.stream() .map(v -> CoerceUtil.coerce(v, val.getClass())) .anyMatch(val::equals); }; }
private static <T> Predicate<T> getComparator(String field, List<Object> values, RequestScope requestScope, Predicate<Integer> condition) { return (T entity) -> { if (values.size() == 0) { throw new InvalidPredicateException("No value to compare"); } Object fieldVal = getFieldValue(entity, field, requestScope); return fieldVal != null && values.stream() .anyMatch(testVal -> condition.test(compare(fieldVal, testVal))); }; }
private static <T> Predicate<T> getComparator(String field, List<Object> values, RequestScope requestScope, Predicate<Integer> condition) { return (T entity) -> { if (values.size() == 0) { throw new InvalidPredicateException("No value to compare"); } Object fieldVal = getFieldValue(entity, field, requestScope); return fieldVal != null && values.stream() .anyMatch(testVal -> condition.test(compare(fieldVal, testVal))); }; }
private static <T> Predicate<T> in(String field, List<Object> values, RequestScope requestScope, Function<String, String> transform) { return (T entity) -> { Class type = requestScope.getDictionary().getType(entity, field); if (!type.isAssignableFrom(String.class)) { throw new IllegalStateException("Cannot case insensitive compare non-string values"); } String val = transform.apply((String) getFieldValue(entity, field, requestScope)); return val != null && values.stream() .map(v -> transform.apply(CoerceUtil.coerce(v, String.class))) .anyMatch(val::equals); }; }
private static <T> Predicate<T> infix(String field, List<Object> values, RequestScope requestScope, Function<String, String> transform) { return (T entity) -> { if (values.size() != 1) { throw new InvalidPredicateException("INFIX can only take one argument"); } Object val = getFieldValue(entity, field, requestScope); String valStr = CoerceUtil.coerce(val, String.class); String filterStr = CoerceUtil.coerce(values.get(0), String.class); return valStr != null && filterStr != null && transform.apply(valStr).contains(transform.apply(filterStr)); }; }
private static <T> Predicate<T> in(String field, List<Object> values, RequestScope requestScope, Function<String, String> transform) { return (T entity) -> { Class type = requestScope.getDictionary().getType(entity, field); if (!type.isAssignableFrom(String.class)) { throw new IllegalStateException("Cannot case insensitive compare non-string values"); } String val = transform.apply((String) getFieldValue(entity, field, requestScope)); return val != null && values.stream() .map(v -> transform.apply(CoerceUtil.coerce(v, String.class))) .anyMatch(val::equals); }; }
private static <T> Predicate<T> prefix(String field, List<Object> values, RequestScope requestScope, Function<String, String> transform) { return (T entity) -> { if (values.size() != 1) { throw new InvalidPredicateException("PREFIX can only take one argument"); } Object val = getFieldValue(entity, field, requestScope); String valStr = CoerceUtil.coerce(val, String.class); String filterStr = CoerceUtil.coerce(values.get(0), String.class); return valStr != null && filterStr != null && transform.apply(valStr).startsWith(transform.apply(filterStr)); }; }
private static <T> Predicate<T> postfix(String field, List<Object> values, RequestScope requestScope, Function<String, String> transform) { return (T entity) -> { if (values.size() != 1) { throw new InvalidPredicateException("POSTFIX can only take one argument"); } Object val = getFieldValue(entity, field, requestScope); String valStr = CoerceUtil.coerce(val, String.class); String filterStr = CoerceUtil.coerce(values.get(0), String.class); return valStr != null && filterStr != null && transform.apply(valStr).endsWith(transform.apply(filterStr)); }; }
private static <T> Predicate<T> prefix(String field, List<Object> values, RequestScope requestScope, Function<String, String> transform) { return (T entity) -> { if (values.size() != 1) { throw new InvalidPredicateException("PREFIX can only take one argument"); } Object val = getFieldValue(entity, field, requestScope); String valStr = CoerceUtil.coerce(val, String.class); String filterStr = CoerceUtil.coerce(values.get(0), String.class); return valStr != null && filterStr != null && transform.apply(valStr).startsWith(transform.apply(filterStr)); }; }
private static <T> Predicate<T> postfix(String field, List<Object> values, RequestScope requestScope, Function<String, String> transform) { return (T entity) -> { if (values.size() != 1) { throw new InvalidPredicateException("POSTFIX can only take one argument"); } Object val = getFieldValue(entity, field, requestScope); String valStr = CoerceUtil.coerce(val, String.class); String filterStr = CoerceUtil.coerce(values.get(0), String.class); return valStr != null && filterStr != null && transform.apply(valStr).endsWith(transform.apply(filterStr)); }; }
private static <T> Predicate<T> infix(String field, List<Object> values, RequestScope requestScope, Function<String, String> transform) { return (T entity) -> { if (values.size() != 1) { throw new InvalidPredicateException("INFIX can only take one argument"); } Object val = getFieldValue(entity, field, requestScope); String valStr = CoerceUtil.coerce(val, String.class); String filterStr = CoerceUtil.coerce(values.get(0), String.class); return valStr != null && filterStr != null && transform.apply(valStr).contains(transform.apply(filterStr)); }; }