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.
65 lines
1.2 KiB
65 lines
1.2 KiB
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class Pair<K, V> {
|
|
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<V, K> swap() {
|
|
return new Pair<>(second, first);
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "Pair{" + first + ", " + second + "}";
|
|
}
|
|
}
|
|
|
|
class Cache<K, V> {
|
|
private final Map<K, V> 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();
|
|
}
|
|
}
|