zoukankan      html  css  js  c++  java
  • Map KEY 排序

        List<String> snList = new ArrayList<>();
        List<Position> positionList = VehicleControlUtil.getVehicleLocationBaiDuFromSn(strSn);
        StringBuffer sb2 = new StringBuffer();
        for(Position position : positionList)
        {
         sb2.append(position.getY()+","+position.getX()+"|");
         snList.add(position.getSn());
        }
        String destination = sb2.toString().substring(0, sb2.toString().length() - 1);
        Map<String, Double> mapSNandDistance = new HashMap<String, Double>();
        List<Map> resutlMap = BaiDuAPIUtil.routematrix(latitude+","+longitude, destination);
        int iSort =0;
        for(Map  map:resutlMap){//先取出所有车辆的距离,然后在进行取出最近的6辆车
          Map mapD = (Map) map.get("distance");    
          mapSNandDistance.put(snList.get(iSort).toString(), Double.parseDouble(mapD.get("value").toString()));
          iSort++;
        }
        
        List<Map.Entry<String, Double>> infoIds = new ArrayList<Map.Entry<String, Double>>(mapSNandDistance.entrySet());
        Collections.sort(infoIds, new Comparator<Map.Entry<String, Double>>() {  
            public int compare(Map.Entry<String, Double> o1, Map.Entry<String, Double> o2) {     
                return o2.getValue() - o1.getValue() > 0 ? -1 : 1;
            }
        });
        infoIds = infoIds.subList(0, 6);
        snList = new ArrayList<>();

  • 相关阅读:
    C语言寒假大作战01
    C语言I作业12—学期总结
    C语言I博客作业11
    C语言I博客作业10
    非数值数据的编码方式
    定点数
    C语言||作业01
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
  • 原文地址:https://www.cnblogs.com/cuijinlong/p/6743596.html
Copyright © 2011-2022 走看看