com.github.phantomthief.collection.impl.LazyBufferTrigger Maven / Gradle / Ivy
package com.github.phantomthief.collection.impl;
import static com.github.phantomthief.util.MoreSuppliers.lazy;
import java.util.function.Supplier;
import com.github.phantomthief.collection.BufferTrigger;
import com.github.phantomthief.util.MoreSuppliers.CloseableSupplier;
/**
* @author w.vela
*/
public class LazyBufferTrigger implements BufferTrigger {
private final CloseableSupplier> factory;
LazyBufferTrigger(Supplier> factory) {
this.factory = lazy(factory);
}
@Override
public void enqueue(E element) {
this.factory.get().enqueue(element);
}
@Override
public void manuallyDoTrigger() {
this.factory.ifPresent(BufferTrigger::manuallyDoTrigger);
}
@Override
public long getPendingChanges() {
return this.factory.map(BufferTrigger::getPendingChanges).orElse(0L);
}
@Override
public void close() {
this.factory.ifPresent(BufferTrigger::close);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy