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 map
V - Value type of this map
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>

public class MaxSizeHashMap<K,V> extends LinkedHashMap<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:
  • 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

      protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
      Check the condition if the eldest element needed to be removed or not.
      Overrides:
      removeEldestEntry in class LinkedHashMap<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.