Class LRUMap<KEYTYPE,VALUETYPE>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<K,V>
-
- java.util.LinkedHashMap<KEYTYPE,VALUETYPE>
-
- com.helger.commons.collection.impl.CommonsLinkedHashMap<KEYTYPE,VALUETYPE>
-
- com.helger.commons.collection.map.LRUMap<KEYTYPE,VALUETYPE>
-
- Type Parameters:
KEYTYPE- Key typeVALUETYPE- Value type
- All Implemented Interfaces:
ICommonsMap<KEYTYPE,VALUETYPE>,ICommonsOrderedMap<KEYTYPE,VALUETYPE>,ICloneable<ICommonsMap<KEYTYPE,VALUETYPE>>,Serializable,Cloneable,Map<KEYTYPE,VALUETYPE>
- Direct Known Subclasses:
LoggingLRUMap
@NotThreadSafe @UseDirectEqualsAndHashCode public class LRUMap<KEYTYPE,VALUETYPE> extends CommonsLinkedHashMap<KEYTYPE,VALUETYPE>
A special ordered map, that has an upper limit of contained elements. It is therefore a "Last Recently Used" map.- Author:
- Philip Helger
- See Also:
- Serialized Form
-
-
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>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)LRUMap<KEYTYPE,VALUETYPE>getClone()intgetMaxSize()inthashCode()protected voidonRemoveEldestEntry(int nSize, Map.Entry<KEYTYPE,VALUETYPE> aEldest)Protected method that is invoked every time the oldest entry is removed.protected booleanremoveEldestEntry(Map.Entry<KEYTYPE,VALUETYPE> aEldest)StringtoString()-
Methods inherited from class com.helger.commons.collection.impl.CommonsLinkedHashMap
createInstance
-
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
-
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.collection.impl.ICommonsMap
addAll, containsAnyEntry, containsAnyKey, containsAnyValue, copyOfValues, copyOfValues, copyOfValuesMapped, copyOfValuesMapped, findFirstEntry, findFirstKey, findFirstValue, forEach, forEachKey, forEachKey, forEachValue, forEachValue, getAsUnmodifiable, getFirstEntry, getFirstEntry, getFirstKey, getFirstKey, getFirstValue, getFirstValue, getSortedByKey, getSortedByValue, getSwappedKeyValues, isNotEmpty, put, putAll, putAll, putAllMapped, putAllMapped, putAllMapped, putIf, putIfNotNull, removeAll, removeIf, removeIfKey, removeIfValue, removeObject, setAll
-
Methods inherited from interface com.helger.commons.collection.impl.ICommonsOrderedMap
copyOfEntrySet, copyOfKeySet, copyOfKeySet, getLastKey, getLastKey, getLastValue, getLastValue
-
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
-
-
-
Constructor Detail
-
LRUMap
public LRUMap(@Nonnegative int nMaxSize)
Create a new object with the specified max size.- Parameters:
nMaxSize- The maximum number of elements in this cache. May not be < 0.
-
-
Method Detail
-
getClone
@Nonnull public LRUMap<KEYTYPE,VALUETYPE> getClone()
- Specified by:
getClonein interfaceICloneable<KEYTYPE>- Specified by:
getClonein interfaceICommonsOrderedMap<KEYTYPE,VALUETYPE>- Overrides:
getClonein classCommonsLinkedHashMap<KEYTYPE,VALUETYPE>- Returns:
- A 100% deep-copy of the implementing class.
-
getMaxSize
@Nonnegative public final int getMaxSize()
- Returns:
- The maximum number of elements that can reside inside this object. Never < 0.
-
onRemoveEldestEntry
@OverrideOnDemand protected void onRemoveEldestEntry(@Nonnegative int nSize, @Nonnull Map.Entry<KEYTYPE,VALUETYPE> aEldest)
Protected method that is invoked every time the oldest entry is removed.- Parameters:
nSize- Current size of the map. Always ≥ 0.aEldest- The map entry that is removed. Nevernull.
-
removeEldestEntry
protected final boolean removeEldestEntry(@Nonnull Map.Entry<KEYTYPE,VALUETYPE> aEldest)
- Overrides:
removeEldestEntryin classLinkedHashMap<KEYTYPE,VALUETYPE>
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
toString
public String toString()
- Overrides:
toStringin classAbstractMap<KEYTYPE,VALUETYPE>
-
-