public enum Direction {
North(1), South(0), East(3), West(2), Up(5), Down(4)
private oppositeIndex
Direction getOpposite() {
values()[oppositeIndex]
}
Direction(oppositeIndex) {
this.oppositeIndex = oppositeIndex
}
}
Direction.values().each {
println "opposite of $it is $it.opposite"
}
cHVibGljIGVudW0gRGlyZWN0aW9uIHsKICAgIE5vcnRoKDEpLCBTb3V0aCgwKSwgRWFzdCgzKSwgV2VzdCgyKSwgVXAoNSksIERvd24oNCkKICAgIHByaXZhdGUgb3Bwb3NpdGVJbmRleAogICAgRGlyZWN0aW9uIGdldE9wcG9zaXRlKCkgeyAKICAgICAgICB2YWx1ZXMoKVtvcHBvc2l0ZUluZGV4XQogICAgfQogICAgRGlyZWN0aW9uKG9wcG9zaXRlSW5kZXgpIHsgCiAgICAgICAgdGhpcy5vcHBvc2l0ZUluZGV4ID0gb3Bwb3NpdGVJbmRleAogICAgfQp9CgpEaXJlY3Rpb24udmFsdWVzKCkuZWFjaCB7IAogICAgcHJpbnRsbiAib3Bwb3NpdGUgb2YgJGl0IGlzICRpdC5vcHBvc2l0ZSIKfQo=