Messages posted by bchi49
[Logo]
ICEsoft.org Forums: ICEfaces, ICEmobile, ICEpdf
[Search] Search   [Recent Topics] Recent Topics   [Groups] Home Page | www.icesoft.org  [Login] Login 
Messages posted by: bchi49  XML
Profile for bchi49 -> Messages posted by bchi49 [1]
Author Message
Here's a generic version, please review:



public class LazyLoadingList<E> extends AbstractList<E> {
private LazyLoadable<E> lazyObject;
private List<E> firstList;
private List<E> viewList;
private int currentPage = -1;
private int numResults;
private int pageSize;

public LazyLoadingList(LazyLoadable<E> lazyObject, int pageSize, int numResults) {
this.lazyObject = lazyObject;
this.numResults = numResults;
this.pageSize = pageSize;
}

@Override
public E get(int i) {
if (i < pageSize) {
if (firstList == null)
firstList = lazyObject.getUpdatedList(i, pageSize);
return (E)firstList.get(i);
}
int page = i / pageSize;
if (page != currentPage) {
currentPage = page;
viewList = lazyObject.getUpdatedList(i, pageSize);
}

return viewList.get(i % pageSize);
}

@Override
public int size() {
return numResults;
}

public void setNumResults(int numResults) {
this.numResults = numResults;
}

}







public interface LazyLoadable<E>
{
public List<E> getUpdatedList(int index, int pageSize);
}
 
Profile for bchi49 -> Messages posted by bchi49 [1]
Go to:   
Powered by JForum 2.1.7ice © JForum Team