/**
* 得到优先级最高的集合
* @param list es查询结果
* @return
*/
public List<Group> getMaxPriorityGroup(List<Group> list) {
int maxPriority = list.stream().max((o1, o2) -> o1.getPriority() - o2.getPriority()).get().getPriority();
return list.stream().filter(x -> x.getPriority() == maxPriority).collect(Collectors.toList());
}



/**
* 跟据优先级排序,优先级相同的则随机
* @param campaignList es查询集合
* @return
*/
@Override
public List<EsCampaign> sortByPriority(List<EsCampaign> campaignList) {
if(campaignList.size()==0){
return campaignList;
}

Random random = new Random();
campaignList.stream().map(x -> {
x.setCampaignPriority(x.getCampaignPriority() * 1000 + random.nextInt(999));
return x;
}).collect(Collectors.toList());

campaignList.sort((EsCampaign a, EsCampaign b) -> b.getCampaignPriority() - a.getCampaignPriority());
    //list.parallelStream().sorted(Comparator.comparing(Group::getPriority)).collect(Collectors.toList()).forEach(System.out::println);另一种排序方法 。
    return campaignList;
}

public Map<String, List<Article>> groupByAuthor() { 
    return articles.stream()
        .collect(Collectors.groupingBy(Article::getAuthor));
}


posted on 2017-08-04 10:49  xuxu_dragon  阅读(191)  评论(0编辑  收藏  举报