aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/eu/olli/cowmoonication/handler/PlayerCache.java
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2020-05-04 13:25:39 +0200
committerCow <cow@volloeko.de>2020-05-04 13:25:39 +0200
commit4d45e0bc9afacc8408295aef50b8fd6530f97104 (patch)
treec06e0f2ffbf8c1fc697ee468b4a1e2bf85ee1a45 /src/main/java/eu/olli/cowmoonication/handler/PlayerCache.java
parent6f33fc424111ce46dcabd85f214db68f4ddc8b9d (diff)
downloadCowlection-4d45e0bc9afacc8408295aef50b8fd6530f97104.tar.gz
Cowlection-4d45e0bc9afacc8408295aef50b8fd6530f97104.tar.bz2
Cowlection-4d45e0bc9afacc8408295aef50b8fd6530f97104.zip
Re-organized packages and files
Diffstat (limited to 'src/main/java/eu/olli/cowmoonication/handler/PlayerCache.java')
-rw-r--r--src/main/java/eu/olli/cowmoonication/handler/PlayerCache.java47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/main/java/eu/olli/cowmoonication/handler/PlayerCache.java b/src/main/java/eu/olli/cowmoonication/handler/PlayerCache.java
new file mode 100644
index 0000000..fd1062d
--- /dev/null
+++ b/src/main/java/eu/olli/cowmoonication/handler/PlayerCache.java
@@ -0,0 +1,47 @@
+package eu.olli.cowmoonication.handler;
+
+import com.google.common.collect.EvictingQueue;
+import eu.olli.cowmoonication.Cowmoonication;
+
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+public class PlayerCache {
+ @SuppressWarnings("UnstableApiUsage")
+ private final EvictingQueue<String> nameCache = EvictingQueue.create(50);
+ @SuppressWarnings("UnstableApiUsage")
+ private final EvictingQueue<String> bestFriendCache = EvictingQueue.create(50);
+ private final Cowmoonication main;
+
+ public PlayerCache(Cowmoonication main) {
+ this.main = main;
+ }
+
+ public void add(String name) {
+ // remove old entry (if exists) to 'push' name to the end of the queue
+ nameCache.remove(name);
+ nameCache.add(name);
+ }
+
+ public void addBestFriend(String name) {
+ // remove old entry (if exists) to 'push' name to the end of the queue
+ bestFriendCache.remove(name);
+ bestFriendCache.add(name);
+ }
+
+ public void removeBestFriend(String name) {
+ bestFriendCache.remove(name);
+ }
+
+ public SortedSet<String> getAllNamesSorted() {
+ SortedSet<String> nameList = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+ nameList.addAll(bestFriendCache);
+ nameList.addAll(nameCache);
+ return nameList;
+ }
+
+ public void clearAllCaches() {
+ nameCache.clear();
+ bestFriendCache.clear();
+ }
+}