HotspotFunctions { @NotNull public static Map<VariantHotspot, HotspotAnnotation> convertHotspotMap(@NotNull String source, @NotNull Map<? extends HotspotSourceEntry, List<VariantHotspot>> hotspotsPerEntry) { Map<VariantHotspot, HotspotAnnotation> convertedMap = Maps.newTreeMap(new VariantHotspotComparator()); for (Map.Entry<? extends HotspotSourceEntry, List<VariantHotspot>> entry : hotspotsPerEntry.entrySet()) { HotspotSourceEntry sourceEntry = entry.getKey(); for (VariantHotspot hotspot : entry.getValue()) { HotspotAnnotation newAnnotation = new HotspotAnnotation(Sets.newHashSet(source), sourceEntry.gene(), sourceEntry.transcript(), sourceEntry.proteinAnnotation()); HotspotAnnotation currentAnnotation = convertedMap.get(hotspot); if (currentAnnotation != null) { LOGGER.debug("Annotation '{}' already found previously: '{}'", newAnnotation, currentAnnotation); convertedMap.put(hotspot, mergeHotspotAnnotations(currentAnnotation, newAnnotation)); } else { convertedMap.put(hotspot, newAnnotation); } } } return convertedMap; } 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 canConvertHotspots() { TestHotspotSourceEntry entry1 = new TestHotspotSourceEntry("gene1", null, "annotation1"); TestHotspotSourceEntry entry2 = new TestHotspotSourceEntry("gene1", "transcript1", "annotation2"); Map<TestHotspotSourceEntry, List<VariantHotspot>> map = Maps.newHashMap(); VariantHotspot hotspot1 = ImmutableVariantHotspotImpl.builder().chromosome("1").position(10).ref("AA").alt("TT").build(); VariantHotspot hotspot2 = ImmutableVariantHotspotImpl.builder().chromosome("1").position(11).ref("A").alt("T").build(); VariantHotspot hotspot3 = ImmutableVariantHotspotImpl.builder().chromosome("1").position(10).ref("AA").alt("TT").build(); map.put(entry1, Lists.newArrayList(hotspot1, hotspot2)); map.put(entry2, Lists.newArrayList(hotspot3)); String source = "source"; Map<VariantHotspot, HotspotAnnotation> converted = HotspotFunctions.convertHotspotMap(source, map); assertEquals(2, converted.size()); HotspotAnnotation annotation1 = converted.get(hotspot1); assertEquals("gene1", annotation1.gene()); assertEquals("transcript1", annotation1.transcript()); assertEquals("annotation2", annotation1.proteinAnnotation()); assertEquals(Sets.newHashSet(source), annotation1.sources()); HotspotAnnotation annotation2 = converted.get(hotspot2); assertEquals("gene1", annotation2.gene()); assertNull(annotation2.transcript()); assertEquals("annotation1", annotation2.proteinAnnotation()); assertEquals(Sets.newHashSet(source), annotation2.sources()); }