BetweenPredicate extends PropertyPredicate<T> { @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public boolean test(T t) { if (t == null) { return false; } Object v = ClassUtils.getFieldValue(t, getProperty()); if (v == null) { return false; } return ((Comparable) v).compareTo(getFromValue()) >= 0 && ((Comparable) v).compareTo(toValue) <= 0; } BetweenPredicate(String property, Comparable<?> fromValue, Comparable<?> toValue); @SuppressWarnings({ "unchecked", "rawtypes" }) @Override boolean test(T t); Comparable<?> getFromValue(); Comparable<?> getToValue();  }
@Test public void test() { BetweenPredicate<TestEntity> p1 = new BetweenPredicate<>("age", 10L, 20L); assertFalse(p1.test(null)); TestEntity t1 = new TestEntity(); t1.setAge(4L); assertFalse(p1.test(t1)); t1.setAge(10L); assertTrue(p1.test(t1)); t1.setAge(15L); assertTrue(p1.test(t1)); t1.setAge(20L); assertTrue(p1.test(t1)); t1.setAge(21L); assertFalse(p1.test(t1)); }