fork download
  1. public enum Direction {
  2. North(1), South(0), East(3), West(2), Up(5), Down(4)
  3. private oppositeIndex
  4. Direction getOpposite() {
  5. values()[oppositeIndex]
  6. }
  7. Direction(oppositeIndex) {
  8. this.oppositeIndex = oppositeIndex
  9. }
  10. }
  11.  
  12. Direction.values().each {
  13. println "opposite of $it is $it.opposite"
  14. }
  15.  
Success #stdin #stdout 1.13s 217280KB
stdin
Standard input is empty
stdout
opposite of North is South
opposite of South is North
opposite of East is West
opposite of West is East
opposite of Up is Down
opposite of Down is Up