1 package org.apache.oro.util; 2 3 59 60 import java.util.*; 61 62 81 public abstract class GenericCache implements Cache, java.io.Serializable { 82 86 public static final int DEFAULT_CAPACITY = 20; 87 88 int _numEntries; 89 GenericCacheEntry[] _cache; 90 Hashtable _table; 91 92 101 GenericCache(int capacity) { 102 _numEntries = 0; 103 _table = new Hashtable(capacity); 104 _cache = new GenericCacheEntry[capacity]; 105 106 while(--capacity >= 0) 107 _cache[capacity] = new GenericCacheEntry(capacity); 108 } 109 110 public abstract void addElement(Object key, Object value); 111 112 public synchronized Object getElement(Object key) { 113 Object obj; 114 115 obj = _table.get(key); 116 117 if(obj != null) 118 return ((GenericCacheEntry)obj)._value; 119 120 return null; 121 } 122 123 public final Enumeration keys() { return _table.keys(); } 124 125 133 public final int size() { return _numEntries; } 134 135 140 public final int capacity() { return _cache.length; } 141 142 public final boolean isFull() { return (_numEntries >= _cache.length); } 143 } 144 | Popular Tags |