Rename operand parameter of plus and minus for collections

This commit is contained in:
Ilya Gorbunov
2015-11-20 22:01:08 +03:00
parent 7c726bcaf9
commit 0dbbb6c19c
8 changed files with 587 additions and 587 deletions
+135 -135
View File
@@ -281,141 +281,6 @@ public inline fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArr
return this.asDynamic().slice(fromIndex, toIndex)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun <T> Array<out T>.plus(array: Array<out T>): Array<T> {
return this.asDynamic().concat(array)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun BooleanArray.plus(array: BooleanArray): BooleanArray {
return this.asDynamic().concat(array)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun ByteArray.plus(array: ByteArray): ByteArray {
return this.asDynamic().concat(array)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun CharArray.plus(array: CharArray): CharArray {
return this.asDynamic().concat(array)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun DoubleArray.plus(array: DoubleArray): DoubleArray {
return this.asDynamic().concat(array)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun FloatArray.plus(array: FloatArray): FloatArray {
return this.asDynamic().concat(array)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun IntArray.plus(array: IntArray): IntArray {
return this.asDynamic().concat(array)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun LongArray.plus(array: LongArray): LongArray {
return this.asDynamic().concat(array)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun ShortArray.plus(array: ShortArray): ShortArray {
return this.asDynamic().concat(array)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
public fun <T> Array<out T>.plus(collection: Collection<T>): Array<T> {
return arrayPlusCollection(this, collection)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
public fun BooleanArray.plus(collection: Collection<Boolean>): BooleanArray {
return arrayPlusCollection(this, collection)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
public fun ByteArray.plus(collection: Collection<Byte>): ByteArray {
return arrayPlusCollection(this, collection)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
public fun CharArray.plus(collection: Collection<Char>): CharArray {
return arrayPlusCollection(this, collection)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
public fun DoubleArray.plus(collection: Collection<Double>): DoubleArray {
return arrayPlusCollection(this, collection)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
public fun FloatArray.plus(collection: Collection<Float>): FloatArray {
return arrayPlusCollection(this, collection)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
public fun IntArray.plus(collection: Collection<Int>): IntArray {
return arrayPlusCollection(this, collection)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
public fun LongArray.plus(collection: Collection<Long>): LongArray {
return arrayPlusCollection(this, collection)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
public fun ShortArray.plus(collection: Collection<Short>): ShortArray {
return arrayPlusCollection(this, collection)
}
/**
* Returns an array containing all elements of the original array and then the given [element].
*/
@@ -488,6 +353,141 @@ public inline fun ShortArray.plus(element: Short): ShortArray {
return this.asDynamic().concat(arrayOf(element))
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public fun <T> Array<out T>.plus(elements: Collection<T>): Array<T> {
return arrayPlusCollection(this, elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public fun BooleanArray.plus(elements: Collection<Boolean>): BooleanArray {
return arrayPlusCollection(this, elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public fun ByteArray.plus(elements: Collection<Byte>): ByteArray {
return arrayPlusCollection(this, elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public fun CharArray.plus(elements: Collection<Char>): CharArray {
return arrayPlusCollection(this, elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public fun DoubleArray.plus(elements: Collection<Double>): DoubleArray {
return arrayPlusCollection(this, elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public fun FloatArray.plus(elements: Collection<Float>): FloatArray {
return arrayPlusCollection(this, elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public fun IntArray.plus(elements: Collection<Int>): IntArray {
return arrayPlusCollection(this, elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public fun LongArray.plus(elements: Collection<Long>): LongArray {
return arrayPlusCollection(this, elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
public fun ShortArray.plus(elements: Collection<Short>): ShortArray {
return arrayPlusCollection(this, elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun <T> Array<out T>.plus(elements: Array<out T>): Array<T> {
return this.asDynamic().concat(elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun BooleanArray.plus(elements: BooleanArray): BooleanArray {
return this.asDynamic().concat(elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun ByteArray.plus(elements: ByteArray): ByteArray {
return this.asDynamic().concat(elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun CharArray.plus(elements: CharArray): CharArray {
return this.asDynamic().concat(elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun DoubleArray.plus(elements: DoubleArray): DoubleArray {
return this.asDynamic().concat(elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun FloatArray.plus(elements: FloatArray): FloatArray {
return this.asDynamic().concat(elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun IntArray.plus(elements: IntArray): IntArray {
return this.asDynamic().concat(elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun LongArray.plus(elements: LongArray): LongArray {
return this.asDynamic().concat(elements)
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@Suppress("NOTHING_TO_INLINE")
public inline fun ShortArray.plus(elements: ShortArray): ShortArray {
return this.asDynamic().concat(elements)
}
/**
* Sorts the array in-place.
*/
+207 -207
View File
@@ -11150,213 +11150,6 @@ public fun <C : MutableCollection<in R>, R> Array<*>.filterIsInstanceTo(destinat
return destination
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@kotlin.jvm.JvmVersion
public operator fun BooleanArray.plus(array: BooleanArray): BooleanArray {
val thisSize = size
val arraySize = array.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(array, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@kotlin.jvm.JvmVersion
public operator fun ByteArray.plus(array: ByteArray): ByteArray {
val thisSize = size
val arraySize = array.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(array, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@kotlin.jvm.JvmVersion
public operator fun CharArray.plus(array: CharArray): CharArray {
val thisSize = size
val arraySize = array.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(array, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@kotlin.jvm.JvmVersion
public operator fun DoubleArray.plus(array: DoubleArray): DoubleArray {
val thisSize = size
val arraySize = array.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(array, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@kotlin.jvm.JvmVersion
public operator fun FloatArray.plus(array: FloatArray): FloatArray {
val thisSize = size
val arraySize = array.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(array, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@kotlin.jvm.JvmVersion
public operator fun IntArray.plus(array: IntArray): IntArray {
val thisSize = size
val arraySize = array.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(array, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@kotlin.jvm.JvmVersion
public operator fun LongArray.plus(array: LongArray): LongArray {
val thisSize = size
val arraySize = array.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(array, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@kotlin.jvm.JvmVersion
public operator fun ShortArray.plus(array: ShortArray): ShortArray {
val thisSize = size
val arraySize = array.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(array, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [array].
*/
@kotlin.jvm.JvmVersion
public operator fun <T> Array<T>.plus(array: Array<out T>): Array<T> {
val thisSize = size
val arraySize = array.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(array, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
@kotlin.jvm.JvmVersion
public operator fun BooleanArray.plus(collection: Collection<Boolean>): BooleanArray {
var index = size
val result = Arrays.copyOf(this, index + collection.size)
for (element in collection) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
@kotlin.jvm.JvmVersion
public operator fun ByteArray.plus(collection: Collection<Byte>): ByteArray {
var index = size
val result = Arrays.copyOf(this, index + collection.size)
for (element in collection) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
@kotlin.jvm.JvmVersion
public operator fun CharArray.plus(collection: Collection<Char>): CharArray {
var index = size
val result = Arrays.copyOf(this, index + collection.size)
for (element in collection) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
@kotlin.jvm.JvmVersion
public operator fun DoubleArray.plus(collection: Collection<Double>): DoubleArray {
var index = size
val result = Arrays.copyOf(this, index + collection.size)
for (element in collection) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
@kotlin.jvm.JvmVersion
public operator fun FloatArray.plus(collection: Collection<Float>): FloatArray {
var index = size
val result = Arrays.copyOf(this, index + collection.size)
for (element in collection) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
@kotlin.jvm.JvmVersion
public operator fun IntArray.plus(collection: Collection<Int>): IntArray {
var index = size
val result = Arrays.copyOf(this, index + collection.size)
for (element in collection) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
@kotlin.jvm.JvmVersion
public operator fun LongArray.plus(collection: Collection<Long>): LongArray {
var index = size
val result = Arrays.copyOf(this, index + collection.size)
for (element in collection) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
@kotlin.jvm.JvmVersion
public operator fun ShortArray.plus(collection: Collection<Short>): ShortArray {
var index = size
val result = Arrays.copyOf(this, index + collection.size)
for (element in collection) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [collection].
*/
@kotlin.jvm.JvmVersion
public operator fun <T> Array<T>.plus(collection: Collection<T>): Array<T> {
var index = size
val result = Arrays.copyOf(this, index + collection.size)
for (element in collection) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then the given [element].
*/
@@ -11456,6 +11249,213 @@ public operator fun <T> Array<T>.plus(element: T): Array<T> {
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
@kotlin.jvm.JvmVersion
public operator fun BooleanArray.plus(elements: Collection<Boolean>): BooleanArray {
var index = size
val result = Arrays.copyOf(this, index + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
@kotlin.jvm.JvmVersion
public operator fun ByteArray.plus(elements: Collection<Byte>): ByteArray {
var index = size
val result = Arrays.copyOf(this, index + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
@kotlin.jvm.JvmVersion
public operator fun CharArray.plus(elements: Collection<Char>): CharArray {
var index = size
val result = Arrays.copyOf(this, index + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
@kotlin.jvm.JvmVersion
public operator fun DoubleArray.plus(elements: Collection<Double>): DoubleArray {
var index = size
val result = Arrays.copyOf(this, index + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
@kotlin.jvm.JvmVersion
public operator fun FloatArray.plus(elements: Collection<Float>): FloatArray {
var index = size
val result = Arrays.copyOf(this, index + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
@kotlin.jvm.JvmVersion
public operator fun IntArray.plus(elements: Collection<Int>): IntArray {
var index = size
val result = Arrays.copyOf(this, index + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
@kotlin.jvm.JvmVersion
public operator fun LongArray.plus(elements: Collection<Long>): LongArray {
var index = size
val result = Arrays.copyOf(this, index + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
@kotlin.jvm.JvmVersion
public operator fun ShortArray.plus(elements: Collection<Short>): ShortArray {
var index = size
val result = Arrays.copyOf(this, index + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] collection.
*/
@kotlin.jvm.JvmVersion
public operator fun <T> Array<T>.plus(elements: Collection<T>): Array<T> {
var index = size
val result = Arrays.copyOf(this, index + elements.size)
for (element in elements) result[index++] = element
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@kotlin.jvm.JvmVersion
public operator fun BooleanArray.plus(elements: BooleanArray): BooleanArray {
val thisSize = size
val arraySize = elements.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(elements, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@kotlin.jvm.JvmVersion
public operator fun ByteArray.plus(elements: ByteArray): ByteArray {
val thisSize = size
val arraySize = elements.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(elements, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@kotlin.jvm.JvmVersion
public operator fun CharArray.plus(elements: CharArray): CharArray {
val thisSize = size
val arraySize = elements.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(elements, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@kotlin.jvm.JvmVersion
public operator fun DoubleArray.plus(elements: DoubleArray): DoubleArray {
val thisSize = size
val arraySize = elements.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(elements, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@kotlin.jvm.JvmVersion
public operator fun FloatArray.plus(elements: FloatArray): FloatArray {
val thisSize = size
val arraySize = elements.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(elements, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@kotlin.jvm.JvmVersion
public operator fun IntArray.plus(elements: IntArray): IntArray {
val thisSize = size
val arraySize = elements.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(elements, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@kotlin.jvm.JvmVersion
public operator fun LongArray.plus(elements: LongArray): LongArray {
val thisSize = size
val arraySize = elements.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(elements, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@kotlin.jvm.JvmVersion
public operator fun ShortArray.plus(elements: ShortArray): ShortArray {
val thisSize = size
val arraySize = elements.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(elements, 0, result, thisSize, arraySize)
return result
}
/**
* Returns an array containing all elements of the original array and then all elements of the given [elements] array.
*/
@kotlin.jvm.JvmVersion
public operator fun <T> Array<T>.plus(elements: Array<out T>): Array<T> {
val thisSize = size
val arraySize = elements.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(elements, 0, result, thisSize, arraySize)
return result
}
/**
* Sorts the array in-place.
*/
+77 -77
View File
@@ -1493,25 +1493,6 @@ public fun <T : Any> List<T?>.requireNoNulls(): List<T> {
return this as List<T>
}
/**
* Returns a list containing all elements of the original collection except the elements contained in the given [array].
*/
public operator fun <T> Iterable<T>.minus(array: Array<out T>): List<T> {
if (array.isEmpty()) return this.toList()
val other = array.toHashSet()
return this.filterNot { it in other }
}
/**
* Returns a list containing all elements of the original collection except the elements contained in the given [collection].
*/
public operator fun <T> Iterable<T>.minus(collection: Iterable<T>): List<T> {
val other = collection.convertToSetForSetOperationWith(this)
if (other.isEmpty())
return this.toList()
return this.filterNot { it in other }
}
/**
* Returns a list containing all elements of the original collection without the first occurrence of the given [element].
*/
@@ -1522,10 +1503,29 @@ public operator fun <T> Iterable<T>.minus(element: T): List<T> {
}
/**
* Returns a list containing all elements of the original collection except the elements contained in the given [sequence].
* Returns a list containing all elements of the original collection except the elements contained in the given [elements] array.
*/
public operator fun <T> Iterable<T>.minus(sequence: Sequence<T>): List<T> {
val other = sequence.toHashSet()
public operator fun <T> Iterable<T>.minus(elements: Array<out T>): List<T> {
if (elements.isEmpty()) return this.toList()
val other = elements.toHashSet()
return this.filterNot { it in other }
}
/**
* Returns a list containing all elements of the original collection except the elements contained in the given [elements] collection.
*/
public operator fun <T> Iterable<T>.minus(elements: Iterable<T>): List<T> {
val other = elements.convertToSetForSetOperationWith(this)
if (other.isEmpty())
return this.toList()
return this.filterNot { it in other }
}
/**
* Returns a list containing all elements of the original collection except the elements contained in the given [elements] sequence.
*/
public operator fun <T> Iterable<T>.minus(elements: Sequence<T>): List<T> {
val other = elements.toHashSet()
if (other.isEmpty())
return this.toList()
return this.filterNot { it in other }
@@ -1549,54 +1549,6 @@ public inline fun <T> Iterable<T>.partition(predicate: (T) -> Boolean): Pair<Lis
return Pair(first, second)
}
/**
* Returns a list containing all elements of the original collection and then all elements of the given [array].
*/
public operator fun <T> Collection<T>.plus(array: Array<out T>): List<T> {
val result = ArrayList<T>(this.size + array.size)
result.addAll(this)
result.addAll(array)
return result
}
/**
* Returns a list containing all elements of the original collection and then all elements of the given [array].
*/
public operator fun <T> Iterable<T>.plus(array: Array<out T>): List<T> {
if (this is Collection) return this.plus(array)
val result = ArrayList<T>()
result.addAll(this)
result.addAll(array)
return result
}
/**
* Returns a list containing all elements of the original collection and then all elements of the given [collection].
*/
public operator fun <T> Collection<T>.plus(collection: Iterable<T>): List<T> {
if (collection is Collection) {
val result = ArrayList<T>(this.size + collection.size)
result.addAll(this)
result.addAll(collection)
return result
} else {
val result = ArrayList<T>(this)
result.addAll(collection)
return result
}
}
/**
* Returns a list containing all elements of the original collection and then all elements of the given [collection].
*/
public operator fun <T> Iterable<T>.plus(collection: Iterable<T>): List<T> {
if (this is Collection) return this.plus(collection)
val result = ArrayList<T>()
result.addAll(this)
result.addAll(collection)
return result
}
/**
* Returns a list containing all elements of the original collection and then the given [element].
*/
@@ -1619,22 +1571,70 @@ public operator fun <T> Iterable<T>.plus(element: T): List<T> {
}
/**
* Returns a list containing all elements of the original collection and then all elements of the given [sequence].
* Returns a list containing all elements of the original collection and then all elements of the given [elements] array.
*/
public operator fun <T> Collection<T>.plus(sequence: Sequence<T>): List<T> {
val result = ArrayList<T>(this.size + 10)
public operator fun <T> Collection<T>.plus(elements: Array<out T>): List<T> {
val result = ArrayList<T>(this.size + elements.size)
result.addAll(this)
result.addAll(sequence)
result.addAll(elements)
return result
}
/**
* Returns a list containing all elements of the original collection and then all elements of the given [sequence].
* Returns a list containing all elements of the original collection and then all elements of the given [elements] array.
*/
public operator fun <T> Iterable<T>.plus(sequence: Sequence<T>): List<T> {
public operator fun <T> Iterable<T>.plus(elements: Array<out T>): List<T> {
if (this is Collection) return this.plus(elements)
val result = ArrayList<T>()
result.addAll(this)
result.addAll(sequence)
result.addAll(elements)
return result
}
/**
* Returns a list containing all elements of the original collection and then all elements of the given [elements] collection.
*/
public operator fun <T> Collection<T>.plus(elements: Iterable<T>): List<T> {
if (elements is Collection) {
val result = ArrayList<T>(this.size + elements.size)
result.addAll(this)
result.addAll(elements)
return result
} else {
val result = ArrayList<T>(this)
result.addAll(elements)
return result
}
}
/**
* Returns a list containing all elements of the original collection and then all elements of the given [elements] collection.
*/
public operator fun <T> Iterable<T>.plus(elements: Iterable<T>): List<T> {
if (this is Collection) return this.plus(elements)
val result = ArrayList<T>()
result.addAll(this)
result.addAll(elements)
return result
}
/**
* Returns a list containing all elements of the original collection and then all elements of the given [elements] sequence.
*/
public operator fun <T> Collection<T>.plus(elements: Sequence<T>): List<T> {
val result = ArrayList<T>(this.size + 10)
result.addAll(this)
result.addAll(elements)
return result
}
/**
* Returns a list containing all elements of the original collection and then all elements of the given [elements] sequence.
*/
public operator fun <T> Iterable<T>.plus(elements: Sequence<T>): List<T> {
val result = ArrayList<T>()
result.addAll(this)
result.addAll(elements)
return result
}
+56 -56
View File
@@ -903,38 +903,6 @@ public fun <T : Any> Sequence<T?>.requireNoNulls(): Sequence<T> {
return map { it ?: throw IllegalArgumentException("null element found in $this.") }
}
/**
* Returns a sequence containing all elements of original sequence except the elements contained in the given [array].
* Note that the source sequence and the array being subtracted are iterated only when an `iterator` is requested from
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
*/
public operator fun <T> Sequence<T>.minus(array: Array<out T>): Sequence<T> {
if (array.isEmpty()) return this
return object: Sequence<T> {
override fun iterator(): Iterator<T> {
val other = array.toHashSet()
return this@minus.filterNot { it in other }.iterator()
}
}
}
/**
* Returns a sequence containing all elements of original sequence except the elements contained in the given [collection].
* Note that the source sequence and the collection being subtracted are iterated only when an `iterator` is requested from
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
*/
public operator fun <T> Sequence<T>.minus(collection: Iterable<T>): Sequence<T> {
return object: Sequence<T> {
override fun iterator(): Iterator<T> {
val other = collection.convertToSetForSetOperation()
if (other.isEmpty())
return this@minus.iterator()
else
return this@minus.filterNot { it in other }.iterator()
}
}
}
/**
* Returns a sequence containing all elements of the original sequence without the first occurrence of the given [element].
*/
@@ -948,14 +916,46 @@ public operator fun <T> Sequence<T>.minus(element: T): Sequence<T> {
}
/**
* Returns a sequence containing all elements of original sequence except the elements contained in the given [sequence].
* Returns a sequence containing all elements of original sequence except the elements contained in the given [elements] array.
* Note that the source sequence and the array being subtracted are iterated only when an `iterator` is requested from
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
*/
public operator fun <T> Sequence<T>.minus(elements: Array<out T>): Sequence<T> {
if (elements.isEmpty()) return this
return object: Sequence<T> {
override fun iterator(): Iterator<T> {
val other = elements.toHashSet()
return this@minus.filterNot { it in other }.iterator()
}
}
}
/**
* Returns a sequence containing all elements of original sequence except the elements contained in the given [elements] collection.
* Note that the source sequence and the collection being subtracted are iterated only when an `iterator` is requested from
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
*/
public operator fun <T> Sequence<T>.minus(elements: Iterable<T>): Sequence<T> {
return object: Sequence<T> {
override fun iterator(): Iterator<T> {
val other = elements.convertToSetForSetOperation()
if (other.isEmpty())
return this@minus.iterator()
else
return this@minus.filterNot { it in other }.iterator()
}
}
}
/**
* Returns a sequence containing all elements of original sequence except the elements contained in the given [elements] sequence.
* Note that the source sequence and the sequence being subtracted are iterated only when an `iterator` is requested from
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
*/
public operator fun <T> Sequence<T>.minus(sequence: Sequence<T>): Sequence<T> {
public operator fun <T> Sequence<T>.minus(elements: Sequence<T>): Sequence<T> {
return object: Sequence<T> {
override fun iterator(): Iterator<T> {
val other = sequence.toHashSet()
val other = elements.toHashSet()
if (other.isEmpty())
return this@minus.iterator()
else
@@ -982,24 +982,6 @@ public inline fun <T> Sequence<T>.partition(predicate: (T) -> Boolean): Pair<Lis
return Pair(first, second)
}
/**
* Returns a sequence containing all elements of original sequence and then all elements of the given [array].
* Note that the source sequence and the array being added are iterated only when an `iterator` is requested from
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
*/
public operator fun <T> Sequence<T>.plus(array: Array<out T>): Sequence<T> {
return this.plus(array.asList())
}
/**
* Returns a sequence containing all elements of original sequence and then all elements of the given [collection].
* Note that the source sequence and the collection being added are iterated only when an `iterator` is requested from
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
*/
public operator fun <T> Sequence<T>.plus(collection: Iterable<T>): Sequence<T> {
return sequenceOf(this, collection.asSequence()).flatten()
}
/**
* Returns a sequence containing all elements of the original sequence and then the given [element].
*/
@@ -1008,12 +990,30 @@ public operator fun <T> Sequence<T>.plus(element: T): Sequence<T> {
}
/**
* Returns a sequence containing all elements of original sequence and then all elements of the given [sequence].
* Returns a sequence containing all elements of original sequence and then all elements of the given [elements] array.
* Note that the source sequence and the array being added are iterated only when an `iterator` is requested from
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
*/
public operator fun <T> Sequence<T>.plus(elements: Array<out T>): Sequence<T> {
return this.plus(elements.asList())
}
/**
* Returns a sequence containing all elements of original sequence and then all elements of the given [elements] collection.
* Note that the source sequence and the collection being added are iterated only when an `iterator` is requested from
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
*/
public operator fun <T> Sequence<T>.plus(elements: Iterable<T>): Sequence<T> {
return sequenceOf(this, elements.asSequence()).flatten()
}
/**
* Returns a sequence containing all elements of original sequence and then all elements of the given [elements] sequence.
* Note that the source sequence and the sequence being added are iterated only when an `iterator` is requested from
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
*/
public operator fun <T> Sequence<T>.plus(sequence: Sequence<T>): Sequence<T> {
return sequenceOf(this, sequence).flatten()
public operator fun <T> Sequence<T>.plus(elements: Sequence<T>): Sequence<T> {
return sequenceOf(this, elements).flatten()
}
/**
+42 -42
View File
@@ -13,19 +13,28 @@ import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns a set containing all elements of the original set except the elements contained in the given [array].
* Returns a set containing all elements of the original set except the given [element].
*/
public operator fun <T> Set<T>.minus(array: Array<out T>): Set<T> {
public operator fun <T> Set<T>.minus(element: T): Set<T> {
val result = LinkedHashSet<T>(mapCapacity(size))
var removed = false
return this.filterTo(result) { if (!removed && it == element) { removed = true; false } else true }
}
/**
* Returns a set containing all elements of the original set except the elements contained in the given [elements] array.
*/
public operator fun <T> Set<T>.minus(elements: Array<out T>): Set<T> {
val result = LinkedHashSet<T>(this)
result.removeAll(array)
result.removeAll(elements)
return result
}
/**
* Returns a set containing all elements of the original set except the elements contained in the given [collection].
* Returns a set containing all elements of the original set except the elements contained in the given [elements] collection.
*/
public operator fun <T> Set<T>.minus(collection: Iterable<T>): Set<T> {
val other = collection.convertToSetForSetOperationWith(this)
public operator fun <T> Set<T>.minus(elements: Iterable<T>): Set<T> {
val other = elements.convertToSetForSetOperationWith(this)
if (other.isEmpty())
return this.toSet()
if (other is Set)
@@ -36,40 +45,11 @@ public operator fun <T> Set<T>.minus(collection: Iterable<T>): Set<T> {
}
/**
* Returns a set containing all elements of the original set except the given [element].
* Returns a set containing all elements of the original set except the elements contained in the given [elements] sequence.
*/
public operator fun <T> Set<T>.minus(element: T): Set<T> {
val result = LinkedHashSet<T>(mapCapacity(size))
var removed = false
return this.filterTo(result) { if (!removed && it == element) { removed = true; false } else true }
}
/**
* Returns a set containing all elements of the original set except the elements contained in the given [sequence].
*/
public operator fun <T> Set<T>.minus(sequence: Sequence<T>): Set<T> {
public operator fun <T> Set<T>.minus(elements: Sequence<T>): Set<T> {
val result = LinkedHashSet<T>(this)
result.removeAll(sequence)
return result
}
/**
* Returns a set containing all elements both of the original set and the given [array].
*/
public operator fun <T> Set<T>.plus(array: Array<out T>): Set<T> {
val result = LinkedHashSet<T>(mapCapacity(this.size + array.size))
result.addAll(this)
result.addAll(array)
return result
}
/**
* Returns a set containing all elements both of the original set and the given [collection].
*/
public operator fun <T> Set<T>.plus(collection: Iterable<T>): Set<T> {
val result = LinkedHashSet<T>(mapCapacity(collection.collectionSizeOrNull()?.let { this.size + it } ?: this.size * 2))
result.addAll(this)
result.addAll(collection)
result.removeAll(elements)
return result
}
@@ -84,12 +64,32 @@ public operator fun <T> Set<T>.plus(element: T): Set<T> {
}
/**
* Returns a set containing all elements both of the original set and the given [sequence].
* Returns a set containing all elements both of the original set and the given [elements] array.
*/
public operator fun <T> Set<T>.plus(sequence: Sequence<T>): Set<T> {
val result = LinkedHashSet<T>(mapCapacity(this.size * 2))
public operator fun <T> Set<T>.plus(elements: Array<out T>): Set<T> {
val result = LinkedHashSet<T>(mapCapacity(this.size + elements.size))
result.addAll(this)
result.addAll(sequence)
result.addAll(elements)
return result
}
/**
* Returns a set containing all elements both of the original set and the given [elements] collection.
*/
public operator fun <T> Set<T>.plus(elements: Iterable<T>): Set<T> {
val result = LinkedHashSet<T>(mapCapacity(elements.collectionSizeOrNull()?.let { this.size + it } ?: this.size * 2))
result.addAll(this)
result.addAll(elements)
return result
}
/**
* Returns a set containing all elements both of the original set and the given [elements] sequence.
*/
public operator fun <T> Set<T>.plus(elements: Sequence<T>): Set<T> {
val result = LinkedHashSet<T>(mapCapacity(this.size * 2))
result.addAll(this)
result.addAll(elements)
return result
}
@@ -50,51 +50,51 @@ fun generators(): List<GenericFunction> {
}
}
templates add f("plus(collection: Iterable<T>)") {
templates add f("plus(elements: Iterable<T>)") {
operator(true)
only(Iterables, Collections, Sets, Sequences)
doc { "Returns a list containing all elements of the original collection and then all elements of the given [collection]." }
doc { f -> "Returns a list containing all elements of the original ${f.collection} and then all elements of the given [elements] collection." }
returns("List<T>")
returns("SELF", Sets, Sequences)
body {
"""
if (this is Collection) return this.plus(collection)
if (this is Collection) return this.plus(elements)
val result = ArrayList<T>()
result.addAll(this)
result.addAll(collection)
result.addAll(elements)
return result
"""
}
body(Collections) {
"""
if (collection is Collection) {
val result = ArrayList<T>(this.size + collection.size)
if (elements is Collection) {
val result = ArrayList<T>(this.size + elements.size)
result.addAll(this)
result.addAll(collection)
result.addAll(elements)
return result
} else {
val result = ArrayList<T>(this)
result.addAll(collection)
result.addAll(elements)
return result
}
"""
}
// TODO: use immutable set builder when available
doc(Sets) { "Returns a set containing all elements both of the original set and the given [collection]." }
doc(Sets) { "Returns a set containing all elements both of the original set and the given [elements] collection." }
body(Sets) {
"""
val result = LinkedHashSet<T>(mapCapacity(collection.collectionSizeOrNull()?.let { this.size + it } ?: this.size * 2))
val result = LinkedHashSet<T>(mapCapacity(elements.collectionSizeOrNull()?.let { this.size + it } ?: this.size * 2))
result.addAll(this)
result.addAll(collection)
result.addAll(elements)
return result
"""
}
doc(Sequences) {
"""
Returns a sequence containing all elements of original sequence and then all elements of the given [collection].
Returns a sequence containing all elements of original sequence and then all elements of the given [elements] collection.
Note that the source sequence and the collection being added are iterated only when an `iterator` is requested from
the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
@@ -102,47 +102,47 @@ fun generators(): List<GenericFunction> {
}
body(Sequences) {
"""
return sequenceOf(this, collection.asSequence()).flatten()
return sequenceOf(this, elements.asSequence()).flatten()
"""
}
}
templates add f("plus(array: Array<out T>)") {
templates add f("plus(elements: Array<out T>)") {
operator(true)
only(Iterables, Collections, Sets, Sequences)
doc { "Returns a list containing all elements of the original collection and then all elements of the given [array]." }
doc { "Returns a list containing all elements of the original collection and then all elements of the given [elements] array." }
returns("List<T>")
returns("SELF", Sets, Sequences)
body {
"""
if (this is Collection) return this.plus(array)
if (this is Collection) return this.plus(elements)
val result = ArrayList<T>()
result.addAll(this)
result.addAll(array)
result.addAll(elements)
return result
"""
}
body(Collections) {
"""
val result = ArrayList<T>(this.size + array.size)
val result = ArrayList<T>(this.size + elements.size)
result.addAll(this)
result.addAll(array)
result.addAll(elements)
return result
"""
}
doc(Sets) { "Returns a set containing all elements both of the original set and the given [array]." }
doc(Sets) { "Returns a set containing all elements both of the original set and the given [elements] array." }
body(Sets) {
"""
val result = LinkedHashSet<T>(mapCapacity(this.size + array.size))
val result = LinkedHashSet<T>(mapCapacity(this.size + elements.size))
result.addAll(this)
result.addAll(array)
result.addAll(elements)
return result
"""
}
doc(Sequences) {
"""
Returns a sequence containing all elements of original sequence and then all elements of the given [array].
Returns a sequence containing all elements of original sequence and then all elements of the given [elements] array.
Note that the source sequence and the array being added are iterated only when an `iterator` is requested from
the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
@@ -150,24 +150,24 @@ fun generators(): List<GenericFunction> {
}
body(Sequences) {
"""
return this.plus(array.asList())
return this.plus(elements.asList())
"""
}
}
templates add f("plus(sequence: Sequence<T>)") {
templates add f("plus(elements: Sequence<T>)") {
operator(true)
only(Iterables, Sets, Sequences)
doc { "Returns a list containing all elements of the original collection and then all elements of the given [sequence]." }
doc { "Returns a list containing all elements of the original collection and then all elements of the given [elements] sequence." }
returns("List<T>")
returns("SELF", Sets, Sequences)
body {
"""
val result = ArrayList<T>()
result.addAll(this)
result.addAll(sequence)
result.addAll(elements)
return result
"""
}
@@ -175,25 +175,25 @@ fun generators(): List<GenericFunction> {
"""
val result = ArrayList<T>(this.size + 10)
result.addAll(this)
result.addAll(sequence)
result.addAll(elements)
return result
"""
}
// TODO: use immutable set builder when available
doc(Sets) { "Returns a set containing all elements both of the original set and the given [sequence]." }
doc(Sets) { "Returns a set containing all elements both of the original set and the given [elements] sequence." }
body(Sets) {
"""
val result = LinkedHashSet<T>(mapCapacity(this.size * 2))
result.addAll(this)
result.addAll(sequence)
result.addAll(elements)
return result
"""
}
doc(Sequences) {
"""
Returns a sequence containing all elements of original sequence and then all elements of the given [sequence].
Returns a sequence containing all elements of original sequence and then all elements of the given [elements] sequence.
Note that the source sequence and the sequence being added are iterated only when an `iterator` is requested from
the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
@@ -201,7 +201,7 @@ fun generators(): List<GenericFunction> {
}
body(Sequences) {
"""
return sequenceOf(this, sequence).flatten()
return sequenceOf(this, elements).flatten()
"""
}
}
@@ -245,16 +245,16 @@ fun generators(): List<GenericFunction> {
}
templates add f("minus(collection: Iterable<T>)") {
templates add f("minus(elements: Iterable<T>)") {
operator(true)
only(Iterables, Sets, Sequences)
doc { "Returns a list containing all elements of the original collection except the elements contained in the given [collection]." }
doc { "Returns a list containing all elements of the original collection except the elements contained in the given [elements] collection." }
returns("List<T>")
returns("SELF", Sets, Sequences)
body {
"""
val other = collection.convertToSetForSetOperationWith(this)
val other = elements.convertToSetForSetOperationWith(this)
if (other.isEmpty())
return this.toList()
@@ -262,10 +262,10 @@ fun generators(): List<GenericFunction> {
"""
}
doc(Sets) { "Returns a set containing all elements of the original set except the elements contained in the given [collection]." }
doc(Sets) { "Returns a set containing all elements of the original set except the elements contained in the given [elements] collection." }
body(Sets) {
"""
val other = collection.convertToSetForSetOperationWith(this)
val other = elements.convertToSetForSetOperationWith(this)
if (other.isEmpty())
return this.toSet()
if (other is Set)
@@ -279,7 +279,7 @@ fun generators(): List<GenericFunction> {
doc(Sequences) {
"""
Returns a sequence containing all elements of original sequence except the elements contained in the given [collection].
Returns a sequence containing all elements of original sequence except the elements contained in the given [elements] collection.
Note that the source sequence and the collection being subtracted are iterated only when an `iterator` is requested from
the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
@@ -289,7 +289,7 @@ fun generators(): List<GenericFunction> {
"""
return object: Sequence<T> {
override fun iterator(): Iterator<T> {
val other = collection.convertToSetForSetOperation()
val other = elements.convertToSetForSetOperation()
if (other.isEmpty())
return this@minus.iterator()
else
@@ -300,32 +300,32 @@ fun generators(): List<GenericFunction> {
}
}
templates add f("minus(array: Array<out T>)") {
templates add f("minus(elements: Array<out T>)") {
operator(true)
only(Iterables, Sets, Sequences)
doc { "Returns a list containing all elements of the original collection except the elements contained in the given [array]." }
doc { "Returns a list containing all elements of the original collection except the elements contained in the given [elements] array." }
returns("List<T>")
returns("SELF", Sets, Sequences)
body {
"""
if (array.isEmpty()) return this.toList()
val other = array.toHashSet()
if (elements.isEmpty()) return this.toList()
val other = elements.toHashSet()
return this.filterNot { it in other }
"""
}
doc(Sets) { "Returns a set containing all elements of the original set except the elements contained in the given [array]." }
doc(Sets) { "Returns a set containing all elements of the original set except the elements contained in the given [elements] array." }
body(Sets) {
"""
val result = LinkedHashSet<T>(this)
result.removeAll(array)
result.removeAll(elements)
return result
"""
}
doc(Sequences) {
"""
Returns a sequence containing all elements of original sequence except the elements contained in the given [array].
Returns a sequence containing all elements of original sequence except the elements contained in the given [elements] array.
Note that the source sequence and the array being subtracted are iterated only when an `iterator` is requested from
the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
@@ -333,10 +333,10 @@ fun generators(): List<GenericFunction> {
}
body(Sequences) {
"""
if (array.isEmpty()) return this
if (elements.isEmpty()) return this
return object: Sequence<T> {
override fun iterator(): Iterator<T> {
val other = array.toHashSet()
val other = elements.toHashSet()
return this@minus.filterNot { it in other }.iterator()
}
}
@@ -344,34 +344,34 @@ fun generators(): List<GenericFunction> {
}
}
templates add f("minus(sequence: Sequence<T>)") {
templates add f("minus(elements: Sequence<T>)") {
operator(true)
only(Iterables, Sets)
doc { "Returns a list containing all elements of the original collection except the elements contained in the given [sequence]." }
doc { "Returns a list containing all elements of the original collection except the elements contained in the given [elements] sequence." }
returns("List<T>")
returns("SELF", Sets, Sequences)
body {
"""
val other = sequence.toHashSet()
val other = elements.toHashSet()
if (other.isEmpty())
return this.toList()
return this.filterNot { it in other }
"""
}
doc(Sets) { "Returns a set containing all elements of the original set except the elements contained in the given [sequence]." }
doc(Sets) { "Returns a set containing all elements of the original set except the elements contained in the given [elements] sequence." }
body(Sets) {
"""
val result = LinkedHashSet<T>(this)
result.removeAll(sequence)
result.removeAll(elements)
return result
"""
}
doc(Sequences) {
"""
Returns a sequence containing all elements of original sequence except the elements contained in the given [sequence].
Returns a sequence containing all elements of original sequence except the elements contained in the given [elements] sequence.
Note that the source sequence and the sequence being subtracted are iterated only when an `iterator` is requested from
the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
@@ -381,7 +381,7 @@ fun generators(): List<GenericFunction> {
"""
return object: Sequence<T> {
override fun iterator(): Iterator<T> {
val other = sequence.toHashSet()
val other = elements.toHashSet()
if (other.isEmpty())
return this@minus.iterator()
else
@@ -104,29 +104,29 @@ fun specialJS(): List<GenericFunction> {
}
}
templates add f("plus(collection: Collection<T>)") {
templates add f("plus(elements: Collection<T>)") {
only(ArraysOfObjects, ArraysOfPrimitives)
returns("SELF")
returns(ArraysOfObjects) { "Array<T>" }
doc { "Returns an array containing all elements of the original array and then all elements of the given [collection]." }
doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] collection." }
body {
"""
return arrayPlusCollection(this, collection)
return arrayPlusCollection(this, elements)
"""
}
}
// This overload can cause nulls if array size is expanding, hence different return overload
templates add f("plus(array: SELF)") {
templates add f("plus(elements: SELF)") {
only(ArraysOfObjects, ArraysOfPrimitives)
doc { "Returns an array containing all elements of the original array and then all elements of the given [array]." }
doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] array." }
inline(true)
annotations("""@Suppress("NOTHING_TO_INLINE")""")
returns("SELF")
returns(ArraysOfObjects) { "Array<T>" }
body {
"""
return this.asDynamic().concat(array)
return this.asDynamic().concat(elements)
"""
}
}
@@ -21,35 +21,35 @@ fun specialJVM(): List<GenericFunction> {
}
}
templates add f("plus(collection: Collection<T>)") {
templates add f("plus(elements: Collection<T>)") {
operator(true)
only(InvariantArraysOfObjects, ArraysOfPrimitives)
returns("SELF")
doc { "Returns an array containing all elements of the original array and then all elements of the given [collection]." }
doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] collection." }
body {
"""
var index = size
val result = Arrays.copyOf(this, index + collection.size)
for (element in collection) result[index++] = element
val result = Arrays.copyOf(this, index + elements.size)
for (element in elements) result[index++] = element
return result
"""
}
}
templates add f("plus(array: SELF)") {
templates add f("plus(elements: SELF)") {
operator(true)
only(InvariantArraysOfObjects, ArraysOfPrimitives)
customSignature(InvariantArraysOfObjects) { "plus(array: Array<out T>)" }
doc { "Returns an array containing all elements of the original array and then all elements of the given [array]." }
customSignature(InvariantArraysOfObjects) { "plus(elements: Array<out T>)" }
doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] array." }
returns("SELF")
body {
"""
val thisSize = size
val arraySize = array.size
val arraySize = elements.size
val result = Arrays.copyOf(this, thisSize + arraySize)
System.arraycopy(array, 0, result, thisSize, arraySize)
System.arraycopy(elements, 0, result, thisSize, arraySize)
return result
"""
}