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

bndtools.jareditor.internal.utils.CollectionUtil Maven / Gradle / Ivy

There is a newer version: 7.1.0
Show newest version
package bndtools.jareditor.internal.utils;

import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

public class CollectionUtil {
    public static  Map> invertMapOfCollection(Map> mapOfCollection) {
        Map> result = new TreeMap>();

        for (Entry> inputEntry : mapOfCollection.entrySet()) {
            K inputKey = inputEntry.getKey();
            Collection inputCollection = inputEntry.getValue();

            for (V inputValue : inputCollection) {
                Set resultSet = result.get(inputValue);
                if (resultSet == null) {
                    resultSet = new TreeSet();
                    result.put(inputValue, resultSet);
                }
                resultSet.add(inputKey);
            }
        }

        return result;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy