Skip to content
Buy me a coffee

AbstractSet

Defined in: src/abstract/AbstractSet.ts:22

Skeleton implementation of the Set interface on top of AbstractCollection.

A read-only subclass implements iterator() and size() and must not yield duplicates; a modifiable one also overrides add(e) (which throws UnsupportedOperationException by default) and returns an iterator whose remove() works. It inherits value equals with any Set, hashCode as the sum of element hashes, a removeAll that walks the smaller side, and a DISTINCT spliterator (SORTED | ORDERED too for a set with comparator(), first(), last() and headSet()). There is no modCount: fail-fast behaviour is whatever the subclass’s iterator provides.

E

  • Set<E>

new AbstractSet<E>(): AbstractSet<E>

AbstractSet<E>

AbstractCollection.constructor

get [SET_BRAND](): true

Defined in: src/abstract/AbstractSet.ts:24

Runtime brand that marks this object as a Set (TypeScript interfaces do not exist at runtime); always true.

true

[INSPECT](): string

Defined in: src/abstract/AbstractCollection.ts:195

Node’s util.inspect hook: console.log prints the toString() form.

string

AbstractCollection.[INSPECT]


[iterator](): IterableIterator<E>

Defined in: src/abstract/AbstractCollection.ts:164

Makes the collection usable with for..of and spread; walks iterator().

IterableIterator<E>

Set.[iterator]

AbstractCollection.[iterator]


add(_e): boolean

Defined in: src/abstract/AbstractCollection.ts:60

Adds e; returns true if the collection changed. Not supported by default.

E

boolean

UnsupportedOperationException unless a subclass overrides it

Set.add

AbstractCollection.add


addAll(c): boolean

Defined in: src/abstract/AbstractCollection.ts:96

Calls add for each element of a snapshot of c (so addAll(this) terminates); returns true if any call changed the collection.

Collection<E>

boolean

NullPointerException if c is null

UnsupportedOperationException if add is not supported and c is not empty

Set.addAll

AbstractCollection.addAll


clear(): void

Defined in: src/abstract/AbstractCollection.ts:145

Removes every element by walking the iterator and calling its remove().

void

UnsupportedOperationException if the iterator does not support remove() and the collection is not empty

Set.clear

AbstractCollection.clear


contains(o): boolean

Defined in: src/abstract/AbstractCollection.ts:34

Returns true if some element equals o (by Objects.equals); a linear scan of iterator().

unknown

boolean

Set.contains

AbstractCollection.contains


containsAll(c): boolean

Defined in: src/abstract/AbstractCollection.ts:83

Returns true if this collection contains every element of c (calls contains for each).

Collection<unknown>

boolean

NullPointerException if c is null

Set.containsAll

AbstractCollection.containsAll


equals(o): boolean

Defined in: src/abstract/AbstractSet.ts:37

Returns true if o is a Set of the same size that this set containsAll of; any Set implementation compares. A ClassCastException or NullPointerException from containsAll counts as “not equal”.

unknown

boolean

Set.equals

AbstractCollection.equals


forEach(action): void

Defined in: src/abstract/AbstractCollection.ts:157

Calls action for each element in iteration order.

(e) => void

void

NullPointerException if action is null

Set.forEach

AbstractCollection.forEach


hashCode(): number

Defined in: src/abstract/AbstractSet.ts:81

Returns the sum of the element hashes (32-bit), so equal sets hash the same whatever their order.

number

Set.hashCode

AbstractCollection.hashCode


isEmpty(): boolean

Defined in: src/abstract/AbstractCollection.ts:29

Returns size() === 0.

boolean

Set.isEmpty

AbstractCollection.isEmpty


abstract iterator(): Iterator<E>

Defined in: src/abstract/AbstractCollection.ts:24

Returns an iterator over the elements. Subclasses implement it; its remove() backs every removal method.

Iterator<E>

Set.iterator

AbstractCollection.iterator


parallelStream(): Stream<E>

Defined in: src/abstract/AbstractCollection.ts:180

Returns a stream over spliterator() flagged as parallel.

Stream<E>

Set.parallelStream

AbstractCollection.parallelStream


remove(o): boolean

Defined in: src/abstract/AbstractCollection.ts:68

Removes the first element equal to o through the iterator’s remove(); returns true if one was removed.

unknown

boolean

UnsupportedOperationException if the iterator does not support remove() and a match is found

Set.remove

AbstractCollection.remove


removeAll(c): boolean

Defined in: src/abstract/AbstractSet.ts:56

Removes every element also in c. Walks the smaller side, sized by size(): when this set is larger, iterates c and calls this.remove(e) for each element (so this set’s equality decides, and remove(null) may throw NullPointerException); otherwise iterates this set, removing (iterator.remove, via removeIf) each element c.contains().

Collection<unknown>

boolean

NullPointerException if c is null, or this set contains null and c does not permit null

Set.removeAll

AbstractCollection.removeAll


removeIf(filter): boolean

Defined in: src/abstract/AbstractCollection.ts:128

Removes every element for which filter returns true, through the iterator’s remove(); returns true if any was removed.

(e) => boolean

boolean

NullPointerException if filter is null

Set.removeIf

AbstractCollection.removeIf


retainAll(c): boolean

Defined in: src/abstract/AbstractCollection.ts:118

Removes every element that c does not contain, through the iterator’s remove(); returns true if any was removed.

Collection<unknown>

boolean

NullPointerException if c is null

Set.retainAll

AbstractCollection.retainAll


abstract size(): number

Defined in: src/abstract/AbstractCollection.ts:26

Returns the number of elements. Subclasses implement it.

number

Set.size

AbstractCollection.size


spliterator(): Spliterator<E>

Defined in: src/abstract/AbstractSet.ts:72

Late-binding DISTINCT|SIZED|SUBSIZED spliterator over iterator(); for a sorted set (one with comparator, first, last and headSet) DISTINCT|SORTED|ORDERED|SIZED|SUBSIZED with getComparator() = comparator(). Like the reference, traversal does not lower estimateSize().

Spliterator<E>

Set.spliterator

AbstractCollection.spliterator


stream(): Stream<E>

Defined in: src/abstract/AbstractCollection.ts:175

Returns a sequential stream over spliterator().

Stream<E>

Set.stream

AbstractCollection.stream


toArray(): E[]

Defined in: src/abstract/AbstractCollection.ts:41

Returns a new array of the elements in iteration order.

E[]

Set.toArray

AbstractCollection.toArray

toArray<A>(generator): A

Defined in: src/abstract/AbstractCollection.ts:48

Copies the elements in iteration order into generator(size()) and returns that array.

A extends WritableArrayLike<E>

(length) => A

receives the element count and returns a plain or typed array of at least that length

A

IndexOutOfBoundsException if the generated typed array is too short

NullPointerException if generator or its result is null

Set.toArray

AbstractCollection.toArray


toString(): string

Defined in: src/abstract/AbstractCollection.ts:199

Returns [e1, e2, ...] in iteration order; an element that is this collection prints as (this Collection).

string

Set.toString

AbstractCollection.toString