### Question:
TopKConsumer implements Function<T, Integer> { public static <T> List<T> topK(List<T> items, int topK, Comparator<T> comparator) { TopKConsumer<T> consumer = new TopKConsumer<>(topK, comparator); items.forEach(consumer::apply); return consumer.list(); } @SuppressWarnings("unchecked")  TopKConsumer(int topK, Comparator<T> comparator); static List<T> topK(List<T> items, int topK, Comparator<T> comparator); static Stream<T> topK(Stream<T> items, int topK, Comparator<T> comparator); static TopKConsumer<SimilarityResult>[] initializeTopKConsumers(int length, int topK); Stream<T> stream(); List<T> list(); int apply(TopKConsumer<T> other); @Override Integer apply(final T item);  }### Answer:
@Test void testFindTopKHeap4() { Collection<Item> topItems = TopKConsumer.topK(asList(ITEM1, ITEM3, ITEM2, ITEM4), 4, Item::compareTo); assertEquals(asList(ITEM4,ITEM3,ITEM2,ITEM1),topItems); }
@Test void testFindTopKHeap2of4() { Collection<Item> topItems = TopKConsumer.topK(asList(ITEM2, ITEM4), 4, Item::compareTo); assertEquals(asList(ITEM4,ITEM2),topItems); }
@Test void testFindTopKHeap4of3() { Collection<Item> topItems = TopKConsumer.topK(asList(ITEM2, ITEM1, ITEM4, ITEM3), 3, Item::compareTo); assertEquals(asList(ITEM4,ITEM3,ITEM2),topItems); }
@Test void testFindTopKHeap() { Collection<Item> topItems = TopKConsumer.topK(asList(ITEM1, ITEM3, ITEM2, ITEM4), 2, Item::compareTo); assertEquals(asList(ITEM4,ITEM3),topItems); }
@Test void testFindTopKHeap2() { List<Item> topItems = TopKConsumer.topK(asList(ITEM1, ITEM3, ITEM2, ITEM4), 2, Item::compareTo); assertEquals(asList(ITEM4,ITEM3),topItems); }