Created
March 8, 2015 07:02
-
-
Save iolo/1198ed0dc35516dba955 to your computer and use it in GitHub Desktop.
초간단 LRU 맵 구현
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kr.iolo.common.collection; | |
import java.util.LinkedHashMap; | |
import java.util.Map; | |
/** | |
* LRU 정책에 근거하여 맵의 항목을 유지하는 초간단 LRU 맵 구현. | |
* | |
* @author iolo | |
*/ | |
public class SimpleLRUMap<K, V> extends LinkedHashMap<K, V> { | |
private static final int DEF_MAX_SIZE = 100; | |
private final int maxSize; | |
public SimpleLRUMap() { | |
this(DEF_MAX_SIZE); | |
} | |
public SimpleLRUMap(int maxSize) { | |
this.maxSize = maxSize; | |
} | |
@Override | |
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) { | |
return size() > maxSize; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment