java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
org.litebridge.commons.type.WeakIdentitySet<E>
- Type Parameters:
E- the type of elements maintained by this set
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Set<E>
A Set implementation that uses identity comparison for object equality,
and holds its elements weakly, meaning elements are eligible for garbage
collection if no strong references to them exist outside this set.
This class is backed by a WeakIdentityMap with the keys representing
the elements of the set and values serving as placeholders.
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAllMethods inherited from class java.util.AbstractCollection
addAll, clear, containsAll, isEmpty, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
addAll, clear, containsAll, isEmpty, retainAll, spliterator, toArray, toArray
-
Constructor Details
-
WeakIdentitySet
public WeakIdentitySet()
-
-
Method Details
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
iterator
Returns an iterator over the elements of the set, allowing traversal of the elements while cleaning up any stale entries. This iterator supports theremove()operation to remove the currently returned element from the set, but makes no guarantees about the order in which elements are returned.The iterator ensures that only non-stale elements, whose keys are still strongly reachable, are available for iteration. Stale entries whose references have been garbage-collected are removed as part of the iteration process.
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>
-
contains
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
-
remove
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-