-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLine.java
More file actions
42 lines (32 loc) · 937 Bytes
/
Line.java
File metadata and controls
42 lines (32 loc) · 937 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
37
38
39
40
41
42
package ladder.domain;
import java.util.List;
public class Line {
private final List<Boolean> bridgeStates;
public static Line newInstance(List<Boolean> bridgeStates) {
return new Line(bridgeStates);
}
public Line(List<Boolean> bridgeStates) {
this.bridgeStates = bridgeStates;
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
for (Boolean state : bridgeStates) {
appendColumn(result);
appendBridge(result, state);
}
appendColumn(result);
return " " + String.valueOf(result);
}
private void appendColumn(StringBuilder result) {
result.append("|");
}
private void appendBridge(StringBuilder result, Boolean state) {
if (state) {
result.append("------");
}
if (!state) {
result.append(" ");
}
}
}