Back to project page androidata.
The source code is released under:
Apache License
If you think the Android project androidata listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.stanidesis.androidata; // w w w.j a va 2 s.co m import java.util.LinkedHashMap; import java.util.Map; /** * Created by Stanley Idesis on 11/1/14. */ public class LruCache<A, B> extends LinkedHashMap<A, B> { private static final int DEFAULT_CACHE_SIZE = 100; private final int maxEntries; public LruCache(){ this(DEFAULT_CACHE_SIZE); } public LruCache(final int maxEntries){ super(maxEntries + 1, 1.0f, true); this.maxEntries = maxEntries; } /** * Returns <tt>true</tt> if this <code>LruCache</code> has more entries than the maximum specified when it was * created. * * <p> * This method <em>does not</em> modify the underlying <code>Map</code>; it relies on the implementation of * <code>LinkedHashMap</code> to do that, but that behavior is documented in the JavaDoc for * <code>LinkedHashMap</code>. * </p> * * @param eldest * the <code>Entry</code> in question; this implementation doesn't care what it is, since the * implementation is only dependent on the size of the cache * @return <tt>true</tt> if the oldest * @see java.util.LinkedHashMap#removeEldestEntry(Map.Entry) */ @Override protected boolean removeEldestEntry(final Map.Entry<A, B>eldest){ return super.size() > maxEntries; } }