feat: add deep-array value-equality helpers in sdk-core#149
feat: add deep-array value-equality helpers in sdk-core#149OmarAlJarrah wants to merge 1 commit into
Conversation
Add ValueEquality.contentEquals / contentHashCode to org.dexpace.sdk.core.util for value types that hold array-typed fields. java.util.Objects.equals compares arrays by identity, so structurally-equal ByteArray (or any array) fields are wrongly reported unequal; these helpers compare by content instead. Both helpers handle primitive arrays, object arrays, nulls, and arbitrarily-deep nested / multi-dimensional arrays (via Arrays.deepEquals / deepHashCode), while falling back to ordinary equals/hashCode for non-array values. The two methods are mutually consistent: content-equal values always share a content hash.
|
Adds a The dispatch covers all eight primitive-array types plus object arrays, with |
Summary
Adds
ValueEqualitytoorg.dexpace.sdk.core.util— content-deepcontentEquals/contentHashCodehelpers for value types that hold array-typed fields.java.util.Objects.equals/hashCodecompare arrays by identity, so two structurally-equalByteArrayfields (or any array-typed field) are reported unequal and hash differently. A value type with array fields therefore cannot rely onObjects.equalsfor a correctequals/hashCode. These helpers compare by content instead.Behavior
contentEquals(a, b)/contentHashCode(value), both@JvmStaticand null-safe (two nulls equal; null hashes to 0).ByteArray,IntArray,DoubleArray, …) compared by element value.Arrays.deepEquals/deepHashCode, so nested and arbitrarily-deep multi-dimensional arrays compare structurally, and object-array elements use their ownequals.IntArrayvsLongArray) are not equal even with matching values, mirroring the JVM's distinct array types.equals/hashCode.contentEquals(a, b)is true,contentHashCode(a) == contentHashCode(b).No core type needs it today; it is the hand-usable runtime primitive a DTO generator (or a hand-written value type) targets for array fields. No code generation is introduced.
Tests
ValueEqualityTestcovers nulls, identity shortcut, scalars, every primitive-array kind, object arrays (including null elements), nested object arrays, nested primitive arrays, deeply-nested multi-dimensional arrays, custom value-type elements, cross-kind mismatches, and equals/hashCode consistency.Gated build (module-scoped)
Both BUILD SUCCESSFUL. The regenerated
sdk-core/api/sdk-core.apisnapshot is committed.Closes #49