01: package org.shiftone.cache.adaptor;
02:
03: import org.shiftone.cache.Cache;
04:
05: import java.util.HashMap;
06: import java.util.Map;
07:
08: /**
09: * Makes a map look like a shiftone cache.
10: *
11: * @version $Revision: 1.5 $
12: * @author <a href="mailto:jeff@shiftone.org">Jeff Drost</a>
13: */
14: public class MapCache implements Cache {
15:
16: private final Map map;
17:
18: public MapCache() {
19: this (new HashMap());
20: }
21:
22: public MapCache(Map map) {
23: this .map = map;
24: }
25:
26: public void addObject(Object userKey, Object cacheObject) {
27: map.put(userKey, cacheObject);
28: }
29:
30: public Object getObject(Object key) {
31: return map.get(key);
32: }
33:
34: public int size() {
35: return map.size();
36: }
37:
38: public void remove(Object key) {
39: map.remove(key);
40: }
41:
42: public void clear() {
43: map.clear();
44: }
45:
46: public String toString() {
47: return "MapCache[" + map.getClass().getName() + "]";
48: }
49: }
|