Package com.reve.utils.memory
Class MaxSizeHashMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
com.reve.utils.memory.MaxSizeHashMap<K,V>
- Type Parameters:
K- Key Type of this mapV- Value type of this map
- All Implemented Interfaces:
Serializable,Cloneable,Map<K,,V> SequencedMap<K,V>
This is a specialized
HashMap. Whenever the size of this hashmap grows to it's maximum size,
It will automatically remove the oldest element from the map. The definition of the oldest element is either
can be determined by map entry time or access time.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanremoveEldestEntry(Map.Entry<K, V> eldest) Check the condition if the eldest element needed to be removed or not.Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, newLinkedHashMap, putFirst, putLast, replaceAll, reversed, sequencedEntrySet, sequencedKeySet, sequencedValues, valuesMethods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, sizeMethods 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, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, sizeMethods inherited from interface java.util.SequencedMap
firstEntry, lastEntry, pollFirstEntry, pollLastEntry
-
Constructor Details
-
MaxSizeHashMap
public MaxSizeHashMap(int maxSize) Constructor- Parameters:
maxSize- Maximum allowed size for this map. When size of this map grows to this value the oldest element will automatically be removed.
-
-
Method Details
-
removeEldestEntry
Check the condition if the eldest element needed to be removed or not.- Overrides:
removeEldestEntryin classLinkedHashMap<K,V> - Parameters:
eldest- Eldest map element that is going to be removed.- Returns:
- true if the element is considered to be removed otherwise, false.
-