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

org.simpleflatmapper.util.EnumerableIterator Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 9.0.2
Show newest version
package org.simpleflatmapper.util;

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

public class EnumerableIterator implements Iterator {

    private final Enumerable enumerable;

    private boolean fetch = false;
    private boolean hasValue = false;

    public EnumerableIterator(Enumerable enumerable) {
        this.enumerable = enumerable;
    }

    @Override
    public boolean hasNext() {
        if (!fetch) {
            fetch();
        }
        return hasValue;
    }

    private void fetch() {
        hasValue = enumerable.next();
        fetch = true;
    }

    @Override
    public T next() {
        if (!fetch) {
            fetch();
        }

        if (hasValue) {
            fetch = false;
            hasValue = false;

            return enumerable.currentValue();
        } else {
            throw new NoSuchElementException();
        }
    }

    @Override
    public void remove() {
        throw new UnsupportedOperationException("remove");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy