org.simpleflatmapper.util.PredicatedEnumerable Maven / Gradle / Ivy
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();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy