@MainThread public class ListDatasource<E> extends Object implements Datasource<E>
ArrayList of the elements as
the underlying data storage.| Constructor and Description |
|---|
ListDatasource() |
ListDatasource(List<? extends E> items) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(E e)
Adds a data entity to the end.
|
void |
add(int position,
E e)
Adds a data entity to a given position.
|
void |
addAll(int position,
List<? extends E> items)
Adds all data entities after the specified position.
|
void |
addAll(List<? extends E> items)
Adds all data entities to the end.
|
void |
clear()
Removes all of the elements from this datastore.
|
E |
get(int position)
Returns the element at the specified position.
|
void |
move(int fromPosition,
int toPosition)
Moves entity from one position to another.
|
void |
registerDatasourceObserver(DatasourceObserver observer)
Register a new observer to listen for data changes.
|
E |
remove(int position)
Removes entity at a given position.
|
void |
removeRange(int fromPosition,
int itemCount)
Removes a range of elements.
|
E |
set(int position,
E item)
Replaces the element at the specified position in this list with the
specified element.
|
int |
size()
Returns the number of elements in this datastore.
|
void |
unregisterDatasourceObserver(DatasourceObserver observer)
Unregister an observer currently listening for data changes.
|
@NonNull public E get(int position)
get in interface Datasource<E>position - position of the element to return.public void add(int position,
@NonNull
E e)
position - an index in the data set.e - a data entity.public void addAll(@NonNull List<? extends E> items)
items - a non-null List of data entities.public void addAll(int position,
@NonNull
List<? extends E> items)
position - position at which to insert the first element
from the specified collection.items - a non-null List of data entities.public void move(int fromPosition,
int toPosition)
fromPosition - an initial index.toPosition - a new index.@NonNull public E set(int position, @NonNull E item)
position - index of the element to replace.item - element to be stored at the specified position.@NonNull public E remove(int position)
position - an index in the list of entities.public void removeRange(int fromPosition,
int itemCount)
fromPosition - Position of the first item that be removed.itemCount - Number of items removed from the data set.public void clear()
public int size()
size in interface Datasource<E>public 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.
registerDatasourceObserver in interface Datasource<E>observer - Observer to register.Datasource.unregisterDatasourceObserver(DatasourceObserver)public void unregisterDatasourceObserver(@NonNull DatasourceObserver observer)
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)