Class IdentityWeakHashMap<K,​V>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<K,​V>

    public class IdentityWeakHashMap<K,​V>
    extends java.util.AbstractMap<K,​V>
    implements java.util.Map<K,​V>, java.lang.Cloneable, java.io.Serializable
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

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

      Fields 
      Modifier and Type Field Description
      protected int count  
      protected org.eclipse.persistence.internal.helper.IdentityWeakHashMap.WeakEntry<K,​V>[] entries  
      protected float loadFactor  
      protected java.lang.ref.ReferenceQueue referenceQueue
      This is used by the garbage collector.
      protected int threshold  
    • Constructor Summary

      Constructors 
      Constructor Description
      IdentityWeakHashMap()
      Constructs a new IdentityWeakHashMap with a default initial capacity of 32 and a loadfactor of 0.75.
      IdentityWeakHashMap​(int initialCapacity)
      Constructs a new IdentityWeakHashMap with the given initial capacity and a default loadFactor of 0.75.
      IdentityWeakHashMap​(int initialCapacity, float loadFactor)
      Constructs a new IdentityWeakHashMap with the given initial capacity and the given loadFactor.
      IdentityWeakHashMap​(java.util.Map m)
      Constructs a new IdentityWeakHashMap with the same mappings as the given map.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void cleanUp()  
      void clear()
      Removes all of the mappings from this IdentityWeakHashMap.
      java.lang.Object clone()
      Returns a shallow copy of this IdentityWeakHashMap (the elements are not cloned).
      boolean containsKey​(java.lang.Object key)
      Returns true if this IdentityWeakHashMap contains a mapping for the given key.
      boolean containsValue​(java.lang.Object obj)
      Returns true if this IdentityWeakHashMap contains the given object.
      java.util.Set entrySet()
      Returns a collection view of the mappings contained in this IdentityWeakHashMap.
      V get​(java.lang.Object key)
      Returns the value to which the given key is mapped in this IdentityWeakHashMap.
      boolean isEmpty()  
      java.util.Set keySet()
      Returns a set view of the keys contained in this IdentityWeakHashMap.
      V put​(K key, V obj)
      Associate the given object with the given key in this IdentityWeakHashMap, replacing any existing mapping.
      void putAll​(java.util.Map<? extends K,​? extends V> m)
      Copies all of the mappings from the given map to this IdentityWeakHashMap, replacing any existing mappings.
      V remove​(java.lang.Object key)
      Removes the mapping (key and its corresponding value) from this IdentityWeakHashMap, if present.
      protected boolean removeEntry​(org.eclipse.persistence.internal.helper.IdentityWeakHashMap.WeakEntry o, boolean userModification)  
      int size()  
      java.util.Collection values()
      Returns a collection view of the values contained in this IdentityWeakHashMap.
      • 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

        compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • entries

        protected transient org.eclipse.persistence.internal.helper.IdentityWeakHashMap.WeakEntry<K,​V>[] entries
      • count

        protected transient int count
      • threshold

        protected int threshold
      • loadFactor

        protected float loadFactor
      • referenceQueue

        protected java.lang.ref.ReferenceQueue referenceQueue
        This is used by the garbage collector. Every weak reference that is garbage collected will be enqueued on this. Then only this queue needs to be checked to remove empty references.
    • Constructor Detail

      • IdentityWeakHashMap

        public IdentityWeakHashMap​(int initialCapacity,
                                   float loadFactor)
        Constructs a new IdentityWeakHashMap with the given initial capacity and the given loadFactor.
        Parameters:
        initialCapacity - the initial capacity of this IdentityWeakHashMap.
        loadFactor - the loadFactor of the IdentityWeakHashMap.
        Throws:
        java.lang.IllegalArgumentException - if the initial capacity is less than zero, or if the loadFactor is nonpositive.
      • IdentityWeakHashMap

        public IdentityWeakHashMap​(int initialCapacity)
        Constructs a new IdentityWeakHashMap with the given initial capacity and a default loadFactor of 0.75.
        Parameters:
        initialCapacity - the initial capacity of the IdentityWeakHashMap.
      • IdentityWeakHashMap

        public IdentityWeakHashMap()
        Constructs a new IdentityWeakHashMap with a default initial capacity of 32 and a loadfactor of 0.75.
      • IdentityWeakHashMap

        public IdentityWeakHashMap​(java.util.Map m)
        Constructs a new IdentityWeakHashMap with the same mappings as the given map. The IdentityWeakHashMap is created with a capacity sufficient to hold the elements of the given map.
        Parameters:
        m - the map whose mappings are to be placed in the IdentityWeakHashMap.
    • Method Detail

      • size

        public int size()
        Specified by:
        size in interface java.util.Map<K,​V>
        Overrides:
        size in class java.util.AbstractMap<K,​V>
        Returns:
        the size of this IdentityWeakHashMap.
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<K,​V>
        Overrides:
        isEmpty in class java.util.AbstractMap<K,​V>
        Returns:
        true if this IdentityWeakHashMap is empty.
      • containsValue

        public boolean containsValue​(java.lang.Object obj)
        Returns true if this IdentityWeakHashMap contains the given object. Equality is tested by the equals() method.
        Specified by:
        containsValue in interface java.util.Map<K,​V>
        Overrides:
        containsValue in class java.util.AbstractMap<K,​V>
        Parameters:
        obj - the object to find.
        Returns:
        true if this IdentityWeakHashMap contains obj.
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Returns true if this IdentityWeakHashMap contains a mapping for the given key. Equality is tested by reference.
        Specified by:
        containsKey in interface java.util.Map<K,​V>
        Overrides:
        containsKey in class java.util.AbstractMap<K,​V>
        Parameters:
        key - object to be used as a key into this IdentityWeakHashMap.
        Returns:
        true if this IdentityWeakHashMap contains a mapping for key.
      • get

        public V get​(java.lang.Object key)
        Returns the value to which the given key is mapped in this IdentityWeakHashMap. Returns null if this IdentityWeakHashMap contains no mapping for this key.
        Specified by:
        get in interface java.util.Map<K,​V>
        Overrides:
        get in class java.util.AbstractMap<K,​V>
        Parameters:
        key - key whose associated value is to be returned.
        Returns:
        the value to which this IdentityWeakHashMap maps the given key.
      • put

        public V put​(K key,
                     V obj)
        Associate the given object with the given key in this IdentityWeakHashMap, replacing any existing mapping.
        Specified by:
        put in interface java.util.Map<K,​V>
        Overrides:
        put in class java.util.AbstractMap<K,​V>
        Parameters:
        key - key to map to given object.
        obj - object to be associated with key.
        Returns:
        the previous object for key or null if this IdentityWeakHashMap did not have one.
      • remove

        public V remove​(java.lang.Object key)
        Removes the mapping (key and its corresponding value) from this IdentityWeakHashMap, if present.
        Specified by:
        remove in interface java.util.Map<K,​V>
        Overrides:
        remove in class java.util.AbstractMap<K,​V>
        Parameters:
        key - key whose mapping is to be removed from the map.
        Returns:
        the previous object for key or null if this IdentityWeakHashMap did not have one.
      • removeEntry

        protected boolean removeEntry​(org.eclipse.persistence.internal.helper.IdentityWeakHashMap.WeakEntry o,
                                      boolean userModification)
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends V> m)
        Copies all of the mappings from the given map to this IdentityWeakHashMap, replacing any existing mappings.
        Specified by:
        putAll in interface java.util.Map<K,​V>
        Overrides:
        putAll in class java.util.AbstractMap<K,​V>
        Parameters:
        m - mappings to be stored in this IdentityWeakHashMap.
      • clear

        public void clear()
        Removes all of the mappings from this IdentityWeakHashMap.
        Specified by:
        clear in interface java.util.Map<K,​V>
        Overrides:
        clear in class java.util.AbstractMap<K,​V>
      • cleanUp

        protected void cleanUp()
      • clone

        public java.lang.Object clone()
        Returns a shallow copy of this IdentityWeakHashMap (the elements are not cloned).
        Overrides:
        clone in class java.util.AbstractMap<K,​V>
        Returns:
        a shallow copy of this IdentityWeakHashMap.
      • keySet

        public java.util.Set keySet()
        Returns a set view of the keys contained in this IdentityWeakHashMap. The set is backed by the map, so changes to the map are reflected in the set, and vice versa. The set supports element removal, which removes the corresponding mapping from this map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
        Specified by:
        keySet in interface java.util.Map<K,​V>
        Overrides:
        keySet in class java.util.AbstractMap<K,​V>
        Returns:
        a set view of the keys contained in this IdentityWeakHashMap.
      • values

        public java.util.Collection values()
        Returns a collection view of the values contained in this IdentityWeakHashMap. The collection is backed by the map, so changes to the map are reflected in the collection, and vice versa. The collection supports element removal, which removes the corresponding mapping from this map, via the Iterator.remove, Collection.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
        Specified by:
        values in interface java.util.Map<K,​V>
        Overrides:
        values in class java.util.AbstractMap<K,​V>
        Returns:
        a collection view of the values contained in this IdentityWeakHashMap.
      • entrySet

        public java.util.Set entrySet()
        Returns a collection view of the mappings contained in this IdentityWeakHashMap. Each element in the returned collection is a Map.Entry. The collection is backed by the map, so changes to the map are reflected in the collection, and vice versa. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        Specified by:
        entrySet in class java.util.AbstractMap<K,​V>
        Returns:
        a collection view of the mappings contained in this IdentityWeakHashMap.