首页 新闻 会员 周边 捐助

基于此代码 如何对set根据 Y 、 Q、 M 、三个属性 进行排序?---我不想把map 改成实体类 工作量太大了

0
悬赏园豆:10 [待解决问题]

private void getYeJiDateChuLi_M(List<Map<String, Object>> yejiMapList,
Map<String, Object> yejiMap, List<RowMap> yejiBos1,
List<RowMap> yejiBos2) {
Set<Map<String, Object>> set = new HashSet<Map<String, Object>>();
Map<String, Object> map1 = null;
for (RowMap yejiRow1:yejiBos1) {
map1 = new HashMap<String, Object>();
map1.put("Y", yejiRow1.getString("PLANNED_Y"));
map1.put("Q", yejiRow1.getString("PLANNED_Q"));
map1.put("M", yejiRow1.getString("PLANNED_M"));
set.add(map1);
}
for (RowMap yejiRow2:yejiBos2) {
map1 = new HashMap<String, Object>();
map1.put("Y", yejiRow2.getString("SIGN_Y"));
map1.put("Q", yejiRow2.getString("SIGN_Q"));
map1.put("M", yejiRow2.getString("SIGN_M"));
set.add(map1);
}
if (set.size()>0) {
for (Map<String, Object> rowMap : set) {
yejiMap =new HashMap<String, Object>();
for (RowMap yejiRow1:yejiBos1) {
if (rowMap.get("Y").toString().equals(yejiRow1.getString("PLANNED_Y"))
&&rowMap.get("Q").toString().equals(yejiRow1.getString("PLANNED_Q"))
&&rowMap.get("M").toString().equals(yejiRow1.getString("PLANNED_M"))) {
yejiMap.put("Y", rowMap.get("Y"));
yejiMap.put("Q", rowMap.get("Q"));
yejiMap.put("M",rowMap.get("M"));
if (yejiRow1.get("PLANNED_CONTRACT") == null
||yejiRow1.get("PLANNED_CONTRACT").toString().equals("0.0")) {
yejiMap.put("PLANNED_CONTRACT",0.00);
}else {
yejiMap.put("PLANNED_CONTRACT",yejiRow1.get("PLANNED_CONTRACT"));
}
}
}
for (RowMap yejiRow2:yejiBos2) {
if (rowMap.get("Y").toString().equals(yejiRow2.getString("SIGN_Y"))
&&rowMap.get("Q").toString().equals(yejiRow2.getString("SIGN_Q"))
&&rowMap.get("M").toString().equals(yejiRow2.getString("SIGN_M"))) {
yejiMap.put("Y", rowMap.get("Y"));
yejiMap.put("Q", rowMap.get("Q"));
yejiMap.put("M",rowMap.get("M"));
if (yejiRow2.get("ACTUALCONTRACT") == null
||yejiRow2.get("ACTUALCONTRACT").toString().equals("0.0")) {
yejiMap.put("ACTUALCONTRACT", 0.00);
}else {
yejiMap.put("ACTUALCONTRACT", yejiRow2.get("ACTUALCONTRACT"));
}
}
}
if (yejiMap != null) {
if (yejiMap.get("PLANNED_CONTRACT")== null) {
yejiMap.put("PLANNED_CONTRACT", 0.00);
}
if (yejiMap.get("ACTUALCONTRACT")== null) {
yejiMap.put("ACTUALCONTRACT", 0.00);
}
}
if (yejiMap.get("PLANNED_CONTRACT")==null || yejiMap.get("ACTUALCONTRACT") == null
||yejiMap.get("PLANNED_CONTRACT").toString().equals("0.0") || yejiMap.get("ACTUALCONTRACT").toString().equals("0.0")) {
yejiMap.put("PROPORTION", "0.00"+"%");
}else {
String numStr = double_num.format((Double.valueOf(yejiMap.get("ACTUALCONTRACT").toString())/Double.valueOf(yejiMap.get("PLANNED_CONTRACT").toString()))*100)+"%";
yejiMap.put("PROPORTION", numStr);
}
yejiMapList.add(yejiMap);
}
}

问题补充:

通过时间叠加 加冒泡排序 解决了.............
int aNum=0;
int bNum =0;
int size = crmStrBuOneMapList.size();
Map<String,Object> boOneMap = null;
for(int i = 0 ; i < size-1; i ++) {
for(int j = 0 ;j < size-1-i ; j++){
if (crmStrBuOneMapList.get(j).get("M")!=null) {
aNum = Integer.valueOf(crmStrBuOneMapList.get(j).get("Y").toString()+crmStrBuOneMapList.get(j).get("Q").toString()+crmStrBuOneMapList.get(j).get("M").toString());
bNum = Integer.valueOf(crmStrBuOneMapList.get(j+1).get("Y").toString()+crmStrBuOneMapList.get(j+1).get("Q").toString()+crmStrBuOneMapList.get(j+1).get("M").toString());
}
if (crmStrBuOneMapList.get(j).get("Q")!=null) {
aNum = Integer.valueOf(crmStrBuOneMapList.get(j).get("Y").toString()+crmStrBuOneMapList.get(j).get("Q").toString());
bNum = Integer.valueOf(crmStrBuOneMapList.get(j+1).get("Y").toString()+crmStrBuOneMapList.get(j+1).get("Q").toString());
}
if (crmStrBuOneMapList.get(j).get("Y")!=null) {
aNum = Integer.valueOf(crmStrBuOneMapList.get(j).get("Y").toString());
bNum = Integer.valueOf(crmStrBuOneMapList.get(j+1).get("Y").toString());
}
if( aNum>bNum ){ //交换两map位置
boOneMap =new HashMap<String, Object>();
boOneMap.putAll(crmStrBuOneMapList.get(j));
crmStrBuOneMapList.get(j).putAll(crmStrBuOneMapList.get(j+1));
crmStrBuOneMapList.get(j+1).putAll(boOneMap);
}
}
}

R_Oasis的主页 R_Oasis | 初学一级 | 园豆:73
提问于:2018-09-13 12:31
< >
分享
所有回答(1)
0

可以写一个根据某一个key排序的工具方法。排序的具体实现可以选择算法,或者实现策略模式然后写多个实现。

surriento | 园豆:105 (初学一级) | 2018-09-13 13:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册