Class WeakIdentityCollection

  • All Implemented Interfaces:
    java.lang.Iterable, java.util.Collection

    public class WeakIdentityCollection
    extends java.lang.Object
    implements java.util.Collection
    WeakIdentityCollection implements a Collection with weak values. Equality of elements is tested using the == operator.

    This collection does not hide the fact that the garbage collector will remove a mapping at some point in time. Thus, the Iterator returned by this collection might return null values. The same applies to the method toArray() in both its variants.

    • Constructor Summary

      Constructors 
      Constructor Description
      WeakIdentityCollection​(int initialCapacity)
      Creates a new WeakIdentityCollection.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(java.lang.Object o)
      Adds object o to this collection.
      boolean addAll​(java.util.Collection c)  
      void clear()
      Releases all references held by this collection.
      boolean contains​(java.lang.Object o)
      Returns true if this collection contains o.
      boolean containsAll​(java.util.Collection c)  
      boolean isEmpty()
      Returns true if this collection is empty.
      java.util.Iterator iterator()
      Returns an Iterator over the elements of this collection.
      boolean remove​(java.lang.Object o)
      Removes the object o from this collection if it is present.
      boolean removeAll​(java.util.Collection c)  
      boolean retainAll​(java.util.Collection c)  
      int size()
      Returns the current size of this collection.
      java.lang.Object[] toArray()
      Returns an array containing all of the elements in this collection.
      java.lang.Object[] toArray​(java.lang.Object[] a)
      The returned array may contain null elements!
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Constructor Detail

      • WeakIdentityCollection

        public WeakIdentityCollection​(int initialCapacity)
        Creates a new WeakIdentityCollection.
        Parameters:
        initialCapacity - the initial capacity.
    • Method Detail

      • size

        public int size()
        Returns the current size of this collection.
        Specified by:
        size in interface java.util.Collection
        Returns:
        the current size of this collection.
      • isEmpty

        public boolean isEmpty()
        Returns true if this collection is empty.
        Specified by:
        isEmpty in interface java.util.Collection
        Returns:
        true if this collection is empty.
      • clear

        public void clear()
        Releases all references held by this collection.
        Specified by:
        clear in interface java.util.Collection
      • add

        public boolean add​(java.lang.Object o)
        Adds object o to this collection.
        Specified by:
        add in interface java.util.Collection
        Parameters:
        o - the object to add.
        Returns:
        always true as this collection allows duplicates.
        Throws:
        java.lang.NullPointerException - if o is null.
      • contains

        public boolean contains​(java.lang.Object o)
        Returns true if this collection contains o.
        Specified by:
        contains in interface java.util.Collection
        Parameters:
        o - element whose presence in this collection is to be tested.
        Returns:
        true if this collection contains the specified element
      • remove

        public boolean remove​(java.lang.Object o)
        Removes the object o from this collection if it is present.
        Specified by:
        remove in interface java.util.Collection
        Parameters:
        o - the object to remove.
        Returns:
        true if this collection changed as a result of the call.
      • addAll

        public boolean addAll​(java.util.Collection c)
        Specified by:
        addAll in interface java.util.Collection
        Throws:
        java.lang.UnsupportedOperationException - always.
      • containsAll

        public boolean containsAll​(java.util.Collection c)
        Specified by:
        containsAll in interface java.util.Collection
        Throws:
        java.lang.UnsupportedOperationException - always.
      • removeAll

        public boolean removeAll​(java.util.Collection c)
        Specified by:
        removeAll in interface java.util.Collection
        Throws:
        java.lang.UnsupportedOperationException - always.
      • retainAll

        public boolean retainAll​(java.util.Collection c)
        Specified by:
        retainAll in interface java.util.Collection
        Throws:
        java.lang.UnsupportedOperationException - always.
      • iterator

        public java.util.Iterator iterator()
        Returns an Iterator over the elements of this collection. The returned iterator is not fail-fast. That is, it does not throw a ConcurrentModificationException if this collection is modified while iterating over the collection.
        Specified by:
        iterator in interface java.util.Collection
        Specified by:
        iterator in interface java.lang.Iterable
        Returns:
        an Iterator over the elements of this collection.
      • toArray

        public java.lang.Object[] toArray()
        Returns an array containing all of the elements in this collection. The returned array may contain null elements!
        Specified by:
        toArray in interface java.util.Collection
        Returns:
        an array containing all of the elements in this collection.
      • toArray

        public java.lang.Object[] toArray​(java.lang.Object[] a)
        The returned array may contain null elements!
        Specified by:
        toArray in interface java.util.Collection