Skip to content
Buy me a coffee

AbstractMap

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

Skeleton implementation of the Map interface, built entirely on entrySet().

A read-only subclass implements entrySet() and inherits the whole Map interface: lookups, live keySet() and values() views, value equals/hashCode with any Map, toString(), for..of over [key, value] pairs, and the default methods (getOrDefault, putIfAbsent, replace, compute*, merge, …). To make it modifiable, override put(key, value) (which throws UnsupportedOperationException by default) and give the entry set an iterator whose remove() works (and entries whose setValue works, for replaceAll). Lookups are linear scans of the entry set; override the protected findEntry (or the lookup methods) for faster access. There is no modCount: fail-fast behaviour is whatever the entry-set iterator provides. A null value from get means “absent”, so the defaults treat a key mapped to null like a missing key where the Map contract says so.

K

V

  • Map<K, V>

new AbstractMap<K, V>(): AbstractMap<K, V>

AbstractMap<K, V>

[INSPECT](): string

Defined in: src/abstract/AbstractMap.ts:187

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

string


[iterator](): IterableIterator<[K, V]>

Defined in: src/abstract/AbstractMap.ts:146

Makes the map usable with for..of and spread, yielding [key, value] pairs in entry-set order.

IterableIterator<[K, V]>

Map.[iterator]


clear(): void

Defined in: src/abstract/AbstractMap.ts:125

Removes every mapping via entrySet().clear().

void

Map.clear


compute(key, fn): V | null

Defined in: src/abstract/AbstractMap.ts:301

Puts fn(key, currentValueOrNull), or removes the mapping when fn returns null/undefined; returns the new value or null.

K

(key, value) => V | null | undefined

V | null

NullPointerException if fn is null

Map.compute


computeIfAbsent(key, fn): V | null

Defined in: src/abstract/AbstractMap.ts:268

If key has no value (absent or mapped to null), puts fn(key) unless it returns null/undefined; returns the current (possibly new) value, or null.

K

(key) => V | null | undefined

V | null

NullPointerException if fn is null

Map.computeIfAbsent


computeIfPresent(key, fn): V | null

Defined in: src/abstract/AbstractMap.ts:283

If key has a non-null value, replaces it with fn(key, value), or removes the mapping when fn returns null/undefined; returns the new value or null.

K

(key, value) => V | null | undefined

V | null

NullPointerException if fn is null

Map.computeIfPresent


containsKey(key): boolean

Defined in: src/abstract/AbstractMap.ts:63

Returns true if findEntry(key) finds a mapping (a linear scan by default).

unknown

boolean

Map.containsKey


containsValue(value): boolean

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

Returns true if some mapping’s value equals value; always a linear scan of the entry set.

unknown

boolean

Map.containsValue


abstract entrySet(): Set<MapEntry<K, V>>

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

Returns the set of mappings that every other method is built on. Subclasses implement it.

Set<MapEntry<K, V>>

Map.entrySet


equals(o): boolean

Defined in: src/abstract/AbstractMap.ts:158

Returns true if o is a Map with the same mappings (any Map implementation). A ClassCastException or NullPointerException from o’s lookups counts as “not equal”.

unknown

boolean

Map.equals


forEach(action): void

Defined in: src/abstract/AbstractMap.ts:220

Calls action(key, value) for each mapping in entry-set order.

(key, value) => void

void

NullPointerException if action is null

Map.forEach


get(key): V | null

Defined in: src/abstract/AbstractMap.ts:75

Returns the value mapped to key, or null if there is none; uses findEntry (a linear scan by default).

unknown

V | null

Map.get


getOrDefault(key, defaultValue): V

Defined in: src/abstract/AbstractMap.ts:206

Returns the value mapped to key, or defaultValue when there is no mapping (a mapping to null returns null).

unknown

V

V

Map.getOrDefault

getOrDefault(key, defaultValue): V | null

Defined in: src/abstract/AbstractMap.ts:209

Returns the value mapped to key, or defaultValue when there is no mapping (a mapping to null returns null).

unknown

V | null

V | null

Map.getOrDefault


hashCode(): number

Defined in: src/abstract/AbstractMap.ts:179

Returns the sum of hashCode(key) ^ hashCode(value) over the mappings, so equal maps hash the same.

number

Map.hashCode


isEmpty(): boolean

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

Returns size() === 0.

boolean

Map.isEmpty


keySet(): Set<K>

Defined in: src/abstract/AbstractMap.ts:133

Returns a live view of the keys, backed by the entry set (created once and cached). It supports removal but not addition.

Set<K>

Map.keySet


merge(key, value, fn): V | null

Defined in: src/abstract/AbstractMap.ts:318

Puts value if key has no value (absent or mapped to null), otherwise fn(oldValue, value); removes the mapping when fn returns null/undefined. Returns the new value or null.

K

V

(oldValue, value) => V | null | undefined

V | null

NullPointerException if fn or value is null

Map.merge


put(_key, _value): V | null

Defined in: src/abstract/AbstractMap.ts:84

Maps key to value and returns the previous value, or null. Not supported by default.

K

V

V | null

UnsupportedOperationException unless a subclass overrides it

Map.put


putAll(m): void

Defined in: src/abstract/AbstractMap.ts:119

Calls put for each mapping of a snapshot of m’s entries.

Map<K, V>

void

NullPointerException if m is null

UnsupportedOperationException if put is not supported and m is not empty

Map.putAll


putIfAbsent(key, value): V | null

Defined in: src/abstract/AbstractMap.ts:244

If key has no value (absent or mapped to null), puts value and returns the previous value; else returns the current value.

K

V

V | null

Map.putIfAbsent


remove(key): V | null

Defined in: src/abstract/AbstractMap.ts:92

Removes the mapping for key through the entry-set iterator’s remove() and returns its value, or null if there was none.

unknown

V | null

Map.remove

remove(key, value): boolean

Defined in: src/abstract/AbstractMap.ts:94

Removes the mapping for key only if it is mapped to a value equal to value; returns true if removed.

unknown

unknown

boolean

Map.remove


replace(key, value): V | null

Defined in: src/abstract/AbstractMap.ts:250

Puts value only if key already has a mapping; returns the previous value, or null if there was no mapping.

K

V

V | null

Map.replace

replace(key, oldValue, newValue): boolean

Defined in: src/abstract/AbstractMap.ts:252

Puts newValue only if key is mapped to a value equal to oldValue; returns true if replaced.

K

V

V

boolean

Map.replace


replaceAll(fn): void

Defined in: src/abstract/AbstractMap.ts:234

Replaces each value with fn(key, value), through the entries’ setValue.

(key, value) => V

void

NullPointerException if fn is null

UnsupportedOperationException if the entries do not support setValue

Map.replaceAll


size(): number

Defined in: src/abstract/AbstractMap.ts:32

Returns entrySet().size().

number

Map.size


toString(): string

Defined in: src/abstract/AbstractMap.ts:191

Returns {k1=v1, k2=v2} in entry-set order; a key or value that is this map prints as (this Map).

string

Map.toString


values(): Collection<V>

Defined in: src/abstract/AbstractMap.ts:141

Returns a live view of the values, backed by the entry set (created once and cached). It supports removal but not addition.

Collection<V>

Map.values