-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLottoTicket.java
More file actions
43 lines (33 loc) · 1.35 KB
/
LottoTicket.java
File metadata and controls
43 lines (33 loc) · 1.35 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
package lotto.domain.ticket;
import lotto.domain.LottoNumber;
import java.util.List;
import java.util.stream.IntStream;
import static lotto.domain.LottoGameProperty.COUNT_OF_LOTTO_NUMBER;
public class LottoTicket {
private static final int BONUS_NUMBER_INDEX = 5;
private final List<LottoNumber> lottoNumbers;
public LottoTicket(final List<LottoNumber> lottoNumbers) {
validate(lottoNumbers);
this.lottoNumbers = lottoNumbers;
}
private void validate(final List<LottoNumber> lottoNumbers) {
if (lottoNumbers.size() != COUNT_OF_LOTTO_NUMBER) {
throw new IllegalArgumentException("로또티켓은 중복되지않은 6개의 로또숫자로 이루어져야합니다.");
}
}
public int getMatchCount(LottoTicket lottoTicket) {
return Math.toIntExact(IntStream.range(0, COUNT_OF_LOTTO_NUMBER)
.filter(index -> isSameLottoNumber(index, lottoTicket.lottoNumbers.get(index)))
.count());
}
private boolean isSameLottoNumber(int index, LottoNumber lottoNumber) {
return lottoNumbers.get(index).equals(lottoNumber);
}
public boolean hasBonusNumber(LottoNumber lottoNumber) {
return isSameLottoNumber(BONUS_NUMBER_INDEX, lottoNumber);
}
@Override
public String toString() {
return String.valueOf(lottoNumbers);
}
}