1 package org.jgap.util; 2 3 import java.util.*; 4 5 public class LRUCache extends LinkedHashMap { 6 // Create cache 7 8 private int m_maxEntries; 9 10 public LRUCache(int a_maxExtries) { 11 super(a_maxExtries+1, 0.75F, true); 12 m_maxEntries = a_maxExtries; 13 } 14 // This method is called just after a new entry has been added 15 public boolean removeEldestEntry(Map.Entry eldest) { 16 return size() > m_maxEntries; 17 } 18 19 // If the cache is to be used by multiple threads, 20 // the cache must be wrapped with code to synchronize the methods 21 // cache = (Map) Collections.synchronizedMap(cache); 22 } 23