HotspotFunctions { @NotNull public static Map<VariantHotspot, HotspotAnnotation> mergeHotspotMaps(@NotNull List<Map<VariantHotspot, HotspotAnnotation>> maps) { Map<VariantHotspot, HotspotAnnotation> mergedMap = Maps.newTreeMap(new VariantHotspotComparator()); for (Map<VariantHotspot, HotspotAnnotation> map : maps) { for (Map.Entry<VariantHotspot, HotspotAnnotation> entry : map.entrySet()) { VariantHotspot hotspot = entry.getKey(); HotspotAnnotation newAnnotation = entry.getValue(); HotspotAnnotation currentAnnotation = mergedMap.get(hotspot); if (currentAnnotation != null) { mergedMap.put(hotspot, mergeHotspotAnnotations(currentAnnotation, newAnnotation)); } else { mergedMap.put(hotspot, newAnnotation); } } } return mergedMap; } private  HotspotFunctions(); @NotNull static Map<VariantHotspot, HotspotAnnotation> convertHotspotMap(@NotNull String source,
            @NotNull Map<? extends HotspotSourceEntry, List<VariantHotspot>> hotspotsPerEntry); @NotNull static Map<VariantHotspot, HotspotAnnotation> mergeHotspotMaps(@NotNull List<Map<VariantHotspot, HotspotAnnotation>> maps); @NotNull static HotspotAnnotation mergeHotspotAnnotations(@NotNull HotspotAnnotation annotation1,
            @NotNull HotspotAnnotation annotation2);  }
@Test public void canMergeHotspots() { String source1 = "source1"; String source2 = "source2"; VariantHotspot hotspot1 = ImmutableVariantHotspotImpl.builder().chromosome("1").position(10).ref("A").alt("T").build(); VariantHotspot hotspot2 = ImmutableVariantHotspotImpl.builder().chromosome("1").position(20).ref("A").alt("T").build(); HotspotAnnotation source1Annotation1 = new HotspotAnnotation(Sets.newHashSet(source1), "gene1", "transcript1", "annotation1"); HotspotAnnotation source1Annotation2 = new HotspotAnnotation(Sets.newHashSet(source1), "gene1", "transcript1", "annotation2"); HotspotAnnotation source2Annotation1 = new HotspotAnnotation(Sets.newHashSet(source2), "gene1", "transcript1", "annotation1"); Map<VariantHotspot, HotspotAnnotation> source1Map = Maps.newHashMap(); source1Map.put(hotspot1, source1Annotation1); source1Map.put(hotspot2, source1Annotation2); Map<VariantHotspot, HotspotAnnotation> source2Map = Maps.newHashMap(); source2Map.put(hotspot1, source2Annotation1); Map<VariantHotspot, HotspotAnnotation> mergedMap = HotspotFunctions.mergeHotspotMaps(Lists.newArrayList(source1Map, source2Map)); assertEquals(2, mergedMap.size()); HotspotAnnotation mergedAnnotation1 = mergedMap.get(hotspot1); assertEquals(Sets.newHashSet(source1, source2), mergedAnnotation1.sources()); HotspotAnnotation mergedAnnotation2 = mergedMap.get(hotspot2); assertEquals(Sets.newHashSet(source1), mergedAnnotation2.sources()); }