Represents a direction (left or right).
| 23 | * Represents a direction (left or right). |
| 24 | */ |
| 25 | public enum Direction { |
| 26 | Left, |
| 27 | Right; |
| 28 | |
| 29 | private static final String LEFT = "Left"; |
| 30 | private static final String RIGHT = "Right"; |
| 31 | /** Immutable list of all directions (in order, Left and Right). */ |
| 32 | private static final List<Direction> listOfDirections = |
| 33 | List.of(getDefaultDirection(), getDefaultDirection().getOtherDirection()); |
| 34 | |
| 35 | /** @return The default direction. */ |
| 36 | public static final Direction getDefaultDirection() { return Left; } |
| 37 | |
| 38 | /** @return Immutable list of all directions (in order, Left and Right). */ |
| 39 | public static List<Direction> getListOfDirections() { return listOfDirections; } |
| 40 | |
| 41 | /** @return True if and only if this is the default direction. */ |
| 42 | public boolean isDefaultDirection() { |
| 43 | return this.equals(getDefaultDirection()); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Get the index by which the turn order is shifted, given this Direction. |
| 48 | * @return 1 or -1. |
| 49 | */ |
| 50 | public int getShift() { |
| 51 | if (this.isDefaultDirection()) { |
| 52 | return 1; |
| 53 | } |
| 54 | return -1; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Give the other Direction. |
| 59 | * @return Right if this is Left, and vice versa. |
| 60 | */ |
| 61 | public Direction getOtherDirection() { |
| 62 | switch (this) { |
| 63 | case Left: |
| 64 | return Direction.Right; |
| 65 | case Right: |
| 66 | return Direction.Left; |
| 67 | } |
| 68 | return null; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * {@inheritDoc} |
| 73 | */ |
| 74 | public String toString() { |
| 75 | switch (this) { |
| 76 | case Left: |
| 77 | return LEFT; |
| 78 | case Right: |
| 79 | return RIGHT; |
| 80 | } |
| 81 | return null; |
| 82 | } |
nothing calls this directly
no test coverage detected