private Rotation isValidPermutation ( List < Integer > permutation ) { if ( permutation . size ( ) == 0 ) { return null ; } // cached value if ( evaluatedPermutations . containsKey ( permutation ) ) { return evaluatedPermutations . get ( permutation ) ; } // check if permutation is allowed if ( ! isAllowedPermutation ( permutation ) ) { evaluatedPermutations . put ( permutation , null ) ; return null ; } // check if superimposes Rotation rot = superimposePermutation ( permutation ) ; return rot ; }
Checks if a particular permutation is allowed and superimposes well . Caches results .