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
560 B
32 lines
560 B
package w8;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class Cache<K, V> {
|
|
private final Map<K, V> 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();
|
|
}
|
|
}
|