-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathLineState.java
46 lines (36 loc) · 1.27 KB
/
LineState.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
package nextstep.ladder.domain;
import nextstep.ladder.utils.RandomLineGenerator;
public class LineState {
private final boolean previous;
private final boolean current;
public static LineState previousOf(boolean previous) {
LineGenerator lineGenerator = new RandomLineGenerator();
return new LineState(previous, !previous && lineGenerator.generateLine());
}
public static LineState previousOf(boolean previous, LineGenerator lineGenerator) {
return new LineState(previous, lineGenerator.generateLine());
}
public LineState(boolean previous, boolean current) {
checkForConsecutiveTrue(previous, current);
this.previous = previous;
this.current = current;
}
public boolean getPrevious() {
return previous;
}
public boolean getCurrent() {
return current;
}
private void checkForConsecutiveTrue(boolean previous, boolean current) {
if (previous && current) {
throw new IllegalArgumentException("사다리 라인은 연속으로 겹칠 수 없습니다.");
}
}
@Override
public String toString() {
return "LineState{" +
"previous=" + previous +
", current=" + current +
'}';
}
}