01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: package de.uka.ilkd.key.util;
09:
10: import java.util.LinkedHashMap;
11: import java.util.Map;
12:
13: /**
14: * Simple realisation of an LRU cache.
15: */
16: public class LRUCache extends LinkedHashMap {
17:
18: /** maximal cache size */
19: private final int maxEntries;
20:
21: /**
22: * creates a new LRU cached with maxEntires slots
23: */
24: public LRUCache(int maxEntries) {
25: super ((int) (maxEntries * 1.01), 1.0F, true);
26: this .maxEntries = maxEntries;
27: }
28:
29: /**
30: * removes the eldest entry, i.e. the least recently used one
31: */
32: protected boolean removeEldestEntry(Map.Entry eldest) {
33: return size() > maxEntries;
34: }
35: }
|