org.nlab.json.stream.matcher.EventMatcher Maven / Gradle / Ivy
package org.nlab.json.stream.matcher;
import java.util.function.Predicate;
import org.jooq.lambda.fi.util.function.CheckedFunction;
import org.nlab.json.stream.context.StreamContext;
public class EventMatcher implements CheckedFunction {
private final Predicate predicate;
private final CheckedFunction consumer;
public EventMatcher(Predicate predicate, CheckedFunction consumer) {
this.predicate = predicate;
this.consumer = consumer;
}
@Override
public Boolean apply(StreamContext staxContext) throws Throwable {
if (predicate.test(staxContext)) {
return consumer.apply(staxContext);
}
return true;
}
public Predicate getPredicate() {
return predicate;
}
public CheckedFunction getConsumer() {
return consumer;
}
}