Class WeakIdentityCollection

  • All Implemented Interfaces:
    Iterable, Collection

    public class WeakIdentityCollection
    extends Object
    implements 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 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 Collection
        Returns:
        the current size of this collection.
      • isEmpty

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

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

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

        public boolean contains​(Object o)
        Returns true if this collection contains o.
        Specified by:
        contains in interface 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​(Object o)
        Removes the object o from this collection if it is present.
        Specified by:
        remove in interface Collection
        Parameters:
        o - the object to remove.
        Returns:
        true if this collection changed as a result of the call.
      • toArray

        public 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 Collection
        Returns:
        an array containing all of the elements in this collection.
      • toArray

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