Class TLcdWeakIdentityHashMap<K,V>

java.lang.Object
com.luciad.util.collections.TLcdWeakIdentityHashMap<K,V>
All Implemented Interfaces:
ILcdCloneable, Cloneable, Map<K,V>

public class TLcdWeakIdentityHashMap<K,V> extends Object implements Map<K,V>, ILcdCloneable
Hash map implementation with weak keys and identity-based comparison semantics. Keys are weakly referenced and not protected from a potential garbage collection. If a key becomes garbage collected, the corresponding entry is discarded. Cleanup is not asynchronous; it piggybacks on other operations. See WeakHashMap for a more detailed discussion.
Since:
2012.0
  • Constructor Details

    • TLcdWeakIdentityHashMap

      public TLcdWeakIdentityHashMap()
      Creates a new map with an initial capacity of 16 and load factor of 0.75.
    • TLcdWeakIdentityHashMap

      public TLcdWeakIdentityHashMap(int aInitialCapacity)
      Creates a new map with the given initial capacity and load factor of 0.75.
      Parameters:
      aInitialCapacity - the initial capacity of the map
    • TLcdWeakIdentityHashMap

      public TLcdWeakIdentityHashMap(int aInitialCapacity, float aLoadFactor)
      Creates a new map with the given initial capacity and the given load factor.
      Parameters:
      aInitialCapacity - the initial capacity of the map
      aLoadFactor - the load factor
      See Also:
    • TLcdWeakIdentityHashMap

      public TLcdWeakIdentityHashMap(Map aMap)
      Creates a new map containing all entries in the given map. The effect of this constructor is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map.
      Parameters:
      aMap - the map whose entries to load into this map.
      See Also:
  • Method Details

    • onRemove

      protected void onRemove(Object aKey, V aValue)
      Called when an entry is removed from the map (either by explicitly removing it, when it's overridden, or when it was removed because it was unreferenced)
      Parameters:
      aKey - the key. Can be null if it was unreferenced (when not hard-referenced anymore).
      aValue - the value
    • size

      public int size()
      Specified by:
      size in interface Map<K,V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()

      It is not allowed to access the map (for example calling get) while iterating over the result of this method, except via the Iterator.remove method. Not doing so may lead to ConcurrentModificationExceptions in rare cases.

      Specified by:
      entrySet in interface Map<K,V>
    • keySet

      public Set<K> keySet()

      It is not allowed to access the map (for example calling get) while iterating over the result of this method, except via the Iterator.remove method. Not doing so may lead to ConcurrentModificationExceptions in rare cases.

      Specified by:
      keySet in interface Map<K,V>
    • putAll

      public void putAll(Map<? extends K,? extends V> t)
      Specified by:
      putAll in interface Map<K,V>
    • get

      public V get(Object key)
      Specified by:
      get in interface Map<K,V>
    • remove

      public V remove(Object key)
      Specified by:
      remove in interface Map<K,V>
    • put

      public V put(K key, V value)
      Specified by:
      put in interface Map<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,V>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K,V>
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<K,V>
    • values

      public Collection<V> values()
      Specified by:
      values in interface Map<K,V>
    • clone

      public Object clone()
      Description copied from interface: ILcdCloneable

      Makes Object.clone() public.

      When for example extending from java.lang.Object, it can be implemented like this:
      
       public Object clone() {
         try {
           return super.clone();
         } catch ( CloneNotSupportedException e ) {
           // Cannot happen: extends from Object and implements Cloneable (see also Object.clone)
           throw new RuntimeException( e );
         }
       }
       
      Specified by:
      clone in interface ILcdCloneable
      Overrides:
      clone in class Object
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object