-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathLadderFactory.java
More file actions
40 lines (32 loc) · 1.19 KB
/
LadderFactory.java
File metadata and controls
40 lines (32 loc) · 1.19 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
package nextstep.ladder.domain;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class LadderFactory {
private static final int ONE = 1;
private static final int ZERO = 0;
private final LineFactory lineFactory;
public LadderFactory(LineFactory lineFactory) {
this.lineFactory = lineFactory;
}
public Ladder create(Participants participants, int height) {
return create(participants.size(), height);
}
public Ladder create(int numberOfLine, int height) {
validateHeight(height);
return new Ladder(lines(numberOfLine, height));
}
private List<Line> lines(int numberOfLine, int height) {
return IntStream.range(ZERO, height)
.mapToObj(index -> lineFactory.create(numberOfConnections(numberOfLine)))
.collect(Collectors.toUnmodifiableList());
}
private int numberOfConnections(int numberOfLine) {
return numberOfLine - ONE;
}
private void validateHeight(int height) {
if(height <= ZERO) {
throw new IllegalArgumentException("사다리의 높이는 0 이하일 수 없습니다: " + height);
}
}
}