class 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();

}