-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathWords.java
More file actions
38 lines (31 loc) · 1.09 KB
/
Copy pathWords.java
File metadata and controls
38 lines (31 loc) · 1.09 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
package domain;
import java.time.LocalDate;
import java.time.Period;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class Words {
private static final LocalDate BASE_DATE_FOR_ANSWER = LocalDate.of(2021, 6, 19);
private final List<Word> words;
public Words(List<Word> words) {
this.words = Collections.unmodifiableList(words);
}
public static Words of(List<String> strings) {
return new Words(strings.stream().map(Word::new).collect(Collectors.toList()));
}
public Word answer(LocalDate from) {
Period period = Period.between(BASE_DATE_FOR_ANSWER, from);
int range = period.getDays() % words.size();
return words.get(range);
}
public Colors matchingAnswer(Word input) {
validate(input);
Word answer = answer(LocalDate.now());
return answer.compareWith(input);
}
private void validate(Word input) {
if (!words.contains(input)) {
throw new IllegalArgumentException("단어집에 없는 단어를 선택하였습니다.");
}
}
}