1 package com.trendmicro.grid.acl.ds.cache.commands;
2
3 import com.trendmicro.grid.acl.ds.cache.CacheSettings;
4 import com.trendmicro.grid.acl.ds.cache.CacheSource;
5
6 import java.util.Collection;
7 import java.util.Iterator;
8 import java.util.Map;
9
10
11
12
13
14
15
16
17
18
19 public class RetainMissingKeysCommand<K, V> extends AbstractCommand<K, V> {
20
21 private CacheSource<K, V> cache;
22
23
24
25
26
27
28
29 public RetainMissingKeysCommand(Collection<K> keys, CacheSource<K, V> cache) {
30 super(keys);
31 this.cache = cache;
32 }
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 protected void retainMissingKeys(Collection<K> keys) {
48 for (Iterator<K> iterator = keys.iterator(); iterator.hasNext();) {
49 if (cache.containsKey(iterator.next())) iterator.remove();
50 }
51 }
52
53
54
55
56 @Override
57 public Map<K, V> call() throws Exception {
58 if (!CacheSettings.NO_NEGATIVE_CACHING) retainMissingKeys(keys);
59
60 return keysToCallResult();
61 }
62 }