SynchronizedWeakHashSet
com.jsmacrosce.SynchronizedWeakHashSet
A set backed by weak keys; each of its own operations is synchronized, but this does not make inherited or compound operations atomic. Iterators are detached snapshots that retain strong references to their elements. A null key is accepted by the set methods, but while one is present, iterator() throws NullPointerException.
js
const Set = Java.type("com.jsmacrosce.SynchronizedWeakHashSet");
const values = new Set();
const JavaObject = Java.type("java.lang.Object");
const item = new JavaObject();
values.add(item);
const snapshot = values.iterator();
values.clear();
snapshot.hasNext(); // still true; the snapshot retains itemType Parameters
E: the element type
Constructors
new SynchronizedWeakHashSet
new SynchronizedWeakHashSet()#Initializes an empty set backed by a weak-key map.
Methods
add
add(E o): boolean#Adds a key if absent; keys are held weakly.
Parameters:
o: the element to add
Returns:
true if the element was previously absentclear
clear(): void#Removes all entries.
contains
iterator
Returns a detached snapshot of the current keys; its iterator does not support removal. A present null key causes snapshot creation to throw NullPointerException.
Returns: an iterator over the snapshot, which strongly retains its elements
remove
size
size(): int#Returns the current number of entries; weakly reachable keys may disappear.
Returns: the current entry count