/** * Wraps this data provider to create a new data provider that is filtered * by comparing an item to the filter value provided in the query. * <p> * The predicate receives the item as the first parameter and the query * filter value as the second parameter, and should return <code>true</code> * if the corresponding item should be included. The query filter value is * never <code>null</code> – all items are included without running the * predicate if the query doesn't define any filter. * * @param predicate * a predicate to use for comparing the item to the query filter, * not <code>null</code> * @param <Q> * the filter type * * @return a data provider that filters accordingly, not <code>null</code> */ default <Q> DataProvider<T, Q> filteringBy( SerializableBiPredicate<T, Q> predicate) { Objects.requireNonNull(predicate, "Predicate cannot be null"); return withConvertedFilter( filterValue -> item -> predicate.test(item, filterValue)); }
/** * Wraps a given data provider so that its filter ignores null items * returned by the given value provider. * * @param dataProvider * the data provider to wrap * @param valueProvider * the value provider for providing values to filter * @param predicate * the predicate to combine null filtering with * @param <T> * the provided data type * @param <Q> * the filter type * @param <V> * the data provider object type * @return the wrapped data provider */ public static <T, V, Q> DataProvider<T, Q> filteringByIgnoreNull( InMemoryDataProvider<T> dataProvider, ValueProvider<T, V> valueProvider, SerializableBiPredicate<V, Q> predicate) { Objects.requireNonNull(predicate, "Predicate cannot be null"); return dataProvider.filteringBy(valueProvider, (itemValue, queryFilter) -> itemValue != null && predicate.test(itemValue, queryFilter)); }
assert locale != null; return predicate.test(itemString.toLowerCase(locale), filterString.toLowerCase(locale)); });
.test(valueProvider.apply(item), filterValue));