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

org.kohsuke.github.PagedIterator Maven / Gradle / Ivy

There is a newer version: 2.0.0-alpha-2
Show newest version
package org.kohsuke.github;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * Iterator over a pagenated data source.
 *
 * Aside from the normal iterator operation, this method exposes {@link #nextPage()}
 * that allows the caller to retrieve items per page.
 *
 * @author Kohsuke Kawaguchi
 */
public abstract class PagedIterator implements Iterator {
    private final Iterator base;

    /**
     * Current batch that we retrieved but haven't returned to the caller.
     */
    private T[] current;
    private int pos;

    /*package*/ PagedIterator(Iterator base) {
        this.base = base;
    }

    protected abstract void wrapUp(T[] page);

    public boolean hasNext() {
        return (current!=null && pos nextPage() {
        fetch();
        List r = Arrays.asList(current);
        r = r.subList(pos,r.size());
        current = null;
        pos = 0;
        return r;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy