ArrivalDataBuffer.java
2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.bsth.vehicle.gpsdata.buffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.bsth.vehicle.common.CommonMapped;
import com.bsth.vehicle.gpsdata.entity.ArrivalInfo;
import com.google.common.collect.ArrayListMultimap;
/**
*
* @ClassName: GpsArrivalDataBuffer
* @Description: TODO(GPS到离站数据缓存)
* @author PanZhao
* @date 2016年6月27日 下午1:08:35
*
*/
public class ArrivalDataBuffer {
/**
* 车辆 时间戳排序的实际进出站
*/
public static ArrayListMultimap<String, ArrivalInfo> allMap;
/**
* 车辆 和 进出站链表索引
*/
public static Map<String, Integer> markMap;
/**
* 时间戳标记,从数据库增量查询时起始时间
*/
public static Long markTime;
public static List<ArrivalInfo> pops(String nbbm) {
Integer mark = null;
if (!markMap.containsKey(nbbm))
mark = 0;
else
mark = markMap.get(nbbm);
List<ArrivalInfo> all = allMap.get(nbbm);
int size = all.size();
if(size == 0)
return new ArrayList<>(0);
List<ArrivalInfo> rs = all.subList(mark, size);
markMap.put(nbbm, size);
return rs;
}
static {
allMap = ArrayListMultimap.create();
markMap = new HashMap<>();
}
/**
*
* @Title: putAll @Description: TODO(将增量数据添加到缓存) @param @param list
* 设定文件 @return void 返回类型 @throws
*/
public static void putAll(List<ArrivalInfo> list) {
// 按时间戳排序
Collections.sort(list, new Comparator<ArrivalInfo>() {
@Override
public int compare(ArrivalInfo o1, ArrivalInfo o2) {
return (int) (o1.getCreateDate() - o2.getCreateDate());
}
});
int len = list.size();
ArrivalInfo arrival;
String nbbm;
for (int i = 0; i < len; i++) {
arrival = list.get(i);
nbbm = CommonMapped.vehicDeviceBiMap.get(arrival.getDeviceId());
if (null != nbbm)
allMap.put(nbbm, arrival);
}
}
/**
*
* @Title: clear
* @Description: TODO(清除缓存)
* @throws
*/
public static void clear(){
allMap = ArrayListMultimap.create();
markMap = new HashMap<>();
}
}