Skip to content

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 item

Type 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 absent

clear ​

clear(): void#
Removes all entries.

contains ​

contains(Object o): boolean#
Returns whether an equal key is present. A null key can be queried.

Parameters:

  • o: the key to test
Returns: true if an equal key is present

iterator ​

iterator(): Iterator<E>#
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 ​

remove(Object o): boolean#
Removes a matching key if present.

Parameters:

  • o: the key to remove
Returns: true if an entry existed

size ​

size(): int#
Returns the current number of entries; weakly reachable keys may disappear.
Returns: the current entry count