added extension methods MutableCollection#addAll(Iterable) and MutableCollection#addAll(Iterator) (#KT-4202 fixed)
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
package kotlin
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds all elements of the given *iterator* to this [[MutableCollection]]
|
||||||
|
*/
|
||||||
|
public fun <T> MutableCollection<T>.addAll(iterator: Iterator<T>): Unit {
|
||||||
|
for (e in iterator) add(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds all elements of the given *iterable* to this [[MutableCollection]]
|
||||||
|
*/
|
||||||
|
public fun <T> MutableCollection<T>.addAll(iterable: Iterable<T>): Unit {
|
||||||
|
for (e in iterable) add(e)
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package test.collections
|
||||||
|
|
||||||
|
import kotlin.test.*
|
||||||
|
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
import org.junit.Test as test
|
||||||
|
|
||||||
|
class MutableCollectionTest {
|
||||||
|
|
||||||
|
test fun fromIterable() {
|
||||||
|
val data: Iterable<String> = arrayListOf("foo", "bar")
|
||||||
|
|
||||||
|
val collection = ArrayList<String>()
|
||||||
|
collection.addAll(data)
|
||||||
|
|
||||||
|
assertEquals(data, collection)
|
||||||
|
}
|
||||||
|
|
||||||
|
test fun fromIterator() {
|
||||||
|
val list = arrayListOf("foo", "bar")
|
||||||
|
val collection = ArrayList<String>()
|
||||||
|
|
||||||
|
collection.addAll(list.iterator())
|
||||||
|
|
||||||
|
assertEquals(list, collection)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user