BidiMultiMap extends HashMap<K, V> { public List<K> getKeys(V value) { return value2Keys.get(value); }  @Override V put(K key, V value); @Override boolean equals(Object o); @Override int hashCode(); List<K> getKeys(V value); @Override void clear();  }
@Test public void testGetKeys() { BidiMultiMap<String, String> map = new BidiMultiMap<String, String>(); map.put("A", "B"); map.put("B", "D"); map.put("C", "D"); assertEquals("B", map.get("A")); List<String> bs = map.getKeys("B"); assertEquals(1, bs.size()); assertEquals("A", bs.get(0)); assertEquals("D", map.get("B")); List<String> ds = map.getKeys("D"); assertEquals(2, ds.size()); assertEquals("B", ds.get(0)); assertEquals("C", ds.get(1)); assertEquals("D", map.get("C")); List<String> cs = map.getKeys("C"); assertNull(cs); map.clear(); assertNull(map.getKeys("B")); map.put("A", "C"); map.put("B", "C"); map.put("C", "D"); List<String> ab = map.getKeys("C"); for (String key : ab) { map.put(key, "D"); } assertEquals(3, map.size()); assertEquals("D", map.get("A")); assertEquals("D", map.get("B")); assertEquals("D", map.get("C")); List<String> abc = map.getKeys("D"); assertEquals(3, abc.size()); assertEquals("C", abc.get(0)); assertEquals("A", abc.get(1)); assertEquals("B", abc.get(2)); }