### Question:
SynchronizedHashMultiMap { public synchronized Optional<V> removeAny(K k) { Set<Pair<K, V>> set = map.getOrDefault(k.hashCode(), Collections.emptySet()); Optional<Pair<K, V>> pair = set.stream().filter(p -> p.getLeft().equals(k)).findAny(); pair.ifPresent(p -> set.remove(p)); return pair.map(p -> p.getRight()); }  synchronized void put(K k, V v); synchronized Optional<K> getAnyKey(); synchronized Optional<V> removeAny(K k); synchronized int removeIf(BiPredicate<K, V> predicate);  }### Answer:
@Test public void testRemoveAny() { SynchronizedHashMultiMap<Integer, Integer> map = new SynchronizedHashMultiMap<>(); Assert.assertFalse(map.removeAny(1).isPresent()); map.put(1, 2); map.put(1, 3); map.put(2, 4); map.put(2, 4); Optional<Integer> v = map.removeAny(1); int firstVal = v.get(); Assert.assertTrue(firstVal == 2 || firstVal == 3); v = map.removeAny(1); int secondVal = v.get(); Assert.assertTrue(secondVal == 2 || secondVal == 3); Assert.assertNotEquals(secondVal, firstVal); v = map.removeAny(2); Assert.assertTrue(v.isPresent()); Assert.assertEquals(v.get(), Integer.valueOf(4)); Assert.assertFalse(map.removeAny(1).isPresent()); Assert.assertFalse(map.removeAny(2).isPresent()); Assert.assertFalse(map.removeAny(3).isPresent()); }