@Test public void initialPrefetch() { LazyList<User> lazyList = createLazyList(20, 20); assertNull(lazyList.get(9)); drain(); TestCountedDataSource.verifyRange(lazyList, 0, 40); }
@Override @Nullable public Type get(int index) { if (index < 0 || index >= mSize) { throw new IndexOutOfBoundsException(index + " is out of bounds. Size:" + mSize); } mLastAccessed = index; final boolean initialLoadComplete = mItems != null; int minTarget = Math.max(0, index - mConfig.mPrefetchDistance); int maxTarget = Math.min(mSize, index + mConfig.mPrefetchDistance); if (minTarget < mMissedMinIndex) { mMissedMinIndex = minTarget; if (initialLoadComplete) { loadBeforeIfNeeded(); } } if (maxTarget > mMissedMaxIndex) { mMissedMaxIndex = maxTarget; if (initialLoadComplete) { loadAfterIfNeeded(); } } if (initialLoadComplete) { return access(index); } else { triggerInitialLoad(getInitialLoadPositionFor(index)); return null; } }
LazyList extends PagerBase<Type> { @Override @Nullable public Type get(int index) { if (index < 0 || index >= mSize) { throw new IndexOutOfBoundsException(index + " is out of bounds. Size:" + mSize); } mLastAccessed = index; final boolean initialLoadComplete = mItems != null; int minTarget = Math.max(0, index - mConfig.mPrefetchDistance); int maxTarget = Math.min(mSize, index + mConfig.mPrefetchDistance); if (minTarget < mMissedMinIndex) { mMissedMinIndex = minTarget; if (initialLoadComplete) { loadBeforeIfNeeded(); } } if (maxTarget > mMissedMaxIndex) { mMissedMaxIndex = maxTarget; if (initialLoadComplete) { loadAfterIfNeeded(); } } if (initialLoadComplete) { return access(index); } else { triggerInitialLoad(getInitialLoadPositionFor(index)); return null; } } }
LazyList extends PagerBase<Type> { @Override @Nullable public Type get(int index) { if (index < 0 || index >= mSize) { throw new IndexOutOfBoundsException(index + " is out of bounds. Size:" + mSize); } mLastAccessed = index; final boolean initialLoadComplete = mItems != null; int minTarget = Math.max(0, index - mConfig.mPrefetchDistance); int maxTarget = Math.min(mSize, index + mConfig.mPrefetchDistance); if (minTarget < mMissedMinIndex) { mMissedMinIndex = minTarget; if (initialLoadComplete) { loadBeforeIfNeeded(); } } if (maxTarget > mMissedMaxIndex) { mMissedMaxIndex = maxTarget; if (initialLoadComplete) { loadAfterIfNeeded(); } } if (initialLoadComplete) { return access(index); } else { triggerInitialLoad(getInitialLoadPositionFor(index)); return null; } } @WorkerThread  LazyList(@NonNull CountedDataSource<Type> countedDataSource,
            @NonNull Executor mainThreadExecutor, @NonNull Executor backgroundThreadExecutor,
            @NonNull ListConfig config); }
LazyList extends PagerBase<Type> { @Override @Nullable public Type get(int index) { if (index < 0 || index >= mSize) { throw new IndexOutOfBoundsException(index + " is out of bounds. Size:" + mSize); } mLastAccessed = index; final boolean initialLoadComplete = mItems != null; int minTarget = Math.max(0, index - mConfig.mPrefetchDistance); int maxTarget = Math.min(mSize, index + mConfig.mPrefetchDistance); if (minTarget < mMissedMinIndex) { mMissedMinIndex = minTarget; if (initialLoadComplete) { loadBeforeIfNeeded(); } } if (maxTarget > mMissedMaxIndex) { mMissedMaxIndex = maxTarget; if (initialLoadComplete) { loadAfterIfNeeded(); } } if (initialLoadComplete) { return access(index); } else { triggerInitialLoad(getInitialLoadPositionFor(index)); return null; } } @WorkerThread  LazyList(@NonNull CountedDataSource<Type> countedDataSource,
            @NonNull Executor mainThreadExecutor, @NonNull Executor backgroundThreadExecutor,
            @NonNull ListConfig config); @Override @Nullable Type get(int index); @Override int size(); @Override @Nullable Type access(int index); int getInitialLoadPosition(); boolean internalInit(int loadAfterPos); @SuppressWarnings("WeakerAccess") void addCallback(ChangeCallback callback); @SuppressWarnings("WeakerAccess") void removeCallback(ChangeCallback callback); }
LazyList extends PagerBase<Type> { @Override @Nullable public Type get(int index) { if (index < 0 || index >= mSize) { throw new IndexOutOfBoundsException(index + " is out of bounds. Size:" + mSize); } mLastAccessed = index; final boolean initialLoadComplete = mItems != null; int minTarget = Math.max(0, index - mConfig.mPrefetchDistance); int maxTarget = Math.min(mSize, index + mConfig.mPrefetchDistance); if (minTarget < mMissedMinIndex) { mMissedMinIndex = minTarget; if (initialLoadComplete) { loadBeforeIfNeeded(); } } if (maxTarget > mMissedMaxIndex) { mMissedMaxIndex = maxTarget; if (initialLoadComplete) { loadAfterIfNeeded(); } } if (initialLoadComplete) { return access(index); } else { triggerInitialLoad(getInitialLoadPositionFor(index)); return null; } } @WorkerThread  LazyList(@NonNull CountedDataSource<Type> countedDataSource,
            @NonNull Executor mainThreadExecutor, @NonNull Executor backgroundThreadExecutor,
            @NonNull ListConfig config); @Override @Nullable Type get(int index); @Override int size(); @Override @Nullable Type access(int index); int getInitialLoadPosition(); boolean internalInit(int loadAfterPos); @SuppressWarnings("WeakerAccess") void addCallback(ChangeCallback callback); @SuppressWarnings("WeakerAccess") void removeCallback(ChangeCallback callback);  }