1、以经纬度数据为key,用户数为value 的格式将数据进行缓存;
2、将每次接收到的热力图数据与已缓存的数据进行比对,key匹配上的将已缓存value替换,未匹配的直接缓存;
@Data
public class Points {
private Double lon;
private Double lat;
private Integer userCnt;
private Integer isInner;
}
public static void main(String[] args) {
ArrayList<Points> olderList = new ArrayList<>();
// 推送过来的数据
ArrayList<Points> newList = new ArrayList<>();
//ba把经纬度拿出来 作为key
Map<String, Points> oldlist2 = olderList.stream().collect(Collectors.toMap(y -> (y.getLat() + "," + y.getLon()), x ->x));
// 判断缓存是否包含
newList.stream().forEach(x -> {
String latLon = x.getLat() + "," + x.getLon();
boolean b = oldlist2.containsKey(latLon);
//包含修改 userCnt;
if(b){
Points point = (Points)MapUtils.getObject(oldlist2, latLon);
point.setUserCnt(x.getUserCnt());
}else {
//不包含就添加s
oldlist2.put(latLon,x);
}
});
//map的 value 得到一个新的list
Collection<Points> values = oldlist2.values();
System.out.println(values);
}