added annotations for Collections and Arrays

This commit is contained in:
Svetlana Isakova
2012-09-24 14:18:04 +04:00
parent 32d707ca9b
commit 85f3dbf4fc
10 changed files with 409 additions and 13 deletions
@@ -106,14 +106,14 @@ public fun <T> Iterable<T>.withIndices(): List<Pair<Int, T>> {
return answer
}
public inline fun <in T: Comparable<T>> Iterable<T>.sort() : List<T> {
val list = toList()
public inline fun <in T: Comparable<T>> MutableIterable<T>.sort() : List<T> {
val list = toCollection(ArrayList<T>())
java.util.Collections.sort(list)
return list
}
public inline fun <in T> Iterable<T>.sort(comparator: java.util.Comparator<T>) : List<T> {
val list = toList()
val list = toCollection(ArrayList<T>())
java.util.Collections.sort(list, comparator)
return list
}
@@ -2,6 +2,7 @@ package kotlin
import java.util.AbstractList
import java.util.Comparator
import java.util.ArrayList
// TODO this function is here as it breaks the JS compiler; lets move back to JLangIterablesSpecial when it works again :)
@@ -13,7 +14,7 @@ import java.util.Comparator
* @includeFunctionBody ../../test/CollectionTest.kt sortBy
*/
public inline fun <in T, R: Comparable<in R>> Iterable<T>.sortBy(f: (T) -> R): List<T> {
val sortedList = this.toList()
val sortedList = toCollection(ArrayList<T>())
val sortBy: Comparator<T> = comparator<T> {(x: T, y: T) ->
val xr = f(x)
val yr = f(y)
+1 -1
View File
@@ -36,7 +36,7 @@ public inline fun <T> Collection<T>?.orEmpty() : Collection<T>
/** TODO these functions don't work when they generate the Array<T> versions when they are in JLIterables */
public inline fun <in T: Comparable<T>> Iterable<T>.toSortedList() : List<T> = toList().sort()
public inline fun <in T: Comparable<T>> Iterable<T>.toSortedList() : List<T> = toCollection(ArrayList<T>()).sort()
public inline fun <in T: Comparable<T>> Iterable<T>.toSortedList(comparator: java.util.Comparator<T>) : List<T> = toList().sort(comparator)