日期:2014-05-19 浏览次数:20838 次
List<YtOaRole_temp> rolelist = rolemanagerbiz.getRolePage(pageBean); List<YtOaRole_temp> rolelist2 = new ArrayList(Arrays.asList(new YtOaRole_temp[rolelist.size()])); Collections.copy(rolelist2, rolelist); List<YtOaRole_temp> rolelist3=new ArrayList(); if(rolelist.size()>0) { for(int i=0;i<rolelist.size();i++) { YtOaRole_temp tem=new YtOaRole_temp(); tem=rolelist.get(i); for(int j=0;j<rolelist2.size();j++) { YtOaRole_temp tem1=new YtOaRole_temp(); tem1=rolelist2.get(j); if(tem.getRoleId().equals(tem1.getRoleId())) { tem.setPurviewId(tem.getPurviewId()+","+tem1.getPurviewId()); tem.setPurviewName(tem.getPurviewName()+","+tem1.getPurviewName()); //rolelist2.remove(j); //rolelist.remove(i); }else { rolelist3.add(tem); } }rolelist3.add(tem); } }
例如:2 普通用户角色 13,5,6.... 文件归档权限,文件审批菜单权限,归档库菜单权限...... roleid rolename purid purname是YtOaRole_temp的4个属性吧? List<YtOaRole_temp> list; Map<roleid,YtOaRole_temp> map=new Map<roleid,YtOaRole_temp>(); for(int i=0;i<list.size();i++){ YtOaRole_temp back=map.put(roleid,list.get(i)); if(!back=null){ map.get(roleid).setpurid(list.get(i).getpurid()+","+back.getpurid()); map.get(roleid).setpurname(list.get(i).getpurname()+","+back.getpurname()); } System.out.println(map.get(roleid).getroleid()+" "+map.get(roleid).getrolename()+" "+map.get(roleid).getpurid()+" "+map.get(roleid).getpurname();); }
------解决方案--------------------
先排序再合并,可以避免查找
for example
List<YtOaRole_temp> rolelist = rolemanagerbiz.getRolePage(pageBean); //获得原始数据 Collections.sort(rolelist, new Comparator<YtOaRole_temp>() { //先按roleid排序 public int compare(YtOaRole_temp y1, YtOaRole_temp y2) { return Integer.valueOf(y1.getRoleId()).compareTo(Integer.valu