com.redijedi.tapestry.internal.pagedloop.PagedSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redijedi-t5-components
Show all versions of redijedi-t5-components
A collection of components built specifically for Tapestry 5.
The newest version!
package com.redijedi.tapestry.internal.pagedloop;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Provides an {@link java.util.Iterable} implementation that will only iterate
* over the objects within the range provided when prepare() is called.
*
* @author torr
*
*/
public class PagedSource implements Iterable {
private List _source = new ArrayList();
private List _pageSource = new ArrayList();
private Integer _iterableSize;
public PagedSource(Iterable source) {
Iterator i = source.iterator();
while (i.hasNext()) {
_source.add(i.next());
}
System.out.println("Paging");
}
/**
* @return
* @see java.lang.Iterable#iterator()
*/
public Iterator iterator() {
return _pageSource.iterator();
}
public int getTotalRowCount() {
if (_iterableSize != null) {
return _iterableSize.intValue();
}
_iterableSize = 0;
Iterator> it = _source.iterator();
while (it.hasNext()) {
it.next();
_iterableSize++;
}
return _iterableSize.intValue();
}
public void prepare(int startIndex, int endIndex) {
for (int i = startIndex; i <= endIndex; i++) {
_pageSource.add(_source.get(i));
}
}
}