public final Assignment union ( Assignment other ) { Preconditions . checkNotNull ( other ) ; if ( other . size ( ) == 0 ) { return this ; } if ( vars . length == 0 ) { return other ; } // Merge varnums / values int [ ] otherNums = other . getVariableNumsArray ( ) ; int [ ] myNums = getVariableNumsArray ( ) ; Object [ ] otherVals = other . getValuesArray ( ) ; Object [ ] myVals = getValuesArray ( ) ; int [ ] mergedNums = new int [ otherNums . length + myNums . length ] ; Object [ ] mergedVals = new Object [ otherNums . length + myNums . length ] ; int i = 0 ; int j = 0 ; int numFilled = 0 ; while ( i < otherNums . length && j < myNums . length ) { if ( otherNums [ i ] < myNums [ j ] ) { mergedNums [ numFilled ] = otherNums [ i ] ; mergedVals [ numFilled ] = otherVals [ i ] ; i ++ ; numFilled ++ ; } else if ( otherNums [ i ] > myNums [ j ] ) { mergedNums [ numFilled ] = myNums [ j ] ; mergedVals [ numFilled ] = myVals [ j ] ; j ++ ; numFilled ++ ; } else { Preconditions . checkState ( false , "Cannot combine non-disjoint assignments: %s with %s" , this , other ) ; } } // One list might still have elements in it. while ( i < otherNums . length ) { mergedNums [ numFilled ] = otherNums [ i ] ; mergedVals [ numFilled ] = otherVals [ i ] ; i ++ ; numFilled ++ ; } while ( j < myNums . length ) { mergedNums [ numFilled ] = myNums [ j ] ; mergedVals [ numFilled ] = myVals [ j ] ; j ++ ; numFilled ++ ; } Preconditions . checkState ( numFilled == mergedNums . length ) ; return Assignment . fromSortedArrays ( mergedNums , mergedVals ) ; }
Combines two assignments into a single joint assignment to all of the variables in each assignment . The two assignments must contain disjoint sets of variables .