# 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()](#com.jsmacrosce.SynchronizedWeakHashSet_iterator-) throws [NullPointerException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/NullPointerException.html).  
```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 {#com.jsmacrosce.SynchronizedWeakHashSet_constructor-}

```js
new SynchronizedWeakHashSet()
```

Initializes an empty set backed by a weak-key map.

## Methods

### add {#com.jsmacrosce.SynchronizedWeakHashSet_add-E-}

```js
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 {#com.jsmacrosce.SynchronizedWeakHashSet_clear-}

```js
clear(): void
```

Removes all entries.

### contains {#com.jsmacrosce.SynchronizedWeakHashSet_contains-Object-}

```js
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 {#com.jsmacrosce.SynchronizedWeakHashSet_iterator-}

```js
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](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/NullPointerException.html).

**Returns:** an iterator over the snapshot, which strongly retains its elements

### remove {#com.jsmacrosce.SynchronizedWeakHashSet_remove-Object-}

```js
remove(Object o): boolean
```

Removes a matching key if present.

**Parameters:**
- `o`: the key to remove

**Returns:** `true` if an entry existed

### size {#com.jsmacrosce.SynchronizedWeakHashSet_size-}

```js
size(): int
```

Returns the current number of entries; weakly reachable keys may disappear.

**Returns:** the current entry count
