- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- org.arakhne.afc.references.AbstractReferencedSet<E,WeakReference<E>>
-
- org.arakhne.afc.references.WeakHashSet<E>
-
- Type Parameters:
E
- is the type of the values.
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Set<E>
public class WeakHashSet<E> extends AbstractReferencedSet<E,WeakReference<E>>
A Set implementation withweak values
. An entry in a WeakHashSet will automatically be removed when its value is no longer in ordinary use or null.This class was inspirated from
WeakHashMap
and uses aHashSet
as its internal data structure.This class has a special flag which permits to control the way how the released references are expurged:
AbstractReferencedSet.isDeeplyExpurge()
,AbstractReferencedSet.setDeeplyExpurge(boolean)
. If this flag istrue
, all the released references will be immediately removed from the map even if they are not enqueued by the virtual machine (seeAbstractReferencedSet.expurge()
. If this flag isfalse
, only the enqueued references will be removed from the map (seeAbstractReferencedSet.expurgeQueuedReferences()
.If this map does not use a "deep expurge" of the released references, it could contains
null
values that corresponds to values that are released by the garbage collector. If a "deep expurge" is used, all the values released by the garbage collector will be removed from the map."Deep expurge" consumes much more time that "No deep expurge". This is the reason why this feature is not activated by default.
The "deep expurge" feature was added to fix the uncoherent behavior of the garbage collector which seems to not always enqueued the released values (sometimes the queue is empty even if a value was released).
- Since:
- 5.9
- Version:
- 17.0 2020-01-04 14:41:38
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- references
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.arakhne.afc.references.AbstractReferencedSet
AbstractReferencedSet.ReferenceComparator<E,R extends Reference<E>>
-
-
Constructor Summary
Constructors Constructor Description WeakHashSet()
Constructs an empty HashSet.WeakHashSet(int initialCapacity)
Constructs a new, empty set; the backing HashSet instance has the specified initial capacity and default load factor (0.75).WeakHashSet(int initialCapacity, float loadFactor)
Constructs a new, empty set; the backing HashSet instance has the specified initial capacity and the specified load factor.WeakHashSet(Collection<? extends E> collection)
Constructs a new set containing the elements in the specified collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected WeakReference<E>
createReference(E element)
Create a reference on the given object.-
Methods inherited from class org.arakhne.afc.references.AbstractReferencedSet
add, equals, expurge, expurgeNow, expurgeQueuedReferences, hashCode, isDeeplyExpurge, iterator, setDeeplyExpurge, size
-
Methods inherited from class java.util.AbstractSet
removeAll
-
Methods inherited from class java.util.AbstractCollection
addAll, clear, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
-
-
-
Constructor Detail
-
WeakHashSet
public WeakHashSet()
Constructs an empty HashSet.
-
WeakHashSet
public WeakHashSet(int initialCapacity)
Constructs a new, empty set; the backing HashSet instance has the specified initial capacity and default load factor (0.75).- Parameters:
initialCapacity
- the initial capacity of the hash table- Throws:
IllegalArgumentException
- if the initial capacity is less than zero
-
WeakHashSet
public WeakHashSet(int initialCapacity, float loadFactor)
Constructs a new, empty set; the backing HashSet instance has the specified initial capacity and the specified load factor.- Parameters:
initialCapacity
- the initial capacity of the hash maploadFactor
- the load factor of the hash map- Throws:
IllegalArgumentException
- if the initial capacity is less than zero, or if the load factor is nonpositive
-
WeakHashSet
public WeakHashSet(Collection<? extends E> collection)
Constructs a new set containing the elements in the specified collection. The HashSet is created with default load factor (0.75) and an initial capacity sufficient to contain the elements in the specified collection.- Parameters:
collection
- the collection whose elements are to be placed into this set- Throws:
NullPointerException
- if the specified collection is null
-
-
Method Detail
-
createReference
protected final WeakReference<E> createReference(E element)
Description copied from class:AbstractReferencedSet
Create a reference on the given object.- Specified by:
createReference
in classAbstractReferencedSet<E,WeakReference<E>>
- Parameters:
element
- is the element to wrap into a reference- Returns:
- the reference of the given element.
-
-