private Pair<int, int> max(DoubleMatrix2D matrix) { if (matrix == null) { return null; } int row = 0; int column = 0; double value = 0; for (int r = 0; r < matrix.rows(); r++) { for (int c = 0; c < matrix.columns(); c++) { double currentValue = matrix.getQuick(r, c); if (currentValue > value) { value = currentValue; row = r; column = c; } } } if (value > 0) { return new Pair<int, int>(row, column); } else { return null; } }