Nullable Array.contentEquals/contentHashCode/contentToString #KT-34161

This commit is contained in:
Abduqodiri Qurbonzoda
2020-02-27 14:44:33 +03:00
parent 179ec41a6b
commit e632d58936
16 changed files with 1897 additions and 133 deletions
+367 -25
View File
@@ -194,7 +194,25 @@ public actual fun CharArray.asList(): List<Char> {
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual infix fun <T> Array<out T>.contentDeepEquals(other: Array<out T>): Boolean {
return this.contentDeepEquals(other)
}
/**
* Returns `true` if the two specified arrays are *deeply* equal to one another,
* i.e. contain the same number of the same elements in the same order.
*
* The specified arrays are also considered deeply equal if both are `null`.
*
* If two corresponding elements are nested arrays, they are also compared deeply.
* If any of arrays contains itself on any nesting level the behavior is undefined.
*
* The elements of other types are compared for equality with the [equals][Any.equals] function.
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.4")
public actual infix fun <T> Array<out T>?.contentDeepEquals(other: Array<out T>?): Boolean {
return contentDeepEqualsImpl(other)
}
@@ -205,7 +223,19 @@ public actual infix fun <T> Array<out T>.contentDeepEquals(other: Array<out T>):
* If any of arrays contains itself on any nesting level the behavior is undefined.
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun <T> Array<out T>.contentDeepHashCode(): Int {
return this.contentDeepHashCode()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
* Nested arrays are treated as lists too.
*
* If any of arrays contains itself on any nesting level the behavior is undefined.
*/
@SinceKotlin("1.4")
public actual fun <T> Array<out T>?.contentDeepHashCode(): Int {
return contentDeepHashCodeInternal()
}
@@ -219,7 +249,22 @@ public actual fun <T> Array<out T>.contentDeepHashCode(): Int {
* @sample samples.collections.Arrays.ContentOperations.contentDeepToString
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun <T> Array<out T>.contentDeepToString(): String {
return this.contentDeepToString()
}
/**
* Returns a string representation of the contents of this array as if it is a [List].
* Nested arrays are treated as lists too.
*
* If any of arrays contains itself on any nesting level that reference
* is rendered as `"[...]"` to prevent recursion.
*
* @sample samples.collections.Arrays.ContentOperations.contentDeepToString
*/
@SinceKotlin("1.4")
public actual fun <T> Array<out T>?.contentDeepToString(): String {
return contentDeepToStringImpl()
}
@@ -231,8 +276,9 @@ public actual fun <T> Array<out T>.contentDeepToString(): String {
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual infix fun <T> Array<out T>.contentEquals(other: Array<out T>): Boolean {
return contentEqualsInternal(other)
return this.contentEquals(other)
}
/**
@@ -243,8 +289,9 @@ public actual infix fun <T> Array<out T>.contentEquals(other: Array<out T>): Boo
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean {
return contentEqualsInternal(other)
return this.contentEquals(other)
}
/**
@@ -255,8 +302,9 @@ public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean {
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean {
return contentEqualsInternal(other)
return this.contentEquals(other)
}
/**
@@ -267,8 +315,9 @@ public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean {
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual infix fun IntArray.contentEquals(other: IntArray): Boolean {
return contentEqualsInternal(other)
return this.contentEquals(other)
}
/**
@@ -279,8 +328,9 @@ public actual infix fun IntArray.contentEquals(other: IntArray): Boolean {
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual infix fun LongArray.contentEquals(other: LongArray): Boolean {
return contentEqualsInternal(other)
return this.contentEquals(other)
}
/**
@@ -291,8 +341,9 @@ public actual infix fun LongArray.contentEquals(other: LongArray): Boolean {
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean {
return contentEqualsInternal(other)
return this.contentEquals(other)
}
/**
@@ -303,8 +354,9 @@ public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean {
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean {
return contentEqualsInternal(other)
return this.contentEquals(other)
}
/**
@@ -315,8 +367,9 @@ public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean {
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean {
return contentEqualsInternal(other)
return this.contentEquals(other)
}
/**
@@ -327,7 +380,116 @@ public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual infix fun CharArray.contentEquals(other: CharArray): Boolean {
return this.contentEquals(other)
}
/**
* Returns `true` if the two specified arrays are *structurally* equal to one another,
* i.e. contain the same number of the same elements in the same order.
*
* The elements are compared for equality with the [equals][Any.equals] function.
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.4")
public actual infix fun <T> Array<out T>?.contentEquals(other: Array<out T>?): Boolean {
return contentEqualsInternal(other)
}
/**
* Returns `true` if the two specified arrays are *structurally* equal to one another,
* i.e. contain the same number of the same elements in the same order.
*
* The elements are compared for equality with the [equals][Any.equals] function.
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.4")
public actual infix fun ByteArray?.contentEquals(other: ByteArray?): Boolean {
return contentEqualsInternal(other)
}
/**
* Returns `true` if the two specified arrays are *structurally* equal to one another,
* i.e. contain the same number of the same elements in the same order.
*
* The elements are compared for equality with the [equals][Any.equals] function.
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.4")
public actual infix fun ShortArray?.contentEquals(other: ShortArray?): Boolean {
return contentEqualsInternal(other)
}
/**
* Returns `true` if the two specified arrays are *structurally* equal to one another,
* i.e. contain the same number of the same elements in the same order.
*
* The elements are compared for equality with the [equals][Any.equals] function.
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.4")
public actual infix fun IntArray?.contentEquals(other: IntArray?): Boolean {
return contentEqualsInternal(other)
}
/**
* Returns `true` if the two specified arrays are *structurally* equal to one another,
* i.e. contain the same number of the same elements in the same order.
*
* The elements are compared for equality with the [equals][Any.equals] function.
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.4")
public actual infix fun LongArray?.contentEquals(other: LongArray?): Boolean {
return contentEqualsInternal(other)
}
/**
* Returns `true` if the two specified arrays are *structurally* equal to one another,
* i.e. contain the same number of the same elements in the same order.
*
* The elements are compared for equality with the [equals][Any.equals] function.
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.4")
public actual infix fun FloatArray?.contentEquals(other: FloatArray?): Boolean {
return contentEqualsInternal(other)
}
/**
* Returns `true` if the two specified arrays are *structurally* equal to one another,
* i.e. contain the same number of the same elements in the same order.
*
* The elements are compared for equality with the [equals][Any.equals] function.
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.4")
public actual infix fun DoubleArray?.contentEquals(other: DoubleArray?): Boolean {
return contentEqualsInternal(other)
}
/**
* Returns `true` if the two specified arrays are *structurally* equal to one another,
* i.e. contain the same number of the same elements in the same order.
*
* The elements are compared for equality with the [equals][Any.equals] function.
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.4")
public actual infix fun BooleanArray?.contentEquals(other: BooleanArray?): Boolean {
return contentEqualsInternal(other)
}
/**
* Returns `true` if the two specified arrays are *structurally* equal to one another,
* i.e. contain the same number of the same elements in the same order.
*
* The elements are compared for equality with the [equals][Any.equals] function.
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.4")
public actual infix fun CharArray?.contentEquals(other: CharArray?): Boolean {
return contentEqualsInternal(other)
}
@@ -335,71 +497,152 @@ public actual infix fun CharArray.contentEquals(other: CharArray): Boolean {
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun <T> Array<out T>.contentHashCode(): Int {
return contentHashCodeInternal()
return this.contentHashCode()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun ByteArray.contentHashCode(): Int {
return contentHashCodeInternal()
return this.contentHashCode()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun ShortArray.contentHashCode(): Int {
return contentHashCodeInternal()
return this.contentHashCode()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun IntArray.contentHashCode(): Int {
return contentHashCodeInternal()
return this.contentHashCode()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun LongArray.contentHashCode(): Int {
return contentHashCodeInternal()
return this.contentHashCode()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun FloatArray.contentHashCode(): Int {
return contentHashCodeInternal()
return this.contentHashCode()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun DoubleArray.contentHashCode(): Int {
return contentHashCodeInternal()
return this.contentHashCode()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun BooleanArray.contentHashCode(): Int {
return contentHashCodeInternal()
return this.contentHashCode()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun CharArray.contentHashCode(): Int {
return this.contentHashCode()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.4")
public actual fun <T> Array<out T>?.contentHashCode(): Int {
return contentHashCodeInternal()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.4")
public actual fun ByteArray?.contentHashCode(): Int {
return contentHashCodeInternal()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.4")
public actual fun ShortArray?.contentHashCode(): Int {
return contentHashCodeInternal()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.4")
public actual fun IntArray?.contentHashCode(): Int {
return contentHashCodeInternal()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.4")
public actual fun LongArray?.contentHashCode(): Int {
return contentHashCodeInternal()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.4")
public actual fun FloatArray?.contentHashCode(): Int {
return contentHashCodeInternal()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.4")
public actual fun DoubleArray?.contentHashCode(): Int {
return contentHashCodeInternal()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.4")
public actual fun BooleanArray?.contentHashCode(): Int {
return contentHashCodeInternal()
}
/**
* Returns a hash code based on the contents of this array as if it is [List].
*/
@SinceKotlin("1.4")
public actual fun CharArray?.contentHashCode(): Int {
return contentHashCodeInternal()
}
@@ -409,8 +652,9 @@ public actual fun CharArray.contentHashCode(): Int {
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun <T> Array<out T>.contentToString(): String {
return joinToString(", ", "[", "]")
return this.contentToString()
}
/**
@@ -419,8 +663,9 @@ public actual fun <T> Array<out T>.contentToString(): String {
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun ByteArray.contentToString(): String {
return joinToString(", ", "[", "]")
return this.contentToString()
}
/**
@@ -429,8 +674,9 @@ public actual fun ByteArray.contentToString(): String {
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun ShortArray.contentToString(): String {
return joinToString(", ", "[", "]")
return this.contentToString()
}
/**
@@ -439,8 +685,9 @@ public actual fun ShortArray.contentToString(): String {
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun IntArray.contentToString(): String {
return joinToString(", ", "[", "]")
return this.contentToString()
}
/**
@@ -449,8 +696,9 @@ public actual fun IntArray.contentToString(): String {
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun LongArray.contentToString(): String {
return joinToString(", ", "[", "]")
return this.contentToString()
}
/**
@@ -459,8 +707,9 @@ public actual fun LongArray.contentToString(): String {
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun FloatArray.contentToString(): String {
return joinToString(", ", "[", "]")
return this.contentToString()
}
/**
@@ -469,8 +718,9 @@ public actual fun FloatArray.contentToString(): String {
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun DoubleArray.contentToString(): String {
return joinToString(", ", "[", "]")
return this.contentToString()
}
/**
@@ -479,8 +729,9 @@ public actual fun DoubleArray.contentToString(): String {
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun BooleanArray.contentToString(): String {
return joinToString(", ", "[", "]")
return this.contentToString()
}
/**
@@ -489,8 +740,99 @@ public actual fun BooleanArray.contentToString(): String {
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.1")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun CharArray.contentToString(): String {
return joinToString(", ", "[", "]")
return this.contentToString()
}
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.4")
public actual fun <T> Array<out T>?.contentToString(): String {
return this?.joinToString(", ", "[", "]") ?: "null"
}
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.4")
public actual fun ByteArray?.contentToString(): String {
return this?.joinToString(", ", "[", "]") ?: "null"
}
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.4")
public actual fun ShortArray?.contentToString(): String {
return this?.joinToString(", ", "[", "]") ?: "null"
}
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.4")
public actual fun IntArray?.contentToString(): String {
return this?.joinToString(", ", "[", "]") ?: "null"
}
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.4")
public actual fun LongArray?.contentToString(): String {
return this?.joinToString(", ", "[", "]") ?: "null"
}
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.4")
public actual fun FloatArray?.contentToString(): String {
return this?.joinToString(", ", "[", "]") ?: "null"
}
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.4")
public actual fun DoubleArray?.contentToString(): String {
return this?.joinToString(", ", "[", "]") ?: "null"
}
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.4")
public actual fun BooleanArray?.contentToString(): String {
return this?.joinToString(", ", "[", "]") ?: "null"
}
/**
* Returns a string representation of the contents of the specified array as if it is [List].
*
* @sample samples.collections.Arrays.ContentOperations.contentToString
*/
@SinceKotlin("1.4")
public actual fun CharArray?.contentToString(): String {
return this?.joinToString(", ", "[", "]") ?: "null"
}
/**