今日遇到一个问题,需要整理每个分类下所缺少的尺码和颜色。
输入形式是一个
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中。
求实现方法、
感觉逻辑太复杂了,弄混了
输入形式是一个
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中。
求实现方法、
感觉逻辑太复杂了,弄混了
你做成map的时候,颜色的属性值到哪里去了。
建议把颜色,尺码什么的封装到一个类中
先创建一个类,把属性封装到类里面,这样就不会那么复杂了。
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;
}
}
不知道你做哪个平台的,我是做京东的。
在我原有的代码基础上改了改,你试试把。
你把每种类型整合为一个类不是很方便么。class Goods{
String id;
Set<String> colors;
Set<String> sizes;
//getter and setter
}