Package com.oorian.data
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>
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 Summary
ConstructorsConstructorDescriptionListDataProvider(List<T> items) Creates a list data provider wrapping the given items.ListDataProvider(T... items) Creates a list data provider from varargs items. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an item and notifies listeners.Fetches a page of data matching the query parameters.getItems()Returns the underlying items (unmodifiable view).booleanremoveItem(T item) Removes an item and notifies listeners.voidReplaces all items and notifies listeners.intReturns the total number of items matching the query's filters.Methods inherited from class com.oorian.data.AbstractDataProvider
addDataChangeListener, refresh, removeDataChangeListener
-
Constructor Details
-
ListDataProvider
Creates a list data provider wrapping the given items.- Parameters:
items- the items (a copy is made)
-
ListDataProvider
Creates a list data provider from varargs items.- Parameters:
items- the items
-
-
Method Details
-
setItems
Replaces all items and notifies listeners.- Parameters:
items- the new items
-
addItem
Adds an item and notifies listeners.- Parameters:
item- the item to add
-
removeItem
Removes an item and notifies listeners.- Parameters:
item- the item to remove- Returns:
trueif the item was found and removed
-
getItems
Returns the underlying items (unmodifiable view).- Returns:
- unmodifiable list of all items
-
fetch
Description copied from interface:DataProviderFetches 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
Description copied from interface:DataProviderReturns 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
-