public abstract class

DataSource.Factory<Key, Value>

extends java.lang.Object

 java.lang.Object

↳androidx.paging.DataSource.Factory<Key, Value>

Overview

Factory for DataSources.

Data-loading systems of an application or library can implement this interface to allow LiveDatas 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.

Summary

Constructors
publicFactory()

Methods
public abstract DataSource<java.lang.Object, java.lang.Object>create()

Create a DataSource.

public DataSource.Factory<java.lang.Object, java.lang.Object>map(Function<java.lang.Object, java.lang.Object> function)

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

public DataSource.Factory<java.lang.Object, java.lang.Object>mapByPage(Function<java.util.List, java.util.List> function)

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

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Factory()

Methods

public abstract DataSource<java.lang.Object, java.lang.Object> create()

Create a DataSource.

The DataSource should invalidate itself if the snapshot is no longer valid. If a DataSource becomes invalid, the only way to query more data is to create a new DataSource from the Factory.

LivePagedListBuilder for example will construct a new PagedList and DataSource when the current DataSource is invalidated, and pass the new PagedList through the LiveData to observers.

Returns:

the new DataSource.

public DataSource.Factory<java.lang.Object, java.lang.Object> map(Function<java.lang.Object, java.lang.Object> function)

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

Same as DataSource.Factory.mapByPage(Function, List>), but operates on individual items.

Parameters:

function: Function that runs on each loaded item, returning items of a potentially new type.

Returns:

A new DataSource.Factory, which transforms items using the given function.

See also: DataSource.Factory.mapByPage(Function, List>), DataSource.map(Function), DataSource.mapByPage(Function, List>)

public DataSource.Factory<java.lang.Object, java.lang.Object> mapByPage(Function<java.util.List, java.util.List> function)

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

Same as DataSource.Factory.map(Function), but allows for batch conversions.

Parameters:

function: Function that runs on each loaded page, returning items of a potentially new type.

Returns:

A new DataSource.Factory, which transforms items using the given function.

See also: DataSource.Factory.map(Function), DataSource.map(Function), DataSource.mapByPage(Function, List>)