今日遇到一个问题,需要整理每个分类下所缺少的尺码和颜色。
输入形式是一个
Execl表格
产品编码号颜色   属性值
产品编码号尺码   属性值
例如:
123颜色 蓝色,绿色
123尺码 M,L,LL
123颜色 黑色,绿色
123尺码 M,L
我现在已经整理成了Map的形式
    cid     颜色,尺码<属性值>
Map<String,<String,Set<String>>> map=
现在获取另一个map2,形式如下
    cid     颜色,尺码<属性值>
Map<String,<String,List<String>>> map=
要求遍历map1,查找出map2中没有的属性并放入到map3中。
求实现方法、
感觉逻辑太复杂了,弄混了

解决方案 »

  1.   

    不是很懂你的意思
    你做成map的时候,颜色的属性值到哪里去了。
    建议把颜色,尺码什么的封装到一个类中
      

  2.   

    历map1,查找出map2中没有的属性?是key和value都必须相同吗?直接遍历就行了,判断key是否相同,不同就放到map3里面,相同就在比较value,不同也放map3里,同就跳过。
      

  3.   

    那你如果这样写的话KEY值不都是一样的吗!
    先创建一个类,把属性封装到类里面,这样就不会那么复杂了。
      

  4.   


    public class Test4 {
    public static void main(String[] args) {
    Map<String,Map<String,Set<String>>> oldmap=new HashMap<String, Map<String,Set<String>>>();

    }
    public Map<String,Map<String,Set<String>>> getothermap(Map<String,Map<String,Set<String>>> oldmap,Map<String,Map<String,Set<String>>> newmap){
    Map<String,Map<String,Set<String>>> othermap=new HashMap<String, Map<String,Set<String>>>();

    for(String cid:oldmap.keySet()){
    Map<String,Set<String>> oldcidmap=oldmap.get(cid);
    Map<String,Set<String>> newcidmap=newmap.get(cid);
    Map<String,Set<String>> othercidmap=new HashMap<String, Set<String>>();
    Set<String> oldcolorset=oldcidmap.get("color");
    Set<String> oldsizeset=oldcidmap.get("size");
    Set<String> newcolorset=newcidmap.get("color");
    Set<String> newsizeset=newcidmap.get("size");
    Set<String> othercolorset=new HashSet<String>();
    Set<String> othersizeset=new HashSet<String>();
    othercidmap.put("color", othercolorset);
    othercidmap.put("size", othersizeset);

    for(String attval:oldcolorset){
    if(!newcolorset.contains(attval)){
    othercolorset.add(attval);
    }
    }
    for(String attval:oldsizeset){
    if(!newsizeset.contains(attval)){
    othersizeset.add(attval);
    }
    }
    }
    return othermap;

    }
    }
    不知道你做哪个平台的,我是做京东的。
    在我原有的代码基础上改了改,你试试把。
      

  5.   

    你为什么要把他弄成这个奇怪的一个数据结构。。
    你把每种类型整合为一个类不是很方便么。class Goods{
    String id;
    Set<String> colors;
    Set<String> sizes;
    //getter and setter
    }