Class InMemoryDataProviderHelpers

java.lang.Object
com.vaadin.flow.data.provider.InMemoryDataProviderHelpers

public class InMemoryDataProviderHelpers extends Object
Helper methods for implementing InMemoryDataProviders.

This class is intended primarily for internal use.

Since:
1.0
Author:
Vaadin Ltd
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.vaadin.flow.function.SerializableSupplier<Locale>
    Supplier that attempts to resolve a locale from the current UI.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T, V> com.vaadin.flow.function.SerializablePredicate<T>
    createEqualsFilter(com.vaadin.flow.function.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> com.vaadin.flow.function.SerializablePredicate<T>
    createValueProviderFilter(com.vaadin.flow.function.ValueProvider<T,V> valueProvider, com.vaadin.flow.function.SerializablePredicate<V> valueFilter)
    Creates a new predicate from the given predicate and value provider.
    static <T> DataProvider<T,String>
    filteringByCaseInsensitiveString(InMemoryDataProvider<T> dataProvider, com.vaadin.flow.function.ValueProvider<T,String> valueProvider, com.vaadin.flow.function.SerializableBiPredicate<String,String> predicate, com.vaadin.flow.function.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, com.vaadin.flow.function.ValueProvider<T,V> valueProvider, com.vaadin.flow.function.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>
    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>
    com.vaadin.flow.function.SerializableComparator<T>
    propertyComparator(com.vaadin.flow.function.ValueProvider<T,V> valueProvider, SortDirection sortDirection)
    Creates a comparator for the return type of the given ValueProvider, sorted in the direction specified by the given SortDirection.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CURRENT_LOCALE_SUPPLIER

      public static final com.vaadin.flow.function.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 Details

    • filteringByIgnoreNull

      public static <T, V, Q> DataProvider<T,Q> filteringByIgnoreNull(InMemoryDataProvider<T> dataProvider, com.vaadin.flow.function.ValueProvider<T,V> valueProvider, com.vaadin.flow.function.SerializableBiPredicate<V,Q> predicate)
      Wraps a given data provider so that its filter ignores null items returned by the given value provider.
      Type Parameters:
      T - the provided data type
      V - the data provider object type
      Q - the filter type
      Parameters:
      dataProvider - the data provider to wrap
      valueProvider - the value provider for providing values to filter
      predicate - the predicate to combine null filtering with
      Returns:
      the wrapped data provider
    • filteringByCaseInsensitiveString

      public static <T> DataProvider<T,String> filteringByCaseInsensitiveString(InMemoryDataProvider<T> dataProvider, com.vaadin.flow.function.ValueProvider<T,String> valueProvider, com.vaadin.flow.function.SerializableBiPredicate<String,String> predicate, com.vaadin.flow.function.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.
      Type Parameters:
      T - the data provider object type
      Parameters:
      dataProvider - the data provider to wrap
      valueProvider - the value provider for providing string values to filter
      predicate - the predicate to use for comparing the resulting lower case strings
      localeSupplier - the locale to use when converting strings to lower case
      Returns:
      the wrapped data provider
    • propertyComparator

      public static <V extends Comparable<? super V>, T> com.vaadin.flow.function.SerializableComparator<T> propertyComparator(com.vaadin.flow.function.ValueProvider<T,V> valueProvider, SortDirection sortDirection)
      Creates a comparator for the return type of the given ValueProvider, sorted in the direction specified by the given SortDirection.
      Type Parameters:
      V - the provided value type
      T - the data provider object type
      Parameters:
      valueProvider - the value provider to use
      sortDirection - the sort direction to use
      Returns:
      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.
      Type Parameters:
      V - the objects to compare
      Parameters:
      sortDirection - the sort direction to use
      Returns:
      the natural comparator, with ordering defined by the given sort direction
    • createValueProviderFilter

      public static <T, V> com.vaadin.flow.function.SerializablePredicate<T> createValueProviderFilter(com.vaadin.flow.function.ValueProvider<T,V> valueProvider, com.vaadin.flow.function.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.
      Type Parameters:
      T - the data provider object type
      V - the provided value type
      Parameters:
      valueProvider - the value provider to use
      valueFilter - the original predicate
      Returns:
      the created predicate
    • createEqualsFilter

      public static <T, V> com.vaadin.flow.function.SerializablePredicate<T> createEqualsFilter(com.vaadin.flow.function.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.
      Type Parameters:
      T - the data provider object type
      V - the provided value type
      Parameters:
      valueProvider - the value provider to use
      requiredValue - the required value
      Returns:
      the created predicate