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

org.reflections8.util.AbstractIterator Maven / Gradle / Ivy

There is a newer version: 0.11.7
Show newest version
package org.reflections8.util;

import java.util.Iterator;
import java.util.NoSuchElementException;

public abstract class AbstractIterator implements Iterator {

    private T tmp = null;

    private boolean endOfData = false;

    protected T endOfData() {
        endOfData = true;
        return null;
    }

    protected abstract T computeNext();

    public T next() {
        if (endOfData || !hasNext()) {
            throw new NoSuchElementException("nothing left");
        }
        T res = tmp;
        tmp = null;
        return res;
    }

    @Override
    public boolean hasNext() {
        if (tmp != null)
            return true;
        tmp = computeNext();
        return !endOfData;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy