paging/common/src/main/java/androidx/paging/PositionalDataSource.java
@SuppressWarnings("WeakerAccess")
    public static int computeInitialLoadSize(@NonNull LoadInitialParams params,
            int initialLoadPosition, int totalCount) {
        return Math.min(totalCount - initialLoadPosition, params.requestedLoadSize);
    }
/**
     * Helper for computing an initial load size in
     * {@link #loadInitial(LoadInitialParams, LoadInitialCallback)} when total data set size can be
     * computed ahead of loading.
     * <p>
     * This function takes the requested load size, and bounds checks it against the value returned
     * by {@link #computeInitialLoadPosition(LoadInitialParams, int)}.
     * <p>
     * Example usage in a PositionalDataSource subclass:
     * <pre>
     * class ItemDataSource extends PositionalDataSource&lt;Item> {
     *     private int computeCount() {
     *         // actual count code here
     *     }
     *
     *     private List&lt;Item> loadRangeInternal(int startPosition, int loadCount) {
     *         // actual load code here
     *     }
     *
     *     {@literal @}Override
     *     public void loadInitial({@literal @}NonNull LoadInitialParams params,
     *             {@literal @}NonNull LoadInitialCallback&lt;Item> callback) {
     *         int totalCount = computeCount();
     *         int position = computeInitialLoadPosition(params, totalCount);
     *         int loadSize = computeInitialLoadSize(params, position, totalCount);
     *         callback.onResult(loadRangeInternal(position, loadSize), position, totalCount);
     *     }
     *
     *     {@literal @}Override
     *     public void loadRange({@literal @}NonNull LoadRangeParams params,
     *             {@literal @}NonNull LoadRangeCallback&lt;Item> callback) {
     *         callback.onResult(loadRangeInternal(params.startPosition, params.loadSize));
     *     }
     * }</pre>
     *
     * @param params Params passed to {@link #loadInitial(LoadInitialParams, LoadInitialCallback)},
     *               including page size, and requested start/loadSize.
     * @param initialLoadPosition Value returned by
     *                          {@link #computeInitialLoadPosition(LoadInitialParams, int)}
     * @param totalCount Total size of the data set.
     * @return Number of items to load.
     *
     * @see #computeInitialLoadPosition(LoadInitialParams, int)
     */
Helper for computing an initial load size in
#loadInitial(LoadInitialParams, LoadInitialCallback) when total data set size can be
computed ahead of loading.

This function takes the requested load size, and bounds checks it against the value returned
by  #computeInitialLoadPosition(LoadInitialParams, int).

Example usage in a PositionalDataSource subclass:

class ItemDataSource extends PositionalDataSource<Item> {
private int computeCount() {
actual count code here
}

private List<Item> loadRangeInternal(int startPosition, int loadCount) {
actual load code here
}

Override
public void loadInitial( NonNull LoadInitialParams params,
NonNull LoadInitialCallback<Item> callback) {
int totalCount = computeCount();
int position = computeInitialLoadPosition(params, totalCount);
int loadSize = computeInitialLoadSize(params, position, totalCount);
callback.onResult(loadRangeInternal(position, loadSize), position, totalCount);
}



@param params Params passed to  #loadInitial(LoadInitialParams, LoadInitialCallback),
including page size, and requested start/loadSize.
@param initialLoadPosition Value returned by
#computeInitialLoadPosition(LoadInitialParams, int)
@param totalCount Total size of the data set.
@return Number of items to load.


Helper for computing an initial load size in #loadInitial ( LoadInitialParams LoadInitialCallback ) when total data set size can be computed ahead of loading . This function takes the requested load size and bounds checks it against the value returned by #computeInitialLoadPosition ( LoadInitialParams int ) . Example usage in a PositionalDataSource subclass : class ItemDataSource extends PositionalDataSource<Item > { private int computeCount () { actual count code here } private List<Item > loadRangeInternal ( int startPosition int loadCount ) { actual load code here } Override public void loadInitial ( NonNull LoadInitialParams params NonNull LoadInitialCallback<Item > callback ) { int totalCount = computeCount () ; int position = computeInitialLoadPosition ( params totalCount ) ; int loadSize = computeInitialLoadSize ( params position totalCount ) ; callback . onResult ( loadRangeInternal ( position loadSize ) position totalCount ) ; } @param params Params passed to #loadInitial ( LoadInitialParams LoadInitialCallback ) including page size and requested start / loadSize . @param initialLoadPosition Value returned by #computeInitialLoadPosition ( LoadInitialParams int ) @param totalCount Total size of the data set . @return Number of items to load .
@SuppressWarnings("WeakerAccess")
    public static int computeInitialLoadSize(@NonNull LoadInitialParams params,
            int initialLoadPosition, int totalCount) {
        return Math.min(totalCount - initialLoadPosition, params.requestedLoadSize);
    }
@ SuppressWarnings ( "WeakerAccess" ) public static int computeInitialLoadSize ( @ NonNull LoadInitialParams params , int initialLoadPosition , int totalCount ) { return Math . min ( totalCount - initialLoadPosition , params . requestedLoadSize ) ; }
Helper for computing an initial load size in
 {@link #loadInitial(LoadInitialParams, LoadInitialCallback)} when total data set size can be
 computed ahead of loading.
Helper for computing an initial load size in { @link #loadInitial ( LoadInitialParams LoadInitialCallback ) } when total data set size can be computed ahead of loading .