01: package org.shiftone.cache.policy.fifo;
02:
03: import org.shiftone.cache.Cache;
04:
05: /**
06: * @version $Revision: 1.2 $
07: * @author <a href="mailto:jeff@shiftone.org">Jeff Drost</a>
08: */
09: public class RingFifoCache implements Cache {
10:
11: private final int maxSize;
12: private final int[] indexes;
13: private final Object[] keys;
14: private final Object[] values;
15: private int nextIndexIndex = 0;
16:
17: public RingFifoCache(int maxSize) {
18:
19: this .maxSize = maxSize;
20: indexes = new int[maxSize];
21: keys = new Object[maxSize];
22: values = new Object[maxSize];
23: }
24:
25: private int getIndex(Object key) {
26: return (key.hashCode() % maxSize);
27: }
28:
29: public void addObject(Object userKey, Object cacheObject) {
30:
31: int index = getIndex(userKey);
32:
33: indexes[nextIndexIndex] = index;
34: nextIndexIndex = (nextIndexIndex + 1) % maxSize;
35: keys[index] = userKey;
36: values[index] = cacheObject;
37: }
38:
39: public Object getObject(Object key) {
40:
41: int index = getIndex(key);
42: Object k = keys[index];
43:
44: if ((k != null) && (k.equals(key))) {
45: return values[index];
46: }
47:
48: return null;
49: }
50:
51: public int size() {
52: return 0;
53: }
54:
55: public void remove(Object key) {
56: }
57:
58: public void clear() {
59: }
60: }
|