- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- org.arakhne.afc.references.AbstractReferencedSet<E,ComparableSoftReference<E>>
-
- org.arakhne.afc.references.SoftTreeSet<E>
-
- Type Parameters:
E
- is the type of the values.
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Set<E>
public class SoftTreeSet<E> extends AbstractReferencedSet<E,ComparableSoftReference<E>>
A Set implementation withsoft values
. An entry in a SoftTreeSet 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 SoftTreeSet()
Constructs an empty TreeSet.SoftTreeSet(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.SoftTreeSet(Comparator<? super E> comparator)
Constructs a new, empty tree set, sorted according to the specified comparator.SoftTreeSet(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 ComparableSoftReference<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
-
SoftTreeSet
public SoftTreeSet()
Constructs an empty TreeSet.
-
SoftTreeSet
public SoftTreeSet(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
-
SoftTreeSet
public SoftTreeSet(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
-
SoftTreeSet
public SoftTreeSet(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 ComparableSoftReference<E> createReference(E element)
Description copied from class:AbstractReferencedSet
Create a reference on the given object.- Specified by:
createReference
in classAbstractReferencedSet<E,ComparableSoftReference<E>>
- Parameters:
element
- is the element to wrap into a reference- Returns:
- the reference of the given element.
-
-