Class ListDataProvider<T>

java.lang.Object
com.oorian.data.AbstractDataProvider<T>
com.oorian.data.ListDataProvider<T>
Type Parameters:
T - the data item type
All Implemented Interfaces:
DataProvider<T>

public class ListDataProvider<T> extends AbstractDataProvider<T>
An in-memory data provider that wraps a List.

Supports sorting and filtering from Query descriptors using reflection to access item fields. Suitable for small to medium datasets that fit in memory.


 // From a list
 List<User> users = userService.getAllUsers();
 ListDataProvider<User> provider = new ListDataProvider<>(users);

 // Mutate and auto-refresh
 provider.addItem(newUser);
 provider.removeItem(oldUser);
 provider.setItems(freshList);
 
Since:
2.1
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • ListDataProvider

      public ListDataProvider(List<T> items)
      Creates a list data provider wrapping the given items.
      Parameters:
      items - the items (a copy is made)
    • ListDataProvider

      @SafeVarargs public ListDataProvider(T... items)
      Creates a list data provider from varargs items.
      Parameters:
      items - the items
  • Method Details

    • setItems

      public void setItems(List<T> items)
      Replaces all items and notifies listeners.
      Parameters:
      items - the new items
    • addItem

      public void addItem(T item)
      Adds an item and notifies listeners.
      Parameters:
      item - the item to add
    • removeItem

      public boolean removeItem(T item)
      Removes an item and notifies listeners.
      Parameters:
      item - the item to remove
      Returns:
      true if the item was found and removed
    • getItems

      public List<T> getItems()
      Returns the underlying items (unmodifiable view).
      Returns:
      unmodifiable list of all items
    • fetch

      public DataResult<T> fetch(Query query)
      Description copied from interface: DataProvider
      Fetches a page of data matching the query parameters.
      Parameters:
      query - the query with offset, limit, sorts, and filters
      Returns:
      the result containing items and total count
    • size

      public int size(Query query)
      Description copied from interface: DataProvider
      Returns the total number of items matching the query's filters.
      Parameters:
      query - the query (only filters are relevant; offset/limit are ignored)
      Returns:
      the total count of matching items