com.github.hdy.common.util.CollectionUtils Maven / Gradle / Ivy
package com.github.hdy.common.util;
import java.util.*;
/**
* Collection工具类
*
* @author 贺大爷
* @date 2019/6/25
*/
public class CollectionUtils {
/**
* 校验集合是否为空
*
* @param coll 入参
*
* @return boolean
*/
public static boolean isEmpty(Collection> coll) {
return (coll == null || coll.isEmpty());
}
/**
* 校验集合是否不为空
*
* @param coll 入参
*
* @return boolean
*/
public static boolean isNotEmpty(Collection> coll) {
return !isEmpty(coll);
}
/**
* 判断Map是否为空
*
* @param map 入参
*
* @return boolean
*/
public static boolean isEmpty(Map, ?> map) {
return (map == null || map.isEmpty());
}
/**
* 判断Map是否不为空
*
* @param map 入参
*
* @return boolean
*/
public static boolean isNotEmpty(Map, ?> map) {
return !isEmpty(map);
}
@SuppressWarnings({"rawtypes", "unchecked"})
public static Collection getDiffent(Collection collmax, Collection collmin) {
//使用LinkeList防止差异过大时,元素拷贝
Collection csReturn = new LinkedList();
Collection max = collmax;
Collection min = collmin;
//先比较大小,这样会减少后续map的if判断次数
if (collmax.size() < collmin.size()) {
max = collmin;
min = collmax;
}
//直接指定大小,防止再散列
Map