/** * @return A page for current paged results. Don't modify it ! */ public final Page getCurrentPage() { return pagedResult.getPage(); }
public int getCurrentPageNumber() { return getCurrentPageNumber(pagedResult.getPage()); }
/** * @return Index of the last result in cached paged results. */ protected int getEndIndex() { return pagedResult.getPage().getStartIndex() + pagedResult.getResult().size() - 1; }
/** * Forces list to invalidate its current fetched page and fetch again. */ public void reload(final ICallback<Void> callback) { Page page = (pagedResult == null ? new Page(0, defaultPageSize) : pagedResult.getPage()); fetchPage(page, callback); }
public int getLastPageNumber() { return getLastPageNumber(pagedResult.getTotalResultCount(), pagedResult.getPage().getPageSize()); }
/** * @param index * Index of requested result within range of total available * number of results in data source. * @return True if index is out of cached paged result range. */ protected boolean isOutOfCachedPagedResult(int index) { return !(index >= getPagedResult().getPage().getStartIndex() && index <= getEndIndex()); }
private E getFromLoadedPageResult(int index) { int fetchIndex = index % getPagedResult().getPage().getPageSize(); // System.out.println("get " + index); return getPagedResult().getResult().get(fetchIndex); }
/** * Returns element directly if it is within fetched (cached) page, else throw exception. * * @see java.util.List#get(int) */ public E get(int index) throws IndexOutOfBoundsException { if (index < 0) throw new IndexOutOfBoundsException("Index (" + index + ") shouldn't be less than 0"); if (isOutOfCachedPagedResult(index)) { throw new IndexOutOfBoundsException( "Index should be within range <" + getPagedResult().getPage().getStartIndex() + " ; " + getEndIndex() + ">"); } int fetchIndex = index % getPagedResult().getPage().getPageSize(); // System.out.println("get " + index); return getPagedResult().getResult().get(fetchIndex); }
/** * Returns element directly if it is within fetched page, else fetch a new * page if available. * * @see java.util.List#get(int) */ public E get(int index) throws IndexOutOfBoundsException { if (index < 0) throw new IndexOutOfBoundsException("Index (" + index + ") shouldn't be less than 0"); if (isOutOfCachedPagedResult(index)) { int nearestStartIndex = getNearestIndexToPageSize(index, defaultPageSize); fetchPage(new Page(nearestStartIndex, defaultPageSize)); // System.out.println("fetch " + index); } if (index >= getPagedResult().getTotalResultCount()) throw new IndexOutOfBoundsException("Index (" + index + ") shouldn't be greater than total number of elements."); int fetchIndex = index % getPagedResult().getPage().getPageSize(); // System.out.println("get " + index); return getPagedResult().getResult().get(fetchIndex); }