- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- org.arakhne.afc.references.AbstractReferencedSet<E,ComparableWeakReference<E>>
-
- org.arakhne.afc.references.WeakTreeSet<E>
-
- Type Parameters:
E
- is the type of the values.
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Set<E>
public class WeakTreeSet<E> extends AbstractReferencedSet<E,ComparableWeakReference<E>>
A Set implementation withweak values
. An entry in a WeakTreeSet will automatically be removed when its value is no longer in ordinary use or null.This class was inspirated from
WeakHashMap
and uses aTreeSet
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 WeakTreeSet()
Constructs an empty TreeSet.WeakTreeSet(Collection<? extends E> collection)
Constructs a new tree set containing the elements in the specified collection, sorted according to the natural ordering of its elements.WeakTreeSet(Comparator<? super E> comparator)
Constructs a new, empty tree set, sorted according to the specified comparator.WeakTreeSet(SortedSet<? extends E> set)
Constructs a new tree set containing the same elements and using the same ordering as the specified sorted set.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ComparableWeakReference<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
-
WeakTreeSet
public WeakTreeSet()
Constructs an empty TreeSet.
-
WeakTreeSet
public WeakTreeSet(Collection<? extends E> collection)
Constructs a new tree set containing the elements in the specified collection, sorted according to the natural ordering of its elements. All elements inserted into the set must implement theComparable
interface. Furthermore, all such elements must be mutually comparable:e1.compareTo(e2)
must not throw aClassCastException
for any elementse1
ande2
in the set.- Parameters:
collection
- collection whose elements will comprise the new set- Throws:
ClassCastException
- if the elements inc
are notComparable
, or are not mutually comparableNullPointerException
- if the specified collection is null
-
WeakTreeSet
public WeakTreeSet(SortedSet<? extends E> set)
Constructs a new tree set containing the same elements and using the same ordering as the specified sorted set.- Parameters:
set
- sorted set whose elements will comprise the new set- Throws:
NullPointerException
- if the specified sorted set is null
-
WeakTreeSet
public WeakTreeSet(Comparator<? super E> comparator)
Constructs a new, empty tree set, sorted according to the specified comparator. All elements inserted into the set must be mutually comparable by the specified comparator:comparator.compare(e1, e2)
must not throw aClassCastException
for any elementse1
ande2
in the set. If the user attempts to add an element to the set that violates this constraint, theadd
call will throw aClassCastException
.- Parameters:
comparator
- the comparator that will be used to order this set. Ifnull
, the natural ordering of the elements will be used.
-
-
Method Detail
-
createReference
protected final ComparableWeakReference<E> createReference(E element)
Description copied from class:AbstractReferencedSet
Create a reference on the given object.- Specified by:
createReference
in classAbstractReferencedSet<E,ComparableWeakReference<E>>
- Parameters:
element
- is the element to wrap into a reference- Returns:
- the reference of the given element.
-
-