假设有集合A和集合B,集合A表示最新的配置,集合B表示原有的旧配置
public static <T> Map<String, List<T>> mergeCollection(List<T> resList,List<T> targetList){
Map<String, List<T>> resultMap = Maps.newHashMap();
List<T> preAddList = Collections.emptyList();
List<T> preDelList = Collections.emptyList();
if(CollUtil.isEmpty(resList)){
preDelList.addAll(targetList);
}
if(CollUtil.isEmpty(targetList)){
preAddList.addAll(targetList);
}
if(CollUtil.isNotEmpty(resList) && CollUtil.isNotEmpty(targetList)){
//获取交集
Collection<T> interactList = CollUtil.intersection(resList,targetList);
Collection<T> preAddData = CollUtil.disjunction(resList, interactList);
Collection<T> preDelData = CollUtil.disjunction(targetList, interactList);
preAddList.addAll(preAddData);
preDelList.addAll(preDelData);
}
resultMap.put(PRE_ADD_DATA,preAddList);
resultMap.put(PRE_DEL_DATA,preDelList);
return resultMap;
}