@MainThread public class DatasourceProxy<E> extends Object implements Datasource<E>, DatasourceSwappable<E>
| Constructor and Description |
|---|
DatasourceProxy(Datasource<? extends E> datasource,
DiffCallbackFactory<E> diffCallbackFactory) |
| 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.
|
Datasource<? extends E> |
swap(Datasource<? extends E> datasource)
Performs swapping the internal components and returns the previous component.
|
void |
unregisterDatasourceObserver(DatasourceObserver observer)
Unregister an observer currently listening for data changes.
|
public DatasourceProxy(@NonNull Datasource<? extends E> datasource, @Nullable DiffCallbackFactory<E> diffCallbackFactory)
@Nullable public Datasource<? extends E> swap(@NonNull Datasource<? extends E> datasource)
Swappableswap in interface Swappable<Datasource<? extends E>>datasource - The new component that should replace the old one.@NonNull public E get(int position)
Datasourceget in interface Datasource<E>position - position of the element to return.public int size()
Datasourcesize in interface Datasource<E>public void registerDatasourceObserver(@NonNull DatasourceObserver observer)
Datasource
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.
registerDatasourceObserver in interface Datasource<E>observer - Observer to register.Datasource.unregisterDatasourceObserver(DatasourceObserver)public void unregisterDatasourceObserver(@NonNull DatasourceObserver observer)
Datasource
The unregistered observer will no longer receive events about changes to the datasource.
unregisterDatasourceObserver in interface Datasource<E>observer - Observer to unregister.Datasource.registerDatasourceObserver(DatasourceObserver)