-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAim.java
78 lines (64 loc) · 1.71 KB
/
Aim.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
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
import java.util.HashMap;
import java.util.Map;
/**
* Represents a direction in which to move an ant.
*/
public enum Aim {
/** North direction, or up. */
NORTH(-1, 0, 'n'),
/** East direction or right. */
EAST(0, 1, 'e'),
/** South direction or down. */
SOUTH(1, 0, 's'),
/** West direction or left. */
WEST(0, -1, 'w');
private static final Map<Character, Aim> symbolLookup = new HashMap<Character, Aim>();
static {
symbolLookup.put('n', NORTH);
symbolLookup.put('e', EAST);
symbolLookup.put('s', SOUTH);
symbolLookup.put('w', WEST);
}
private final int rowDelta;
private final int colDelta;
private final char symbol;
Aim(int rowDelta, int colDelta, char symbol) {
this.rowDelta = rowDelta;
this.colDelta = colDelta;
this.symbol = symbol;
}
/**
* Returns rows delta.
*
* @return rows delta.
*/
public int getRowDelta() {
return rowDelta;
}
/**
* Returns columns delta.
*
* @return columns delta.
*/
public int getColDelta() {
return colDelta;
}
/**
* Returns symbol associated with this direction.
*
* @return symbol associated with this direction.
*/
public char getSymbol() {
return symbol;
}
/**
* Returns direction associated with specified symbol.
*
* @param symbol <code>n</code>, <code>e</code>, <code>s</code> or <code>w</code> character
*
* @return direction associated with specified symbol
*/
public static Aim fromSymbol(char symbol) {
return symbolLookup.get(symbol);
}
}