forked from next-step/java-lotto
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLottoTicketGenerator.java
More file actions
53 lines (41 loc) · 1.41 KB
/
LottoTicketGenerator.java
File metadata and controls
53 lines (41 loc) · 1.41 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
49
50
51
52
53
package lotto.domain;
import static lotto.domain.LottoTicket.MAX_LOTTO_NUMBER;
import static lotto.domain.LottoTicket.MIN_LOTTO_NUMBER;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class LottoTicketGenerator {
/**
* 자동 로또 번호를 생성하고 반환합니다.
*
* @return List<Integer> 생성된 로또 티켓 목록
*/
public LottoTicket autoGenerate() {
List<Integer> numbers = new ArrayList<>();
for (int i = MIN_LOTTO_NUMBER ; i <= MAX_LOTTO_NUMBER ; i++) {
numbers.add(i);
}
Collections.shuffle(numbers);
List<Integer> shuffledNumber = numbers.subList(0, 6);
Collections.sort(shuffledNumber);
return new LottoTicket(shuffledNumber);
}
/**
* 수동 로또 번호를 전달 받아 LottoTicket 객체로 반환 합니다.
*
* @param numbers 로또 번호
*
* @return LottoTicket
*/
public LottoTicket manualGenerate(String[] numbers) {
List<Integer> lottoNumbers = Arrays.stream(numbers)
.map(Integer::parseInt)
.collect(Collectors.toList());
// 유효성 체크
LottoValidator validator = new LottoValidator();
validator.winningNumbersValidation(lottoNumbers);
return new LottoTicket(lottoNumbers);
}
}