TagGroupUtils { public static void addAll(@NonNull Map<String, Set<String>> lh, @NonNull Map<String, Set<String>> rh) { for (Map.Entry<String, Set<String>> entry : rh.entrySet()) { Set<String> tags = lh.get(entry.getKey()); if (tags == null) { tags = new HashSet<>(); lh.put(entry.getKey(), tags); } tags.addAll(entry.getValue()); } }  @NonNull static Map<String, Set<String>> union(@NonNull Map<String, Set<String>> lh, @NonNull Map<String, Set<String>> rh); static void addAll(@NonNull Map<String, Set<String>> lh, @NonNull Map<String, Set<String>> rh); static boolean containsAll(@NonNull Map<String, Set<String>> lh, @NonNull Map<String, Set<String>> rh); @NonNull static Map<String, Set<String>> intersect(@NonNull Map<String, Set<String>> lh, @NonNull Map<String, Set<String>> rh); @NonNull static Map<String, Set<String>> parseTags(@Nullable JsonValue value);  }
@Test public void testAddAll() { Map<String, Set<String>> tags = new HashMap<>(); Map<String, Set<String>> tagGroupsOne = new HashMap<>(); tagGroupsOne.put("shared-group", tagSet("cool", "awesome")); tagGroupsOne.put("unique-group", tagSet("nice", "amazing")); Map<String, Set<String>> tagGroupsTwo = new HashMap<>(); tagGroupsTwo.put("shared-group", tagSet("rad")); TagGroupUtils.addAll(tags, tagGroupsOne); assertEquals(tags, tagGroupsOne); TagGroupUtils.addAll(tags, tagGroupsTwo); assertEquals(tags, TagGroupUtils.union(tagGroupsOne, tagGroupsTwo)); }