You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
646 B
32 lines
646 B
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class Cache<K, V> {
|
|
private final Map<K, V> cache = new HashMap<>();
|
|
|
|
public void put(K key, V value) {
|
|
cache.put(key, value);
|
|
}
|
|
|
|
public V get(K key) {
|
|
return cache.get(key);
|
|
}
|
|
|
|
public void remove(K key) {
|
|
cache.remove(key);
|
|
}
|
|
|
|
public void clear() {
|
|
cache.clear();
|
|
}
|
|
|
|
public int size() {
|
|
return cache.size();
|
|
}
|
|
|
|
public void printAll() {
|
|
for (Map.Entry<K, V> entry : cache.entrySet()) {
|
|
System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue());
|
|
}
|
|
}
|
|
}
|