GeoCacheData.java
5.27 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package com.bsth.data.geo;
import com.bsth.entity.CarPark;
import com.bsth.entity.GpsEntity;
import com.bsth.entity.SectionRoute;
import com.bsth.entity.StationRoute;
import com.bsth.util.geo.Point;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* 站点和路段空间数据缓存
*/
public class GeoCacheData {
/**
* K: lineCode_upDown V: 完整的路段
*/
private static ListMultimap<String, Point> fullSectionMaps;
/**
* K: lineCode_upDown
*/
private static ListMultimap<String, StationRoute> srsListMultiMap;
/**
* K: lineCode_upDown_stationCode
*/
private static ConcurrentMap<String, StationRoute> codeMap;
/**
* K: lineCode_upDown_stationName
*/
private static ConcurrentMap<String, StationRoute> nameMap;
/**
* K: lineCode_upDown 原始路段信息
*/
private static ListMultimap<String, SectionRoute> sectionMultiMap;
/**
* 停车场
*/
public static ConcurrentMap<String, CarPark> tccMap;
/**
* K: lineCode_upDown V: 0:有效的路段数据
*/
public static ConcurrentMap<String, Integer> lineValidMap;
static {
srsListMultiMap = Multimaps.synchronizedListMultimap(ArrayListMultimap.create());
fullSectionMaps = Multimaps.synchronizedListMultimap(ArrayListMultimap.create());
sectionMultiMap = ArrayListMultimap.create();
codeMap = new ConcurrentHashMap<>();
nameMap = new ConcurrentHashMap<>();
tccMap = new ConcurrentHashMap<>();
lineValidMap = new ConcurrentHashMap<>();
}
public static boolean isValidSection(String lineCode, int upDown) {
String k = lineCode + "_" + upDown;
if (!lineValidMap.containsKey(k))
return false;
return lineValidMap.get(k) != 1;
}
public static void put(ListMultimap<String, StationRoute> mMap,
ListMultimap<String, SectionRoute> sectionMaps,
ListMultimap<String, Point> fSectionMap) {
List<StationRoute> srs;
//put station
Set<String> ks = mMap.keySet();
for (String k : ks) {
srs = mMap.get(k);
srsListMultiMap.removeAll(k);
srsListMultiMap.putAll(k, srs);
//标记线路的路段数据是否有效
lineValidMap.put(k, 0);
for (StationRoute s : srs) {
if (null == s.getPaths() && !"E".equals(s.getMark())) {
lineValidMap.put(k, 1);//无效的路段数据
break;
}
}
}
Collection<StationRoute> vs = mMap.values();
String prefix;
for (StationRoute s : vs) {
prefix = s.getLineCode() + "_" + s.getUpDown() + "_";
codeMap.put(prefix + s.getStationCode(), s);
nameMap.put(prefix + s.getName(), s);
}
//put section
ks = sectionMaps.keySet();
for (String k : ks) {
sectionMultiMap.removeAll(k);
sectionMultiMap.putAll(k, sectionMaps.get(k));
}
//put full section
ks = fSectionMap.keySet();
for (String k : ks) {
fullSectionMaps.removeAll(k);
fullSectionMaps.putAll(k, fSectionMap.get(k));
}
}
public static List<Point> getFullSection(String lineCode, int upDown) {
return fullSectionMaps.get(lineCode + "_" + upDown);
}
public static void setTccMap(List<CarPark> list) {
ConcurrentMap<String, CarPark> map = new ConcurrentHashMap<>();
for (CarPark cp : list) {
map.put(cp.getCode(), cp);
}
tccMap = map;
}
public static CarPark getCarPark(String code) {
return tccMap.get(code);
}
public static Collection<CarPark> carPacks() {
return tccMap.values();
}
public static StationRoute findByName(String lineCode, int upDown, String name) {
return nameMap.get(lineCode + "_" + upDown + "_" + name);
}
public static StationRoute findByCode(String lineCode, int upDown, String code) {
return codeMap.get(lineCode + "_" + upDown + "_" + code);
}
public static StationRoute findByCode(GpsEntity gps) {
return codeMap.get(gps.getLineId() + "_" + gps.getUpDown() + "_" + gps.getStationCode());
}
public static List<StationRoute> find(String lineCode, int upDown) {
return srsListMultiMap.get(lineCode + "_" + upDown);
}
public static List<StationRoute>[] find(String lineCode) {
List<StationRoute>[] lists = new List[2];
lists[0] = find(lineCode, 0);
lists[1] = find(lineCode, 1);
return lists;
}
public static List<SectionRoute> findSections(String lineCode, int upDown) {
return sectionMultiMap.get(lineCode + "_" + upDown);
}
public static List<SectionRoute>[] findSections(String lineCode) {
List<SectionRoute>[] lists = new List[2];
lists[0] = findSections(lineCode, 0);
lists[1] = findSections(lineCode, 1);
return lists;
}
}