Multiverse-Core/src/main/java/com/onarandombox/MultiverseCore/utils/metrics/MetricsHelper.java

34 lines
1.1 KiB
Java
Raw Normal View History

package com.onarandombox.MultiverseCore.utils.metrics;
2021-04-24 20:08:09 +02:00
import org.bstats.charts.AdvancedPie;
import org.bstats.charts.MultiLineChart;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
enum MetricsHelper {
;
/**
* Adds one to the value in the given map with the given key. If the key does not exist in the map, it will be added with a value of 1.
*/
static void incrementCount(Map<String, Integer> map, String key) {
Integer count = map.getOrDefault(key, 0);
map.put(key, count + 1);
}
2021-04-24 20:08:09 +02:00
static AdvancedPie createAdvancedPieChart(String chartId, Consumer<Map<String, Integer>> metricsFunc) {
Map<String, Integer> map = new HashMap<>();
metricsFunc.accept(map);
2021-04-24 20:08:09 +02:00
return new AdvancedPie(chartId, () -> map);
}
2021-04-24 20:08:09 +02:00
static MultiLineChart createMultiLineChart(String chartId, Consumer<Map<String, Integer>> metricsFunc) {
Map<String, Integer> map = new HashMap<>();
metricsFunc.accept(map);
2021-04-24 20:08:09 +02:00
return new MultiLineChart(chartId, () -> map);
}
}