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

no.ssb.lds.api.persistence.TransactionStatistics Maven / Gradle / Ivy

There is a newer version: 0.13
Show newest version
package no.ssb.lds.api.persistence;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

public class TransactionStatistics {
    final Map statistics = new ConcurrentHashMap<>();

    public TransactionStatistics add(String statistic, int increment) {
        statistics.computeIfAbsent(statistic, s -> new AtomicLong(0)).addAndGet(increment);
        return this;
    }

    public Map map() {
        Map result = new LinkedHashMap<>();
        for (Map.Entry e : statistics.entrySet()) {
            result.put(e.getKey(), e.getValue().get());
        }
        return result;
    }

    @Override
    public String toString() {
        return "TransactionStatistics{" +
                "statistics=" + statistics +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy