DRY
Code for columns and rows is identical except the board access (
board[i][j]
andboard[j][i]
respectively). Such minute difference is hard to spot, and the reviewer (or maintainer) has hard time understanding what's going on. I recommend to factor the common part out, along the lines of:bool rowCheck() { return boardCheck(rowWize); } bool columnCheck() { return boardCheck(columnWize); } bool boardCheck(Callable<Integer,Integer> boardAccess) { .... value = boardAccess(i, j); .... }
or with lambdas instead of callable wrappers. See this discussionthis discussion for details.
HashMap
seems like overkill. A
bool seen[size]
initialized tofalse
andvalue = board[i][j] - 1; if (seen[value]) { return false; } else { seen[value] = true; }
achieves the same goal with much less overhead. Of course you'd need a bound check.
The side effect of this approach is that your way may have false positives as @CaptainMan noticed in the comment.