去重方法
單個字段為條件去重
/**
* 單字段去重
* @param jackpotList1 新集合
* @param jackpotList 需要去重的集合
* @return
*/
private List<Jackpot> distinctList1(List<Jackpot> jackpotList1, List<Jackpot> jackpotList) {
jackpotList1.addAll(jackpotList);
return jackpotList1.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Jackpot::getPrizeId))),ArrayList::new
)
);
}
多個字段為條件去重
/**
* 多字段去重
* @param jackpotList1 新集合
* @param jackpotList 需要去重的集合
* @return
*/
private List<Jackpot> distinctList(List<Jackpot> jackpotList1, List<Jackpot> jackpotList) {
jackpotList1.addAll(jackpotList);
return jackpotList1.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(jackpot -> jackpot.getMyOrderId() + ";" + jackpot.getPrizeId()))),ArrayList::new
)
);
}