Misc code householding

- Checkstyle config: allow todo comments with issue number
- Create consistency tests across all classes, ensuring: unique class names, users of expiring collectors implement HasCleanup, non-private fields are only constants
- Fix tag replacement in PlayerListener for {DISPLAYNAME}
This commit is contained in:
ljacqu
2017-03-26 13:20:40 +02:00
parent 8cf7983027
commit 75f84945fc
9 changed files with 210 additions and 11 deletions
@@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit;
*/
public class ExpiringMap<K, V> {
protected final Map<K, ExpiringEntry<V>> entries = new ConcurrentHashMap<>();
private final Map<K, ExpiringEntry<V>> entries = new ConcurrentHashMap<>();
private long expirationMillis;
/**
@@ -105,6 +105,13 @@ public class ExpiringMap<K, V> {
return entries.isEmpty();
}
/**
* @return the internal map
*/
protected Map<K, ExpiringEntry<V>> getEntries() {
return entries;
}
/**
* Class holding a value paired with an expiration timestamp.
*
@@ -44,13 +44,13 @@ public class TimedCounter<K> extends ExpiringMap<K, Integer> {
* @param key the key to increment the counter for
*/
public void decrement(K key) {
ExpiringEntry<Integer> e = entries.get(key);
ExpiringEntry<Integer> e = getEntries().get(key);
if (e != null) {
if (e.getValue() <= 0) {
remove(key);
} else {
entries.put(key, new ExpiringEntry<>(e.getValue() - 1, e.getExpiration()));
getEntries().put(key, new ExpiringEntry<>(e.getValue() - 1, e.getExpiration()));
}
}
}
@@ -62,7 +62,7 @@ public class TimedCounter<K> extends ExpiringMap<K, Integer> {
*/
public int total() {
long currentTime = System.currentTimeMillis();
return entries.values().stream()
return getEntries().values().stream()
.filter(entry -> currentTime <= entry.getExpiration())
.map(ExpiringEntry::getValue)
.reduce(0, Integer::sum);