-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathLines.java
More file actions
36 lines (28 loc) · 939 Bytes
/
Lines.java
File metadata and controls
36 lines (28 loc) · 939 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
35
36
package nextstep.ladder.domain;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Lines {
private final List<Line> lines;
private Lines(List<Line> lines) {
validate(lines);
this.lines = lines;
}
private void validate(List<Line> lines) {
if (lines == null || lines.isEmpty()) {
throw new IllegalArgumentException("사다리 높이는 1 이상이어야 합니다.");
}
}
public static Lines of(int numberOfPlayers, int height) {
List<Line> lines = IntStream.range(0, height)
.mapToObj(i -> LineBuilder.buildWithRandomPoints(numberOfPlayers))
.collect(Collectors.toList());
return new Lines(lines);
}
public int getHeight() {
return lines.size();
}
public Line getLine(int targetHeight) {
return lines.get(targetHeight);
}
}