-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathLine.java
More file actions
56 lines (43 loc) · 1.53 KB
/
Line.java
File metadata and controls
56 lines (43 loc) · 1.53 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
package nextstep.ladder.domain;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;
public class Line {
private static final int BEGIN_INDEX = 0;
private static final boolean EMPTY_POINT = false;
private static final double HALF = 0.5;
private final List<Boolean> horizontalLines;
public Line(List<Boolean> horizontalLines) {
this.horizontalLines = horizontalLines;
}
public Line(int countOfPerson) {
this(generateLine(countOfPerson));
}
public static List<Boolean> generateLine(int countOfPerson) {
List<Boolean> horizontalLines = new ArrayList<>();
IntStream.range(BEGIN_INDEX, countOfPerson - 1)
.forEach(idx -> horizontalLines.add(createPoint(idx, horizontalLines)));
return horizontalLines;
}
private static Boolean createPoint(int idx, List<Boolean> horizontalLines) {
if (BEGIN_INDEX == idx) {
return isCurrPointNonEmpty();
}
return isPrevPointEmpty(idx, horizontalLines) && isCurrPointNonEmpty();
}
private static boolean isPrevPointEmpty(int idx, List<Boolean> horizontalLines) {
return EMPTY_POINT == horizontalLines.get(idx - 1);
}
private static boolean isCurrPointNonEmpty() {
return HALF < Math.random();
}
public List<Boolean> value() {
return horizontalLines;
}
@Override
public String toString() {
return "Line{" +
"horizontalLines=" + horizontalLines +
'}';
}
}