DataSource.Factory

public abstract class DataSource.Factory<Key extends Object, Value extends Object>


Factory for DataSources.

Data-loading systems of an application or library can implement this interface to allow LiveData<PagedList>s to be created. For example, Room can provide a DataSource.Factory for a given SQL query:

@Dao
interface UserDao {
@Query("SELECT * FROM user ORDER BY lastName ASC")
public abstract DataSource.Factory<Integer, User> usersByLastName();
}

In the above sample, Integer is used because it is the Key type of PositionalDataSource. Currently, Room uses the LIMIT/OFFSET SQL keywords to page a large query with a PositionalDataSource.

Parameters
<Key extends Object>

Key identifying items in DataSource.

<Value extends Object>

Type of items in the list loaded by the DataSources.

Summary

Public constructors

<Key extends Object, Value extends Object> Factory()

Public methods

final @NonNull Function0<@NonNull PagingSource<@NonNull Key, @NonNull Value>>
abstract @NonNull DataSource<@NonNull Key, @NonNull Value>

Create a DataSource.

@NonNull DataSource.Factory<@NonNull Key, @NonNull ToValue>
<ToValue extends Object> map(Function<Value, ToValue> function)

Applies the given function to each value emitted by DataSources produced by this Factory.

@NonNull DataSource.Factory<@NonNull Key, @NonNull ToValue>
<ToValue extends Object> mapByPage(
    Function<List<Value>, List<ToValue>> function
)

Applies the given function to each value emitted by DataSources produced by this Factory.

Public constructors

Factory

public final <Key extends Object, Value extends Object> Factory()
Parameters
<Key extends Object>

Key identifying items in DataSource.

<Value extends Object>

Type of items in the list loaded by the DataSources.

Public methods

asPagingSourceFactory

public final @