@Test public void testFilterByProperty() throws Exception { TestObjectFilter objectFilter = new TestObjectFilter(); Assert.assertFalse("Matched 'no match'!", objectFilter.filterByProperty(testObject, "no match", Object::toString, String::contains)); Assert.assertFalse("Matched 'null'!", objectFilter.filterByProperty(testObject, "match", ignored -> null, String::contains)); Assert.assertTrue("Didn't match 'match'!", objectFilter.filterByProperty(testObject, "match", Object::toString, String::contains)); Assert.assertFalse("Match an intermediate null pointer!", objectFilter.filterByProperty(testObject, "no match", TestObjectFilter::nullPointerLambda, String::contains)); }
final <V> boolean filterByProperty(T object, String filterValue, Function<T, V> propertyExtractor, BiPredicate<V, String> filterFunction) { V property; try { property = propertyExtractor.apply(object); } catch (NullPointerException ignored) { return false; } return property != null && filterFunction.test(property, filterValue); }
PaginationFilter implements Predicate<T> { final <V> boolean filterByProperty(T object, String filterValue, Function<T, V> propertyExtractor, BiPredicate<V, String> filterFunction) { V property; try { property = propertyExtractor.apply(object); } catch (NullPointerException ignored) { return false; } return property != null && filterFunction.test(property, filterValue); } }
PaginationFilter implements Predicate<T> { final <V> boolean filterByProperty(T object, String filterValue, Function<T, V> propertyExtractor, BiPredicate<V, String> filterFunction) { V property; try { property = propertyExtractor.apply(object); } catch (NullPointerException ignored) { return false; } return property != null && filterFunction.test(property, filterValue); }  }
PaginationFilter implements Predicate<T> { final <V> boolean filterByProperty(T object, String filterValue, Function<T, V> propertyExtractor, BiPredicate<V, String> filterFunction) { V property; try { property = propertyExtractor.apply(object); } catch (NullPointerException ignored) { return false; } return property != null && filterFunction.test(property, filterValue); }  PaginationFilter<T> replaceFilter(final String filter, final String timeZoneOffset); final boolean test(T object, Class<V> enumType); }
PaginationFilter implements Predicate<T> { final <V> boolean filterByProperty(T object, String filterValue, Function<T, V> propertyExtractor, BiPredicate<V, String> filterFunction) { V property; try { property = propertyExtractor.apply(object); } catch (NullPointerException ignored) { return false; } return property != null && filterFunction.test(property, filterValue); }  PaginationFilter<T> replaceFilter(final String filter, final String timeZoneOffset); final boolean test(T object, Class<V> enumType);  }