PositionalDataSource

public abstract class PositionalDataSource<T extends Object> extends DataSource

Object
   ↳ DataSource
     ↳ PositionalDataSource

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 PositionalDataSource.

Summary

Nested types

PositionalDataSource.LoadInitialCallback

Callback for loadInitial to return data, position, and count.

PositionalDataSource.LoadInitialParams

Holder object for inputs to loadInitial.

PositionalDataSource.LoadRangeCallback

Callback for PositionalDataSource loadRange to return data.

PositionalDataSource.LoadRangeParams

Holder object for inputs to loadRange.

Public constructors

Public methods

abstract @WorkerThread void

Load initial list data.

abstract @WorkerThread void

Called to load a range of data from the DataSource.

final @NonNull 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.

final @NonNull 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.

final @NonNull 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.

final @NonNull 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.

Inherited methods

From class DataSource
@AnyThread void

Add a callback to invoke when the DataSource is first invalidated.

@AnyThread void

Signal the data source to stop loading, and notify its callback.

@AnyThread void

Remove a previously added invalidate callback.

Public constructors

PositionalDataSource

public final <T extends Object> PositionalDataSource()
Parameters
<T extends Object>

Type of items being loaded by the PositionalDataSource.

Public methods