-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathLadder.java
More file actions
44 lines (36 loc) · 1.12 KB
/
Ladder.java
File metadata and controls
44 lines (36 loc) · 1.12 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
package nextstep.ladder.domain;
import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
@Getter
public class Ladder {
private List<Line> lines = new ArrayList<>();
public static Ladder createLadder(int countOfUsers, int height, BridgeStrategy strategy) {
return new Ladder(countOfUsers, height, strategy);
}
private Ladder(int countOfUsers, int height, BridgeStrategy strategy) {
for (int i = 0; i < height; i++) {
Line line = Line.createLine(countOfUsers, strategy);
lines.add(line);
}
}
public String status() {
String result = "";
int height = lines.size();
for (int i = 0; i < height; i++) {
Line line = lines.get(i);
result += line.status();
}
return result;
}
public int findLastPosition(int position) {
if (lines.isEmpty()) {
return position;
}
int currentPosition = position;
for (Line line : lines) {
currentPosition = line.getNextPosition(currentPosition);
}
return currentPosition;
}
}