Objects
constObjects: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.
Type Declaration
Section titled “Type Declaration”checkFromIndexSize
Section titled “checkFromIndexSize”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).
Parameters
Section titled “Parameters”fromIndex
Section titled “fromIndex”number
number
length
Section titled “length”number
Returns
Section titled “Returns”number
fromIndex.
Throws
Section titled “Throws”IndexOutOfBoundsException
Throws
Section titled “Throws”IndexOutOfBoundsException otherwise
checkFromToIndex
Section titled “checkFromToIndex”checkFromToIndex: (
fromIndex,toIndex,length) =>number
Returns fromIndex when 0 <= fromIndex <= toIndex <= length (all integers).
Checks 0 <= fromIndex <= toIndex <= length.
Parameters
Section titled “Parameters”fromIndex
Section titled “fromIndex”number
toIndex
Section titled “toIndex”number
length
Section titled “length”number
Returns
Section titled “Returns”number
fromIndex.
Throws
Section titled “Throws”IndexOutOfBoundsException
Throws
Section titled “Throws”IndexOutOfBoundsException otherwise
checkIndex
Section titled “checkIndex”checkIndex: (
index,length) =>number
Returns index when it is an integer with 0 <= index < length.
Parameters
Section titled “Parameters”number
length
Section titled “length”number
Returns
Section titled “Returns”number
Throws
Section titled “Throws”IndexOutOfBoundsException otherwise
compare
Section titled “compare”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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”T
T
(a, b) => number
Returns
Section titled “Returns”number
deepEquals
Section titled “deepEquals”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.
Parameters
Section titled “Parameters”unknown
unknown
Returns
Section titled “Returns”boolean
equals
Section titled “equals”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.
Parameters
Section titled “Parameters”unknown
unknown
Returns
Section titled “Returns”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).
Parameters
Section titled “Parameters”values
Section titled “values”…unknown[]
Returns
Section titled “Returns”number
hashCode
Section titled “hashCode”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.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”number
identityHashCode
Section titled “identityHashCode”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.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”number
isNull
Section titled “isNull”isNull: (
o) => o is null | undefined
Returns true when o is null or undefined.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”o is null | undefined
nonNull
Section titled “nonNull”nonNull: (
o) =>o is {}
Returns true when o is neither null nor undefined.
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”o is {}
requireNonNull
Section titled “requireNonNull”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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”T
message?
Section titled “message?”string | (() => string)
Returns
Section titled “Returns”NonNullable<T>
message
error message, or a function producing it that is called only on failure
Throws
Section titled “Throws”NullPointerException if o is null or undefined
requireNonNullElse
Section titled “requireNonNullElse”requireNonNullElse: <
T>(o,defaultObj) =>NonNullable<T>
Returns o, or defaultObj when o is null or undefined.
o, or defaultObj when o is null/undefined.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”T | null | undefined
defaultObj
Section titled “defaultObj”T
Returns
Section titled “Returns”NonNullable<T>
Throws
Section titled “Throws”NullPointerException if both are null
Throws
Section titled “Throws”NullPointerException if both are null or undefined
requireNonNullElseGet
Section titled “requireNonNullElseGet”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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”T | null | undefined
supplier
Section titled “supplier”() => T
Returns
Section titled “Returns”NonNullable<T>
Throws
Section titled “Throws”NullPointerException if the supplier or its result is null
Throws
Section titled “Throws”NullPointerException if the supplier is needed and it or its result is null/undefined
toIdentityString
Section titled “toIdentityString”toIdentityString: (
o) =>string
Returns ConstructorName@hexhash built from the identity hash, ignoring any toString()/hashCode() method.
${constructorName}@${hex identity hash}, ignoring any toString()/hashCode().
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”string
Throws
Section titled “Throws”NullPointerException for null
Throws
Section titled “Throws”NullPointerException if o is null or undefined
toString
Section titled “toString”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.
Parameters
Section titled “Parameters”unknown
nullDefault?
Section titled “nullDefault?”string
Returns
Section titled “Returns”string