一、得到需要排序的list
for(String meter :meterList){
//根據電表編號獲取計量點名稱
String mpName = cusMeterDao.selectMpNameByMeter(meter);
PieReturn pieReturn = new PieReturn();
BigDecimal bigDecimal = stringBigDecimalMap.get(meter);
if(bigDecimal!=null ){
/*if(bigDecimal.compareTo(new BigDecimal(0))<0){//發現負值強制歸零
bigDecimal=new BigDecimal(0);
}*/
pieReturn.setValue(MathUtils.towDecimal(bigDecimal));
pieReturn.setName(mpName);
dataList.add(pieReturn);
}
}
二、對list進行排序-排序規則是自定義的一個規則,從對象中去除一個屬性值進行比較大小
//對返回的list進行排序
Collections.sort(dataList,new Comparator<PieReturn>(){ //排序
@Override
public int compare(PieReturn o1, PieReturn o2) {
if(o1.getValue()!=null && o2.getValue()!=null){
return o1.getValue().compareTo(o2.getValue());
}else {
return -1;
}
}
});
