EMMA Coverage Report (generated Tue Apr 17 08:51:20 BST 2007)
[all classes][org.jtoolkit.essence.data.impl]

COVERAGE SUMMARY FOR SOURCE FILE [CacheStore.java]

nameclass, %method, %block, %line, %
CacheStore.java100% (5/5)30%  (18/60)27%  (188/701)29%  (36.4/126)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CacheStore$StoreView100% (1/1)25%  (7/28)12%  (53/432)13%  (9/71)
addListener (CacheListener): void 0%   (0/1)0%   (0/14)0%   (0/1)
containsKey (Object): boolean 0%   (0/1)0%   (0/6)0%   (0/1)
containsValue (Object): boolean 0%   (0/1)0%   (0/6)0%   (0/1)
entrySet (): Set 0%   (0/1)0%   (0/22)0%   (0/3)
evict (): void 0%   (0/1)0%   (0/1)0%   (0/1)
getAll (Collection): Map 0%   (0/1)0%   (0/39)0%   (0/6)
getCacheStatistics (): CacheStatistics 0%   (0/1)0%   (0/14)0%   (0/1)
isEmpty (): boolean 0%   (0/1)0%   (0/5)0%   (0/1)
load (Object): void 0%   (0/1)0%   (0/1)0%   (0/1)
loadAll (Collection): void 0%   (0/1)0%   (0/1)0%   (0/1)
peek (Object): Object 0%   (0/1)0%   (0/6)0%   (0/1)
putAll (Map): void 0%   (0/1)0%   (0/6)0%   (0/2)
putIfAbsent (Object, Object): Object 0%   (0/1)0%   (0/34)0%   (0/4)
remove (Object): Object 0%   (0/1)0%   (0/6)0%   (0/1)
remove (Object, Object): boolean 0%   (0/1)0%   (0/39)0%   (0/6)
removeListener (CacheListener): void 0%   (0/1)0%   (0/1)0%   (0/1)
removeMatching (Predicate): int 0%   (0/1)0%   (0/36)0%   (0/8)
replace (Object, Object): Object 0%   (0/1)0%   (0/30)0%   (0/5)
replace (Object, Object, Object): boolean 0%   (0/1)0%   (0/40)0%   (0/6)
selectMatching (Predicate): Map 0%   (0/1)0%   (0/45)0%   (0/7)
values (): Collection 0%   (0/1)0%   (0/22)0%   (0/3)
keySet (): Set 100% (1/1)77%  (17/22)67%  (2/3)
CacheStore$StoreView (CacheStore): void 100% (1/1)100% (6/6)100% (1/1)
clear (): void 100% (1/1)100% (5/5)100% (2/2)
get (Object): Object 100% (1/1)100% (6/6)100% (1/1)
getCacheEntry (Object): CacheEntry 100% (1/1)100% (7/7)100% (1/1)
put (Object, Object): Object 100% (1/1)100% (7/7)100% (1/1)
size (): int 100% (1/1)100% (5/5)100% (1/1)
     
class CacheStore100% (1/1)29%  (5/17)40%  (66/167)53%  (20.5/39)
access$100 (CacheStore): String 0%   (0/1)0%   (0/3)0%   (0/1)
asMap (): Map 0%   (0/1)0%   (0/3)0%   (0/1)
getCacheView (): Cache 0%   (0/1)0%   (0/3)0%   (0/1)
getCluster (): Cluster 0%   (0/1)0%   (0/13)0%   (0/1)
getListenerSet (): Event$ListenerSet 0%   (0/1)0%   (0/4)0%   (0/1)
getName (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getQueueView (): Queue 0%   (0/1)0%   (0/4)0%   (0/1)
isClosed (): boolean 0%   (0/1)0%   (0/3)0%   (0/1)
removeMatching (Predicate): int 0%   (0/1)0%   (0/5)0%   (0/1)
selectMatching (Predicate): Map 0%   (0/1)0%   (0/5)0%   (0/1)
throwUseACluster (): Object 0%   (0/1)0%   (0/13)0%   (0/1)
visit (Visitor): Object 0%   (0/1)0%   (0/4)0%   (0/1)
CacheStore (int, CacheComponentBuilder$CacheData): void 100% (1/1)58%  (52/90)70%  (16/23)
<static initializer> 100% (1/1)100% (4/4)100% (1/1)
access$000 (CacheStore): Map 100% (1/1)100% (3/3)100% (1/1)
close (): void 100% (1/1)100% (4/4)100% (2/2)
getMapView (): ConcurrentMap 100% (1/1)100% (3/3)100% (1/1)
     
class CacheStore$CSCacheEntry100% (1/1)25%  (3/12)40%  (19/48)36%  (5/14)
getCost (): long 0%   (0/1)0%   (0/2)0%   (0/1)
getCreationTime (): long 0%   (0/1)0%   (0/2)0%   (0/1)
getExpirationTime (): long 0%   (0/1)0%   (0/2)0%   (0/1)
getHits (): int 0%   (0/1)0%   (0/2)0%   (0/1)
getLastAccessTime (): long 0%   (0/1)0%   (0/2)0%   (0/1)
getLastUpdateTime (): long 0%   (0/1)0%   (0/2)0%   (0/1)
getVersion (): long 0%   (0/1)0%   (0/2)0%   (0/1)
isValid (): boolean 0%   (0/1)0%   (0/7)0%   (0/1)
setValue (Object): Object 0%   (0/1)0%   (0/8)0%   (0/1)
CacheStore$CSCacheEntry (CacheStore, Object): void 100% (1/1)100% (9/9)100% (3/3)
getKey (): Object 100% (1/1)100% (3/3)100% (1/1)
getValue (): Object 100% (1/1)100% (7/7)100% (1/1)
     
class CacheStore$2100% (1/1)100% (1/1)88%  (29/33)87%  (0.9/1)
<static initializer> 100% (1/1)88%  (29/33)87%  (0.9/1)
     
class CacheStore$1100% (1/1)100% (2/2)100% (21/21)100% (2/2)
CacheStore$1 (CacheStore, int, float, boolean, int): void 100% (1/1)100% (12/12)100% (1/1)
removeEldestEntry (Map$Entry): boolean 100% (1/1)100% (9/9)100% (1/1)

1package org.jtoolkit.essence.data.impl;
2 
3import org.apache.commons.logging.Log;
4import org.apache.commons.logging.LogFactory;
5import org.jetbrains.annotations.NotNull;
6import org.jetbrains.annotations.Nullable;
7import org.jtoolkit.essence.data.*;
8import org.jtoolkit.essence.data.EvictionStrategy;
9 
10import javax.cache.*;
11import java.util.*;
12import java.util.concurrent.ConcurrentMap;
13 
14public class CacheStore<K, V> implements Store<K, V> {
15    private static final Log LOG = LogFactory.getLog(CacheStore.class);
16    private final String name;
17    private final Map<K, V> map;
18    private final StoreView view;
19    private boolean closed = false;
20 
21    public CacheStore(int defaultCacheSize, CacheComponentBuilder.CacheData cd) {
22        name = cd.name;
23        int cacheSize = defaultCacheSize;
24        if (cd.cacheSize == null) {
25            if (cd.evictionStrategy != EvictionStrategy.NONE)
26                LOG.info(cd.name + ": The default cache size of " + defaultCacheSize + " is used.");
27        } else {
28            cacheSize = cd.cacheSize;
29        }
30        boolean reordered = false;
31        switch (cd.evictionStrategy) {
32            case LFU:
33                LOG.warn(cd.name + ": Eviction policy LFU not supported, LRU used instead.");
34                reordered = true;
35                break;
36            case LRU:
37                reordered = true;
38                break;
39            case FIFO:
40                reordered = false;
41                break;
42            case NONE:
43                reordered = false;
44                cacheSize = Integer.MAX_VALUE;
45                break;
46        }
47        final int cacheSize2 = cacheSize;
48        //noinspection ClassExtendsConcreteCollection
49        map = Collections.synchronizedMap(new LinkedHashMap<K, V>(64, 0.7f, reordered) {
50            protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
51                return size() > cacheSize2;
52            }
53        });
54        view = new StoreView();
55    }
56 
57    public Cluster getCluster() {
58        throw new UnsupportedOperationException(name + ": Not a member of a cluster");
59    }
60 
61    @NotNull public Event.ListenerSet getListenerSet() {
62        return throwUseACluster();
63    }
64 
65    private <T> T throwUseACluster() {
66        throw new UnsupportedOperationException(name + ": Not supported for simple cache, use a Cluster.");
67    }
68 
69    @NotNull public Cache<K, V> getCacheView() {
70        return view;
71    }
72 
73    @NotNull public ConcurrentMap<K, V> getMapView() {
74        return view;
75    }
76 
77    @NotNull public Queue<V> getQueueView() {
78        return throwUseACluster();
79    }
80 
81    @NotNull public Map<K, V> asMap() {
82        return view;
83    }
84 
85    public Map<K, V> selectMatching(Predicate<Map.Entry<K, V>> predicate) {
86        return view.selectMatching(predicate);
87    }
88 
89    public int removeMatching(Predicate<Map.Entry<K, V>> predicate) {
90        return view.removeMatching(predicate);
91    }
92 
93    public void close() {
94        closed = true;
95    }
96 
97    public boolean isClosed() {
98        return closed;
99    }
100 
101    @NotNull public String getName() {
102        return name;
103    }
104 
105    public <R> R visit(@NotNull Visitor<Store<K, V>, R> visitor) throws VisitorException {
106        return visitor.visit(this);
107    }
108 
109    class StoreView implements Cache<K, V>, ConcurrentMap<K, V> {
110 
111        public V get(Object key) {
112            return map.get(key);
113        }
114 
115        public Map<K, V> getAll(@NotNull Collection<K> keys) throws CacheException {
116            Map<K, V> ret = new LinkedHashMap<K, V>();
117            synchronized (map) {
118                for (K key : keys)
119                    ret.put(key, map.get(key));
120            }
121            return ret;
122        }
123 
124        public void load(@NotNull K key) throws CacheException {
125        }
126 
127        public void loadAll(@NotNull Collection<K> keys) throws CacheException {
128        }
129 
130        public V peek(@NotNull K key) {
131            return map.get(key);
132        }
133 
134        public CacheEntry<K, V> getCacheEntry(@NotNull final K key) {
135            return new CSCacheEntry(key);
136        }
137 
138        public CacheStatistics getCacheStatistics() {
139            throw new UnsupportedOperationException(name + ": CacheStats not supported, try Cluster");
140        }
141 
142        public void evict() {
143        }
144 
145        public void addListener(@NotNull CacheListener<K> cacheListener) {
146            throw new UnsupportedOperationException(name + ": CacheListeners not supported, try Cluster");
147        }
148 
149        public void removeListener(@NotNull CacheListener<K> cacheListener) {
150        }
151 
152        public int size() {
153            return map.size();
154        }
155 
156        public boolean isEmpty() {
157            return map.isEmpty();
158        }
159 
160        public boolean containsKey(Object key) {
161            return map.containsKey(key);
162        }
163 
164        public boolean containsValue(Object value) {
165            return map.containsValue(value);
166        }
167 
168        public V put(K key, V value) {
169            return map.put(key, value);
170        }
171 
172        public V remove(Object key) {
173            return map.remove(key);
174        }
175 
176        public void putAll(Map<? extends K, ? extends V> t) {
177            map.putAll(t);
178        }
179 
180        public void clear() {
181            map.clear();
182        }
183 
184        public Set<K> keySet() {
185            synchronized (map) {
186                return Collections.unmodifiableSet(new LinkedHashSet<K>(map.keySet()));
187            }
188        }
189 
190        public Collection<V> values() {
191            synchronized (map) {
192                return Collections.unmodifiableCollection(new ArrayList<V>(map.values()));
193            }
194        }
195 
196        public Set<Entry<K, V>> entrySet() {
197            synchronized (map) {
198                return Collections.unmodifiableMap(new LinkedHashMap<K, V>(map)).entrySet();
199            }
200        }
201 
202        public V putIfAbsent(K key, V value) {
203            synchronized (map) {
204                if (map.containsKey(key)) return map.get(key);
205                else return map.put(key, value);
206            }
207        }
208 
209        @SuppressWarnings({"SuspiciousMethodCalls"})
210        public boolean remove(Object key, Object value) {
211            synchronized (map) {
212                if (map.containsKey(key) && map.get(key).equals(value)) {
213                    map.remove(key);
214                    return true;
215                } else return false;
216            }
217        }
218 
219        public boolean replace(K key, V oldValue, V newValue) {
220            synchronized (map) {
221                if (map.containsKey(key) && map.get(key).equals(oldValue)) {
222                    map.put(key, newValue);
223                    return true;
224                } else return false;
225            }
226        }
227 
228        @Nullable public V replace(K key, V value) {
229            synchronized (map) {
230                if (map.containsKey(key)) {
231                    return map.put(key, value);
232                } else return null;
233            }
234        }
235 
236        public Map<K, V> selectMatching(Predicate<Entry<K, V>> predicate) {
237            Map<K, V> ret = new LinkedHashMap<K, V>();
238            synchronized (map) {
239                for (Map.Entry<K, V> entry : map.entrySet())
240                    if (predicate.isSatisfiedBy(entry))
241                        ret.put(entry.getKey(), entry.getValue());
242            }
243            return ret;
244        }
245 
246        public int removeMatching(Predicate<Entry<K, V>> predicate) {
247            int count = 0;
248            synchronized (map) {
249                for (Iterator<Map.Entry<K, V>> i = map.entrySet().iterator(); i.hasNext();)
250                    if (predicate.isSatisfiedBy(i.next())) {
251                        i.remove();
252                        count++;
253                    }
254            }
255            return count;
256        }
257    }
258 
259    private class CSCacheEntry implements CacheEntry<K, V> {
260        private final K key;
261 
262        CSCacheEntry(K key) {
263            this.key = key;
264        }
265 
266        public long getCost() {
267            return -1;
268        }
269 
270        public long getCreationTime() {
271            return -1;
272        }
273 
274        public long getExpirationTime() {
275            return Long.MAX_VALUE;
276        }
277 
278        public int getHits() {
279            return -1;
280        }
281 
282        public long getLastAccessTime() {
283            return -1;
284        }
285 
286        public long getLastUpdateTime() {
287            return -1;
288        }
289 
290        public long getVersion() {
291            return -1;
292        }
293 
294        public boolean isValid() {
295            return map.containsKey(key);
296        }
297 
298        public K getKey() {
299            return key;
300        }
301 
302        public V getValue() {
303            return map.get(key);
304        }
305 
306        public V setValue(V value) {
307            return map.put(key, value);
308        }
309    }
310}

[all classes][org.jtoolkit.essence.data.impl]
EMMA 2.0.5312 (C) Vladimir Roubtsov