-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathResultView.java
51 lines (42 loc) · 1.59 KB
/
ResultView.java
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
package view;
import java.util.List;
public class ResultView {
public void printLadder(List<String> ladderLines) {
printResultHeader();
StringBuilder resultBuilder = new StringBuilder();
processLadderLines(resultBuilder, ladderLines);
outputResult(resultBuilder);
}
private void printResultHeader() {
System.out.println("실행결과");
System.out.println();
}
private void processLadderLines(StringBuilder resultBuilder, List<String> ladderLines) {
for (String line : ladderLines) {
String[] points = parseLine(line);
resultBuilder.append(LineCharacter.VERTICAL.getSymbol());
appendSymbolsForPoints(points, resultBuilder);
resultBuilder.append("\n");
}
}
private String[] parseLine(String line) {
return line.replaceAll("[\\[\\] ]", "").split(",");
}
private void appendSymbolsForPoints(String[] points, StringBuilder resultBuilder) {
for (String point : points) {
appendSymbolToBuilder(resultBuilder, point);
resultBuilder.append(LineCharacter.VERTICAL.getSymbol());
}
}
private void appendSymbolToBuilder(StringBuilder resultBuilder, String point) {
if (point.equals("HAS_POINT")) {
resultBuilder.append(LineCharacter.CONNECTED.getSymbol());
}
if (point.equals("NO_POINT")) {
resultBuilder.append(LineCharacter.DISCONNECTED.getSymbol());
}
}
private void outputResult(StringBuilder resultBuilder) {
System.out.println(resultBuilder);
}
}