All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy