-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathLine.java
More file actions
65 lines (50 loc) · 1.87 KB
/
Line.java
File metadata and controls
65 lines (50 loc) · 1.87 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package domain;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import util.Errors;
public class Line {
private final Player player;
private final String outcome;
private final List<Point> points;
private Line(Player player, String outcome, List<Point> points) {
this.player = player;
this.outcome = outcome;
this.points = points;
}
public static Line of(Player player, String outcome, List<Boolean> leftRungsStatus,
List<Boolean> rightRungsStatus) {
validateHeight(leftRungsStatus, rightRungsStatus);
List<Point> points = IntStream.range(0, leftRungsStatus.size())
.mapToObj(position -> new Point(leftRungsStatus.get(position), rightRungsStatus.get(position)))
.collect(Collectors.toList());
return new Line(player, outcome, points);
}
private static void validateHeight(List<Boolean> leftRungsStatus, List<Boolean> rightRungsStatus) {
if (leftRungsStatus.size() != rightRungsStatus.size()) {
throw new IllegalArgumentException(Errors.RUNG_STATUS_LENGTH_MUST_MATCH);
}
}
public List<Boolean> getRightStatus() {
return points.stream()
.map(Point::isConnectedToRightLadder)
.collect(Collectors.toList());
}
public int getHeight() {
return this.points.size();
}
public String getName() {
return player.getName();
}
public String getOutcome() {
return outcome;
}
public boolean isConnectedToLeftLineAt(int position) {
Point nowPoint = this.points.get(position);
return nowPoint.isConnectedToLeftLadder();
}
public boolean isConnectedToRightLineAt(int position) {
Point nowPoint = this.points.get(position);
return nowPoint.isConnectedToRightLadder();
}
}