private Map<Product, Product> diffProducts(List<Product> pcm1Products, List<Product> pcm2Products, PCMElementComparator comparator, DiffResult result) {
        List<Product> commonProducts = new ArrayList<Product>();
        List<Product> productsOnlyInPCM1 = new ArrayList<Product>();
        List<Product> productsOnlyInPCM2 = new ArrayList<Product>(pcm2Products);

        Map<Product, Product> equivalentProducts = new HashMap<Product, Product>();

        for (Product p1 : pcm1Products) {

            boolean similarProduct = false;

            for (Product p2 : pcm2Products) {
                similarProduct = comparator.similarProduct(p1, p2);
                if (similarProduct) {
                    commonProducts.add(p1);
                    productsOnlyInPCM2.remove(p2);
                    equivalentProducts.put(p1, p2);
                    break;
                }
            }

            if (!similarProduct) {
                productsOnlyInPCM1.add(p1);
            }

        }

        result.setCommonProducts(commonProducts);
        result.setProductsOnlyInPCM1(productsOnlyInPCM1);
        result.setProductsOnlyInPCM2(productsOnlyInPCM2);

        return equivalentProducts;
    }
private Map < Product , Product > diffProducts ( List < Product > pcm1Products , List < Product > pcm2Products , PCMElementComparator comparator , DiffResult result ) { List < Product > commonProducts = new ArrayList < Product > ( ) ; List < Product > productsOnlyInPCM1 = new ArrayList < Product > ( ) ; List < Product > productsOnlyInPCM2 = new ArrayList < Product > ( pcm2Products ) ; Map < Product , Product > equivalentProducts = new HashMap < Product , Product > ( ) ; for ( Product p1 : pcm1Products ) { boolean similarProduct = false ; for ( Product p2 : pcm2Products ) { similarProduct = comparator . similarProduct ( p1 , p2 ) ; if ( similarProduct ) { commonProducts . add ( p1 ) ; productsOnlyInPCM2 . remove ( p2 ) ; equivalentProducts . put ( p1 , p2 ) ; break ; } } if ( ! similarProduct ) { productsOnlyInPCM1 . add ( p1 ) ; } } result . setCommonProducts ( commonProducts ) ; result . setProductsOnlyInPCM1 ( productsOnlyInPCM1 ) ; result . setProductsOnlyInPCM2 ( productsOnlyInPCM2 ) ; return equivalentProducts ; }
Compare the products of two PCMs
@param pcm1Products
@param pcm2Products
@param comparator
@param result
@return equivalent products