Skip to content
Buy me a coffee

AbstractCollection

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

Skeleton implementation of the Collection interface, built entirely on iterator() and size().

A read-only subclass implements those two methods and inherits everything else: contains, toArray, the bulk operations, forEach, stream(), spliterator(), for..of and toString(). To make it modifiable, override add(e) (which throws UnsupportedOperationException by default) and return an iterator whose remove() works; remove, removeIf, removeAll, retainAll and clear all go through it. There is no modCount here: fail-fast behaviour is whatever the subclass’s iterator provides. equals/hashCode are identity-based; override them (or extend AbstractList/AbstractSet) for value equality. The defaults are linear scans; override any method the storage can do faster.

E

new AbstractCollection<E>(): AbstractCollection<E>

AbstractCollection<E>

[INSPECT](): string

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

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

string


[iterator](): IterableIterator<E>

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

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

IterableIterator<E>

Collection.[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

Collection.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

Collection.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

Collection.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

Collection.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

Collection.containsAll


equals(o): boolean

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

Identity by default; List/Set/Map subclasses override with value equality.

unknown

boolean

Collection.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

Collection.forEach


hashCode(): number

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

Identity hash by default, consistent with the identity equals.

number

Collection.hashCode


isEmpty(): boolean

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

Returns size() === 0.

boolean

Collection.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>

Collection.iterator


parallelStream(): Stream<E>

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

Returns a stream over spliterator() flagged as parallel.

Stream<E>

Collection.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

Collection.remove


removeAll(c): boolean

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

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

Collection<unknown>

boolean

NullPointerException if c is null

Collection.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

Collection.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

Collection.retainAll


abstract size(): number

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

Returns the number of elements. Subclasses implement it.

number

Collection.size


spliterator(): Spliterator<E>

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

Late-binding SIZED|SUBSIZED spliterator over iterator(), splitting in batches; collections override with faster ones.

Spliterator<E>

Collection.spliterator


stream(): Stream<E>

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

Returns a sequential stream over spliterator().

Stream<E>

Collection.stream


toArray(): E[]

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

Returns a new array of the elements in iteration order.

E[]

Collection.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

Collection.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

Collection.toString