All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.phantomthief.collection.impl.LazyBufferTrigger Maven / Gradle / Ivy

There is a newer version: 0.2.5
Show newest version
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