1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.cache;
24
25 import java.io.Serializable;
26 import java.util.Collection;
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.util.Set;
30
31
32 /***
33 * Simple cache implementation using a HashMap.
34 *
35 * <b>Note that this implementation is not synchronized.</b> If multiple
36 * threads access this cache concurrently, and at least one of the threads
37 * modifies the cache structurally, it <i>must</i> be synchronized externally.
38 * (A structural modification is any operation that adds or deletes one or
39 * more mappings; merely changing the value associated with a key that an
40 * instance already contains is not a structural modification.)<p>
41 *
42 *
43 * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
44 */
45 public final class SimpleCache extends AbstractBaseCache implements Serializable {
46
47 /*** serial version ID for serialization. */
48 private static final long serialVersionUID = 4740967132553277227L;
49
50 /***
51 * Constructor.
52 */
53 public SimpleCache() {
54 super();
55 }
56
57 /***
58 * {@inheritDoc}
59 * @see de.bea.domingo.cache.AbstractBaseCache#createMap()
60 */
61 protected Map createMap() {
62 return new HashMap();
63 }
64
65 /***
66 * {@inheritDoc}
67 * @see de.bea.domingo.cache.Cache#get(java.lang.Object)
68 */
69 public Object get(final Object key) {
70 return getMap().get(key);
71 }
72
73 /***
74 * {@inheritDoc}
75 * @see de.bea.domingo.cache.Cache#put(java.lang.Object, java.lang.Object)
76 */
77 public void put(final Object key, final Object value) {
78 getMap().put(key, value);
79 }
80
81 /***
82 * {@inheritDoc}
83 * @see de.bea.domingo.cache.Cache#containsKey(java.lang.Object)
84 */
85 public boolean containsKey(final Object key) {
86 return getMap().containsKey(key);
87 }
88
89 /***
90 * {@inheritDoc}
91 * @see de.bea.domingo.cache.Cache#remove(java.lang.Object)
92 */
93 public Object remove(final Object key) {
94 return getMap().remove(key);
95 }
96
97 /***
98 * {@inheritDoc}
99 * @see de.bea.domingo.cache.Cache#clear()
100 */
101 public void clear() {
102 getMap().clear();
103 }
104
105 /***
106 * {@inheritDoc}
107 * @see de.bea.domingo.cache.AbstractBaseCache#keySet()
108 */
109 public Set keySet() {
110 return getMap().keySet();
111 }
112
113 /***
114 * {@inheritDoc}
115 * @see de.bea.domingo.cache.AbstractBaseCache#values()
116 */
117 public Collection values() {
118 return getMap().values();
119 }
120 }