Map 排序实例

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;
		}
		
	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值