bndtools.jareditor.internal.utils.CollectionUtil Maven / Gradle / Ivy
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 - 2024 Weber Informatics LLC | Privacy Policy