class 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);
      }
    }
  }

}