1 package org.apache.oro.util; 2 3 59 60 import java.util.*; 61 62 74 75 public final class CacheFIFO extends GenericCache { 76 private int __curent = 0; 77 78 83 public CacheFIFO(int capacity) { 84 super(capacity); 85 } 86 87 88 94 public CacheFIFO(){ 95 this(GenericCache.DEFAULT_CAPACITY); 96 } 97 98 99 107 public final synchronized void addElement(Object key, Object value) { 108 int index; 109 Object obj; 110 111 obj = _table.get(key); 112 113 if(obj != null) { 114 GenericCacheEntry entry; 115 116 entry = (GenericCacheEntry)obj; 119 entry._value = value; 120 entry._key = key; 121 122 return; 123 } 124 125 if(!isFull()) { 127 index = _numEntries; 128 ++_numEntries; 129 } else { 130 index = __curent; 133 134 if(++__curent >= _cache.length) 135 __curent = 0; 136 137 _table.remove(_cache[index]._key); 138 } 139 140 _cache[index]._value = value; 141 _cache[index]._key = key; 142 _table.put(key, _cache[index]); 143 } 144 145 } 146 | Popular Tags |