-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathWords.java
More file actions
34 lines (26 loc) · 917 Bytes
/
Copy pathWords.java
File metadata and controls
34 lines (26 loc) · 917 Bytes
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
package domain;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.stream.Collectors;
public class Words {
public static final LocalDate DEFAULT_DATE = LocalDate.of(2021, 6, 19);
private final List<Word> words;
public Words(List<String> words) {
this.words = convert(words);
}
private List<Word> convert(List<String> words) {
if (words.size() == 0) {
throw new IllegalArgumentException("파일이 비어 있습니다.");
}
return words.stream().map(Word::new).collect(Collectors.toList());
}
public Answer getAnswer(LocalDate now) {
long betweenDay = ChronoUnit.DAYS.between(DEFAULT_DATE, now);
Word answer = this.words.get((int) (betweenDay % words.size()));
return new Answer(answer);
}
public List<Word> getWords() {
return words;
}
}