-
Notifications
You must be signed in to change notification settings - Fork 461
Expand file tree
/
Copy pathColumn.java
More file actions
84 lines (62 loc) · 1.83 KB
/
Column.java
File metadata and controls
84 lines (62 loc) · 1.83 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package chess;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public enum Column {
A,
B,
C,
D,
E,
F,
G,
H;
public static Column from(String columnString) {
return Arrays.stream(Column.values())
.filter(column -> column.name().equals(columnString))
.findAny()
.orElseThrow(() -> new IllegalArgumentException("column 없습니당"));
}
public boolean isFarLeft() {
return ordinal() == 0;
}
public boolean isFarRight() {
return ordinal() + 1 == values().length;
}
public boolean canMoveLeft(final int step) {
return ordinal() - step >= 0;
}
public Column moveLeft() {
return moveLeft(1);
}
public Column moveLeft(final int step) {
if (canMoveLeft(step)) {
return values()[ordinal() - step];
}
throw new IllegalStateException("움직일 수 없는 위치입니다.");
}
public boolean canMoveRight(final int step) {
return ordinal() + step < values().length;
}
public Column moveRight() {
return moveRight(1);
}
public Column moveRight(final int step) {
if (canMoveRight(step)) {
return values()[ordinal() + step];
}
throw new IllegalStateException("움직일 수 없는 위치입니다.");
}
public Column move(final int step) {
return moveRight(step);
}
public List<Column> betweenColumns(Column column) {
List<Column> columnList = new ArrayList<>();
int start = Math.min(this.ordinal(), column.ordinal());
int end = Math.max(this.ordinal(), column.ordinal());
for (int i = start + 1; i < end; i++) {
columnList.add(Column.values()[i]);
}
return columnList;
}
}