sdmxdl.provider.px.drivers.CollectionUtil Maven / Gradle / Ivy
package sdmxdl.provider.px.drivers;
import nbbrd.design.MightBePromoted;
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;
@MightBePromoted
@lombok.experimental.UtilityClass
class CollectionUtil {
public static Map zip(Collection keys, Collection values) {
Map result = new HashMap<>();
Iterator keysIter = keys.iterator();
Iterator valuesIter = values.iterator();
for (int i = 0; i < keys.size(); i++) {
result.put(keysIter.next(), valuesIter.next());
}
return result;
}
public static Stream> indexedStreamOf(List list) {
return IntStream.range(0, list.size()).mapToObj(index -> new IndexedElement<>(index, list.get(index)));
}
@lombok.Value
public static class IndexedElement {
int index;
T element;
}
}