public LinkedList<Map> getHomePageFocusVehiclesDistrictnam() {
JedisCluster jedis = RedisUtil.getRedisUtil().getJedis();
LinkedList<Map> numspotmaplist = new LinkedList<Map>();
// int a= Integer.MAX_VALUE;//无穷大
Map<String,Integer> gcdw = null;
String nowtime=DateUtil.NowDate();//获取当前时间
Set<String> member=jedis.zrevrange(nowtime+"_day_focus_vehicles_passtime_districtname_num", 0, -1);
gcdw=new HashMap<String, Integer>();
for (String str : member) {
String dianwei= str.split(",")[1];
if(gcdw.get(dianwei)==null||gcdw.get(dianwei).equals("")||gcdw.get(dianwei).equals("null")) {
gcdw.put(dianwei, 1);
}else {
gcdw.put(dianwei, gcdw.get(dianwei)+1);
}
}
List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(gcdw.entrySet());
Comparator<Map.Entry<String, Integer>> comparator = (Map.Entry<String, Integer> m1, Map.Entry<String, Integer> m2) -> m1.getValue().compareTo(m2.getValue());
list.sort(comparator.reversed()); //倒叙排序
Map <String,String> gcdwreturn;
if(list.size()>=8) {
for(int i= 0;i<7;i++) {
gcdwreturn=new HashMap<String, String>();
Entry<String, Integer> paixu= list.get(i);
gcdwreturn.put("key", paixu.getKey());
gcdwreturn.put("value", String.valueOf(paixu.getValue()));
numspotmaplist.add(gcdwreturn);
}
}else {
for(int i= 0;i<list.size();i++) {
gcdwreturn=new HashMap<String, String>();
Entry<String, Integer> paixu= list.get(i);
gcdwreturn.put("key", paixu.getKey());
gcdwreturn.put("value", String.valueOf(paixu.getValue()));
numspotmaplist.add(gcdwreturn);
}
}
return numspotmaplist;
}
Map 排序实例
最新推荐文章于 2022-09-07 16:40:42 发布