I have two arrays: Walls and Neighbors.
public boolean[] walls = new boolean[4];
public Cell[] neighbors = new Cell[4];
and I have an Enum:
If you are not persisting the arrays or in any other way are making yourself dependent on different versions of your enum class, it's safe to use ordinal().
If you want don't want to rely on the implicit ordering of the enum values, you could introduce a private index value:
public enum Direction {
NORTH(0),
SOUTH(1),
EAST(2),
WEST(3);
private int _index;
private Direction (int index_)
{
_index = index_;
}
public int getIndex()
{
return _index;
}
}
From here it's easy to both allow for easy lookup of index to Direction (By creating a Map in a static block for compact persistence; Do uniqueness check in static block etc.