首页  >  问答  >  正文

java - 两个size大小大于300w个的List<Map<String,Obkect>>进行配对运算,及排序.这样速度是不是很慢

这样的运行速度快吗
private List<Map<String, Object>> getRankingList(RankingCachingParameter parameterObject) {

    List<Map<String,Object>> nowDay = isMapper.getdata(parameterObject.day)//从数据库中得到数据;
    List<Map<String,Object>> yesterdayDay =     isMapper.getdata(parameterObject.yesterday)//从数据库中得到数据;
    Map<String,Map<String,Object>> yesterdayDayMap=new HashMap<String,Map<String,Object>>(65536);
    yesterdayDay.parallelStream().forEach((Map<String,Object> map) ->{
        Long numiid=(Long) map.get("numiid");
        Integer type=(Integer) map.get("type");
        Integer page=(Integer) map.get("page");
        String gener=""+numiid+type+page;
        yesterdayDayMap.put(gener, map);
    });
    nowDay.parallelStream().forEach((Map<String,Object> map) ->{
        Long numiid=(Long) map.get("numiid");
        Integer type=(Integer) map.get("type");
        Integer page=(Integer) map.get("page");
        Integer nowdayKeyWord=(Integer) map.get("keywordCount");
        String gener=""+numiid+type+page;
        Integer yesterdayKeyWord = (Integer) yesterdayDayMap.get(gener).get("keywordCount");
        double growthIndex = (nowdayKeyWord-yesterdayKeyWord)/nowdayKeyWord;
        map.put("growthIndex", growthIndex);
    });
    if(parameterObject.orderBy.equals("growthIndex")){
        nowDay.sort((Map<String,Object> map1,Map<String,Object> map2) ->{
            Double growthIndex1 = (Double) map1.get("growthIndex");
            Double growthIndex2 = (Double) map2.get("growthIndex");
            if (growthIndex2 != null) {
                return growthIndex1.compareTo(growthIndex2);
            }
               return 0;
              
        });
    }
    return nowDay;
}
PHP中文网PHP中文网2765 天前481

全部回复(1)我来回复

  • 阿神

    阿神2017-04-17 17:48:28

    额。。。。。 直接 list.sorted((o1,o2)->o1.keySet().hashCode() - o2.keySet().hashCode()).forEach(...)
    哪有你这么麻烦。

    回复
    0
  • 取消回复