-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathResultView.java
More file actions
46 lines (35 loc) · 1.36 KB
/
ResultView.java
File metadata and controls
46 lines (35 loc) · 1.36 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
package nextstep.view;
import nextstep.domain.Line;
import nextstep.util.StringUtils;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.stream.IntStream;
public class ResultView {
public static final String EMPTY_LADDER = " ";
public static final String FULL_LADDER = "-----";
public static final String PIPE = "|";
public static final int MAX_NAME_LENGTH = 5;
public static final String NL = System.lineSeparator();
public static void printResult(String[] names, int ladderHeight, LinkedList<Line> lines) {
StringBuilder sb = new StringBuilder();
sb.append("실행 결과")
.append(NL)
.append(Arrays.stream(names)
.map(name -> StringUtils.lpad(name, MAX_NAME_LENGTH))
.reduce("", String::concat))
.append(NL);
IntStream.range(0, ladderHeight)
.forEach(idx -> {
sb.append(EMPTY_LADDER)
.append(lines.stream()
.map(line -> draw(line.isPoint(idx)))
.reduce("", String::concat))
.append(PIPE)
.append(NL);
});
System.out.println(sb.toString());
}
private static String draw(boolean point) {
return PIPE.concat(point ? FULL_LADDER : EMPTY_LADDER);
}
}