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 and Description |
---|
WeakIdentityCollection(int initialCapacity)
Creates a new WeakIdentityCollection.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Object o)
Adds object
o to this collection. |
boolean |
addAll(Collection c) |
void |
clear()
Releases all references held by this collection.
|
boolean |
contains(Object o)
Returns
true if this collection contains o . |
boolean |
containsAll(Collection c) |
boolean |
isEmpty()
Returns
true if this collection is empty. |
Iterator |
iterator()
Returns an
Iterator over the elements of this
collection. |
boolean |
remove(Object o)
Removes the object
o from this collection if it is present. |
boolean |
removeAll(Collection c) |
boolean |
retainAll(Collection c) |
int |
size()
Returns the current size of this collection.
|
Object[] |
toArray()
Returns an array containing all of the elements in this collection.
|
Object[] |
toArray(Object[] a)
The returned array may contain
null elements!
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
equals, hashCode, parallelStream, removeIf, spliterator, stream
public WeakIdentityCollection(int initialCapacity)
initialCapacity
- the initial capacity.public int size()
size
in interface Collection
public boolean isEmpty()
true
if this collection is empty.isEmpty
in interface Collection
true
if this collection is empty.public void clear()
clear
in interface Collection
public boolean add(Object o)
o
to this collection.add
in interface Collection
o
- the object to add.true
as this collection allows duplicates.NullPointerException
- if o
is null
.public boolean contains(Object o)
true
if this collection contains o
.contains
in interface Collection
o
- element whose presence in this collection is to be tested.true
if this collection contains the specified
elementpublic boolean remove(Object o)
o
from this collection if it is present.remove
in interface Collection
o
- the object to remove.true
if this collection changed as a result of the
call.public boolean addAll(Collection c)
addAll
in interface Collection
UnsupportedOperationException
- always.public boolean containsAll(Collection c)
containsAll
in interface Collection
UnsupportedOperationException
- always.public boolean removeAll(Collection c)
removeAll
in interface Collection
UnsupportedOperationException
- always.public boolean retainAll(Collection c)
retainAll
in interface Collection
UnsupportedOperationException
- always.public Iterator iterator()
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.iterator
in interface Iterable
iterator
in interface Collection
Iterator
over the elements of this
collection.public Object[] toArray()
null
elements!toArray
in interface Collection
public Object[] toArray(Object[] a)
null
elements!
toArray
in interface Collection
Copyright © 2004–2022 The Apache Software Foundation. All rights reserved.