E - Type of elements handled by datastore.@MainThread public interface Datasource<E>
| Modifier and Type | Method and Description |
|---|---|
E |
get(int position)
Returns the element at the specified position.
|
void |
registerDatasourceObserver(DatasourceObserver observer)
Register a new observer to listen for data changes.
|
int |
size()
Returns the number of elements in this datastore.
|
void |
unregisterDatasourceObserver(DatasourceObserver observer)
Unregister an observer currently listening for data changes.
|
@NonNull E get(int position)
position - position of the element to return.IndexOutOfBoundsException - if the index is out of range
(index < 0 || index >= size())int size()
void registerDatasourceObserver(@NonNull DatasourceObserver observer)
The datasource may publish a variety of events describing specific changes.
Not all datasource may support all change types and some may fall back to a generic
DatasourceObserver.onChanged() "something changed" event
if more specific data is not available.
Components registering observers with a datasource are responsible for
unregistering those observers when finished.
observer - Observer to register.unregisterDatasourceObserver(DatasourceObserver)void unregisterDatasourceObserver(@NonNull DatasourceObserver observer)
The unregistered observer will no longer receive events about changes to the datasource.
observer - Observer to unregister.registerDatasourceObserver(DatasourceObserver)