private long getProduct(int row, int col, int adjacentNumbers, Directions... directions) { long product = 1; int currentRow = row; int currentCol = col; int positionChange = 0; do { int currentValue = EULER_PROBLEM[currentRow][currentCol]; if (currentValue == 0) { return 0; } product *= currentValue; for (Directions direction : directions) { currentRow += direction.getRowChange(); currentCol += direction.getColChange(); } positionChange++; } while (currentRow > 0 && currentRow < ROWS && currentCol > 0 && currentCol < COLS && positionChange < adjacentNumbers); return product; }