Add two private helper methods validateCoordinates() and xyTo1D().