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

org.mydotey.util.DataBuffer Maven / Gradle / Ivy

The newest version!
package org.mydotey.util;

import java.util.Objects;
import java.util.function.Consumer;

/**
 * @author koqizhao
 *
 * Jul 25, 2018
 */
public class DataBuffer extends TimeSequenceCircularBuffer> {

    public DataBuffer(DataBufferConfig bufferConfig) {
        super(bufferConfig);
    }

    @Override
    public DataBufferConfig getConfig() {
        return (DataBufferConfig) super.getConfig();
    }

    @Override
    protected DataBucket newBucket(long startTime, long ttl) {
        return new DataBucket(startTime, ttl, getConfig().getBucketCapacity());
    }

    public void add(T data) {
        getCurrentBucket().add(data);
    }

    public void consume(Consumer consumer) {
        Objects.requireNonNull(consumer, "consumer is null");

        forEach(bucket -> {
            for (int i = 0; i < bucket.count(); i++) {
                T item = bucket.get(i);
                if (item == null)
                    continue;
                consumer.accept(item);
            }
        });
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy