//videoList是根据条件从mongo中查出的一个集合
List<VideoTotal> videoList= mongoTemplate.find(query, VideoTotal.class, videoTotalcollection);
//map 是最终list分组后的 集合
Map<String,List<VideoTotal>> map = new HashMap<String,List<VideoTotal>>();
for (int i = 0;i < videoList.size(); i++) {
VideoTotal obj = videoList.get(i);
String key = obj.getVideoNum();
if (map.containsKey(key)) {
List<VideoTotal> lists = (List<VideoTotal>) map.get(key);
lists.add(obj);
} else {
List<VideoTotal> lists = new ArrayList<VideoTotal>();
lists.add(obj);
map.put(key, lists);
}
}
//根据userno属性去重方法
private static ArrayList<VideoTotal> removeUser(List<VideoTotal> users) {
Set<VideoTotal> set = new TreeSet<VideoTotal>(new Comparator<VideoTotal>(){
@Override
public int compare(VideoTotal o1, VideoTotal o2) {
return o1.getUserno().compareTo(o2.getUserno());
}
});
set.addAll(users);
return new ArrayList<VideoTotal>(set);
}