Package org.apache.jackrabbit.util
Class WeakIdentityCollection
- java.lang.Object
-
- org.apache.jackrabbit.util.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 returnnull
values. The same applies to the methodtoArray()
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(Object o)
Adds objecto
to this collection.boolean
addAll(Collection c)
void
clear()
Releases all references held by this collection.boolean
contains(Object o)
Returnstrue
if this collection containso
.boolean
containsAll(Collection c)
boolean
isEmpty()
Returnstrue
if this collection is empty.Iterator
iterator()
Returns anIterator
over the elements of this collection.boolean
remove(Object o)
Removes the objecto
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 containnull
elements!-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
Method Detail
-
size
public int size()
Returns the current size of this collection.- Specified by:
size
in interfaceCollection
- Returns:
- the current size of this collection.
-
isEmpty
public boolean isEmpty()
Returnstrue
if this collection is empty.- Specified by:
isEmpty
in interfaceCollection
- Returns:
true
if this collection is empty.
-
clear
public void clear()
Releases all references held by this collection.- Specified by:
clear
in interfaceCollection
-
add
public boolean add(Object o)
Adds objecto
to this collection.- Specified by:
add
in interfaceCollection
- Parameters:
o
- the object to add.- Returns:
- always
true
as this collection allows duplicates. - Throws:
NullPointerException
- ifo
isnull
.
-
contains
public boolean contains(Object o)
Returnstrue
if this collection containso
.- Specified by:
contains
in interfaceCollection
- 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 objecto
from this collection if it is present.- Specified by:
remove
in interfaceCollection
- Parameters:
o
- the object to remove.- Returns:
true
if this collection changed as a result of the call.
-
addAll
public boolean addAll(Collection c)
- Specified by:
addAll
in interfaceCollection
- Throws:
UnsupportedOperationException
- always.
-
containsAll
public boolean containsAll(Collection c)
- Specified by:
containsAll
in interfaceCollection
- Throws:
UnsupportedOperationException
- always.
-
removeAll
public boolean removeAll(Collection c)
- Specified by:
removeAll
in interfaceCollection
- Throws:
UnsupportedOperationException
- always.
-
retainAll
public boolean retainAll(Collection c)
- Specified by:
retainAll
in interfaceCollection
- Throws:
UnsupportedOperationException
- always.
-
iterator
public Iterator iterator()
Returns anIterator
over the elements of this collection. The returned iterator is not fail-fast. That is, it does not throw aConcurrentModificationException
if this collection is modified while iterating over the collection.- Specified by:
iterator
in interfaceCollection
- Specified by:
iterator
in interfaceIterable
- Returns:
- an
Iterator
over the elements of this collection.
-
toArray
public Object[] toArray()
Returns an array containing all of the elements in this collection. The returned array may containnull
elements!- Specified by:
toArray
in interfaceCollection
- Returns:
- an array containing all of the elements in this collection.
-
toArray
public Object[] toArray(Object[] a)
The returned array may containnull
elements!- Specified by:
toArray
in interfaceCollection
-
-