com.github.dennisit.vplus.data.utils.CollectionUtils Maven / Gradle / Ivy
/*--------------------------------------------------------------------------
* Copyright (c) 2010-2020, Elon.su All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the elon developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Elon.su, you can also mail [email protected]
*--------------------------------------------------------------------------
*/
package com.github.dennisit.vplus.data.utils;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
import java.util.*;
import java.util.stream.Collectors;
/**
* Created by Elon.su on 17/5/29.
*/
public class CollectionUtils{
/**
* 集合是否为空
* @param coll 目标集合
* @return 不为空返回true
*/
public static boolean isNotEmpty(final Collection> coll){
return !isEmpty(coll);
}
/**
* 集合是否为空
* @param coll 目标集合
* @return 为空返回true
*/
public static boolean isEmpty(final Collection> coll){
return org.apache.commons.collections4.CollectionUtils.isEmpty(coll);
}
/**
* 进行map集合中相同元素的value值聚合
* @param target 目标Map
* @param multis 往目标Map上追加的多个Map
* @param 泛型约束Key
* @param 泛型约束Map
* @return 多个mapKey聚合后的结果, key相同的元素, value值进行合并
*/
public static Map> keyMerged(Map> target, Map>... multis){
Map> base = Optional.ofNullable(target).orElse(Maps.newHashMap());
// 待追加的多个map元素
List