public final class AggregateUtil extends Object
类似于sql里面的 统计函数 (Aggregate functions)
Modifier and Type | Method and Description |
---|---|
static <O> Map<String,BigDecimal> |
avg(Iterable<O> beanIterable,
String[] propertyNames,
int scale)
算术平均值.
|
static <O> BigDecimal |
avg(Iterable<O> beanIterable,
String propertyName,
int scale)
算术平均值.
|
static <O> Map<String,Map<Object,Integer>> |
groupCount(Iterable<O> beanIterable,
String... propertyNames)
循环
beanIterable ,只选择符合 includePredicate 的对象,统计 propertyName 的值出现的次数. |
static <O,T> Map<T,Integer> |
groupCount(Iterable<O> beanIterable,
String propertyName)
循环
beanIterable ,统计 propertyName 的值出现的次数. |
static <O> Map<String,Map<Object,Integer>> |
groupCount(Iterable<O> beanIterable,
String[] propertyNames,
Map<String,Transformer<Object,Object>> propertyValueAndTransformerMap)
循环
beanIterable ,分别统计 propertyNames 的值出现的次数,统计的时候支持使用
propertyValueAndTransformerMap 属性值的转换. |
static <O> Map<String,Map<Object,Integer>> |
groupCount(Iterable<O> beanIterable,
String[] propertyNames,
Map<String,Transformer<Object,Object>> propertyValueAndTransformerMap,
Predicate<O> includePredicate)
循环
beanIterable ,只选择符合 includePredicate 的对象,分别统计 propertyNames 的值出现的次数,统计的时候支持使用
propertyValueAndTransformerMap 属性值的转换. |
static <O> Map<String,Map<Object,Integer>> |
groupCount(Iterable<O> beanIterable,
String[] propertyNames,
Predicate<O> includePredicate)
循环
beanIterable ,只选择符合 includePredicate 的对象,分别统计 propertyNames 的值出现的次数. |
static <O,T> Map<T,Integer> |
groupCount(Iterable<O> beanIterable,
String propertyName,
Predicate<O> includePredicate)
循环
beanIterable ,只选择符合 includePredicate 的对象,统计 propertyName 的值出现的次数. |
static <O,T> Map<T,BigDecimal> |
groupSum(Iterable<O> beanIterable,
String keyPropertyName,
String sumPropertyName)
迭代
beanIterable ,取元素 keyPropertyName 的值为 key ,累计 sumPropertyName 属性值 为 value,返回 map. |
static <O,T> Map<T,BigDecimal> |
groupSum(Iterable<O> beanIterable,
String keyPropertyName,
String sumPropertyName,
Predicate<O> includePredicate)
迭代
beanIterable ,提取符合 includePredicate 的元素,取元素 keyPropertyName 的值为 key ,累计
sumPropertyName 属性值 为 value,返回 map. |
static <O> Map<String,BigDecimal> |
sum(Iterable<O> beanIterable,
String... propertyNames)
总和,计算集合对象
beanIterable 内指定的属性名 propertyNames 值的总和. |
static <O> BigDecimal |
sum(Iterable<O> beanIterable,
String propertyName)
总和,计算集合对象
beanIterable 内指定的属性名 propertyName 值的总和. |
static <O> Map<String,BigDecimal> |
sum(Iterable<O> beanIterable,
String[] propertyNames,
Predicate<O> includePredicate)
迭代
beanIterable ,提取符合 includePredicate 的元素的指定 propertyNames 元素的值 ,累计总和. |
static <O> BigDecimal |
sum(Iterable<O> beanIterable,
String propertyName,
Predicate<O> includePredicate)
迭代
beanIterable ,提取 符合 includePredicate 的元素的指定 propertyName 元素的值 ,累计总和. |
public static <O> BigDecimal avg(Iterable<O> beanIterable, String propertyName, int scale)
场景: 求的User list 里面 id属性 的平均值
List返回: 4.00<User>
list = new ArrayList<>
(); list.add(new User(2L)); list.add(new User(5L)); list.add(new User(5L)); AggregateUtil.avg(list, "id", 2)
O
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等propertyName
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNamescale
- 标度,小数的位数,四舍五入,用于 BigDecimal.setScale(int, RoundingMode)
beanIterable
是null或者empty,返回 nullpropertyName
是null,抛出 NullPointerException
propertyName
是blank,抛出 IllegalArgumentException
sum(Iterable, String...)
public static <O> Map<String,BigDecimal> avg(Iterable<O> beanIterable, String[] propertyNames, int scale)
- 返回的
LinkedHashMap
,key是propertyNames
的元素,value是基于这个属性名称获得的值的平均值;key的顺序是依照propertyNames
元素的顺序
场景: 求的User list 里面 age 以及id属性 的平均值
User user1 = new User(2L); user1.setAge(18); User user2 = new User(3L); user2.setAge(30); List返回:<User>
list = toList(user1, user2); Map<String, BigDecimal>
map = AggregateUtil.avg(list, ConvertUtil.toArray("id", "age"), 2); LOGGER.info(JsonUtil.format(map));{ "id": 2.5, "age": 24 }
O
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等propertyNames
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNamescale
- 标度,小数的位数,四舍五入,用于 BigDecimal.setScale(int, RoundingMode)
beanIterable
是null或者empty,返回 Collections.emptyMap()
propertyNames
是null 抛出 NullPointerException
异常propertyNames
有元素是null 抛出 IllegalArgumentException
sum(Iterable, String...)
public static <O> BigDecimal sum(Iterable<O> beanIterable, String propertyName)
beanIterable
内指定的属性名 propertyName
值的总和.
- 如果通过反射某个元素值是null,则使用默认值0代替,再进行累加
List返回: 12<User>
list = new ArrayList<>
(); list.add(new User(2L)); list.add(new User(5L)); list.add(new User(5L)); LOGGER.info("" + AggregateUtil.sum(list, "id"));
当你需要写这样的代码的时候,
protected Integer getCookieShoppingCartLinesQty(List<CookieShoppingCartLine>
cartLineList){ Integer qty = 0; //获取cookie中的购物车行集合 if (null != cartLineList && cartLineList.size() > 0
){ for (Iterator iterator = cartLineList.iterator(); iterator.hasNext();){ CookieShoppingCartLine cookieShoppingCartLine = (CookieShoppingCartLine) iterator.next(); qty += cookieShoppingCartLine.getQuantity(); } } return qty; }你可以写成:
protected Integer getCookieShoppingCartLinesQty(List<CookieShoppingCartLine>
cartLineList){ return isNullOrEmpty(cartLineList) ? 0 : AggregateUtil.sum(cartLineList, "quantity").intValue(); }
O
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等propertyName
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNamebeanIterable
是null或者 empty,返回 nullpropertyName
是null,抛出 NullPointerException
propertyName
是blank,抛出 IllegalArgumentException
sum(Iterable, String...)
public static <O> BigDecimal sum(Iterable<O> beanIterable, String propertyName, Predicate<O> includePredicate)
beanIterable
,提取 符合 includePredicate
的元素的指定 propertyName
元素的值 ,累计总和.
- 如果通过反射某个元素值是null,则使用默认值0代替,再进行累加
场景: 统计user list(条件是 id
>
10),id属性值的总和List<User>
list = new ArrayList<>
(); list.add(new User(2L)); list.add(new User(50L)); list.add(new User(50L)); AggregateUtil.sum(list, "id", new Predicate<User>
(){@Override
public boolean evaluate(User user){ return user.getId()>
10L; } });返回: new BigDecimal(100L)
当然这段代码,你还可以优化成:
Predicate<Long>
predicate = new ComparatorPredicate<Long>
(10L, ComparatorUtils.<Long>
naturalComparator(), Criterion.LESS); BigDecimal sum = AggregateUtil.sum(list, "id", new BeanPredicate<User>
("id", predicate));
O
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等propertyName
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNameincludePredicate
- the include predicatebeanIterable
是null或者 empty,返回 nullpropertyName
是null,抛出 NullPointerException
propertyName
是blank,抛出 IllegalArgumentException
includePredicate
是null,那么迭代所有的元素beanIterable
没有符合 includePredicate
的元素,返回 null
sum(Iterable, String[], Predicate)
public static <O> Map<String,BigDecimal> sum(Iterable<O> beanIterable, String... propertyNames)
beanIterable
内指定的属性名 propertyNames
值的总和.
- 如果通过反射某个元素值是null,则使用默认值0代替,再进行累加
场景: 在user list 中,分别统计 id属性以及age属性值总和
User user1 = new User(2L); user1.setAge(18); User user2 = new User(3L); user2.setAge(30); Map返回:<String, BigDecimal>
map = AggregateUtil.sum(toList(user1, user2), "id", "age"); LOGGER.info(JsonUtil.format(map));{ "id": 5, "age": 48 }
O
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等propertyNames
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNamebeanIterable
是null或者empty,返回 Collections.emptyMap()
propertyNames
是null 抛出 NullPointerException
异常propertyNames
有元素是null 抛出 IllegalArgumentException
sum(Iterable, String[], Predicate)
public static <O> Map<String,BigDecimal> sum(Iterable<O> beanIterable, String[] propertyNames, Predicate<O> includePredicate)
beanIterable
,提取符合 includePredicate
的元素的指定 propertyNames
元素的值 ,累计总和.
User user1 = new User(10L); user1.setName("刘备"); user1.setAge(50); User user2 = new User(20L); user1.setName("关羽"); user2.setAge(50); User user3 = new User(100L); user3.setName("张飞"); user3.setAge(100); List返回:<User>
list = toList(user1, user2, user3); Map<String, BigDecimal>
map = AggregateUtil.sum(list, ConvertUtil.toArray("id", "age"), new Predicate<User>
(){@Override
public boolean evaluate(User user){ return !"张飞".equals(user.getName()); } }); LOGGER.debug(JsonUtil.format(map));{ "id": 30, "age": 100 }
O
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等propertyNames
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNameincludePredicate
- the include predicatebeanIterable
是null或者empty,返回 Collections.emptyMap()
includePredicate
是null,那么迭代所有的元素beanIterable
没有符合 includePredicate
的元素,返回 new LinkedHashMap
NullPointerException
- 如果propertyNames
是nullIllegalArgumentException
- 果propertyNames
有元素 是null public static <O,T> Map<T,BigDecimal> groupSum(Iterable<O> beanIterable, String keyPropertyName, String sumPropertyName)
beanIterable
,取元素 keyPropertyName
的值为 key ,累计 sumPropertyName
属性值 为 value,返回 map.
统计 user list 按照姓名分组, 累加每个人的 age 总和
ListassertThat:<User>
list = toList(// new User("张飞", 20), new User("关羽", 20), new User("刘备", 20), new User("刘备", 20)); Map<String, BigDecimal>
map = AggregateUtil.groupSum(list, "name", "age");assertThat( map, allOf(// hasEntry("刘备", toBigDecimal(40)), hasEntry("张飞", toBigDecimal(20)), hasEntry("关羽", toBigDecimal(20))));
O
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等keyPropertyName
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNamesumPropertyName
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNamebeanIterable
是null或者empty,返回 Collections.emptyMap()
keyPropertyName
是null,抛出 NullPointerException
keyPropertyName
是blank,抛出 IllegalArgumentException
sumPropertyName
是null,抛出 NullPointerException
sumPropertyName
是blank,抛出 IllegalArgumentException
public static <O,T> Map<T,BigDecimal> groupSum(Iterable<O> beanIterable, String keyPropertyName, String sumPropertyName, Predicate<O> includePredicate)
beanIterable
,提取符合 includePredicate
的元素,取元素 keyPropertyName
的值为 key ,累计
sumPropertyName
属性值 为 value,返回 map.
统计 user list 所有 age 小于等于30的, 按照姓名分组, 累加每个人的 age 总和
PredicateassertThat:<User>
comparatorPredicate = BeanPredicateUtil.comparatorPredicate("age", 30, Criterion.GREATER_OR_EQUAL); List<User>
list = toList(// new User("张飞", 20), new User("关羽", 20), new User("刘备", 20), new User("刘备", 50), new User("刘备", 20)); Map<String, BigDecimal>
map = AggregateUtil.groupSum(list, "name", "age",comparatorPredicate);
assertThat( map, allOf(// hasEntry("刘备", toBigDecimal(40)), hasEntry("张飞", toBigDecimal(20)), hasEntry("关羽", toBigDecimal(20))));
O
- the generic typeT
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等keyPropertyName
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNamesumPropertyName
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNameincludePredicate
- the include predicatebeanIterable
是null或者empty,返回 Collections.emptyMap()
includePredicate
是null,那么迭代所有的元素beanIterable
没有符合 includePredicate
的元素,返回 new LinkedHashMap
如果 keyPropertyName
是null,抛出 NullPointerException
keyPropertyName
是blank,抛出 IllegalArgumentException
sumPropertyName
是null,抛出 NullPointerException
sumPropertyName
是blank,抛出 IllegalArgumentException
public static <O,T> Map<T,Integer> groupCount(Iterable<O> beanIterable, String propertyName)
beanIterable
,统计 propertyName
的值出现的次数.
- 返回的
LinkedHashMap
,key是propertyName
对应的值,value是该值出现的次数;
顺序是beanIterable
propertyName
的值的顺序
场景: 统计user list,属性名字是name 的值的数量
List返回:<User>
list = new ArrayList<>
(); list.add(new User("张飞")); list.add(new User("关羽")); list.add(new User("刘备")); list.add(new User("刘备")); Map<String, Integer>
map = AggregateUtil.groupCount(list, "name"); LOGGER.info(JsonUtil.format(map));{ "张飞": 1, "关羽": 1, "刘备": 2 }
O
- the generic typeT
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等propertyName
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNamebeanIterable
是null或者empty,返回 Collections.emptyMap()
propertyName
是null,抛出 NullPointerException
propertyName
是blank,抛出 IllegalArgumentException
groupCount(Iterable , String, Predicate)
,
CollectionUtils.getCardinalityMap(Iterable)
public static <O,T> Map<T,Integer> groupCount(Iterable<O> beanIterable, String propertyName, Predicate<O> includePredicate)
beanIterable
,只选择符合 includePredicate
的对象,统计 propertyName
的值出现的次数.
- 返回的
LinkedHashMap
,key是propertyName
对应的值,value是该值出现的次数;
顺序是beanIterable
propertyName
的值的顺序
场景: 统计user list(条件是 age
>
30 的user),name属性值的数量List返回:<User>
list = new ArrayList<>
(); list.add(new User("张飞", 20)); list.add(new User("关羽", 30)); list.add(new User("刘备", 40)); list.add(new User("赵云", 50)); Map<String, Integer>
map = AggregateUtil.groupCount(list, "name", new Predicate<User>
(){@Override
public boolean evaluate(User user){ return user.getAge()>
30; } }); LOGGER.debug(JsonUtil.format(map));{ "刘备": 1, "赵云": 1 }
O
- the generic typeT
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等propertyName
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNameincludePredicate
- 只选择 符合 includePredicate
的对象,如果是null 则统计集合中全部的元素beanIterable
是null或者empty,返回 Collections.emptyMap()
propertyName
是null,抛出 NullPointerException
propertyName
是blank,抛出 IllegalArgumentException
includePredicate
是null,则统计集合中全部的元素CollectionUtils.getCardinalityMap(Iterable)
public static <O> Map<String,Map<Object,Integer>> groupCount(Iterable<O> beanIterable, String... propertyNames)
beanIterable
,只选择符合 includePredicate
的对象,统计 propertyName
的值出现的次数.
- 返回的
LinkedHashMap
,key是propertyName
名字,子map的key是propertyName
对应的值,value是该值出现的次数;
顺序是beanIterable
propertyName
的值的顺序
场景: 统计user list,属性名字是name 的值的数量 以及age值的数量
List返回:<User>
list = toList(// new User("张飞", 20), new User("关羽", 30), new User("赵云", 50), new User("刘备", 40), new User("刘备", 30), new User("赵云", 50)); Map<String, Map<Object, Integer>>
map = AggregateUtil.groupCount(list, toArray("name", "age")); LOGGER.debug(JsonUtil.format(map));{ "age": { "20": 1, "30": 2, "50": 2, "40": 1 }, "name": { "张飞": 1, "关羽": 1, "赵云": 2, "刘备": 2 } }
O
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等propertyNames
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNamebeanIterable
是null或者empty,返回 Collections.emptyMap()
propertyNames
是null,抛出 NullPointerException
propertyNames
是empty,抛出 IllegalArgumentException
propertyName
是null,抛出 NullPointerException
propertyName
是empty或者blank,抛出 IllegalArgumentException
String[] propertyNames
to String...propertyNames
Map<String, Map<T, Integer>>
to Map<String, Map<Object, Integer>>
CollectionUtils.getCardinalityMap(Iterable)
public static <O> Map<String,Map<Object,Integer>> groupCount(Iterable<O> beanIterable, String[] propertyNames, Predicate<O> includePredicate)
beanIterable
,只选择符合 includePredicate
的对象,分别统计 propertyNames
的值出现的次数.
- 返回的
LinkedHashMap
,key是propertyName
名字,子map的key是propertyName
对应的值,value是该值出现的次数;
顺序是beanIterable
propertyName
的值的顺序
场景: 统计user list(条件是 age
>
30 的user),name属性值的数量以及age 的数量List返回:<User>
list = toList(// new User("张飞", 20), new User("关羽", 30), new User("赵云", 50), new User("刘备", 40), new User("刘备", 30), new User("赵云", 50)); Predicate<User>
comparatorPredicate = BeanPredicateUtil.comparatorPredicate("age", 30, Criterion.LESS); Map<String, Map<Object, Integer>>
map = AggregateUtil.groupCount(list, toArray("name", "age"), comparatorPredicate); LOGGER.debug(JsonUtil.format(map));{ "age": { "50": 2, "40": 1 }, "name": { "赵云": 2, "刘备": 1 } }
O
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等propertyNames
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNameincludePredicate
- 只选择 符合 includePredicate
的对象,如果是null 则统计集合中全部的元素beanIterable
是null或者empty,返回 Collections.emptyMap()
propertyNames
是null,抛出 NullPointerException
propertyNames
是empty,抛出 IllegalArgumentException
propertyName
是null,抛出 NullPointerException
propertyName
是empty或者blank,抛出 IllegalArgumentException
includePredicate
是null,则统计集合中全部的元素Map<String, Map<T, Integer>>
to Map<String, Map<Object, Integer>>
CollectionUtils.getCardinalityMap(Iterable)
public static <O> Map<String,Map<Object,Integer>> groupCount(Iterable<O> beanIterable, String[] propertyNames, Map<String,Transformer<Object,Object>> propertyValueAndTransformerMap)
beanIterable
,分别统计 propertyNames
的值出现的次数,统计的时候支持使用
propertyValueAndTransformerMap
属性值的转换.
- 返回的
LinkedHashMap
,key是propertyName
名字,子map的key是propertyName
对应的值,value是该值出现的次数;
顺序是beanIterable
propertyName
的值的顺序
场景: 统计user list,name属性值的数量以及age 的数量,并且 age以范围区间统计
List返回:<User>
list = toList(// new User("张飞", 20), new User("关羽", 30), new User("刘备", 32), new User("刘备", 40), new User("赵云", 51), new User("赵云", 50)); Transformer<?, ?>
transformer = new Transformer<Integer, String>
(){ public String transform(Integer input){ if (input >= 50
){ return">=50"
; } if (input >= 30 && input < 50
){ return">=30&&<50"
; } if (input >= 20 && input < 30
){ return">=20&&<30"
; } throw new UnsupportedOperationException("value not support!"); } }; //--------------------------------------------------------------- Map<String, Transformer<Object, Object>>
propertyValueAndTransformerMap = toMap("age", (Transformer<Object, Object>
) transformer); //--------------------------------------------------------------- Map<String, Map<Object, Integer>>
map = AggregateUtil .groupCount(list, toArray("name", "age"), propertyValueAndTransformerMap); LOGGER.debug(JsonUtil.format(map));{ "name": { "张飞": 1, "关羽": 1, "刘备": 2, "赵云": 2 }, "age": {">=20&&<30"
: 1,">=30&&<50"
: 3,">=50"
: 2 } }
O
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等propertyNames
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNamepropertyValueAndTransformerMap
- the property name value converter mappropertyValueAndTransformerMap
是null或者empty,方法等于 groupCount(Iterable, String[], Predicate)
beanIterable
是null或者empty,返回 Collections.emptyMap()
propertyNames
是null,抛出 NullPointerException
propertyNames
是empty,抛出 IllegalArgumentException
propertyName
是null,抛出 NullPointerException
propertyName
是empty或者blank,抛出 IllegalArgumentException
CollectionUtils.getCardinalityMap(Iterable)
public static <O> Map<String,Map<Object,Integer>> groupCount(Iterable<O> beanIterable, String[] propertyNames, Map<String,Transformer<Object,Object>> propertyValueAndTransformerMap, Predicate<O> includePredicate)
beanIterable
,只选择符合 includePredicate
的对象,分别统计 propertyNames
的值出现的次数,统计的时候支持使用
propertyValueAndTransformerMap
属性值的转换.
- 返回的
LinkedHashMap
,key是propertyName
名字,子map的key是propertyName
对应的值,value是该值出现的次数;
顺序是beanIterable
propertyName
的值的顺序
场景: 统计user list(条件是 age
>
30 的user),name属性值的数量以及age 的数量,并且 age以范围区间统计List返回:<User>
list = toList(// new User("张飞", 20), new User("关羽", 30), new User("刘备", 32), new User("刘备", 40), new User("赵云", 51), new User("赵云", 50)); Transformer<?, ?>
transformer = new Transformer<Integer, String>
(){ public String transform(Integer input){ if (input >= 50
){ return">=50"
; } if (input >= 30 && input < 50
){ return">=30&&<50"
; } throw new UnsupportedOperationException("value not support!"); } }; //--------------------------------------------------------------- Map<String, Transformer<Object, Object>>
propertyValueAndTransformerMap = toMap("age", (Transformer<Object, Object>
) transformer); Predicate<User>
comparatorPredicate = BeanPredicateUtil.comparatorPredicate("age", 30, Criterion.LESS); //--------------------------------------------------------------- Map<String, Map<Object, Integer>>
map = AggregateUtil .groupCount(list, toArray("name", "age"), propertyValueAndTransformerMap, comparatorPredicate); LOGGER.debug(JsonUtil.format(map));{ "name": { "刘备": 2, "赵云": 2 }, "age": {">=30&&<50"
: 2,">=50"
: 2 } }
O
- the generic typebeanIterable
- bean Iterable,诸如List<User>
,Set<User>
等propertyNames
- 泛型O对象指定的属性名称,Possibly indexed and/or nested name of the property to be modified,参见
propertyNamepropertyValueAndTransformerMap
- the property name value converter mapincludePredicate
- 只选择 符合 includePredicate
的对象,如果是null 则统计集合中全部的元素propertyValueAndTransformerMap
是null或者empty,方法等于 groupCount(Iterable, String[], Predicate)
beanIterable
是null或者empty,返回 Collections.emptyMap()
propertyNames
是null,抛出 NullPointerException
propertyNames
是empty,抛出 IllegalArgumentException
propertyName
是null,抛出 NullPointerException
propertyName
是empty或者blank,抛出 IllegalArgumentException
includePredicate
是null,则统计集合中全部的元素CollectionUtils.getCardinalityMap(Iterable)
Copyright © 2008-2019 by feilong