### Question:
LookupUtils { public static <T> List<ExactMatch<T>> removeSubsetsAndSmallerOverlaps(final List<ExactMatch<T>> exactMatches) { final List<ExactMatch<T>> exactMatchesFiltered = new ArrayList<>(); final List<ExactMatch<T>> exactMatchesSorted = new ArrayList<>(exactMatches); exactMatchesSorted.sort(COMPARE_EXACT_MATCH_BY_SIZE_DESC.thenComparing(COMPARE_EXACT_MATCH_BY_LOOKUP_START_ASC)); exactMatchesSorted.stream() .filter(current -> exactMatchesFiltered.stream() .allMatch(compared -> sequencesDoNotOverlap(current.lookupStart, current.lookupExclusiveEnd - 1, compared.lookupStart, compared.lookupExclusiveEnd - 1))) .forEach(exactMatchesFiltered::add); exactMatchesFiltered.sort(COMPARE_EXACT_MATCH_BY_LOOKUP_START_ASC); return exactMatchesFiltered; } private  LookupUtils(); static List<ExactMatch<T>> removeSubsetsAndSmallerOverlaps(final List<ExactMatch<T>> exactMatches); static final Comparator<ExactMatch<?>> COMPARE_EXACT_MATCH_BY_LOOKUP_OFFSET_DESC; static final Comparator<State<?>> COMPARE_STATE_BY_INDEX_DESC; static final Comparator<SuffixMatch<?>> COMPARE_SUFFIX_MATCH_BY_LOOKUP_OFFSET_DESC; static final Comparator<PrefixMatch<?>> COMPARE_PREFIX_MATCH_BY_LOOKUP_OFFSET_DESC; }### Answer:
@Test public void testManyOverlappingBoundaries() { List<ExactMatch<String>> exactMatches = LookupUtils.removeSubsetsAndSmallerOverlaps(Arrays.asList( exactMatch(1, 3), exactMatch(1, 2), exactMatch(1, 4), exactMatch(0, 4), exactMatch(4, 5), exactMatch(2, 3))); assertThat(exactMatches).hasSize(2); assertThat(exactMatches).containsExactlyInAnyOrder( exactMatch(0, 4), exactMatch(4, 5) ); }
@Test public void testOverlappingBoundariesBiggerSequenceOnRightSide() { List<ExactMatch<String>> exactMatches = LookupUtils.removeSubsetsAndSmallerOverlaps(Arrays.asList( exactMatch(3, 7), exactMatch(5, 10), exactMatch(3, 6))); assertThat(exactMatches).hasSize(1); assertThat(exactMatches).containsExactlyInAnyOrder( exactMatch(5, 10) ); }
@Test public void testOverlappingBoundariesBiggerSequenceOnLeftSide() { List<ExactMatch<String>> exactMatches = LookupUtils.removeSubsetsAndSmallerOverlaps(Arrays.asList( exactMatch(3, 7), exactMatch(5, 8), exactMatch(3, 6))); assertThat(exactMatches).hasSize(1); assertThat(exactMatches).containsExactlyInAnyOrder( exactMatch(3, 7) ); }
@Test public void testOverlappingBoundariesEquallySized() { List<ExactMatch<String>> exactMatches = LookupUtils.removeSubsetsAndSmallerOverlaps(Arrays.asList( exactMatch(0, 3), exactMatch(1, 4), exactMatch(2, 5), exactMatch(3, 6), exactMatch(4, 7), exactMatch(5, 8), exactMatch(6, 9))); assertThat(exactMatches).hasSize(3); assertThat(exactMatches).containsExactlyInAnyOrder( exactMatch(0, 3), exactMatch(3, 6), exactMatch(6, 9) ); }
@Test public void testNoOverlapWithSmoothCrossover() { List<ExactMatch<String>> exactMatches = LookupUtils.removeSubsetsAndSmallerOverlaps(Arrays.asList( exactMatch(0, 1), exactMatch(1, 2), exactMatch(2, 3))); assertThat(exactMatches).hasSize(3); }