com.vaadin.data.provider.
Class InMemoryDataProviderHelpers
- java.lang.Object
-
- com.vaadin.data.provider.InMemoryDataProviderHelpers
-
public class InMemoryDataProviderHelpers extends Object
A class containing a number of static helper methods for implementing
InMemoryDataProvider
s.This class is intended primarily for internal use.
Since:
8.1
Author:
Vaadin Ltd
-
-
Field Summary
Fields Modifier and Type Field Description static SerializableSupplier<Locale>
CURRENT_LOCALE_SUPPLIER
Supplier that attempts to resolve a locale from the current UI.
-
Constructor Summary
Constructors Constructor Description InMemoryDataProviderHelpers()
-
Method Summary
All Methods Modifier and Type Method Description static <T,V>
SerializablePredicate<T>createEqualsFilter(ValueProvider<T,V> valueProvider, V requiredValue)
Creates a predicate that compares equality of the given required value to the value the given value provider obtains.
static <T,V>
SerializablePredicate<T>createValueProviderFilter(ValueProvider<T,V> valueProvider, SerializablePredicate<V> valueFilter)
Creates a new predicate from the given predicate and value provider.
static <T> DataProvider<T,String>
filteringByCaseInsensitiveString(InMemoryDataProvider<T> dataProvider, ValueProvider<T,String> valueProvider, SerializableBiPredicate<String,String> predicate, SerializableSupplier<Locale> localeSupplier)
Wraps a given data provider so that its filter tests the given predicate with the lower case string provided by the given value provider.
static <T,V,Q>
DataProvider<T,Q>filteringByIgnoreNull(InMemoryDataProvider<T> dataProvider, ValueProvider<T,V> valueProvider, SerializableBiPredicate<V,Q> predicate)
Wraps a given data provider so that its filter ignores null items returned by the given value provider.
static <V extends Comparable<? super V>>
Comparator<V>getNaturalSortComparator(SortDirection sortDirection)
Gets the natural order comparator for the type argument, or the natural order comparator reversed if the given sorting direction is
SortDirection.DESCENDING
.static <V extends Comparable<? super V>,T>
SerializableComparator<T>propertyComparator(ValueProvider<T,V> valueProvider, SortDirection sortDirection)
Creates a comparator for the return type of the given
ValueProvider
, sorted in the direction specified by the givenSortDirection
.
-
-
-
Field Detail
-
CURRENT_LOCALE_SUPPLIER
public static final SerializableSupplier<Locale> CURRENT_LOCALE_SUPPLIER
Supplier that attempts to resolve a locale from the current UI. Returns the system's default locale as a fallback.
-
-
Method Detail
-
filteringByIgnoreNull
public static <T,V,Q> DataProvider<T,Q> filteringByIgnoreNull(InMemoryDataProvider<T> dataProvider, ValueProvider<T,V> valueProvider, SerializableBiPredicate<V,Q> predicate)
Wraps a given data provider so that its filter ignores null items returned by the given value provider.
Parameters:
dataProvider
- the data provider to wrapvalueProvider
- the value provider for providing values to filterpredicate
- the predicate to combine null filtering withReturns:
the wrapped data provider
-
filteringByCaseInsensitiveString
public static <T> DataProvider<T,String> filteringByCaseInsensitiveString(InMemoryDataProvider<T> dataProvider, ValueProvider<T,String> valueProvider, SerializableBiPredicate<String,String> predicate, SerializableSupplier<Locale> localeSupplier)
Wraps a given data provider so that its filter tests the given predicate with the lower case string provided by the given value provider.
Parameters:
dataProvider
- the data provider to wrapvalueProvider
- the value provider for providing string values to filterpredicate
- the predicate to use for comparing the resulting lower case stringslocaleSupplier
- the locale to use when converting strings to lower caseReturns:
the wrapped data provider
-
propertyComparator
public static <V extends Comparable<? super V>,T> SerializableComparator<T> propertyComparator(ValueProvider<T,V> valueProvider, SortDirection sortDirection)
Creates a comparator for the return type of the given
ValueProvider
, sorted in the direction specified by the givenSortDirection
.Parameters:
valueProvider
- the value provider to usesortDirection
- the sort direction to useReturns:
the created comparator
-
getNaturalSortComparator
public static <V extends Comparable<? super V>> Comparator<V> getNaturalSortComparator(SortDirection sortDirection)
Gets the natural order comparator for the type argument, or the natural order comparator reversed if the given sorting direction is
SortDirection.DESCENDING
.Parameters:
sortDirection
- the sort direction to useReturns:
the natural comparator, with ordering defined by the given sort direction
-
createValueProviderFilter
public static <T,V> SerializablePredicate<T> createValueProviderFilter(ValueProvider<T,V> valueProvider, SerializablePredicate<V> valueFilter)
Creates a new predicate from the given predicate and value provider. This allows using a predicate of the value providers return type with objects of the value providers type.
Parameters:
valueProvider
- the value provider to usevalueFilter
- the original predicateReturns:
the created predicate
-
createEqualsFilter
public static <T,V> SerializablePredicate<T> createEqualsFilter(ValueProvider<T,V> valueProvider, V requiredValue)
Creates a predicate that compares equality of the given required value to the value the given value provider obtains.
Parameters:
valueProvider
- the value provider to userequiredValue
- the required valueReturns:
the created predicate
-
-