Interface InMemoryDataProvider<T>

Type Parameters:
T - data type
All Superinterfaces:
ConfigurableFilterDataProvider<T,SerializablePredicate<T>,SerializablePredicate<T>>, DataProvider<T,SerializablePredicate<T>>, Serializable
All Known Implementing Classes:
DataCommunicator.EmptyDataProvider, ListDataProvider, TreeDataProvider

public interface InMemoryDataProvider<T> extends ConfigurableFilterDataProvider<T,SerializablePredicate<T>,SerializablePredicate<T>>
A mixin interface for in-memory data providers. Contains methods for configuring sorting and filtering.
Since:
1.0
Author:
Vaadin Ltd
  • Method Details

    • isInMemory

      default boolean isInMemory()
      Description copied from interface: DataProvider
      Gets whether the DataProvider content all available in memory or does it use some external backend.
      Specified by:
      isInMemory in interface DataProvider<T,SerializablePredicate<T>>
      Returns:
      true if all data is in memory; false if not
    • getFilter

      SerializablePredicate<T> getFilter()
      Gets the current filter of this data provider.
      Returns:
      the filter of this data provider
    • setFilter

      void setFilter(SerializablePredicate<T> filter)
      Sets a filter to be applied to all queries. The filter replaces any filter that has been set or added previously.
      Specified by:
      setFilter in interface ConfigurableFilterDataProvider<T,SerializablePredicate<T>,SerializablePredicate<T>>
      Parameters:
      filter - the filter to set, or null to remove any set filters
      See Also:
    • setFilter

      default <V> void setFilter(ValueProvider<T,V> valueProvider, SerializablePredicate<V> valueFilter)
      Sets a filter for an item property. The filter replaces any filter that has been set or added previously.
      Type Parameters:
      V - the provided value type
      Parameters:
      valueProvider - value provider that gets the property value, not null
      valueFilter - filter for testing the property value, not null
      See Also:
    • addFilter

      default void addFilter(SerializablePredicate<T> filter)
      Adds a filter to be applied to all queries. The filter will be used in addition to any filter that has been set or added previously.
      Parameters:
      filter - the filter to add, not null
      See Also:
    • addFilter

      default <V> void addFilter(ValueProvider<T,V> valueProvider, SerializablePredicate<V> valueFilter)
      Adds a filter for an item property. The filter will be used in addition to any filter that has been set or added previously.
      Type Parameters:
      V - the provided value type
      Parameters:
      valueProvider - value provider that gets the property value, not null
      valueFilter - filter for testing the property value, not null
      See Also:
    • setFilterByValue

      default <V> void setFilterByValue(ValueProvider<T,V> valueProvider, V requiredValue)
      Sets a filter that requires an item property to have a specific value. The property value and the provided value are compared using Object.equals(Object). The filter replaces any filter that has been set or added previously.
      Type Parameters:
      V - the provided value type
      Parameters:
      valueProvider - value provider that gets the property value, not null
      requiredValue - the value that the property must have for the filter to pass
      See Also:
    • addFilterByValue

      default <V> void addFilterByValue(ValueProvider<T,V> valueProvider, V requiredValue)
      Adds a filter that requires an item property to have a specific value. The property value and the provided value are compared using Object.equals(Object).The filter will be used in addition to any filter that has been set or added previously.
      Type Parameters:
      V - the provided value type
      Parameters:
      valueProvider - value provider that gets the property value, not null
      requiredValue - the value that the property must have for the filter to pass
      See Also:
    • clearFilters

      default void clearFilters()
      Removes any filter that has been set or added previously.
      See Also:
    • getSortComparator

      SerializableComparator<T> getSortComparator()
      Gets the current sort comparator of this data provider.
      Returns:
      the sort comparator of this data provider
    • setSortComparator

      void setSortComparator(SerializableComparator<T> comparator)
      Sets the comparator to use as the default sorting for this data provider. This overrides the sorting set by any other method that manipulates the default sorting of this data provider.

      The default sorting is used if the query defines no sorting. The default sorting is also used to determine the ordering of items that are considered equal by the sorting defined in the query.

      Parameters:
      comparator - a comparator to use, or null to clear any previously set sort order
      See Also:
    • addSortComparator

      default void addSortComparator(SerializableComparator<T> comparator)
      Adds a comparator to the default sorting for this data provider. If no default sorting has been defined, then the provided comparator will be used as the default sorting. If a default sorting has been defined, then the provided comparator will be used to determine the ordering of items that are considered equal by the previously defined default sorting.

      The default sorting is used if the query defines no sorting. The default sorting is also used to determine the ordering of items that are considered equal by the sorting defined in the query.

      Parameters:
      comparator - a comparator to add, not null
      See Also:
    • setSortOrder

      default <V extends Comparable<? super V>> void setSortOrder(ValueProvider<T,V> valueProvider, SortDirection sortDirection)
      Sets the property and direction to use as the default sorting for this data provider. This overrides the sorting set by any other method that manipulates the default sorting of this data provider.

      The default sorting is used if the query defines no sorting. The default sorting is also used to determine the ordering of items that are considered equal by the sorting defined in the query.

      Type Parameters:
      V - the provided value type
      Parameters:
      valueProvider - the value provider that defines the property do sort by, not null
      sortDirection - the sort direction to use, not null
      See Also:
    • addSortOrder

      default <V extends Comparable<? super V>> void addSortOrder(ValueProvider<T,V> valueProvider, SortDirection sortDirection)
      Adds a property and direction to the default sorting for this data provider. If no default sorting has been defined, then the provided sort order will be used as the default sorting. If a default sorting has been defined, then the provided sort order will be used to determine the ordering of items that are considered equal by the previously defined default sorting.

      The default sorting is used if the query defines no sorting. The default sorting is also used to determine the ordering of items that are considered equal by the sorting defined in the query.

      Type Parameters:
      V - the provided value type
      Parameters:
      valueProvider - the value provider that defines the property do sort by, not null
      sortDirection - the sort direction to use, not null
      See Also:
    • filteringBy

      default <Q> DataProvider<T,Q> filteringBy(SerializableBiPredicate<T,Q> predicate)
      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.

      The predicate receives the item as the first parameter and the query filter value as the second parameter, and should return true if the corresponding item should be included. The query filter value is never null – all items are included without running the predicate if the query doesn't define any filter.

      Type Parameters:
      Q - the filter type
      Parameters:
      predicate - a predicate to use for comparing the item to the query filter, not null
      Returns:
      a data provider that filters accordingly, not null
    • filteringBy

      default <V, Q> DataProvider<T,Q> filteringBy(ValueProvider<T,V> valueProvider, SerializableBiPredicate<V,Q> predicate)
      Wraps this data provider to create a new data provider that is filtered by comparing an item property value to the filter value provided in the query.

      The predicate receives the property value as the first parameter and the query filter value as the second parameter, and should return true if the corresponding item should be included. The query filter value is never null – all items are included without running either callback if the query doesn't define any filter.

      Type Parameters:
      V - the provided value type
      Q - the filter type
      Parameters:
      valueProvider - a value provider that gets the property value, not null
      predicate - a predicate to use for comparing the property value to the query filter, not null
      Returns:
      a data provider that filters accordingly, not null
    • filteringByEquals

      default <V> DataProvider<T,V> filteringByEquals(ValueProvider<T,V> valueProvider)
      Wraps this data provider to create a new data provider that is filtered by testing whether the value of a property is equals to the filter value provided in the query. Equality is tested using Objects.equals(Object, Object).
      Type Parameters:
      V - the provided value type
      Parameters:
      valueProvider - a value provider that gets the property value, not null
      Returns:
      a data provider that filters accordingly, not null
    • filteringBySubstring

      default DataProvider<T,String> filteringBySubstring(ValueProvider<T,String> valueProvider, Locale locale)
      Wraps this data provider to create a new data provider that is filtered by a string by checking whether the lower case representation of the filter value provided in the query is a substring of the lower case representation of an item property value. The filter never passes if the item property value is null.
      Parameters:
      valueProvider - a value provider that gets the string property value, not null
      locale - the locale to use for converting the strings to lower case, not null
      Returns:
      a data provider that filters accordingly, not null
    • filteringBySubstring

      default DataProvider<T,String> filteringBySubstring(ValueProvider<T,String> valueProvider)
      Wraps this data provider to create a new data provider that is filtered by a string by checking whether the lower case representation of the filter value provided in the query is a substring of the lower case representation of an item property value. Conversion to lower case is done using the locale of the current UI if available, or otherwise the default locale. The filter never passes if the item property value is null.
      Parameters:
      valueProvider - a value provider that gets the string property value, not null
      Returns:
      a data provider that filters accordingly, not null
    • filteringByPrefix

      default DataProvider<T,String> filteringByPrefix(ValueProvider<T,String> valueProvider, Locale locale)
      Wraps this data provider to create a new data provider that is filtered by a string by checking whether the lower case representation of an item property value starts with the lower case representation of the filter value provided in the query. The filter never passes if the item property value is null.
      Parameters:
      valueProvider - a value provider that gets the string property value, not null
      locale - the locale to use for converting the strings to lower case, not null
      Returns:
      a data provider that filters accordingly, not null
    • filteringByPrefix

      default DataProvider<T,String> filteringByPrefix(ValueProvider<T,String> valueProvider)
      Wraps this data provider to create a new data provider that is filtered by a string by checking whether the lower case representation of an item property value starts with the lower case representation of the filter value provided in the query. Conversion to lower case is done using the locale of the current UI if available, or otherwise the default locale. The filter never passes if the item property value is null.
      Parameters:
      valueProvider - a value provider that gets the string property value, not null
      Returns:
      a data provider that filters accordingly, not null