1 package org.apache.jcs.engine.memory;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23 import java.io.Serializable;
24 import java.util.HashMap;
25 import java.util.Iterator;
26 import java.util.Set;
27
28 import org.apache.jcs.engine.behavior.ICacheElement;
29 import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
30 import org.apache.jcs.engine.control.CompositeCache;
31 import org.apache.jcs.engine.stats.behavior.IStats;
32
33 /***
34 * Mock implementation of a memory cache for testing things like the memory
35 * shrinker.
36 * <p>
37 * @author Aaron Smuts
38 */
39 public class MemoryCacheMockImpl
40 implements MemoryCache
41 {
42 private ICompositeCacheAttributes cacheAttr;
43
44 private HashMap map = new HashMap();
45
46 /***
47 * The number of times waterfall was called.
48 */
49 public int waterfallCallCount = 0;
50
51 /***
52 * The number passed to the last call of free elements.
53 */
54 public int lastNumberOfFreedElements = 0;
55
56 public void initialize( CompositeCache cache )
57 {
58
59 }
60
61 public void dispose()
62 throws IOException
63 {
64
65
66 }
67
68 public int getSize()
69 {
70 return map.size();
71 }
72
73 public IStats getStatistics()
74 {
75
76 return null;
77 }
78
79 public Iterator getIterator()
80 {
81
82 return null;
83 }
84
85 public Object[] getKeyArray()
86 {
87 return map.keySet().toArray();
88 }
89
90 public boolean remove( Serializable key )
91 throws IOException
92 {
93 return map.remove( key ) != null;
94 }
95
96 public void removeAll()
97 throws IOException
98 {
99 map.clear();
100 }
101
102 public ICacheElement get( Serializable key )
103 throws IOException
104 {
105 return (ICacheElement) map.get( key );
106 }
107
108 public ICacheElement getQuiet( Serializable key )
109 throws IOException
110 {
111 return (ICacheElement) map.get( key );
112 }
113
114 public void waterfal( ICacheElement ce )
115 throws IOException
116 {
117 waterfallCallCount++;
118 }
119
120 public void update( ICacheElement ce )
121 throws IOException
122 {
123 if ( ce != null )
124 {
125 map.put( ce.getKey(), ce );
126 }
127 }
128
129
130
131
132
133
134 public ICompositeCacheAttributes getCacheAttributes()
135 {
136 return cacheAttr;
137 }
138
139
140
141
142
143
144 public void setCacheAttributes( ICompositeCacheAttributes cattr )
145 {
146 this.cacheAttr = cattr;
147 }
148
149 public CompositeCache getCompositeCache()
150 {
151
152 return null;
153 }
154
155 public Set getGroupKeys( String group )
156 {
157
158 return null;
159 }
160
161
162
163
164 public int freeElements( int numberToFree )
165 throws IOException
166 {
167 lastNumberOfFreedElements = numberToFree;
168 return 0;
169 }
170 }