org.simpleflatmapper.util.PredicatedEnumerable 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;
public class PredicatedEnumerable implements Enumerable {
private final Enumerable extends T> delegate;
private final Predicate super T> predicate;
public PredicatedEnumerable(Enumerable extends T> delegate, Predicate super T> predicate) {
if (delegate instanceof PredicatedEnumerable) {
PredicatedEnumerable pe = (PredicatedEnumerable) delegate;
this.delegate = pe.delegate;
this.predicate = new AndPredicate(pe.predicate, predicate);
} else {
this.delegate = delegate;
this.predicate = predicate;
}
}
@Override
public boolean next() {
while (delegate.next()) {
if (predicate.test(delegate.currentValue())) {
return true;
}
}
return false;
}
@Override
public T currentValue() {
return delegate.currentValue();
}
}