From 87e613a8c28e8f3766628829fcdf2471a9356bb1 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Mon, 16 Apr 2012 19:59:12 +0100 Subject: [PATCH] refactored the to(Collection) methods to be called toCollection(Collection) to avoid clashing with a potentially new method called to(T) for making a pair/tuple/Map.Entry --- .../src/generated/ArraysFromJLangIterables.kt | 12 ++++++------ .../src/generated/ArraysFromJLangIterablesLazy.kt | 4 ++-- .../src/generated/ArraysFromJUtilCollections.kt | 7 +++++-- .../JUtilIterablesFromJUtilCollections.kt | 7 +++++-- .../generated/JUtilIteratorsFromJLangIterables.kt | 12 ++++++------ .../src/generated/StandardFromJLangIterables.kt | 12 ++++++------ .../generated/StandardFromJLangIterablesLazy.kt | 4 ++-- .../src/generated/StandardFromJUtilCollections.kt | 7 +++++-- libraries/stdlib/src/kotlin/JLangIterables.kt | 12 ++++++------ libraries/stdlib/src/kotlin/JLangIterablesLazy.kt | 4 ++-- libraries/stdlib/src/kotlin/JUtil.kt | 10 +++++----- libraries/stdlib/src/kotlin/Standard.kt | 14 +++++++------- libraries/stdlib/src/kotlin/nullable/Nullables.kt | 10 +++++----- 13 files changed, 62 insertions(+), 53 deletions(-) diff --git a/libraries/stdlib/src/generated/ArraysFromJLangIterables.kt b/libraries/stdlib/src/generated/ArraysFromJLangIterables.kt index c8d1fed1ab7..2d370e35619 100644 --- a/libraries/stdlib/src/generated/ArraysFromJLangIterables.kt +++ b/libraries/stdlib/src/generated/ArraysFromJLangIterables.kt @@ -193,25 +193,25 @@ public inline fun Array.reverse() : List { } /** Copies all elements into the given collection */ -public inline fun > Array.to(result: C) : C { +public inline fun > Array.toCollection(result: C) : C { for (element in this) result.add(element) return result } /** Copies all elements into a [[LinkedList]] */ -public inline fun Array.toLinkedList() : LinkedList = to(LinkedList()) +public inline fun Array.toLinkedList() : LinkedList = toCollection(LinkedList()) /** Copies all elements into a [[List]] */ -public inline fun Array.toList() : List = to(ArrayList()) +public inline fun Array.toList() : List = toCollection(ArrayList()) /** Copies all elements into a [[List] */ -public inline fun Array.toCollection() : Collection = to(ArrayList()) +public inline fun Array.toCollection() : Collection = toCollection(ArrayList()) /** Copies all elements into a [[Set]] */ -public inline fun Array.toSet() : Set = to(HashSet()) +public inline fun Array.toSet() : Set = toCollection(HashSet()) /** Copies all elements into a [[SortedSet]] */ -public inline fun Array.toSortedSet() : SortedSet = to(TreeSet()) +public inline fun Array.toSortedSet() : SortedSet = toCollection(TreeSet()) /** TODO figure out necessary variance/generics ninja stuff... :) diff --git a/libraries/stdlib/src/generated/ArraysFromJLangIterablesLazy.kt b/libraries/stdlib/src/generated/ArraysFromJLangIterablesLazy.kt index 6bd375e692c..82a8c13afb7 100644 --- a/libraries/stdlib/src/generated/ArraysFromJLangIterablesLazy.kt +++ b/libraries/stdlib/src/generated/ArraysFromJLangIterablesLazy.kt @@ -48,7 +48,7 @@ public inline fun Array.flatMap(transform: (T)-> Collection) : Coll * @includeFunctionBody ../../test/CollectionTest.kt plus */ public inline fun Array.plus(element: T): List { - val list = to(ArrayList()) + val list = toCollection(ArrayList()) list.add(element) return list } @@ -60,7 +60,7 @@ public inline fun Array.plus(element: T): List { * @includeFunctionBody ../../test/CollectionTest.kt plusCollection */ public inline fun Array.plus(elements: Array): List { - val list = to(ArrayList()) + val list = toCollection(ArrayList()) list.addAll(elements.toCollection()) return list } diff --git a/libraries/stdlib/src/generated/ArraysFromJUtilCollections.kt b/libraries/stdlib/src/generated/ArraysFromJUtilCollections.kt index 2ec6befa344..e14666b5178 100644 --- a/libraries/stdlib/src/generated/ArraysFromJUtilCollections.kt +++ b/libraries/stdlib/src/generated/ArraysFromJUtilCollections.kt @@ -11,7 +11,7 @@ import java.util.* // /** - * Returns a new List containing the results of applying the given function to each element in this collection + * Returns a new List containing the results of applying the given *transform* function to each element in this collection * * @includeFunctionBody ../../test/CollectionTest.kt map */ @@ -19,7 +19,10 @@ public inline fun Array.map(transform : (T) -> R) : java.util.List return mapTo(java.util.ArrayList(this.size), transform) } -/** Transforms each element of this collection with the given function then adds the results to the given collection */ +/** + * Transforms each element of this collection with the given *transform* function and + * adds each return value to the given *results* collection + */ public inline fun > Array.mapTo(result: C, transform : (T) -> R) : C { for (item in this) result.add(transform(item)) diff --git a/libraries/stdlib/src/generated/JUtilIterablesFromJUtilCollections.kt b/libraries/stdlib/src/generated/JUtilIterablesFromJUtilCollections.kt index 6cdb191c32e..6c8c4c84e70 100644 --- a/libraries/stdlib/src/generated/JUtilIterablesFromJUtilCollections.kt +++ b/libraries/stdlib/src/generated/JUtilIterablesFromJUtilCollections.kt @@ -11,7 +11,7 @@ import java.util.* // /** - * Returns a new List containing the results of applying the given function to each element in this collection + * Returns a new List containing the results of applying the given *transform* function to each element in this collection * * @includeFunctionBody ../../test/CollectionTest.kt map */ @@ -19,7 +19,10 @@ public inline fun java.lang.Iterable.map(transform : (T) -> R) : java. return mapTo(java.util.ArrayList(), transform) } -/** Transforms each element of this collection with the given function then adds the results to the given collection */ +/** + * Transforms each element of this collection with the given *transform* function and + * adds each return value to the given *results* collection + */ public inline fun > java.lang.Iterable.mapTo(result: C, transform : (T) -> R) : C { for (item in this) result.add(transform(item)) diff --git a/libraries/stdlib/src/generated/JUtilIteratorsFromJLangIterables.kt b/libraries/stdlib/src/generated/JUtilIteratorsFromJLangIterables.kt index a5f246eb0cf..3e3b1c39591 100644 --- a/libraries/stdlib/src/generated/JUtilIteratorsFromJLangIterables.kt +++ b/libraries/stdlib/src/generated/JUtilIteratorsFromJLangIterables.kt @@ -191,25 +191,25 @@ public inline fun java.util.Iterator.reverse() : List { } /** Copies all elements into the given collection */ -public inline fun > java.util.Iterator.to(result: C) : C { +public inline fun > java.util.Iterator.toCollection(result: C) : C { for (element in this) result.add(element) return result } /** Copies all elements into a [[LinkedList]] */ -public inline fun java.util.Iterator.toLinkedList() : LinkedList = to(LinkedList()) +public inline fun java.util.Iterator.toLinkedList() : LinkedList = toCollection(LinkedList()) /** Copies all elements into a [[List]] */ -public inline fun java.util.Iterator.toList() : List = to(ArrayList()) +public inline fun java.util.Iterator.toList() : List = toCollection(ArrayList()) /** Copies all elements into a [[List] */ -public inline fun java.util.Iterator.toCollection() : Collection = to(ArrayList()) +public inline fun java.util.Iterator.toCollection() : Collection = toCollection(ArrayList()) /** Copies all elements into a [[Set]] */ -public inline fun java.util.Iterator.toSet() : Set = to(HashSet()) +public inline fun java.util.Iterator.toSet() : Set = toCollection(HashSet()) /** Copies all elements into a [[SortedSet]] */ -public inline fun java.util.Iterator.toSortedSet() : SortedSet = to(TreeSet()) +public inline fun java.util.Iterator.toSortedSet() : SortedSet = toCollection(TreeSet()) /** TODO figure out necessary variance/generics ninja stuff... :) diff --git a/libraries/stdlib/src/generated/StandardFromJLangIterables.kt b/libraries/stdlib/src/generated/StandardFromJLangIterables.kt index 037ebe1ba58..e9684b9457e 100644 --- a/libraries/stdlib/src/generated/StandardFromJLangIterables.kt +++ b/libraries/stdlib/src/generated/StandardFromJLangIterables.kt @@ -193,25 +193,25 @@ public inline fun Iterable.reverse() : List { } /** Copies all elements into the given collection */ -public inline fun > Iterable.to(result: C) : C { +public inline fun > Iterable.toCollection(result: C) : C { for (element in this) result.add(element) return result } /** Copies all elements into a [[LinkedList]] */ -public inline fun Iterable.toLinkedList() : LinkedList = to(LinkedList()) +public inline fun Iterable.toLinkedList() : LinkedList = toCollection(LinkedList()) /** Copies all elements into a [[List]] */ -public inline fun Iterable.toList() : List = to(ArrayList()) +public inline fun Iterable.toList() : List = toCollection(ArrayList()) /** Copies all elements into a [[List] */ -public inline fun Iterable.toCollection() : Collection = to(ArrayList()) +public inline fun Iterable.toCollection() : Collection = toCollection(ArrayList()) /** Copies all elements into a [[Set]] */ -public inline fun Iterable.toSet() : Set = to(HashSet()) +public inline fun Iterable.toSet() : Set = toCollection(HashSet()) /** Copies all elements into a [[SortedSet]] */ -public inline fun Iterable.toSortedSet() : SortedSet = to(TreeSet()) +public inline fun Iterable.toSortedSet() : SortedSet = toCollection(TreeSet()) /** TODO figure out necessary variance/generics ninja stuff... :) diff --git a/libraries/stdlib/src/generated/StandardFromJLangIterablesLazy.kt b/libraries/stdlib/src/generated/StandardFromJLangIterablesLazy.kt index da63be3f6c9..65c3248dc2b 100644 --- a/libraries/stdlib/src/generated/StandardFromJLangIterablesLazy.kt +++ b/libraries/stdlib/src/generated/StandardFromJLangIterablesLazy.kt @@ -48,7 +48,7 @@ public inline fun Iterable.flatMap(transform: (T)-> Collection) : C * @includeFunctionBody ../../test/CollectionTest.kt plus */ public inline fun Iterable.plus(element: T): List { - val list = to(ArrayList()) + val list = toCollection(ArrayList()) list.add(element) return list } @@ -60,7 +60,7 @@ public inline fun Iterable.plus(element: T): List { * @includeFunctionBody ../../test/CollectionTest.kt plusCollection */ public inline fun Iterable.plus(elements: Iterable): List { - val list = to(ArrayList()) + val list = toCollection(ArrayList()) list.addAll(elements.toCollection()) return list } diff --git a/libraries/stdlib/src/generated/StandardFromJUtilCollections.kt b/libraries/stdlib/src/generated/StandardFromJUtilCollections.kt index 9820e5dfd94..4dbe8042091 100644 --- a/libraries/stdlib/src/generated/StandardFromJUtilCollections.kt +++ b/libraries/stdlib/src/generated/StandardFromJUtilCollections.kt @@ -11,7 +11,7 @@ import java.util.* // /** - * Returns a new List containing the results of applying the given function to each element in this collection + * Returns a new List containing the results of applying the given *transform* function to each element in this collection * * @includeFunctionBody ../../test/CollectionTest.kt map */ @@ -19,7 +19,10 @@ public inline fun Iterable.map(transform : (T) -> R) : java.util.List< return mapTo(java.util.ArrayList(), transform) } -/** Transforms each element of this collection with the given function then adds the results to the given collection */ +/** + * Transforms each element of this collection with the given *transform* function and + * adds each return value to the given *results* collection + */ public inline fun > Iterable.mapTo(result: C, transform : (T) -> R) : C { for (item in this) result.add(transform(item)) diff --git a/libraries/stdlib/src/kotlin/JLangIterables.kt b/libraries/stdlib/src/kotlin/JLangIterables.kt index 63a3400fbda..cee9694517d 100644 --- a/libraries/stdlib/src/kotlin/JLangIterables.kt +++ b/libraries/stdlib/src/kotlin/JLangIterables.kt @@ -190,25 +190,25 @@ public inline fun java.lang.Iterable.reverse() : List { } /** Copies all elements into the given collection */ -public inline fun > java.lang.Iterable.to(result: C) : C { +public inline fun > java.lang.Iterable.toCollection(result: C) : C { for (element in this) result.add(element) return result } /** Copies all elements into a [[LinkedList]] */ -public inline fun java.lang.Iterable.toLinkedList() : LinkedList = to(LinkedList()) +public inline fun java.lang.Iterable.toLinkedList() : LinkedList = toCollection(LinkedList()) /** Copies all elements into a [[List]] */ -public inline fun java.lang.Iterable.toList() : List = to(ArrayList()) +public inline fun java.lang.Iterable.toList() : List = toCollection(ArrayList()) /** Copies all elements into a [[List] */ -public inline fun java.lang.Iterable.toCollection() : Collection = to(ArrayList()) +public inline fun java.lang.Iterable.toCollection() : Collection = toCollection(ArrayList()) /** Copies all elements into a [[Set]] */ -public inline fun java.lang.Iterable.toSet() : Set = to(HashSet()) +public inline fun java.lang.Iterable.toSet() : Set = toCollection(HashSet()) /** Copies all elements into a [[SortedSet]] */ -public inline fun java.lang.Iterable.toSortedSet() : SortedSet = to(TreeSet()) +public inline fun java.lang.Iterable.toSortedSet() : SortedSet = toCollection(TreeSet()) /** TODO figure out necessary variance/generics ninja stuff... :) diff --git a/libraries/stdlib/src/kotlin/JLangIterablesLazy.kt b/libraries/stdlib/src/kotlin/JLangIterablesLazy.kt index 60acefb602e..314748efd14 100644 --- a/libraries/stdlib/src/kotlin/JLangIterablesLazy.kt +++ b/libraries/stdlib/src/kotlin/JLangIterablesLazy.kt @@ -45,7 +45,7 @@ public inline fun java.lang.Iterable.flatMap(transform: (T)-> Collecti * @includeFunctionBody ../../test/CollectionTest.kt plus */ public inline fun java.lang.Iterable.plus(element: T): List { - val list = to(ArrayList()) + val list = toCollection(ArrayList()) list.add(element) return list } @@ -57,7 +57,7 @@ public inline fun java.lang.Iterable.plus(element: T): List { * @includeFunctionBody ../../test/CollectionTest.kt plusCollection */ public inline fun java.lang.Iterable.plus(elements: java.lang.Iterable): List { - val list = to(ArrayList()) + val list = toCollection(ArrayList()) list.addAll(elements.toCollection()) return list } diff --git a/libraries/stdlib/src/kotlin/JUtil.kt b/libraries/stdlib/src/kotlin/JUtil.kt index 1fa691766c2..10bac18540c 100644 --- a/libraries/stdlib/src/kotlin/JUtil.kt +++ b/libraries/stdlib/src/kotlin/JUtil.kt @@ -12,23 +12,23 @@ val Collection<*>.empty : Boolean get() = isEmpty() /** Returns a new ArrayList with a variable number of initial elements */ -public inline fun arrayList(vararg values: T) : ArrayList = values.to(ArrayList(values.size)) +public inline fun arrayList(vararg values: T) : ArrayList = values.toCollection(ArrayList(values.size)) /** Returns a new LinkedList with a variable number of initial elements */ -public inline fun linkedList(vararg values: T) : LinkedList = values.to(LinkedList()) +public inline fun linkedList(vararg values: T) : LinkedList = values.toCollection(LinkedList()) /** Returns a new HashSet with a variable number of initial elements */ -public inline fun hashSet(vararg values: T) : HashSet = values.to(HashSet(values.size)) +public inline fun hashSet(vararg values: T) : HashSet = values.toCollection(HashSet(values.size)) /** * Returns a new [[SortedSet]] with the initial elements */ -public inline fun sortedSet(vararg values: T) : TreeSet = values.to(TreeSet()) +public inline fun sortedSet(vararg values: T) : TreeSet = values.toCollection(TreeSet()) /** * Returns a new [[SortedSet]] with the given *comparator* and the initial elements */ -public inline fun sortedSet(comparator: Comparator, vararg values: T) : TreeSet = values.to(TreeSet(comparator)) +public inline fun sortedSet(comparator: Comparator, vararg values: T) : TreeSet = values.toCollection(TreeSet(comparator)) /** * Returns a new [[HashMap]] populated with the given tuple values where the first value in each tuple diff --git a/libraries/stdlib/src/kotlin/Standard.kt b/libraries/stdlib/src/kotlin/Standard.kt index ec63b159b77..eaa5ff71019 100644 --- a/libraries/stdlib/src/kotlin/Standard.kt +++ b/libraries/stdlib/src/kotlin/Standard.kt @@ -36,7 +36,7 @@ public fun java.util.Enumeration.iterator(): Iterator = object: /** Add iterated elements to given container */ -public fun > Iterator.to(container: U) : U { +public fun > Iterator.toCollection(container: U) : U { while(hasNext) container.add(next()) return container @@ -45,33 +45,33 @@ public fun > Iterator.to(container: U) : U { /** Add iterated elements to java.util.ArrayList */ -public inline fun Iterator.toArrayList() : ArrayList = to(ArrayList()) +public inline fun Iterator.toArrayList() : ArrayList = toCollection(ArrayList()) /** Add iterated elements to java.util.LinkedList */ -public inline fun Iterator.toLinkedList() : LinkedList = to(LinkedList()) +public inline fun Iterator.toLinkedList() : LinkedList = toCollection(LinkedList()) /** Add iterated elements to java.util.HashSet */ -public inline fun Iterator.toHashSet() : HashSet = to(HashSet()) +public inline fun Iterator.toHashSet() : HashSet = toCollection(HashSet()) /** * Add iterated elements to a [[LinkedHashSet]] to preserve insertion order */ -public inline fun Iterator.toLinkedSet() : LinkedHashSet = to(LinkedHashSet()) +public inline fun Iterator.toLinkedSet() : LinkedHashSet = toCollection(LinkedHashSet()) /** * Add iterated elements to [[SortedSet]] to ensure iteration is in the order of the default comparator * for the type */ -public inline fun Iterator.toSortedSet() : SortedSet = to(TreeSet()) +public inline fun Iterator.toSortedSet() : SortedSet = toCollection(TreeSet()) /** * Add iterated elements to [[SortedSet]] with the given *comparator* to ensure iteration is in the order of the given comparator */ -public inline fun Iterator.toSortedSet(comparator: Comparator) : SortedSet = to(TreeSet(comparator)) +public inline fun Iterator.toSortedSet(comparator: Comparator) : SortedSet = toCollection(TreeSet(comparator)) /** Run function f diff --git a/libraries/stdlib/src/kotlin/nullable/Nullables.kt b/libraries/stdlib/src/kotlin/nullable/Nullables.kt index a41e65dab05..7066dcbf329 100644 --- a/libraries/stdlib/src/kotlin/nullable/Nullables.kt +++ b/libraries/stdlib/src/kotlin/nullable/Nullables.kt @@ -156,23 +156,23 @@ public inline fun T?.reverse(): T? { } /** Copies the collection into the given collection */ -public inline fun > T?.to(result: C): C { +public inline fun > T?.toCollection(result: C): C { if (this != null) result.add(this) return result } /** Converts the collection into a LinkedList */ -public inline fun T?.toLinkedList(): LinkedList = this.to(LinkedList()) +public inline fun T?.toLinkedList(): LinkedList = this.toCollection(LinkedList()) /** Converts the collection into a List */ -public inline fun T?.toList(): List = this.to(ArrayList()) +public inline fun T?.toList(): List = this.toCollection(ArrayList()) /** Converts the collection into a Set */ -public inline fun T?.toSet(): Set = this.to(HashSet()) +public inline fun T?.toSet(): Set = this.toCollection(HashSet()) /** Converts the collection into a SortedSet */ -public inline fun T?.toSortedSet(): SortedSet = this.to(TreeSet()) +public inline fun T?.toSortedSet(): SortedSet = this.toCollection(TreeSet()) /** TODO figure out necessary variance/generics ninja stuff... :) public inline fun T?.toSortedList(transform: fun(T) : java.lang.Comparable<*>) : List {