From a3cd86d2cd937f66a983c23d783b5db5336649b9 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Mon, 16 Nov 2015 23:20:16 +0300 Subject: [PATCH] StdLib: Rename method parameters (Collections) --- js/js.libraries/src/core/kotlin.kt | 28 ++--- .../src/kotlin/collections/ArraysJVM.kt | 18 +-- .../stdlib/src/kotlin/collections/JUtil.kt | 30 ++--- .../kotlin/collections/MutableCollections.kt | 104 +++++++++--------- .../stdlib/src/kotlin/collections/Sets.kt | 18 +-- 5 files changed, 99 insertions(+), 99 deletions(-) diff --git a/js/js.libraries/src/core/kotlin.kt b/js/js.libraries/src/core/kotlin.kt index 2b1a01fc1c5..c8085aa61c9 100644 --- a/js/js.libraries/src/core/kotlin.kt +++ b/js/js.libraries/src/core/kotlin.kt @@ -3,53 +3,53 @@ package kotlin import java.util.* @library -public fun arrayOf(vararg value : T): Array = noImpl +public fun arrayOf(vararg elements: T): Array = noImpl // "constructors" for primitive types array @library -public fun doubleArrayOf(vararg content : Double): DoubleArray = noImpl +public fun doubleArrayOf(vararg elements: Double): DoubleArray = noImpl @library -public fun floatArrayOf(vararg content : Float): FloatArray = noImpl +public fun floatArrayOf(vararg elements: Float): FloatArray = noImpl @library -public fun longArrayOf(vararg content : Long): LongArray = noImpl +public fun longArrayOf(vararg elements: Long): LongArray = noImpl @library -public fun intArrayOf(vararg content : Int): IntArray = noImpl +public fun intArrayOf(vararg elements: Int): IntArray = noImpl @library -public fun charArrayOf(vararg content : Char): CharArray = noImpl +public fun charArrayOf(vararg elements: Char): CharArray = noImpl @library -public fun shortArrayOf(vararg content : Short): ShortArray = noImpl +public fun shortArrayOf(vararg elements: Short): ShortArray = noImpl @library -public fun byteArrayOf(vararg content : Byte): ByteArray = noImpl +public fun byteArrayOf(vararg elements: Byte): ByteArray = noImpl @library -public fun booleanArrayOf(vararg content : Boolean): BooleanArray = noImpl +public fun booleanArrayOf(vararg elements: Boolean): BooleanArray = noImpl @library("copyToArray") public fun Collection.toTypedArray(): Array = noImpl /** - * Returns an immutable list containing only the specified object [value]. + * Returns an immutable list containing only the specified object [element]. */ -public fun listOf(value: T): List = arrayListOf(value) +public fun listOf(element: T): List = arrayListOf(element) /** - * Returns an immutable set containing only the specified object [value]. + * Returns an immutable set containing only the specified object [element]. */ -public fun setOf(value: T): Set = hashSetOf(value) +public fun setOf(element: T): Set = hashSetOf(element) /** * Returns an immutable map, mapping only the specified key to the * specified value. */ -public fun mapOf(keyValuePair: Pair): Map = hashMapOf(keyValuePair) +public fun mapOf(pair: Pair): Map = hashMapOf(pair) /** * Creates a new instance of the [Lazy] that uses the specified initialization function [initializer]. diff --git a/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt b/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt index 70aa7a940f8..82813ea74d7 100644 --- a/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt +++ b/libraries/stdlib/src/kotlin/collections/ArraysJVM.kt @@ -11,48 +11,48 @@ import kotlin.jvm.internal.Intrinsic /** * Returns an array containing the specified elements. */ -@Intrinsic("kotlin.arrays.array") public fun arrayOf(vararg t : T) : Array = t as Array +@Intrinsic("kotlin.arrays.array") public fun arrayOf(vararg elements: T) : Array = elements as Array // "constructors" for primitive types array /** * Returns an array containing the specified [Double] numbers. */ -@Intrinsic("kotlin.arrays.array") public fun doubleArrayOf(vararg content : Double) : DoubleArray = content +@Intrinsic("kotlin.arrays.array") public fun doubleArrayOf(vararg elements: Double) : DoubleArray = elements /** * Returns an array containing the specified [Float] numbers. */ -@Intrinsic("kotlin.arrays.array") public fun floatArrayOf(vararg content : Float) : FloatArray = content +@Intrinsic("kotlin.arrays.array") public fun floatArrayOf(vararg elements: Float) : FloatArray = elements /** * Returns an array containing the specified [Long] numbers. */ -@Intrinsic("kotlin.arrays.array") public fun longArrayOf(vararg content : Long) : LongArray = content +@Intrinsic("kotlin.arrays.array") public fun longArrayOf(vararg elements: Long) : LongArray = elements /** * Returns an array containing the specified [Int] numbers. */ -@Intrinsic("kotlin.arrays.array") public fun intArrayOf(vararg content : Int) : IntArray = content +@Intrinsic("kotlin.arrays.array") public fun intArrayOf(vararg elements: Int) : IntArray = elements /** * Returns an array containing the specified characters. */ -@Intrinsic("kotlin.arrays.array") public fun charArrayOf(vararg content : Char) : CharArray = content +@Intrinsic("kotlin.arrays.array") public fun charArrayOf(vararg elements: Char) : CharArray = elements /** * Returns an array containing the specified [Short] numbers. */ -@Intrinsic("kotlin.arrays.array") public fun shortArrayOf(vararg content : Short) : ShortArray = content +@Intrinsic("kotlin.arrays.array") public fun shortArrayOf(vararg elements: Short) : ShortArray = elements /** * Returns an array containing the specified [Byte] numbers. */ -@Intrinsic("kotlin.arrays.array") public fun byteArrayOf(vararg content : Byte) : ByteArray = content +@Intrinsic("kotlin.arrays.array") public fun byteArrayOf(vararg elements: Byte) : ByteArray = elements /** * Returns an array containing the specified boolean values. */ -@Intrinsic("kotlin.arrays.array") public fun booleanArrayOf(vararg content : Boolean) : BooleanArray = content +@Intrinsic("kotlin.arrays.array") public fun booleanArrayOf(vararg elements: Boolean) : BooleanArray = elements /** * Converts the contents of this byte array to a string using the specified [charset]. diff --git a/libraries/stdlib/src/kotlin/collections/JUtil.kt b/libraries/stdlib/src/kotlin/collections/JUtil.kt index 71fb9dd7e28..1819294cb87 100644 --- a/libraries/stdlib/src/kotlin/collections/JUtil.kt +++ b/libraries/stdlib/src/kotlin/collections/JUtil.kt @@ -22,12 +22,12 @@ internal object EmptyList : List, Serializable { override val size: Int get() = 0 override fun isEmpty(): Boolean = true - override fun contains(o: Nothing): Boolean = false - override fun containsAll(c: Collection): Boolean = c.isEmpty() + override fun contains(element: Nothing): Boolean = false + override fun containsAll(elements: Collection): Boolean = elements.isEmpty() override fun get(index: Int): Nothing = throw IndexOutOfBoundsException("Index $index is out of bound of empty list.") - override fun indexOf(o: Nothing): Int = -1 - override fun lastIndexOf(o: Nothing): Int = -1 + override fun indexOf(element: Nothing): Int = -1 + override fun lastIndexOf(element: Nothing): Int = -1 override fun iterator(): Iterator = EmptyIterator override fun listIterator(): ListIterator = EmptyIterator @@ -49,8 +49,8 @@ internal fun Array.asCollection(): Collection = ArrayAsCollection( private class ArrayAsCollection(val values: Array): Collection { override val size: Int get() = values.size override fun isEmpty(): Boolean = values.isEmpty() - override fun contains(o: T): Boolean = values.contains(o) - override fun containsAll(c: Collection): Boolean = c.all { contains(it) } + override fun contains(element: T): Boolean = values.contains(element) + override fun containsAll(elements: Collection): Boolean = elements.all { contains(it) } override fun iterator(): Iterator = values.iterator() // override hidden toArray implementation to prevent copying of values array public fun toArray(): Array = values.varargToArrayOfAny() @@ -60,32 +60,32 @@ private class ArrayAsCollection(val values: Array): Collection { public fun emptyList(): List = EmptyList /** Returns a new read-only list of given elements. The returned list is serializable (JVM). */ -public fun listOf(vararg values: T): List = if (values.size > 0) values.asList() else emptyList() +public fun listOf(vararg elements: T): List = if (elements.size > 0) elements.asList() else emptyList() /** Returns an empty read-only list. The returned list is serializable (JVM). */ public fun listOf(): List = emptyList() /** - * Returns an immutable list containing only the specified object [value]. + * Returns an immutable list containing only the specified object [element]. * The returned list is serializable. */ @JvmVersion -public fun listOf(value: T): List = Collections.singletonList(value) +public fun listOf(element: T): List = Collections.singletonList(element) /** Returns a new [LinkedList] with the given elements. */ @JvmVersion -public fun linkedListOf(vararg values: T): LinkedList - = if (values.size == 0) LinkedList() else LinkedList(ArrayAsCollection(values)) +public fun linkedListOf(vararg elements: T): LinkedList + = if (elements.size == 0) LinkedList() else LinkedList(ArrayAsCollection(elements)) /** Returns a new [ArrayList] with the given elements. */ -public fun arrayListOf(vararg values: T): ArrayList - = if (values.size == 0) ArrayList() else ArrayList(ArrayAsCollection(values)) +public fun arrayListOf(vararg elements: T): ArrayList + = if (elements.size == 0) ArrayList() else ArrayList(ArrayAsCollection(elements)) /** Returns a new read-only list either of single given element, if it is not null, or empty list it the element is null. The returned list is serializable (JVM). */ -public fun listOfNotNull(value: T?): List = if (value != null) listOf(value) else emptyList() +public fun listOfNotNull(element: T?): List = if (element != null) listOf(element) else emptyList() /** Returns a new read-only list only of those given elements, that are not null. The returned list is serializable (JVM). */ -public fun listOfNotNull(vararg values: T?): List = values.filterNotNull() +public fun listOfNotNull(vararg elements: T?): List = elements.filterNotNull() /** * Returns an [IntRange] of the valid indices for this collection. diff --git a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt index 30d70cc7a9f..04756efcbbd 100644 --- a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt +++ b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt @@ -11,7 +11,7 @@ import java.util.* * Allows to overcome type-safety restriction of `containsAll` that requires to pass a collection of type `Collection`. */ @Suppress("NOTHING_TO_INLINE") -public inline fun Collection<*>.containsAllRaw(collection: Collection): Boolean = (this as Collection).containsAll(collection) +public inline fun Collection<*>.containsAllRaw(elements: Collection): Boolean = (this as Collection).containsAll(elements) /** * Removes a single instance of the specified element from this @@ -32,7 +32,7 @@ public inline fun MutableCollection.removeRaw(element: Any?): Boolean = ( * @return `true` if any of the specified elements was removed from the collection, `false` if the collection was not modified. */ @Suppress("NOTHING_TO_INLINE") -public inline fun MutableCollection.removeAllRaw(collection: Collection): Boolean = (this as MutableCollection).removeAll(collection) +public inline fun MutableCollection.removeAllRaw(elements: Collection): Boolean = (this as MutableCollection).removeAll(elements) /** * Retains only the elements in this collection that are contained in the specified collection. @@ -42,7 +42,7 @@ public inline fun MutableCollection.removeAllRaw(collection: Collection MutableCollection.retainAllRaw(collection: Collection): Boolean = (this as MutableCollection).retainAll(collection) +public inline fun MutableCollection.retainAllRaw(elements: Collection): Boolean = (this as MutableCollection).retainAll(elements) @@ -123,24 +123,24 @@ public operator fun MutableCollection.plusAssign(element: T) { } /** - * Adds all elements of the given [collection] to this mutable collection. + * Adds all elements of the given [elements] collection to this mutable collection. */ -public operator fun MutableCollection.plusAssign(collection: Iterable) { - this.addAll(collection) +public operator fun MutableCollection.plusAssign(elements: Iterable) { + this.addAll(elements) } /** - * Adds all elements of the given [array] to this mutable collection. + * Adds all elements of the given [elements] array to this mutable collection. */ -public operator fun MutableCollection.plusAssign(array: Array) { - this.addAll(array) +public operator fun MutableCollection.plusAssign(elements: Array) { + this.addAll(elements) } /** - * Adds all elements of the given [sequence] to this mutable collection. + * Adds all elements of the given [elements] sequence to this mutable collection. */ -public operator fun MutableCollection.plusAssign(sequence: Sequence) { - this.addAll(sequence) +public operator fun MutableCollection.plusAssign(elements: Sequence) { + this.addAll(elements) } /** @@ -151,99 +151,99 @@ public operator fun MutableCollection.minusAssign(element: T) { } /** - * Removes all elements contained in the given [collection] from this mutable collection. + * Removes all elements contained in the given [elements] collection from this mutable collection. */ -public operator fun MutableCollection.minusAssign(collection: Iterable) { - this.removeAll(collection) +public operator fun MutableCollection.minusAssign(elements: Iterable) { + this.removeAll(elements) } /** - * Removes all elements contained in the given [array] from this mutable collection. + * Removes all elements contained in the given [elements] array from this mutable collection. */ -public operator fun MutableCollection.minusAssign(array: Array) { - this.removeAll(array) +public operator fun MutableCollection.minusAssign(elements: Array) { + this.removeAll(elements) } /** - * Removes all elements contained in the given [sequence] from this mutable collection. + * Removes all elements contained in the given [elements] sequence from this mutable collection. */ -public operator fun MutableCollection.minusAssign(sequence: Sequence) { - this.removeAll(sequence) +public operator fun MutableCollection.minusAssign(elements: Sequence) { + this.removeAll(elements) } /** - * Adds all elements of the given [iterable] to this [MutableCollection]. + * Adds all elements of the given [elements] collection to this [MutableCollection]. */ -public fun MutableCollection.addAll(iterable: Iterable) { - when (iterable) { - is Collection -> addAll(iterable) - else -> for (item in iterable) add(item) +public fun MutableCollection.addAll(elements: Iterable) { + when (elements) { + is Collection -> addAll(elements) + else -> for (item in elements) add(item) } } /** - * Adds all elements of the given [sequence] to this [MutableCollection]. + * Adds all elements of the given [elements] sequence to this [MutableCollection]. */ -public fun MutableCollection.addAll(sequence: Sequence) { - for (item in sequence) add(item) +public fun MutableCollection.addAll(elements: Sequence) { + for (item in elements) add(item) } /** - * Adds all elements of the given [array] to this [MutableCollection]. + * Adds all elements of the given [elements] array to this [MutableCollection]. */ -public fun MutableCollection.addAll(array: Array) { - addAll(array.asList()) +public fun MutableCollection.addAll(elements: Array) { + addAll(elements.asList()) } /** - * Removes all elements from this [MutableCollection] that are also contained in the given [iterable]. + * Removes all elements from this [MutableCollection] that are also contained in the given [elements] collection. */ -public fun MutableCollection.removeAll(iterable: Iterable) { - removeAll(iterable.convertToSetForSetOperationWith(this)) +public fun MutableCollection.removeAll(elements: Iterable) { + removeAll(elements.convertToSetForSetOperationWith(this)) } /** - * Removes all elements from this [MutableCollection] that are also contained in the given [sequence]. + * Removes all elements from this [MutableCollection] that are also contained in the given [elements] sequence. */ -public fun MutableCollection.removeAll(sequence: Sequence) { - val set = sequence.toHashSet() +public fun MutableCollection.removeAll(elements: Sequence) { + val set = elements.toHashSet() if (set.isNotEmpty()) removeAll(set) } /** - * Removes all elements from this [MutableCollection] that are also contained in the given [array]. + * Removes all elements from this [MutableCollection] that are also contained in the given [elements] array. */ -public fun MutableCollection.removeAll(array: Array) { - if (array.isNotEmpty()) - removeAll(array.toHashSet()) +public fun MutableCollection.removeAll(elements: Array) { + if (elements.isNotEmpty()) + removeAll(elements.toHashSet()) // else // removeAll(emptyList()) } /** - * Retains only elements of this [MutableCollection] that are contained in the given [iterable]. + * Retains only elements of this [MutableCollection] that are contained in the given [elements] collection. */ -public fun MutableCollection.retainAll(iterable: Iterable) { - retainAll(iterable.convertToSetForSetOperationWith(this)) +public fun MutableCollection.retainAll(elements: Iterable) { + retainAll(elements.convertToSetForSetOperationWith(this)) } /** - * Retains only elements of this [MutableCollection] that are contained in the given [array]. + * Retains only elements of this [MutableCollection] that are contained in the given [elements] array. */ -public fun MutableCollection.retainAll(array: Array) { - if (array.isNotEmpty()) - retainAll(array.toHashSet()) +public fun MutableCollection.retainAll(elements: Array) { + if (elements.isNotEmpty()) + retainAll(elements.toHashSet()) else clear() // retainAll(emptyList()) } /** - * Retains only elements of this [MutableCollection] that are contained in the given [sequence]. + * Retains only elements of this [MutableCollection] that are contained in the given [elements] sequence. */ -public fun MutableCollection.retainAll(sequence: Sequence) { - val set = sequence.toHashSet() +public fun MutableCollection.retainAll(elements: Sequence) { + val set = elements.toHashSet() if (set.isNotEmpty()) retainAll(set) else diff --git a/libraries/stdlib/src/kotlin/collections/Sets.kt b/libraries/stdlib/src/kotlin/collections/Sets.kt index 8e7b0dcda5c..89fa1a681cd 100644 --- a/libraries/stdlib/src/kotlin/collections/Sets.kt +++ b/libraries/stdlib/src/kotlin/collections/Sets.kt @@ -14,8 +14,8 @@ internal object EmptySet : Set, Serializable { override val size: Int get() = 0 override fun isEmpty(): Boolean = true - override fun contains(o: Nothing): Boolean = false - override fun containsAll(c: Collection): Boolean = c.isEmpty() + override fun contains(element: Nothing): Boolean = false + override fun containsAll(elements: Collection): Boolean = elements.isEmpty() override fun iterator(): Iterator = EmptyIterator @@ -26,37 +26,37 @@ internal object EmptySet : Set, Serializable { /** Returns an empty read-only set. The returned set is serializable (JVM). */ public fun emptySet(): Set = EmptySet /** Returns a new read-only ordered set with the given elements. The returned set is serializable (JVM). */ -public fun setOf(vararg values: T): Set = if (values.size > 0) values.toSet() else emptySet() +public fun setOf(vararg elements: T): Set = if (elements.size > 0) elements.toSet() else emptySet() /** Returns an empty read-only set. The returned set is serializable (JVM). */ public fun setOf(): Set = emptySet() /** Returns a new [HashSet] with the given elements. */ -public fun hashSetOf(vararg values: T): HashSet = values.toCollection(HashSet(mapCapacity(values.size))) +public fun hashSetOf(vararg elements: T): HashSet = elements.toCollection(HashSet(mapCapacity(elements.size))) /** Returns a new [LinkedHashSet] with the given elements. */ -public fun linkedSetOf(vararg values: T): LinkedHashSet = values.toCollection(LinkedHashSet(mapCapacity(values.size))) +public fun linkedSetOf(vararg elements: T): LinkedHashSet = elements.toCollection(LinkedHashSet(mapCapacity(elements.size))) /** Returns this Set if it's not `null` and the empty set otherwise. */ public fun Set?.orEmpty(): Set = this ?: emptySet() /** - * Returns an immutable set containing only the specified object [value]. + * Returns an immutable set containing only the specified object [element]. * The returned set is serializable. */ @JvmVersion -public fun setOf(value: T): Set = Collections.singleton(value) +public fun setOf(element: T): Set = Collections.singleton(element) /** * Returns a new [SortedSet] with the given elements. */ @JvmVersion -public fun sortedSetOf(vararg values: T): TreeSet = values.toCollection(TreeSet()) +public fun sortedSetOf(vararg elements: T): TreeSet = elements.toCollection(TreeSet()) /** * Returns a new [SortedSet] with the given [comparator] and elements. */ @JvmVersion -public fun sortedSetOf(comparator: Comparator, vararg values: T): TreeSet = values.toCollection(TreeSet(comparator)) +public fun sortedSetOf(comparator: Comparator, vararg elements: T): TreeSet = elements.toCollection(TreeSet(comparator))