From 21149f1fdd50e0c49dca7d550f19ddfe13d2923a Mon Sep 17 00:00:00 2001 From: Zhoutianyu <1941587995@qq.com> Date: Wed, 29 Apr 2026 18:32:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'w8'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w8 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 w8 diff --git a/w8 b/w8 new file mode 100644 index 0000000..36639ed --- /dev/null +++ b/w8 @@ -0,0 +1,31 @@ +public class Pair { + private K key; + private V value; + + public Pair(K key, V value) { + this.key = key; + this.value = value; + } + + public K getKey() { return key; } + public V getValue() { return value; } + + // swap:交换后原key变value,原value变key,返回新Pair + public Pair swap() { + return new Pair<>(value, key); + } +} + + +import java.util.concurrent.ConcurrentHashMap; + +public class Cache { + private final ConcurrentHashMap cache = new ConcurrentHashMap<>(); + + public void put(K key, V value) { cache.put(key, value); } + public V get(K key) { return cache.get(key); } + public V remove(K key) { return cache.remove(key); } + public void clear() { cache.clear(); } + public int size() { return cache.size(); } + public boolean containsKey(K key) { return cache.containsKey(key); } +} \ No newline at end of file