diff options
author | Cow <cow@volloeko.de> | 2020-07-28 00:12:36 +0200 |
---|---|---|
committer | Cow <cow@volloeko.de> | 2020-07-28 00:12:36 +0200 |
commit | b393636cb3f7e05ef8b34804eeb06357f1b9cfbe (patch) | |
tree | d754561fd2e2f09ac66f41b2645ac5f351c1cace /src/main/java/de/cowtipper/cowlection/handler/PlayerCache.java | |
parent | 023589c75ae72ddc5ff75fa7235bce4d102b2ad1 (diff) | |
download | Cowlection-b393636cb3f7e05ef8b34804eeb06357f1b9cfbe.tar.gz Cowlection-b393636cb3f7e05ef8b34804eeb06357f1b9cfbe.tar.bz2 Cowlection-b393636cb3f7e05ef8b34804eeb06357f1b9cfbe.zip |
Renamed package to match cowtipper.de
Diffstat (limited to 'src/main/java/de/cowtipper/cowlection/handler/PlayerCache.java')
-rw-r--r-- | src/main/java/de/cowtipper/cowlection/handler/PlayerCache.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/handler/PlayerCache.java b/src/main/java/de/cowtipper/cowlection/handler/PlayerCache.java new file mode 100644 index 0000000..2206473 --- /dev/null +++ b/src/main/java/de/cowtipper/cowlection/handler/PlayerCache.java @@ -0,0 +1,47 @@ +package de.cowtipper.cowlection.handler; + +import com.google.common.collect.EvictingQueue; +import de.cowtipper.cowlection.Cowlection; + +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 Cowlection main; + + public PlayerCache(Cowlection 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(); + } +} |