From aabc9bbbb2b533d7fbaa53ee94b8b2ac87f9e677 Mon Sep 17 00:00:00 2001 From: Fuyuxinge <1876397977@qq.com> Date: Thu, 14 May 2026 17:16:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AC=A1=E6=8F=90=E4=BA=A4=EF=BC=9A?= =?UTF-8?q?=E6=B3=9B=E5=9E=8B=E7=B1=BBJava=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kv.java | 31 +++++++++++++++++++++++++++++++ kv1.java | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 kv.java create mode 100644 kv1.java diff --git a/kv.java b/kv.java new file mode 100644 index 0000000..42ffdf1 --- /dev/null +++ b/kv.java @@ -0,0 +1,31 @@ +package w8; + +public class Pair { + private K key; + private V value; + + public Pair(K key, V value) { + this.key = key; + this.value = value; + } + + public Pair swap() { + return new Pair<>(this.value, this.key); + } + + public K getKey() { + return key; + } + + public void setKey(K key) { + this.key = key; + } + + public V getValue() { + return value; + } + + public void setValue(V value) { + this.value = value; + } +} diff --git a/kv1.java b/kv1.java new file mode 100644 index 0000000..3693f2e --- /dev/null +++ b/kv1.java @@ -0,0 +1,32 @@ +package w8; + +import java.util.HashMap; +import java.util.Map; + +public class Cache { + private final Map cacheMap; + + public Cache() { + cacheMap = new HashMap<>(); + } + + public void put(K key, V value) { + cacheMap.put(key, value); + } + + public V get(K key) { + return cacheMap.get(key); + } + + public void remove(K key) { + cacheMap.remove(key); + } + + public void clear() { + cacheMap.clear(); + } + + public int size() { + return cacheMap.size(); + } +} \ No newline at end of file