Skip to content
Buy me a coffee

Objects

const Objects: object

Defined in: src/util/Objects.ts:196

Static helpers for values: the equality, hashing, null-check and index-check rules every collection in this library uses. equals and hashCode here define what “equal elements” and “equal keys” mean.

checkFromIndexSize: (fromIndex, size, length) => number

Returns fromIndex when the range [fromIndex, fromIndex + size) lies within [0, length) (all non-negative integers).

Checks [fromIndex, fromIndex + size) lies within [0, length).

number

number

number

number

fromIndex.

IndexOutOfBoundsException

IndexOutOfBoundsException otherwise

checkFromToIndex: (fromIndex, toIndex, length) => number

Returns fromIndex when 0 <= fromIndex <= toIndex <= length (all integers).

Checks 0 <= fromIndex <= toIndex <= length.

number

number

number

number

fromIndex.

IndexOutOfBoundsException

IndexOutOfBoundsException otherwise

checkIndex: (index, length) => number

Returns index when it is an integer with 0 <= index < length.

number

number

number

IndexOutOfBoundsException otherwise

compare: <T>(a, b, c) => number

Returns 0 when a === b (without calling c), otherwise c(a, b).

0 if a and b are identical (===), else c(a, b); c is not called for identical arguments.

T

T

T

(a, b) => number

number

deepEquals: (a, b) => boolean

Like Objects.equals, but plain and typed arrays compare element by element, recursively.

Like equals, but arrays (plain and typed) compare element by element, recursively.

unknown

unknown

boolean

equals: (a, b) => boolean

Returns true when a and b are equal: a.equals(b) when a has an equals method, otherwise SameValueZero (NaN equals NaN, +0 equals -0); Dates compare by time. null and undefined equal only themselves.

Value equality. Uses a.equals(b) when defined; otherwise SameValueZero (like JS Map/Set: NaN equals NaN, +0 equals -0). Dates compare by time, so invalid Dates are equal.

unknown

unknown

boolean

hash: (…values) => number

Returns a combined hash of the values (h = 31 * h + hashCode(v), starting at 1), e.g. for a hashCode() method.

Combined hash of several values (31 * h + hash).

…unknown[]

number

hashCode: (o) => number

Returns a 32-bit hash consistent with Objects.equals: integer numbers in 32-bit range hash to themselves, other numbers by their bits, strings by 31 * h + charCode, booleans to 1231/1237, bigints by their 64-bit value, Dates by time, objects through their hashCode() method or else by identity. null/undefined give 0.

Value hash. Values that are equals always hash the same: int32 numbers hash like Integer, other numbers like Double, strings like String, booleans like Boolean, bigints like Long, Dates by time, objects via hashCode() or identity.

unknown

number

identityHashCode: (o) => number

Returns a hash that is stable per object reference and ignores any hashCode() method; null/undefined give 0 and primitives hash by value.

Identity hash: stable per reference, ignores any hashCode() method.

unknown

number

isNull: (o) => o is null | undefined

Returns true when o is null or undefined.

unknown

o is null | undefined

nonNull: (o) => o is {}

Returns true when o is neither null nor undefined.

unknown

o is {}

requireNonNull: <T>(o, message?) => NonNullable<T>

Returns o when it is neither null nor undefined.

Throws NullPointerException for null or undefined. message may be a supplier, called only on failure.

T

T

string | (() => string)

NonNullable<T>

message

error message, or a function producing it that is called only on failure

NullPointerException if o is null or undefined

requireNonNullElse: <T>(o, defaultObj) => NonNullable<T>

Returns o, or defaultObj when o is null or undefined.

o, or defaultObj when o is null/undefined.

T

T | null | undefined

T

NonNullable<T>

NullPointerException if both are null

NullPointerException if both are null or undefined

requireNonNullElseGet: <T>(o, supplier) => NonNullable<T>

Returns o, or supplier() when o is null or undefined; the supplier is called only then.

o, or supplier() when o is null/undefined.

T

T | null | undefined

() => T

NonNullable<T>

NullPointerException if the supplier or its result is null

NullPointerException if the supplier is needed and it or its result is null/undefined

toIdentityString: (o) => string

Returns ConstructorName@hexhash built from the identity hash, ignoring any toString()/hashCode() method.

${constructorName}@${hex identity hash}, ignoring any toString()/hashCode().

unknown

string

NullPointerException for null

NullPointerException if o is null or undefined

toString: (o, nullDefault?) => string

Returns the string form collections use in toString(): String(o), with null as "null" and undefined as "undefined". With nullDefault, both null and undefined give nullDefault.

String form used by collection toString(): null -> “null”, undefined -> “undefined”. With nullDefault, null and undefined both give nullDefault.

unknown

string

string