private void validateInput(int[][] matrix) {
    if (matrix == null) {
      throw new IllegalArgumentException("You can't pass a null instance of matrix as parameter.");
    } else if (matrix.length == 0) {
      throw new IllegalArgumentException(
          "You can't pass an empty instance of matrix as parameter.");
    } else if (matrix.length != matrix[0].length) {
      throw new IllegalArgumentException(
          "You can't pass a matrix with different height and width.");
    }
  }
Iterative algorithm to solve this problem. This solution is based on move 4 positions per
iteration. With this approach we can reduce the complexity order in space terms from O(N^2) to
O(1). In time terms, the complexity order is O(N^2) where N is the height or width of the
matrix.
src/main/java/com/github/pedrovgs/problem54/RotateMatrix.java