@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptMatrixWithDifferentHeightAndWidth() { int[][] matrix = new int[6][3]; rotateMatrix.rotate(matrix); }
public void rotate(int[][] matrix) { validateInput(matrix); int length = matrix.length; for (int i = 0; i < length / 2; ++i) { int first = i; int last = length - 1 - i; for (int j = first; j < last; ++j) { int offset = j - first; int top = matrix[first][j]; moveLeftToTop(matrix, first, last, j, offset); moveBottomToLeft(matrix, first, last, offset); moveRithToBottom(matrix, last, j, offset); moveTopToRight(matrix, last, j, top); } } }
RotateMatrix { public void rotate(int[][] matrix) { validateInput(matrix); int length = matrix.length; for (int i = 0; i < length / 2; ++i) { int first = i; int last = length - 1 - i; for (int j = first; j < last; ++j) { int offset = j - first; int top = matrix[first][j]; moveLeftToTop(matrix, first, last, j, offset); moveBottomToLeft(matrix, first, last, offset); moveRithToBottom(matrix, last, j, offset); moveTopToRight(matrix, last, j, top); } } } }
RotateMatrix { public void rotate(int[][] matrix) { validateInput(matrix); int length = matrix.length; for (int i = 0; i < length / 2; ++i) { int first = i; int last = length - 1 - i; for (int j = first; j < last; ++j) { int offset = j - first; int top = matrix[first][j]; moveLeftToTop(matrix, first, last, j, offset); moveBottomToLeft(matrix, first, last, offset); moveRithToBottom(matrix, last, j, offset); moveTopToRight(matrix, last, j, top); } } }  }
RotateMatrix { public void rotate(int[][] matrix) { validateInput(matrix); int length = matrix.length; for (int i = 0; i < length / 2; ++i) { int first = i; int last = length - 1 - i; for (int j = first; j < last; ++j) { int offset = j - first; int top = matrix[first][j]; moveLeftToTop(matrix, first, last, j, offset); moveBottomToLeft(matrix, first, last, offset); moveRithToBottom(matrix, last, j, offset); moveTopToRight(matrix, last, j, top); } } }  void rotate(int[][] matrix); }
RotateMatrix { public void rotate(int[][] matrix) { validateInput(matrix); int length = matrix.length; for (int i = 0; i < length / 2; ++i) { int first = i; int last = length - 1 - i; for (int j = first; j < last; ++j) { int offset = j - first; int top = matrix[first][j]; moveLeftToTop(matrix, first, last, j, offset); moveBottomToLeft(matrix, first, last, offset); moveRithToBottom(matrix, last, j, offset); moveTopToRight(matrix, last, j, top); } } }  void rotate(int[][] matrix);  }