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<>();

  • 相关阅读:
    Delphi TWebBrowser[11] 读写html代码
    Nginx 配置反向代理
    清除git中缓存的凭证(用户名及密码)
    python 摄像头
    a 链接控制打开新窗口 无地址栏
    树形多级菜单数据源嵌套结构与扁平结构互转
    使用 git 的正确姿势
    JavaScript this
    JavaScript Scope Chain
    JavaScript Scope Context
  • 原文地址:https://www.cnblogs.com/cuijinlong/p/6743596.html
Copyright © 2011-2022 走看看