java 两个不同list<map> 取差集 并相互补全

public static BatchMetric list(BatchMetric metric, List> list1, List> list2){
        System.out.println("#---------前"+list1);
        System.out.println("#---------前"+list2);
        Map map1 = list1.get(0);
        Map map2 = list2.get(0);
        MapDifference difference = Maps.difference(map1,map2);
        // 是否有差异,返回boolean
        boolean areEqual = difference.areEqual();
        //System.out.println("比较两个Map是否有差异:" + areEqual);
        if (areEqual){
            System.out.println("两个Map没有差异");
        }else {
            System.out.println("两个Map有差异");
            // 键只存在于左边Map的映射项
            Map onlyOnLeft = difference.entriesOnlyOnLeft();
            System.out.println("键只存在于第一个clickMap的映射项:" + onlyOnLeft);
            if (StringUtil.isNotEmpty(onlyOnLeft)){
                for (Object key : onlyOnLeft.keySet()) {
                    System.out.println("key= " + key + " and value= " + onlyOnLeft.get(key));
                    map2.put(key,0);
                }
            }
            // 键只存在于右边Map的映射项
            Map entriesOnlyOnRight = difference.entriesOnlyOnRight();
            System.out.println("键只存在于第二个reptileMap的映射项:" + entriesOnlyOnRight);
            if (StringUtil.isNotEmpty(entriesOnlyOnRight)){
                for (Object key : entriesOnlyOnRight.keySet()) {
                    System.out.println("key= " + key + " and value= " + entriesOnlyOnRight.get(key));
                    map1.put(key,0);
                }
            }
        }
        System.out.println("#---------后"+list1);
        System.out.println("#---------后"+list2);
        metric.setHours_click(list1);
        metric.setHours_reptile(list2);
        return metric;
    }

你可能感兴趣的:(java 两个不同list<map> 取差集 并相互补全)