void () { MostlySingularMultiMap<String, String> map = new MostlySingularMultiMap<>(); assertEquals(Collections.emptyList(), map.get("key")); assertEquals(Collections.emptyList(), map.get("otherKey")); assertEquals(Collections.emptyList(), map.get("multiKey")); map.add("key", "single"); assertEquals(Collections.singletonList("single"), map.get("key")); assertEquals(Collections.emptyList(), map.get("otherKey")); assertEquals(Collections.emptyList(), map.get("multiKey")); map.add("otherKey", "single"); assertEquals(Collections.singletonList("single"), map.get("otherKey")); assertEquals(Collections.singletonList("single"), map.get("key")); assertEquals(Collections.emptyList(), map.get("multiKey")); map.add("multiKey", "multi1"); assertEquals(Collections.singletonList("multi1"), map.get("multiKey")); assertEquals(Collections.singletonList("single"), map.get("key")); assertEquals(Collections.singletonList("single"), map.get("otherKey")); map.add("multiKey", "multi2"); assertEquals(List.of("multi1", "multi2"), map.get("multiKey")); assertEquals(Collections.singletonList("single"), map.get("key")); assertEquals(Collections.singletonList("single"), map.get("otherKey")); map.add("multiKey", "multi3"); assertEquals(List.of("multi1", "multi2", "multi3"), map.get("multiKey")); assertEquals(Collections.singletonList("single"), map.get("key")); assertEquals(Collections.singletonList("single"), map.get("otherKey")); map.remove("multiKey", "multi1"); assertEquals(List.of("multi2", "multi3"), map.get("multiKey")); assertEquals(Collections.singletonList("single"), map.get("key")); assertEquals(Collections.singletonList("single"), map.get("otherKey")); for (int i = 4; i < 24; i++) { map.add("multiKey", "multi" + i); } assertEquals(2 + 20, ContainerUtil.newArrayList(map.get("multiKey")).size()); assertEquals(2 + 20, map.valuesForKey("multiKey")); assertThat(ContainerUtil.newArrayList(map.get("multiKey"))).contains("multi10"); assertEquals(Collections.singletonList("single"), map.get("key")); assertEquals(1, map.valuesForKey("key")); assertEquals(Collections.singletonList("single"), map.get("otherKey")); assertEquals(1, map.valuesForKey("otherKey")); for (int i = 23; i >= 4; i--) { map.remove("multiKey", "multi" + i); } assertEquals(List.of("multi2", "multi3"), map.get("multiKey")); assertEquals(Collections.singletonList("single"), map.get("key")); assertEquals(Collections.singletonList("single"), map.get("otherKey")); assertTrue(map.removeAllValues("key")); assertEquals(Collections.emptyList(), map.get("key")); assertEquals(Collections.singletonList("single"), map.get("otherKey")); assertEquals(List.of("multi2", "multi3"), map.get("multiKey")); assertFalse(map.removeAllValues("key")); assertTrue(map.removeAllValues("otherKey")); assertEquals(Collections.emptyList(), map.get("key")); assertEquals(Collections.emptyList(), map.get("otherKey")); assertEquals(List.of("multi2", "multi3"), map.get("multiKey")); assertTrue(map.removeAllValues("multiKey")); assertEquals(Collections.emptyList(), map.get("key")); assertEquals(Collections.emptyList(), map.get("otherKey")); assertEquals(Collections.emptyList(), map.get("multiKey")); }