no.ssb.lds.api.persistence.TransactionStatistics Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of linked-data-store-persistence-provider-api Show documentation
Show all versions of linked-data-store-persistence-provider-api Show documentation
LinkedDataStore Persistence Provider API
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 +
'}';
}
}