Class CacheMap<K,​V>

  • Type Parameters:
    K - the type of keys maintained by this map
    V - the type of mapped values
    All Implemented Interfaces:
    java.util.Map<K,​V>
    Direct Known Subclasses:
    ReportObjectFactory

    public class CacheMap<K,​V>
    extends SoftReferenceMap<K,​V>
    This is a Map implementation designed specifically for people intending to create a cache. The keys are held strongly, but the values are held softly, so the values can be garbage-collected. When an entry is garbage-collected, its key is removed from the Map on the next Map activity.

    The entrySet() and values() methods of this class do not work.

    Author:
    Matthew Wakeling
    See Also:
    SoftReference
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      CacheMap()
      Constructs a new, empty CacheMap with the default initial capacity (16) and the default load factor (0.75).
      CacheMap​(int initialCapacity)
      Constructs a new, empty CacheMap with the given initial capacity and the default load factor, which is 0.75.
      CacheMap​(int initialCapacity, float loadFactor)
      Constructs a new, empty CacheMap with the given initial capacity and the given load factor.
      CacheMap​(java.lang.String name)
      Constructs a new, empty CacheMap with the default initial capacity (16) and the default load factor (0.75), and a name.
      CacheMap​(java.util.Map<K,​V> t)
      Constructs a new CacheMap with the same mappings as the specified Map.
    • Constructor Detail

      • CacheMap

        public CacheMap​(int initialCapacity,
                        float loadFactor)
        Constructs a new, empty CacheMap with the given initial capacity and the given load factor.
        Parameters:
        initialCapacity - The initial capacity of the CacheMap
        loadFactor - The load factor of the CacheMap
        Throws:
        java.lang.IllegalArgumentException - If the initial capacity is negative, or if the load factor is nonpositive.
      • CacheMap

        public CacheMap​(int initialCapacity)
        Constructs a new, empty CacheMap with the given initial capacity and the default load factor, which is 0.75.
        Parameters:
        initialCapacity - The initial capacity of the CacheMap
        Throws:
        java.lang.IllegalArgumentException - If the initial capacity is negative.
      • CacheMap

        public CacheMap()
        Constructs a new, empty CacheMap with the default initial capacity (16) and the default load factor (0.75).
      • CacheMap

        public CacheMap​(java.lang.String name)
        Constructs a new, empty CacheMap with the default initial capacity (16) and the default load factor (0.75), and a name.
        Parameters:
        name - the name of the CacheMap - printed out in log messages
      • CacheMap

        public CacheMap​(java.util.Map<K,​V> t)
        Constructs a new CacheMap with the same mappings as the specified Map. The CacheMap is created with default load factor, which is 0.75 and an initial capacity sufficient to hold the mappings in the specified Map.
        Parameters:
        t - the map whose mappings are to be placed in this map.
        Throws:
        java.lang.NullPointerException - if the specified map is null.