01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.sail.nativerdf;
07:
08: import java.util.LinkedHashMap;
09: import java.util.Map;
10:
11: /**
12: * Utility subclass of {@link LinkedHashMap} the makes it a fixed-size LRU
13: * cache.
14: *
15: * @author Arjohn Kampman
16: */
17: class LRUCache<K, V> extends LinkedHashMap<K, V> {
18:
19: private static final long serialVersionUID = -8180282377977820910L;
20:
21: private int capacity;
22:
23: public LRUCache(int capacity) {
24: this (capacity, 0.75f);
25: }
26:
27: public LRUCache(int capacity, float loadFactor) {
28: super ((int) (capacity / loadFactor), loadFactor, true);
29: this .capacity = capacity;
30: }
31:
32: public int getCapacity() {
33: return capacity;
34: }
35:
36: @Override
37: protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
38: return size() > capacity;
39: }
40: }
|