forked from next-step/java-lotto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLottoTicket.java
More file actions
48 lines (36 loc) · 1.26 KB
/
LottoTicket.java
File metadata and controls
48 lines (36 loc) · 1.26 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package step2.domain;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
public class LottoTicket {
private final List<Integer> lottoTicket;
public LottoTicket(List<Integer> lottoTicket) {
validInputNumber(lottoTicket);
this.lottoTicket = lottoTicket;
}
public LottoTicket(Set<Integer> numbers) {
validInputNumber(numbers);
lottoTicket = new ArrayList<>(numbers);
}
private static void validInputNumber(Collection<Integer> numbers) {
if (numbers.size() != LottoCommonValue.DEFAULT_LOTTO_NUMBER_COUNT.value()) {
throw new IllegalArgumentException(numbers + " : 입력한 숫자를 확인해 주세요");
}
}
public boolean isContain(Integer number) {
return this.lottoTicket.contains(number);
}
public Rank checkLottoTicket(LottoTicket winningTicket, int bonusNumber) {
int count = (int) lottoTicket.stream()
.filter(i -> winningTicket.isContain(i))
.count();
if(count == 5 && isContain(bonusNumber)) {
return Rank.SECOND;
}
return Rank.toPrizeMoney(count);
}
public String printTicket() {
return lottoTicket.toString();
}
}