All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.redijedi.tapestry.internal.pagedloop.PagedSource Maven / Gradle / Ivy

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));
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy