diff --git a/w8/AI协同文件.docx b/w8/AI协同文件.docx new file mode 100644 index 0000000..57fd58a Binary files /dev/null and b/w8/AI协同文件.docx differ diff --git a/w8/Cache.class b/w8/Cache.class new file mode 100644 index 0000000..1f06c5c Binary files /dev/null and b/w8/Cache.class differ diff --git a/w8/Pair.class b/w8/Pair.class new file mode 100644 index 0000000..224f92d Binary files /dev/null and b/w8/Pair.class differ diff --git a/w8/Pair.java b/w8/Pair.java new file mode 100644 index 0000000..05ac0ec --- /dev/null +++ b/w8/Pair.java @@ -0,0 +1,65 @@ +import java.util.HashMap; +import java.util.Map; + +public class Pair { + private K first; + private V second; + + public Pair(K first, V second) { + this.first = first; + this.second = second; + } + + public K getFirst() { + return first; + } + + public V getSecond() { + return second; + } + + public Pair swap() { + return new Pair<>(second, first); + } + + @Override + public String toString() { + return "Pair{" + first + ", " + second + "}"; + } +} + +class Cache { + private final Map cache; + + public Cache() { + this.cache = new HashMap<>(); + } + + 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 boolean containsKey(K key) { + return cache.containsKey(key); + } + + public int size() { + return cache.size(); + } + + public boolean isEmpty() { + return cache.isEmpty(); + } +} \ No newline at end of file