### Question:
TopKConsumer implements Function<T, Integer> { public List<T> list() { List<T> list = Arrays.asList(heap); return count< topK ? list.subList(0,count) : 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 addingDuplicateItems() { TopKConsumer<Item> consumer = new TopKConsumer<>(1, Item::compareTo); asList(ITEM3, ITEM3, ITEM3).forEach(consumer::apply); assertThat(consumer.list(), contains(ITEM3)); }