package com.charego.freecellfx.util; import java.util.HashMap; import java.util.Map; /** * Maps a pair of coordinates to an object. * * @param the first coordinate * @param the second coordinate * @param the treasure */ public class DoubleKeyedMap { private Map> map = new HashMap<>(); public boolean contains(K1 firstKey, K2 secondKey) { return map.containsKey(firstKey) && map.get(firstKey).containsKey(secondKey); } public V get(K1 firstKey, K2 secondKey) { return map.get(firstKey).get(secondKey); } /** * Returns the old value if it exists, or null. */ public V put(K1 firstKey, K2 secondKey, V newValue) { if (!map.containsKey(firstKey)) { map.put(firstKey, new HashMap<>()); } return map.get(firstKey).put(secondKey, newValue); } }