4 changed files with 65 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,65 @@ |
|||
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(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue