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

com.neko233.config233.utils.MapUtilsForConfig233 Maven / Gradle / Ivy

There is a newer version: 0.1.8
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy