org.simpleflatmapper.util.EnumerableIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-util Show documentation
Show all versions of sfm-util Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
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");
}
}