com.mizar.commons.collections
Class CacheMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap<K,V>
              extended by com.mizar.commons.collections.CacheMap<K,V>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<K,V>

public class CacheMap<K,V>
extends java.util.LinkedHashMap<K,V>
implements java.util.Map<K,V>, java.lang.Cloneable, java.io.Serializable

Extends java.util.LinkedHashMap implementing the removeEldestEntry method using the maxEntries property, which defaults to 1000. Unlike LinkedHashMap the accessOrder defaults to true

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
CacheMap()
           
CacheMap(int initialCapacity)
          load factor is defaulted to 0.75 accessOrder is defaulted to true
CacheMap(int initialCapacity, float loadFactor)
          accessOrder is defaulted to true
CacheMap(int initialCapacity, float loadFactor, boolean accessOrder)
           
CacheMap(int initialCapacity, int maxEntries)
           
CacheMap(java.util.Map<? extends K,? extends V> m)
          Constructs an insertion-ordered CacheMap instance with the same mappings as the specified map.
 
Method Summary
 int getMaxEntries()
           
protected  boolean removeEldestEntry(java.util.Map.Entry eldest)
           
 void setMaxEntries(int maxEntries)
          Sets the maximum size of the CacheMap.
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, get
 
Methods inherited from class java.util.HashMap
clone, containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

CacheMap

public CacheMap()

CacheMap

public CacheMap(int initialCapacity)
load factor is defaulted to 0.75 accessOrder is defaulted to true

Parameters:
initialCapacity -

CacheMap

public CacheMap(int initialCapacity,
                float loadFactor)
accessOrder is defaulted to true

Parameters:
initialCapacity -
loadFactor -

CacheMap

public CacheMap(int initialCapacity,
                float loadFactor,
                boolean accessOrder)
Parameters:
initialCapacity -
loadFactor -
accessOrder - the ordering mode - true for access-order, false for insertion-order.

CacheMap

public CacheMap(int initialCapacity,
                int maxEntries)
Parameters:
initialCapacity -
maxEntries -

CacheMap

public CacheMap(java.util.Map<? extends K,? extends V> m)
Constructs an insertion-ordered CacheMap instance with the same mappings as the specified map. The CacheMap instance is created with a a default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specified map.

Parameters:
m - the map whose mappings are to be placed in this map.
Method Detail

removeEldestEntry

protected boolean removeEldestEntry(java.util.Map.Entry eldest)
Overrides:
removeEldestEntry in class java.util.LinkedHashMap<K,V>
Parameters:
eldest -
Returns:

setMaxEntries

public void setMaxEntries(int maxEntries)
Sets the maximum size of the CacheMap. This can be increased but never decreased.

Parameters:
maxEntries -

getMaxEntries

public int getMaxEntries()
Returns:
the current setting of maxEntries