use kotlin Iterable/Iterator

instead of java Iterable/Iterator
in Kotlin code in library
This commit is contained in:
Svetlana Isakova
2012-08-14 15:24:13 +04:00
parent df93a26839
commit ca6d7e643e
19 changed files with 88 additions and 104 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ trait Traversable<T> {
fun forEach(operation: (element: T)-> Unit)
/** Returns a new collection containing the results of applying the given function to each element in this collection */
fun <T, R> java.lang.Iterable<T>.map(transform : (T)-> R) : Collection<R>
fun <T, R> Iterable<T>.map(transform : (T)-> R) : Collection<R>
}
/**
+1 -1
View File
@@ -116,7 +116,7 @@ class CollectionJVMTest {
test fun sortFunctionShouldReturnSortedCopyForIterable() {
// TODO fixme Some sort of in/out variance thing - or an issue with Java interop?
todo {
// val list : java.lang.Iterable<Int> = arrayList(2, 3, 1)
// val list : Iterable<Int> = arrayList(2, 3, 1)
// expect(arrayList(1, 2, 3)) { list.sort() }
// expect(arrayList(2, 3, 1)) { list }
}
+4 -3
View File
@@ -3,6 +3,7 @@ package test.collections
import kotlin.test.*
import java.util.*
import jet.Iterator
import org.junit.Test as test
@@ -272,7 +273,7 @@ class CollectionTest {
}
test fun reverseFunctionShouldReturnReversedCopyForIterable() {
val iterable : java.lang.Iterable<Int> = arrayList(2, 3, 1)
val iterable : Iterable<Int> = arrayList(2, 3, 1)
expect(arrayList(1, 3, 2)) { iterable.reverse() }
expect(arrayList(2, 3, 1)) { iterable }
}
@@ -387,10 +388,10 @@ class CollectionTest {
// assertFalse(IterableWrapper(linkedList<Int>()).contains(15))
}
class IterableWrapper<T>(collection : java.lang.Iterable<T>) : java.lang.Iterable<T> {
class IterableWrapper<T>(collection : Iterable<T>) : Iterable<T> {
private val collection = collection
override fun iterator(): java.util.Iterator<T> {
override fun iterator(): Iterator<T> {
return collection.iterator().sure()
}
}
@@ -4,7 +4,7 @@ import kotlin.test.assertEquals
import org.junit.Test as test
import kotlin.test.failsWith
fun fibonacci(): java.util.Iterator<Int> {
fun fibonacci(): Iterator<Int> {
// fibonacci terms
var index = 0; var a = 0; var b = 1
return iterate<Int> { when (index++) { 0 -> a; 1 -> b; else -> { val result = a + b; a = b; b = result; result } } }
@@ -3,7 +3,7 @@ package regressions
import kotlin.test.assertEquals
import org.junit.Test as test
fun f(xs: java.util.Iterator<Int>): Int {
fun f(xs: Iterator<Int>): Int {
var answer = 0
for (x in xs) {
answer += x