From 6df5e8b73a77882df13574c4c93a78d1437f9917 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Mon, 3 Dec 2012 15:23:30 +0400 Subject: [PATCH] Deprecate confusing arrayList(), hashSet() and such. Introduce arrayListOf(...) ans such --- libraries/stdlib/src/kotlin/JUtilJVM.kt | 42 ++++++++++++++++++------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/libraries/stdlib/src/kotlin/JUtilJVM.kt b/libraries/stdlib/src/kotlin/JUtilJVM.kt index af6296cd6b5..039a26f0034 100644 --- a/libraries/stdlib/src/kotlin/JUtilJVM.kt +++ b/libraries/stdlib/src/kotlin/JUtilJVM.kt @@ -3,20 +3,32 @@ package kotlin import java.util.* /** Returns a new LinkedList with a variable number of initial elements */ -public inline fun linkedList(vararg values: T) : LinkedList = values.toCollection(LinkedList()) +public inline fun linkedListOf(vararg values: T) : LinkedList = values.toCollection(LinkedList()) + +deprecated("Use linkedListOf() instead") +public inline fun linkedList(vararg values: T) : LinkedList = linkedListOf(*values) /** Returns a new HashSet with a variable number of initial elements */ -public inline fun hashSet(vararg values: T) : HashSet = values.toCollection(HashSet(values.size)) +public inline fun hashSetOf(vararg values: T) : HashSet = values.toCollection(HashSet(values.size)) + +deprecated("Use hashSetOf() instead") +public inline fun hashSet(vararg values: T) : HashSet = hashSetOf(*values) /** * Returns a new [[SortedSet]] with the initial elements */ -public inline fun sortedSet(vararg values: T) : TreeSet = values.toCollection(TreeSet()) +public inline fun sortedSetOf(vararg values: T) : TreeSet = values.toCollection(TreeSet()) + +deprecated("Use sortedSetOf() instead") +public inline fun sortedSet(vararg values: T) : TreeSet = sortedSetOf(*values) /** * Returns a new [[SortedSet]] with the given *comparator* and the initial elements */ -public inline fun sortedSet(comparator: Comparator, vararg values: T) : TreeSet = values.toCollection(TreeSet(comparator)) +public inline fun sortedSetOf(comparator: Comparator, vararg values: T) : TreeSet = values.toCollection(TreeSet(comparator)) + +deprecated("Use sortedSetOf() instead") +public inline fun sortedSet(comparator: Comparator, vararg values: T) : TreeSet = sortedSetOf(comparator, *values) /** * Returns a new [[HashMap]] populated with the given tuple values where the first value in each tuple @@ -24,7 +36,7 @@ public inline fun sortedSet(comparator: Comparator, vararg values: T) : Tr * * @includeFunctionBody ../../test/MapTest.kt createUsingTuples */ -public inline fun hashMap(vararg values: Pair): HashMap { +public inline fun hashMapOf(vararg values: Pair): HashMap { val answer = HashMap(values.size) /** TODO replace by this simpler call when we can pass vararg values into other methods @@ -36,13 +48,16 @@ public inline fun hashMap(vararg values: Pair): HashMap { return answer } +deprecated("Use hashMapOf() instead") +public inline fun hashMap(vararg values: Pair): HashMap = hashMapOf(*values) + /** * Returns a new [[SortedMap]] populated with the given tuple values where the first value in each tuple * is the key and the second value is the value * * @includeFunctionBody ../../test/MapTest.kt createSortedMap */ -public inline fun sortedMap(vararg values: Pair): SortedMap { +public inline fun sortedMapOf(vararg values: Pair): SortedMap { val answer = TreeMap() /** TODO replace by this simpler call when we can pass vararg values into other methods @@ -54,6 +69,9 @@ public inline fun sortedMap(vararg values: Pair): SortedMap { return answer } +deprecated("Use sortedMapOf() instead") +public inline fun sortedMap(vararg values: Pair): SortedMap = sortedMapOf(*values) + /** * Returns a new [[LinkedHashMap]] populated with the given tuple values where the first value in each tuple * is the key and the second value is the value. This map preserves insertion order so iterating through @@ -61,7 +79,7 @@ public inline fun sortedMap(vararg values: Pair): SortedMap { * * @includeFunctionBody ../../test/MapTest.kt createLinkedMap */ -public inline fun linkedMap(vararg values: Pair): LinkedHashMap { +public inline fun linkedMapOf(vararg values: Pair): LinkedHashMap { val answer = LinkedHashMap(values.size) /** TODO replace by this simpler call when we can pass vararg values into other methods @@ -73,13 +91,15 @@ public inline fun linkedMap(vararg values: Pair): LinkedHashMap return answer } +deprecated("Use linkedMapOf() instead") +public inline fun linkedMap(vararg values: Pair): LinkedHashMap = linkedMapOf(*values) /** Returns the Set if its not null otherwise returns the empty set */ public inline fun Set?.orEmpty() : Set = if (this != null) this else Collections.EMPTY_SET as Set +deprecated("Use arrayListOf() instead") +public inline fun arrayList(vararg values: T) : ArrayList = arrayListOf(*values) + /** Returns a new ArrayList with a variable number of initial elements */ -public inline fun arrayList(vararg values: T) : ArrayList = values.toCollection(ArrayList(values.size)) - - - +public inline fun arrayListOf(vararg values: T) : ArrayList = values.toCollection(ArrayList(values.size)) \ No newline at end of file