forked from next-step/java-lotto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WinningLottery.java
31 lines (25 loc) · 1.04 KB
/
WinningLottery.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package lottery;
import java.util.EnumMap;
import java.util.List;
import java.util.stream.Collectors;
public class WinningLottery extends Lottery {
public WinningLottery(List<LotteryNumber> lotteryNumbers) {
super(lotteryNumbers);
}
public LotteryResult createLotteryResult(List<Lottery> lotteries) {
return new LotteryResult(countEqualNumbers(lotteries), lotteries.size(), LotteryCompany.LOTTERY_PRICE);
}
private EnumMap<LotteryRank, Integer> countEqualNumbers(List<Lottery> lotteries) {
return new EnumMap<>(lotteries.stream()
.map(this::countEqualNumbers)
.filter(LotteryRank::isUsedRank)
.collect(Collectors.toMap(LotteryRank::getInstanceOfRank, value -> 1,
(existing, replacement) -> existing + 1)));
}
private int countEqualNumbers(Lottery lottery) {
return this.lotteryNumbers.stream()
.filter(lottery.lotteryNumbers::contains)
.mapToInt(lotteryNumber -> 1)
.sum();
}
}