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);  }
@Test public void initial() { LazyList<User> lazyList = createLazyList(20, 5); assertNull(lazyList.get(0)); drain(); TestCountedDataSource.verifyRange(lazyList, 0, 20); lazyList = createLazyList(10, 5); assertNull(lazyList.get(0)); drain(); TestCountedDataSource.verifyRange(lazyList, 0, 10); }
@Test public void initialPrefetch() { LazyList<User> lazyList = createLazyList(20, 20); assertNull(lazyList.get(9)); drain(); TestCountedDataSource.verifyRange(lazyList, 0, 40); }
@Test public void initialPrefetchMultiple() { LazyList<User> lazyList = createLazyList(20, 90); lazyList.get(0); drain(); TestCountedDataSource.verifyRange(lazyList, 0, 100); }
@Test public void incrementalLoading() { LazyList<User> lazyList = createLazyList(20, 20); lazyList.get(0); drain(); TestCountedDataSource.verifyRange(lazyList, 0, 40); lazyList.get(39); drain(); TestCountedDataSource.verifyRange(lazyList, 0, 60); lazyList.get(41); drain(); TestCountedDataSource.verifyRange(lazyList, 0, 80); }