com.neko233.config233.utils.MapUtilsForConfig233 Maven / Gradle / Ivy
package com.neko233.config233.utils;
import java.util.Collections;
import java.util.Map;
import java.util.function.BiFunction;
public class MapUtilsForConfig233 {
/**
* 合并所有 Map
*
* @param targetMap output
* @param mergeFunc 合并
* @param otherMapArray 其他 Map..
*/
public static Map mergeAll(Map targetMap,
BiFunction mergeFunc,
Map... otherMapArray
) {
if (targetMap == null) {
return Collections.emptyMap();
}
if (otherMapArray == null) {
return targetMap;
}
for (Map kvMap : otherMapArray) {
if (kvMap == null) {
continue;
}
for (Map.Entry entry : kvMap.entrySet()) {
K key = entry.getKey();
V value = entry.getValue();
targetMap.merge(key, value, mergeFunc);
}
}
return targetMap;
}
}