/ benchmark / hlt / Direction.java
Direction.java
 1  package hlt;
 2  
 3  import java.util.ArrayList;
 4  
 5  public enum Direction {
 6      NORTH('n'),
 7      EAST('e'),
 8      SOUTH('s'),
 9      WEST('w'),
10      STILL('o');
11  
12      public final char charValue;
13  
14      public final static ArrayList<Direction> ALL_CARDINALS = new ArrayList<>();
15      static {
16          ALL_CARDINALS.add(NORTH);
17          ALL_CARDINALS.add(SOUTH);
18          ALL_CARDINALS.add(EAST);
19          ALL_CARDINALS.add(WEST);
20      }
21  
22      public Direction invertDirection() {
23          switch (this) {
24              case NORTH: return SOUTH;
25              case EAST: return WEST;
26              case SOUTH: return NORTH;
27              case WEST: return EAST;
28              case STILL: return STILL;
29              default: throw new IllegalStateException("Unknown direction " + this);
30          }
31      }
32  
33      Direction(final char charValue) {
34          this.charValue = charValue;
35      }
36  }