Class MaxSizeLinkedHashMap<K,V>

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
com.icegreen.greenmail.util.MaxSizeLinkedHashMap<K,V>
Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>

public class MaxSizeLinkedHashMap<K,V> extends LinkedHashMap<K,V>
A LinkedHashMap with a maximum size. Adding an Entry that would exceed this size results in removing the eldest entry.
Author:
Raimund Klein <raimund.klein@gmx.de>
See Also:
  • Constructor Details

    • MaxSizeLinkedHashMap

      public MaxSizeLinkedHashMap(int maxSize)
      Constructs a MaxSizeLinkedHashMap with maximum size maxSize.
      Parameters:
      maxSize - The maximum size for this MaxSizeLinkedHashMap.
      Throws:
      IllegalArgumentException - if maxSize is not positive.
  • Method Details

    • removeEldestEntry

      protected boolean removeEldestEntry(Map.Entry<K,V> eldest)

      This implementation will return true if this MaxSizeLinkedHashMap has reached its maximum size, else false.

      Overrides:
      removeEldestEntry in class LinkedHashMap<K,V>