/** * Return total number of available elements. Doesn't return number of * elements within already fetched page. * * @see java.util.List#size() */ public int size() { return getPagedResult().getTotalResultCount(); }
public <T> T[] toArray(T[] a) { if (a.length < getPagedResult().getTotalResultCount()) { // a = (T[])java.lang.reflect.Array.newInstance( // a.getClass().getComponentType(), getPagedResult().getTotalResultCount()); //FIXME: GWT don't know java.lang.reflect :( throw new IllegalStateException("Provided array of size " + a.length + " is smaller than requested count " + getPagedResult().getTotalResultCount()); } Object[] result = a; for (int i = 0; i < getPagedResult().getTotalResultCount(); i++) result[i] = get(i); if (a.length > getPagedResult().getTotalResultCount()) a[getPagedResult().getTotalResultCount()] = null; return a; }
public Object[] toArray() { Object[] result = new Object[getPagedResult().getTotalResultCount()]; for (int i = 0; i < getPagedResult().getTotalResultCount(); i++) result[i] = get(i); return result; }
public int getLastPageNumber() { return getLastPageNumber(pagedResult.getTotalResultCount(), pagedResult.getPage().getPageSize()); }
/** * 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); }
public void get(final int index, final ICallback<E> callback) throws IndexOutOfBoundsException { if (index < 0) callback.onFailure(new IndexOutOfBoundsException("Index (" + index + ") shouldn't be less than 0")); if (isOutOfCachedPagedResult(index)) { int nearestStartIndex = getNearestIndexToPageSize(index, defaultPageSize); fetchPage(new Page(nearestStartIndex, defaultPageSize), new ICallback<Void>() { public void onFailure(Throwable caught) { callback.onFailure(caught); } public void onSuccess(Void result) { callback.onSuccess(getFromLoadedPageResult(index)); // System.out.println("fetch " + index); } }); } if (index >= getPagedResult().getTotalResultCount()) callback.onFailure(new IndexOutOfBoundsException("Index (" + index + ") shouldn't be greater than total number of elements.")); callback.onSuccess(getFromLoadedPageResult(index)); }