按照指定字段分组,取非空属性最多的对象
public static List<Person> disposeFeedBacks(List<Person> persons) {
List<Person> personList = new ArrayList<>();
Map<String, List<Person>> personMap =
persons.stream().collect(Collectors.groupingBy(Person::getTelegramFlag));
for (Map.Entry<String, List<Person>> entry : personMap.entrySet()) {
Map<String, List<Person>> personMap1 =
personMap.get(entry.getKey()).stream().collect(Collectors.groupingBy(Person::getAge));
for(Map.Entry<String, List<Person>> entry1 : personMap1.entrySet()){
List<Person> list11 = personMap1.get(entry1.getKey()).stream().sorted(Comparator.comparing(Person::getNotNullNumber).reversed()).collect(Collectors.toList());
personList.add(list11.get(0));
}
}
return personList;
}
获取非空属性
private static String[] getNullPropertyNames(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<>();
for(java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue != null){ emptyNames.add(pd.getName());}
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
判断指定属性是否非空
public static List<String> getNullPropertyCount(String[] result){
List<String> resultList = new ArrayList<>();
Arrays.stream(result).forEach(p -> {
if("age".equals(p) || "sex".equals(p) || "name".equals(p) || "id".equals(p)){
resultList.add(p);
}
});
return resultList;
}