Skip to content
This repository was archived by the owner on Nov 14, 2018. It is now read-only.

Commit 4d270f0

Browse files
committed
ClipData: add Sequence property (#497)
Simply missing from previous commits.
1 parent f4d82f7 commit 4d270f0

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package androidx.core.content {
2222
method public static void forEach(android.content.ClipData, kotlin.jvm.functions.Function1<? super android.content.ClipData.Item,kotlin.Unit> action);
2323
method public static void forEachIndexed(android.content.ClipData, kotlin.jvm.functions.Function2<? super java.lang.Integer,? super android.content.ClipData.Item,kotlin.Unit> action);
2424
method public static operator android.content.ClipData.Item get(android.content.ClipData, int index);
25+
method public static kotlin.sequences.Sequence<android.content.ClipData.Item> getItems(android.content.ClipData);
2526
method public static operator java.util.Iterator<android.content.ClipData.Item> iterator(android.content.ClipData);
2627
}
2728

src/androidTest/java/androidx/core/content/ClipDataTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ class ClipDataTest {
108108
}
109109
}
110110

111+
@Test fun items() {
112+
val itemsList = listOf(ClipData.Item(""), ClipData.Item(""))
113+
itemsList.forEach { clip.addItem(it) }
114+
115+
clip.items.forEachIndexed { index, item ->
116+
if (index != 0) {
117+
assertSame(itemsList[index - 1], item)
118+
}
119+
}
120+
}
121+
111122
@Test fun map() {
112123
clip.addItem(ClipData.Item("item1"))
113124
clip.addItem(ClipData.Item("item2"))

src/main/java/androidx/core/content/ClipData.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ operator fun ClipData.iterator() = object : Iterator<ClipData.Item> {
6565
override fun next() = getItemAt(index++) ?: throw IndexOutOfBoundsException()
6666
}
6767

68+
/** Returns a [Sequence] over the items in this ClipData. */
69+
val ClipData.items: Sequence<ClipData.Item>
70+
get() = object : Sequence<ClipData.Item> {
71+
override fun iterator() = this@items.iterator()
72+
}
73+
6874
/**
6975
* Returns a [List] containing the results of applying the given transform function to each
7076
* item in this ClipData.

0 commit comments

Comments
 (0)