code: public static boolean isIdentity(DMatrix a , double tol )
      {
          for( int i = 0; i < a.getNumRows(); i++ ) {
              for( int j = 0; j < a.getNumCols(); j++ ) {
                  if( i == j ) {
                      if( Math.abs(a.get(i,j)-1.0) > tol )
                          return false;
                  } else {
                      if( Math.abs(a.get(i,j)) > tol )
                          return false;
                  }
              }
          }
          return true;
      }
docs: Returns true if the provided matrix is has a value of 1 along the diagonal
  elements and zero along all the other elements.
  
  @param a Matrix being inspected.
  @param tol How close to zero or one each element needs to be.
  @return If it is within tolerance to an identity matrix.