mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-09 08:32:07 -07:00
Timings v2
TODO: Add #isStopping to FullServerTickHandler#stopTiming in patch 191 expose isRunning
This commit is contained in:
39
paper-api/src/main/java/co/aikar/util/Counter.java
Normal file
39
paper-api/src/main/java/co/aikar/util/Counter.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package co.aikar.util;
|
||||
|
||||
import com.google.common.collect.ForwardingMap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public class Counter <T> extends ForwardingMap<T, Long> {
|
||||
private final Map<T, Long> counts = new HashMap<>();
|
||||
|
||||
public long decrement(@Nullable T key) {
|
||||
return increment(key, -1);
|
||||
}
|
||||
public long increment(@Nullable T key) {
|
||||
return increment(key, 1);
|
||||
}
|
||||
public long decrement(@Nullable T key, long amount) {
|
||||
return increment(key, -amount);
|
||||
}
|
||||
public long increment(@Nullable T key, long amount) {
|
||||
Long count = this.getCount(key);
|
||||
count += amount;
|
||||
this.counts.put(key, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
public long getCount(@Nullable T key) {
|
||||
return this.counts.getOrDefault(key, 0L);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Map<T, Long> delegate() {
|
||||
return this.counts;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user