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

cn.joylau.commons.utils.MapUtils Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2017 by JoyLau. All rights reserved
 ******************************************************************************/

package cn.joylau.commons.utils;


import java.util.*;
import java.util.function.Supplier;

public class MapUtils {

    public static boolean isNullOrEmpty(Map map) {
        return map == null || map.isEmpty();
    }

    public static Map removeEmptyValue(Map map) {
        Map newMap = new HashMap<>();
        if (map == null)
            return newMap;
        map.entrySet().stream().filter(entry -> !StringUtils.isNullOrEmpty(entry.getValue())).forEach(entry -> {
            newMap.put(entry.getKey(), entry.getValue());
        });
        return newMap;
    }

    public static  Map sortMapByKey(Map data) {
        Map data_ = new LinkedHashMap<>();
        List list = new LinkedList<>(data.keySet());
        Collections.sort(list);
        for (K k : list) {
            data_.put(k, data.get(k));
        }
        return data_;
    }

    public static  Map merge(Map map, Map maps) {
        return merge(new HashMap<>(), map, maps);
    }

    public static  Map merge(Map target, Map map, Map... maps) {
        target.putAll(map);
        for (int i = 0; i < maps.length; i++) {
            target.putAll(maps[i]);
        }
        return target;
    }

    public static  Map merge(Supplier> supplier, Map map, Map... maps) {
        return merge(supplier.get(), map, maps);
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy