List>>集合排序比较

//实现Comparator接口
public class ComparatorTravelSkyFlights implements Comparator<Map.Entry<String,List<EntityName>>> {
String sortColumn = "";
        public ComparatorT() {

}
        //传参比较
        public ComparatorT(String sortColumn) {
this.sortColumn = sortColumn;
        }
        //实现compare类,获取实体里面的参数进行比较
         @Override
public int compare(Map.Entry<String,List<EntityName>>                    mapping1,Map.Entry<String,List<EntityName>> mapping2){
    if("depTime".equals(this.sortColumn)){
    if(mapping1.getValue().size() > 0
                     && mapping2.getValue().size() > 0){
if(mapping1.getValue().get(0).getDepDate() != null
                     && mapping2.getValue().get(0).getDepDate() !=null){
     return mapping1.getValue().get(0).getDepDate().toString().
                  compareTo(mapping2.getValue().get(0).getDepDate().toString());
   }
   }
else{
if(mapping1.getValue().size() == 0){
return -1;
}
else{
return 1;
}
}
return -1;
    }
  
   }
}

}

//调用方法
List<Map.Entry<String,List<EntityName>>> mappingList = null;
//通过ArrayList构造函数把map.entrySet()转换成list
mappingList = new ArrayList<Map.Entry<String,List<EntityName>>>(entityName.entrySet());
//通过比较器实现比较排序,ordColumn需要排序方式上升或下降
ComparatorTravelSkyFlights comparatorT = new ComparatorTravelSkyFlights(ordColumn);
Collections.sort(mappingList, comparatorT);

你可能感兴趣的:(Map排序,List集合的Map排序,List排序,复杂集合排序)