Consider the following code :
if (xPoint > 0 && yPoint > 0) {
m_navigations = Directions.SouthEast;
}
else if (xPoint > 0 && yP
The simplest and easiest solution is to use multidimensional arrays.
public class CalculateDirections {
private final static Directions DIRECTION_MAP[][] = {
{Directions.NorthWest, Directions.North, Directions.NorthEast},
{Directions.West, null, Directions.East},
{Directions.SouthWest, Directions.South, Directions.SouthEast},
};
public static void main(String[] args) {
int x = Integer.valueOf(args[0]);
int y = Integer.valueOf(args[1]);
int signumX = Integer.signum(x);
int signumY = Integer.signum(y);
Directions direction = DIRECTION_MAP[signumY + 1][signumX + 1];
System.out.println(direction);
}
}
enum Directions {
SouthEast, NorthEast, SouthWest, NorthWest, North, South, East, West
}
There are several advantages: