net.yudichev.jiotty.common.lang.throttling.ThresholdGatedConsumerImpl Maven / Gradle / Ivy
package net.yudichev.jiotty.common.lang.throttling;
import javax.annotation.concurrent.NotThreadSafe;
import java.util.function.Consumer;
import static com.google.common.base.Preconditions.checkNotNull;
@NotThreadSafe
final class ThresholdGatedConsumerImpl implements ThresholdGatedConsumer {
private final Consumer delegate;
private final int threshold;
private int count;
ThresholdGatedConsumerImpl(int threshold, Consumer delegate) {
this.delegate = checkNotNull(delegate);
this.threshold = threshold;
}
@Override
public void accept(T t) {
if (count == threshold) {
delegate.accept(t);
}
count++;
}
@Override
public void reset() {
count = 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy