Package org.qiunet.utils.collection.lru
Class LruHashMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
org.qiunet.utils.collection.lru.LruHashMap<K,V>
- All Implemented Interfaces:
Serializable,Cloneable,Map<K,V>
LruHashMap is an extension of Java's HashMap, which has a bounded size();
When it reaches that size, each time a new element is added, the least recently used (LRU) entry is removed.
Java makes it very easy to implement LruHashMap - all its functionality is already available from LinkedHashMap,
and we just need to configure that properly.
Note that LruHashMap is thread safe
- Author:
- kinson
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(Object key) intprotected booleanremoveEldestEntry(Map.Entry<K, V> eldest) voidsetMaxCapacity(int maxCapacity) intsize()Methods inherited from class java.util.LinkedHashMap
containsValue, entrySet, forEach, getOrDefault, keySet, replaceAll, valuesMethods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, isEmpty, merge, putAll, putIfAbsent, remove, replace, replaceMethods inherited from class java.util.AbstractMap
equals, hashCode, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, hashCode, isEmpty, merge, putAll, putIfAbsent, remove, replace, replace
-
Constructor Details
-
LruHashMap
public LruHashMap() -
LruHashMap
public LruHashMap(int maxCapacity)
-
-
Method Details
-
removeEldestEntry
- Overrides:
removeEldestEntryin classLinkedHashMap<K,V>
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classHashMap<K,V>
-
get
-
put
-
remove
-
size
public int size() -
clear
public void clear() -
getMaxCapacity
public int getMaxCapacity() -
setMaxCapacity
public void setMaxCapacity(int maxCapacity)
-