1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io.cache; |
22 |
|
|
23 |
|
import jalview.bin.Cache; |
24 |
|
|
25 |
|
import java.util.Hashtable; |
26 |
|
import java.util.LinkedHashSet; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@author |
32 |
|
|
33 |
|
|
|
|
| 97.8% |
Uncovered Elements: 1 (45) |
Complexity: 14 |
Complexity Density: 0.48 |
|
34 |
|
public class AppCache |
35 |
|
{ |
36 |
|
public static final String DEFAULT_LIMIT = "99"; |
37 |
|
|
38 |
|
public static final String CACHE_DELIMITER = ";"; |
39 |
|
|
40 |
|
private static AppCache instance = null; |
41 |
|
|
42 |
|
private static final String DEFAULT_LIMIT_KEY = ".DEFAULT_LIMIT"; |
43 |
|
|
44 |
|
private Hashtable<String, LinkedHashSet<String>> cacheItems; |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
46 |
4 |
private AppCache()... |
47 |
|
{ |
48 |
4 |
cacheItems = new Hashtable<String, LinkedHashSet<String>>(); |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@param |
55 |
|
@return |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
57 |
21 |
public LinkedHashSet<String> getAllCachedItemsFor(String cacheKey)... |
58 |
|
{ |
59 |
21 |
LinkedHashSet<String> foundCache = cacheItems.get(cacheKey); |
60 |
21 |
if (foundCache == null) |
61 |
|
{ |
62 |
8 |
foundCache = new LinkedHashSet<String>(); |
63 |
8 |
cacheItems.put(cacheKey, foundCache); |
64 |
|
} |
65 |
21 |
return foundCache; |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
@return |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
73 |
11 |
public static AppCache getInstance()... |
74 |
|
{ |
75 |
11 |
if (instance == null) |
76 |
|
{ |
77 |
4 |
instance = new AppCache(); |
78 |
|
} |
79 |
11 |
return instance; |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
@param |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
87 |
4 |
public void persistCache(String cacheKey)... |
88 |
|
{ |
89 |
4 |
LinkedHashSet<String> foundCacheItems = getAllCachedItemsFor(cacheKey); |
90 |
4 |
StringBuffer delimitedCacheBuf = new StringBuffer(); |
91 |
4 |
for (String cacheItem : foundCacheItems) |
92 |
|
{ |
93 |
10 |
delimitedCacheBuf.append(CACHE_DELIMITER).append(cacheItem); |
94 |
|
} |
95 |
4 |
if (delimitedCacheBuf.length() > 0) |
96 |
|
{ |
97 |
1 |
delimitedCacheBuf.deleteCharAt(0); |
98 |
|
} |
99 |
4 |
String delimitedCacheString = delimitedCacheBuf.toString(); |
100 |
|
|
101 |
4 |
Cache.setProperty(cacheKey, delimitedCacheString); |
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
@param |
108 |
|
|
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
110 |
1 |
public void deleteCacheItems(String cacheKey)... |
111 |
|
{ |
112 |
1 |
cacheItems.put(cacheKey, new LinkedHashSet<String>()); |
113 |
1 |
persistCache(cacheKey); |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
@param |
120 |
|
|
121 |
|
@return |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
123 |
15 |
public String getCacheLimit(String cacheKey)... |
124 |
|
{ |
125 |
15 |
String uniqueKey = cacheKey + DEFAULT_LIMIT_KEY; |
126 |
15 |
return Cache.getDefault(uniqueKey, DEFAULT_LIMIT); |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
@param |
133 |
|
|
134 |
|
@param |
135 |
|
|
136 |
|
|
137 |
|
@return |
138 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 4 |
Complexity Density: 0.57 |
|
139 |
2 |
public int updateCacheLimit(String cacheKey, int newUserLimit)... |
140 |
|
{ |
141 |
2 |
String newLimit = String.valueOf(newUserLimit); |
142 |
2 |
String uniqueKey = cacheKey + DEFAULT_LIMIT_KEY; |
143 |
2 |
String formerLimit = getCacheLimit(cacheKey); |
144 |
2 |
if (newLimit != null && !newLimit.isEmpty() |
145 |
|
&& !formerLimit.equals(newLimit)) |
146 |
|
{ |
147 |
2 |
Cache.setProperty(uniqueKey, newLimit); |
148 |
2 |
formerLimit = newLimit; |
149 |
|
} |
150 |
2 |
return Integer.valueOf(formerLimit); |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
@param |
158 |
|
|
159 |
|
@param |
160 |
|
|
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
162 |
3 |
public void putCache(String cacheKey, LinkedHashSet<String> newCacheItems)... |
163 |
|
{ |
164 |
3 |
cacheItems.put(cacheKey, newCacheItems); |
165 |
|
} |
166 |
|
|
167 |
|
} |