diff options
Diffstat (limited to 'main/src/cgeo/geocaching/Cache.java')
-rw-r--r-- | main/src/cgeo/geocaching/Cache.java | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/Cache.java b/main/src/cgeo/geocaching/Cache.java new file mode 100644 index 0000000..fd94d1f --- /dev/null +++ b/main/src/cgeo/geocaching/Cache.java @@ -0,0 +1,24 @@ +package cgeo.geocaching; + +import java.util.LinkedHashMap; + +/** + * Base class for a caching cache. Don't mix up with a geocache ! + * + * @author blafoo + */ +public class Cache<K, V> extends LinkedHashMap<K, V> { + + private static final long serialVersionUID = -5077882607489806620L; + private final int maxEntries; + + public Cache(int maxEntries) { + this.maxEntries = maxEntries; + } + + @Override + protected boolean removeEldestEntry(java.util.Map.Entry<K, V> eldest) { + return size() > maxEntries; + } + +} |