Open ldicandia opened 5 months ago
Buenas, queria saber si estaba bien hecho el ejercicio.
public class DoubleKeyHashMap<K1, K2, V> extends HashMap<Pair<K1, K2>, V> implements DoubleKeyMap<K1, K2, V> { @Override public boolean containsKey(K1 firstKey, K2 secondKey) { return this.containsKey(new Pair<>(firstKey, secondKey)); } @Override public V get(K1 firstKey, K2 secondKey) { return this.get(new Pair<>(firstKey, secondKey)); } @Override public void put(K1 firstKey, K2 secondKey, V value) { this.put(new Pair<>(firstKey, secondKey), value); } } public class Pair<T1, T2> { private final T1 value1; private final T2 value2; public Pair(T1 value1, T2 value2) { this.value1 = value1; this.value2 = value2; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; return Objects.equals(value1, pair.value1) && Objects.equals(value2, pair.value2); } @Override public int hashCode() { return Objects.hash(value1, value2); } }
Buenas, queria saber si estaba bien hecho el ejercicio.