public Assignment mapVariables ( Map < Integer , Integer > varMap ) { int [ ] newVarNums = new int [ vars . length ] ; Object [ ] newValues = new Object [ vars . length ] ; int numFilled = 0 ; for ( int i = 0 ; i < vars . length ; i ++ ) { if ( varMap . containsKey ( vars [ i ] ) ) { newVarNums [ numFilled ] = varMap . get ( vars [ i ] ) ; newValues [ numFilled ] = values [ i ] ; numFilled ++ ; } } if ( numFilled < newVarNums . length ) { newVarNums = Arrays . copyOf ( newVarNums , numFilled ) ; newValues = Arrays . copyOf ( newValues , numFilled ) ; } return Assignment . fromUnsortedArrays ( newVarNums , newValues ) ; }
Return a new assignment where each var num has been replaced by its value in varMap .