Skip to content
Buy me a coffee

AbstractList

Defined in: src/abstract/AbstractList.ts:35

Skeleton implementation of the List interface for storage with fast positional access.

A read-only subclass implements get(index) and size(). It inherits fail-fast iterators and list iterators, indexOf/lastIndexOf, live subList views, reversed(), sort, replaceAll, the sequenced methods (getFirst, removeLast, …), value equals/hashCode with any List, and an index-based spliterator when the list carries the RandomAccess brand (the brand is not added for you).

To be modifiable, override set(index, e); to grow and shrink, also override addAtIndex(index, e) and removeAt(index). All three throw UnsupportedOperationException by default. Every add/addAll overload, addFirst/addLast, list-iterator add and subList(...).add end in addAtIndex, so override that hook rather than the overloaded add. Each structural change (one that changes the size) MUST increment modCount, so iterators, sublists and spliterators fail fast with ConcurrentModificationException; set is not structural.

E

  • List<E>

new AbstractList<E>(): AbstractList<E>

AbstractList<E>

AbstractCollection.constructor

modCount: number = 0

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

Structural modification counter. Iterators, sublists and spliterators record it and throw ConcurrentModificationException when it changes behind them. Subclasses increment it once per structural change (add, remove, clear); set leaves it alone.

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

List.[iterator]

AbstractCollection.[iterator]


add(e): boolean

Defined in: src/abstract/AbstractList.ts:80

Appends e (via addAtIndex(size(), e)) and returns true.

E

boolean

UnsupportedOperationException if addAtIndex is not overridden

List.add

AbstractCollection.add

add(index, e): void

Defined in: src/abstract/AbstractList.ts:86

Inserts e at index (via addAtIndex), shifting later elements right.

number

E

void

IndexOutOfBoundsException if index < 0 || index > size() (when the subclass checks it)

UnsupportedOperationException if addAtIndex is not overridden

List.add

AbstractCollection.add


addAll(c): boolean

Defined in: src/abstract/AbstractList.ts:100

Appends the elements of c in its iteration order (via addAllAt); returns true if c was not empty.

Collection<E>

boolean

NullPointerException if c is null

List.addAll

AbstractCollection.addAll

addAll(index, c): boolean

Defined in: src/abstract/AbstractList.ts:106

Inserts the elements of c at index in its iteration order (via addAllAt); returns true if c was not empty.

number

Collection<E>

boolean

IndexOutOfBoundsException if index < 0 || index > size()

NullPointerException if c is null

List.addAll

AbstractCollection.addAll


addFirst(e): void

Defined in: src/abstract/AbstractList.ts:237

Inserts e at index 0, via addAtIndex.

E

void

UnsupportedOperationException if addAtIndex is not overridden

List.addFirst


addLast(e): void

Defined in: src/abstract/AbstractList.ts:245

Appends e at the end, via addAtIndex.

E

void

UnsupportedOperationException if addAtIndex is not overridden

List.addLast


clear(): void

Defined in: src/abstract/AbstractList.ts:152

Removes every element via removeRange(0, size()) (list-iterator remove calls).

void

UnsupportedOperationException if removeAt is not overridden and the list is not empty

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

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

List.containsAll

AbstractCollection.containsAll


equals(o): boolean

Defined in: src/abstract/AbstractList.ts:293

Returns true if o is a List with equal elements in the same order (any List implementation).

unknown

boolean

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

List.forEach

AbstractCollection.forEach


abstract get(index): E

Defined in: src/abstract/AbstractList.ts:47

Returns the element at index. Subclasses implement it and should validate with Objects.checkIndex.

number

E

IndexOutOfBoundsException if index < 0 || index >= size()

List.get


getFirst(): E

Defined in: src/abstract/AbstractList.ts:253

Returns the element at index 0.

E

NoSuchElementException if the list is empty

List.getFirst


getLast(): E

Defined in: src/abstract/AbstractList.ts:262

Returns the element at index size() - 1.

E

NoSuchElementException if the list is empty

List.getLast


hashCode(): number

Defined in: src/abstract/AbstractList.ts:303

Returns 31 * h + hashCode(e) over the elements, starting at 1, so equal lists hash the same.

number

List.hashCode

AbstractCollection.hashCode


indexOf(o): number

Defined in: src/abstract/AbstractList.ts:135

Returns the index of the first element equal to o, or -1; a forward scan with a list iterator.

unknown

number

List.indexOf


isEmpty(): boolean

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

Returns size() === 0.

boolean

List.isEmpty

AbstractCollection.isEmpty


iterator(): Iterator<E>

Defined in: src/abstract/AbstractList.ts:173

Returns a fail-fast iterator built on get/removeAt: it throws ConcurrentModificationException when modCount changes other than through the iterator itself.

Iterator<E>

List.iterator

AbstractCollection.iterator


lastIndexOf(o): number

Defined in: src/abstract/AbstractList.ts:142

Returns the index of the last element equal to o, or -1; a backward scan with a list iterator.

unknown

number

List.lastIndexOf


listIterator(index?): ListIterator<E>

Defined in: src/abstract/AbstractList.ts:181

Returns a fail-fast list iterator starting at index, built on get/set/add(index, e)/removeAt.

number = 0

ListIterator<E>

IndexOutOfBoundsException if index < 0 || index > size()

List.listIterator


parallelStream(): Stream<E>

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

Returns a stream over spliterator() flagged as parallel.

Stream<E>

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

List.remove

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

List.removeAll

AbstractCollection.removeAll


removeAt(_index): E

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

Removes and returns the element at index; shifts later elements left. Iterator remove(), removeFirst/ removeLast and the inherited removal methods use it. Overrides must increment modCount.

number

E

UnsupportedOperationException unless a subclass overrides it

List.removeAt


removeFirst(): E

Defined in: src/abstract/AbstractList.ts:271

Removes and returns the element at index 0, via removeAt.

E

NoSuchElementException if the list is empty

List.removeFirst


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

List.removeIf

AbstractCollection.removeIf


removeLast(): E

Defined in: src/abstract/AbstractList.ts:280

Removes and returns the last element, via removeAt.

E

NoSuchElementException if the list is empty

List.removeLast


removeRange(fromIndex, toIndex): void

Defined in: src/abstract/AbstractList.ts:160

Removes [fromIndex, toIndex). Public so views can delegate.

number

number

void

IndexOutOfBoundsException for a bad range, before anything is removed


replaceAll(operator): void

Defined in: src/abstract/AbstractList.ts:211

Replaces each element with operator(element), through the list iterator’s set.

(e) => E

void

NullPointerException if operator is null

List.replaceAll


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

List.retainAll

AbstractCollection.retainAll


reversed(): List<E>

Defined in: src/abstract/AbstractList.ts:286

Returns a live reverse-ordered view; writes through it reach this list. reversed().reversed() is this list.

List<E>

List.reversed


set(_index, _e): E

Defined in: src/abstract/AbstractList.ts:53

Replaces the element at index and returns the old one. Not structural: does not change modCount.

number

E

E

UnsupportedOperationException unless a subclass overrides it

List.set


abstract size(): number

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

Returns the number of elements. Subclasses implement it.

number

List.size

AbstractCollection.size


sort(c?): void

Defined in: src/abstract/AbstractList.ts:222

Sorts the list stably by c (natural ordering when null or omitted): sorts a copy, then writes it back with the list iterator’s set, so it is not a structural change.

Comparator<E> | null = null

void

ClassCastException if natural ordering meets values that cannot be compared

List.sort


spliterator(): Spliterator<E>

Defined in: src/abstract/AbstractList.ts:202

ORDERED|SIZED|SUBSIZED. RandomAccess lists get a late-binding, fail-fast, index-based spliterator that splits in halves; others one over iterator().

Spliterator<E>

List.spliterator

AbstractCollection.spliterator


stream(): Stream<E>

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

Returns a sequential stream over spliterator().

Stream<E>

List.stream

AbstractCollection.stream


subList(fromIndex, toIndex): List<E>

Defined in: src/abstract/AbstractList.ts:193

Returns a live view of [fromIndex, toIndex): changes through it write to this list, and a structural change made to this list directly makes the view throw ConcurrentModificationException. Carries the RandomAccess brand when this list does.

number

number

List<E>

IndexOutOfBoundsException if fromIndex < 0 or toIndex > size()

IllegalArgumentException if fromIndex > toIndex

List.subList


toArray(): E[]

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

Returns a new array of the elements in iteration order.

E[]

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

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

List.toString

AbstractCollection.toString