
top.jfunc.common.utils.MapUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-utils Show documentation
Show all versions of common-utils Show documentation
common utils like IOUtil,StrUtil,HoldProcessor.etc.
The newest version!
package top.jfunc.common.utils;
import java.util.Map;
/**
* @author xiongshiyan at 2019/5/21 , contact me with email [email protected] or phone 15208384257
*/
public class MapUtil {
private MapUtil(){}
/**
* 判断一个map是否为空
* @param map map
* @return true if null or isEmpty
*/
public static boolean isEmpty(Map map){
return null == map || map.isEmpty();
}
/**
* 判断一个map是够非空
* @param map map
* @return true if not null and !isEmpty
*/
public static boolean notEmpty(Map map){
return !isEmpty(map);
}
/**
* 合并两个Map,如果一个为{@code null}就返回另外一个
* @param first 第一个
* @param second 第二个
* @param K
* @param V
* @return 合并后的Map
*/
public static MultiValueMap mergeMap(MultiValueMap first , MultiValueMap second){
if(null == first){
return second;
}
if(null == second){
return first;
}
second.forEachKeyValue(first::add);
return first;
}
/**
* 合并两个Map,如果一个为{@code null}就返回另外一个
* @param first 第一个
* @param second 第二个
* @param holdFirst 同样的key的时候first覆盖second的 if true
* @param K
* @param V
* @return 合并后的Map
*/
public static Map mergeMap(Map first , Map second , boolean holdFirst){
if(null == first){
return second;
}
if(null == second){
return first;
}
//保留第一个:同样的key的时候first覆盖second的
if(holdFirst){
first.forEach(second::put);
return second;
}else {
second.forEach(first::put);
return first;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy