### Question:
CollectionUtil { public static <T> Stream<IntObjectPair<T>> enumerate(Collection<T> items) { int size = items.size(); if (items instanceof List && items instanceof RandomAccess) { List<T> list = (List<T>) items; return IntStream .range(0, size) .mapToObj(idx -> PrimitiveTuples.pair(idx, list.get(idx))); } AtomicInteger index = new AtomicInteger(); return items.stream().map(item -> PrimitiveTuples.pair(index.getAndIncrement(), item)); } private  CollectionUtil(); static Stream<IntObjectPair<T>> enumerate(Collection<T> items);  }### Answer:
@Test void testEnumerateEmptyList() { List<IntObjectPair<Long>> pairs = CollectionUtil .<Long>enumerate(emptyList()) .collect(Collectors.toList()); assertEquals(emptyList(), pairs); }
@Test void testEnumerateSomeCollection() { Collection<Long> items = LazyBatchCollection.of(42, 1, (start, length) -> start); List<IntObjectPair<Long>> pairs = CollectionUtil .enumerate(items) .collect(Collectors.toList()); assertEquals(42, pairs.size()); for (IntObjectPair<Long> pair : pairs) { assertEquals(pair.getOne(), pair.getTwo()); } }