PositionalDataSource
public abstract class PositionalDataSource<T extends Object> extends DataSource
LimitOffsetDataSource |
A simple data source implementation that uses Limit & Offset to page the query. |
Position-based data loader for a fixed-size, countable data set, supporting fixed-size loads at arbitrary page positions.
Extend PositionalDataSource if you can load pages of a requested size at arbitrary positions, and provide a fixed item count. If your data source can't support loading arbitrary requested page sizes (e.g. when network page size constraints are only known at runtime), either use PageKeyedDataSource or ItemKeyedDataSource, or pass the initial result with the two parameter LoadInitialCallback.onResult.
Room can generate a Factory of PositionalDataSources for you:
@Dao
interface UserDao {
@Query("SELECT * FROM user ORDER BY age DESC")
public abstract DataSource.Factory<Integer, User> loadUsersByAgeDesc();
}
| Parameters | |
|---|---|
<T extends Object> |
Type of items being loaded by the |
Summary
Nested types |
|
|---|---|
PositionalDataSource.LoadInitialCallback |
Callback for |
PositionalDataSource.LoadInitialParams |
Holder object for inputs to |
PositionalDataSource.LoadRangeCallback |
Callback for PositionalDataSource |
PositionalDataSource.LoadRangeParams |
Holder object for inputs to |
Public fields |
|
|---|---|
boolean |
|
Public constructors |
|
|---|---|
<T extends Object> PositionalDataSource() |
|
Public methods |
|
|---|---|
abstract @WorkerThread void |
loadInitial(Load initial list data. |
abstract @WorkerThread void |
loadRange(Called to load a range of data from the DataSource. |
final @NonNull PositionalDataSource<@NonNull V> |
Applies the given function to each value emitted by the DataSource. |
final @NonNull PositionalDataSource<@NonNull V> |
Applies the given function to each value emitted by the DataSource. |
final @NonNull PositionalDataSource<@NonNull V> |
<V extends Object> mapByPage(Applies the given function to each value emitted by the DataSource. |
final @NonNull PositionalDataSource<@NonNull V> |
<V extends Object> mapByPage(Applies the given function to each value emitted by the DataSource. |
Inherited methods |
||||||
|---|---|---|---|---|---|---|
|
||||||
Public fields
isInvalid
@NonNull
public boolean isInvalid
| Returns | |
|---|---|
boolean |
|
Public constructors
PositionalDataSource
@NonNull
public final <T extends Object> PositionalDataSource()
| Parameters | |
|---|---|
<T extends Object> |
Type of items being loaded by the |
Public methods
loadInitial
@WorkerThread
@NonNull
public abstract @WorkerThread void loadInitial(
@NonNull PositionalDataSource.LoadInitialParams params,
@NonNull PositionalDataSource.LoadInitialCallback<@NonNull T> callback
)
Load initial list data.
This method is called to load the initial page(s) from the DataSource.
LoadResult list must be a multiple of pageSize to enable efficient tiling.
| Parameters | |
|---|---|
@NonNull PositionalDataSource.LoadInitialParams params |
Parameters for initial load, including requested start position, load size, and page size. |
@NonNull PositionalDataSource.LoadInitialCallback<@NonNull T> callback |
Callback that receives initial load data, including position and total data set size. |
loadRange
@WorkerThread
@NonNull
public abstract @WorkerThread void loadRange(
@NonNull PositionalDataSource.LoadRangeParams params,
@NonNull PositionalDataSource.LoadRangeCallback<@NonNull T> callback
)
Called to load a range of data from the DataSource.
This method is called to load additional pages from the DataSource after the LoadInitialCallback passed to dispatchLoadInitial has initialized a PagedList.
Unlike loadInitial, this method must return the number of items requested, at the position requested.
| Parameters | |
|---|---|
@NonNull PositionalDataSource.LoadRangeParams params |
Parameters for load, including start position and load size. |
@NonNull PositionalDataSource.LoadRangeCallback<@NonNull T> callback |
Callback that receives loaded data. |
map
@NonNull
public final PositionalDataSource<@NonNull V> <V extends Object> map(@NonNull Function<@NonNull T, @NonNull V> function)
Applies the given function to each value emitted by the DataSource.
Same as mapByPage, but operates on individual items.
| Parameters | |
|---|---|
@NonNull Function<@NonNull T, @NonNull V> function |
Function that runs on each loaded item, returning items of a potentially new type. |
| Returns | |
|---|---|
PositionalDataSource<@NonNull V> |
A new DataSource, which transforms items using the given function. |
map
@NonNull
public final PositionalDataSource<@NonNull V> <V extends Object> map(@NonNull Function1<@NonNull T, @NonNull V> function)
Applies the given function to each value emitted by the DataSource.
An overload of map that accepts a kotlin function type.
Same as mapByPage, but operates on individual items.
| Parameters | |
|---|---|
@NonNull Function1<@NonNull T, @NonNull V> function |
Function that runs on each loaded item, returning items of a potentially new type. |
| Returns | |
|---|---|
PositionalDataSource<@NonNull V> |
A new DataSource, which transforms items using the given function. |
mapByPage
@NonNull
public final PositionalDataSource<@NonNull V> <V extends Object> mapByPage(
@NonNull Function<@NonNull List<@NonNull T>, @NonNull List<@NonNull V>> function
)
Applies the given function to each value emitted by the DataSource.
Same as map, but allows for batch conversions.
| Parameters | |
|---|---|
@NonNull Function<@NonNull List<@NonNull T>, @NonNull List<@NonNull V>> function |
Function that runs on each loaded page, returning items of a potentially new type. |
| Returns | |
|---|---|
PositionalDataSource<@NonNull V> |
A new DataSource, which transforms items using the given function. |
mapByPage
@NonNull
public final PositionalDataSource<@NonNull V> <V extends Object> mapByPage(
@NonNull Function1<@NonNull List<@NonNull T>, @NonNull List<@NonNull V>> function
)
Applies the given function to each value emitted by the DataSource.
An overload of mapByPage that accepts a kotlin function type.
Same as map, but allows for batch conversions.
| Parameters | |
|---|---|
@NonNull Function1<@NonNull List<@NonNull T>, @NonNull List<@NonNull V>> function |
Function that runs on each loaded page, returning items of a potentially new type. |
| Returns | |
|---|---|
PositionalDataSource<@NonNull V> |
A new |