Merge "Remove AdvertiseResult" into androidx-main
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/DocumentIdUtilCtsTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/DocumentIdUtilCtsTest.java
index 89d2180..f3cb395 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/DocumentIdUtilCtsTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/DocumentIdUtilCtsTest.java
@@ -23,6 +23,7 @@
import org.junit.Test;
+/*@exportToFramework:SdkSuppress(minSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)*/
public class DocumentIdUtilCtsTest {
@Test
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/JoinSpecCtsTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/JoinSpecCtsTest.java
index a58b892..c04d448 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/JoinSpecCtsTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/JoinSpecCtsTest.java
@@ -23,6 +23,7 @@
import org.junit.Test;
+/*@exportToFramework:SdkSuppress(minSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)*/
public class JoinSpecCtsTest {
@Test
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/PropertyPathCtsTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/PropertyPathCtsTest.java
index b7ed1f8..69a94d3 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/PropertyPathCtsTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/PropertyPathCtsTest.java
@@ -17,7 +17,6 @@
package androidx.appsearch.cts.app;
import static androidx.appsearch.app.PropertyPath.PathSegment.NON_REPEATED_CARDINALITY;
-
import static com.google.common.truth.Truth.assertThat;
import androidx.appsearch.app.PropertyPath;
@@ -30,6 +29,7 @@
import java.util.Iterator;
import java.util.List;
+/*@exportToFramework:SdkSuppress(minSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)*/
public class PropertyPathCtsTest {
@Test
public void testPropertyPathInvalid() {
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/SearchResultCtsTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/SearchResultCtsTest.java
index 426d01a..24d0153 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/SearchResultCtsTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/SearchResultCtsTest.java
@@ -17,7 +17,6 @@
package androidx.appsearch.cts.app;
import static com.google.common.truth.Truth.assertThat;
-
import static org.junit.Assert.assertThrows;
import androidx.appsearch.app.PropertyPath;
@@ -107,6 +106,7 @@
}
@Test
+ /*@exportToFramework:SdkSuppress(minSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)*/
public void testJoinedDocument() {
AppSearchEmail email = new AppSearchEmail.Builder("namespace1", "id1")
.setBody("Hello World.")
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/SearchSuggestionResultCtsTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/SearchSuggestionResultCtsTest.java
index 66fb2ad..675b507 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/SearchSuggestionResultCtsTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/SearchSuggestionResultCtsTest.java
@@ -22,6 +22,7 @@
import org.junit.Test;
+/*@exportToFramework:SdkSuppress(minSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)*/
public class SearchSuggestionResultCtsTest {
@Test
public void testBuildDefaultSearchSuggestionResult() {
diff --git a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/SearchSuggestionSpecCtsTest.java b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/SearchSuggestionSpecCtsTest.java
index 69979c3..d3dd5c3 100644
--- a/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/SearchSuggestionSpecCtsTest.java
+++ b/appsearch/appsearch/src/androidTest/java/androidx/appsearch/cts/app/SearchSuggestionSpecCtsTest.java
@@ -17,7 +17,6 @@
package androidx.appsearch.cts.app;
import static com.google.common.truth.Truth.assertThat;
-
import static org.junit.Assert.assertThrows;
import androidx.appsearch.app.SearchSuggestionSpec;
@@ -26,6 +25,7 @@
import org.junit.Test;
+/*@exportToFramework:SdkSuppress(minSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)*/
public class SearchSuggestionSpecCtsTest {
@Test
public void testBuildDefaultSearchSuggestionSpec() throws Exception {
diff --git a/appsearch/exportToFramework.py b/appsearch/exportToFramework.py
index 615eda8..2625438 100755
--- a/appsearch/exportToFramework.py
+++ b/appsearch/exportToFramework.py
@@ -189,6 +189,12 @@
return contents
def _TransformTestCode(self, contents):
+ # Add imports used in tests
+ imports_to_add = []
+ if '@exportToFramework:SdkSuppress' in contents:
+ imports_to_add.append('androidx.test.filters.SdkSuppress')
+ imports_to_add.append('android.os.Build')
+
contents = (contents
.replace('androidx.appsearch.testutil.', 'android.app.appsearch.testutil.')
.replace(
@@ -199,8 +205,18 @@
'android.app.appsearch.AppSearchManager')
.replace('LocalStorage.', 'AppSearchManager.')
)
+ contents = re.sub(
+ r'/\*@exportToFramework:SdkSuppress\(minSdkVersion = (.*?)\)\*/',
+ r'@SdkSuppress(minSdkVersion = \1)',
+ contents)
for shim in ['AppSearchSession', 'GlobalSearchSession', 'SearchResults']:
contents = re.sub(r"([^a-zA-Z])(%s)([^a-zA-Z0-9])" % shim, r'\1\2Shim\3', contents)
+
+ for import_to_add in imports_to_add:
+ contents = re.sub(
+ r'^(\s*package [^;]+;\s*)$', r'\1\nimport %s;\n' % import_to_add, contents,
+ flags=re.MULTILINE)
+
return self._TransformCommonCode(contents)
def _TransformAndCopyFolder(self, source_dir, dest_dir, transform_func=None):
diff --git a/benchmark/benchmark-macro/src/main/java/androidx/benchmark/macro/BaselineProfiles.kt b/benchmark/benchmark-macro/src/main/java/androidx/benchmark/macro/BaselineProfiles.kt
index 1514db6..54c3276 100644
--- a/benchmark/benchmark-macro/src/main/java/androidx/benchmark/macro/BaselineProfiles.kt
+++ b/benchmark/benchmark-macro/src/main/java/androidx/benchmark/macro/BaselineProfiles.kt
@@ -48,6 +48,8 @@
) {
val scope = buildMacrobenchmarkScope(packageName)
val startTime = System.nanoTime()
+ // Ensure the device is awake
+ scope.device.wakeUp()
val killProcessBlock = scope.killProcessBlock()
// always kill the process at beginning of a collection.
killProcessBlock.invoke()
diff --git a/bluetooth/bluetooth/build.gradle b/bluetooth/bluetooth/build.gradle
index 8e7f695..9d626f8 100644
--- a/bluetooth/bluetooth/build.gradle
+++ b/bluetooth/bluetooth/build.gradle
@@ -26,8 +26,6 @@
implementation(libs.kotlinStdlib)
implementation(libs.kotlinCoroutinesCore)
- implementation(project(":annotation:annotation-experimental"))
-
implementation("androidx.annotation:annotation:1.6.0")
androidTestImplementation(libs.testExtJunit)
diff --git a/car/app/app-samples/showcase/common/src/main/java/androidx/car/app/sample/showcase/common/screens/navigationdemos/navigationtemplates/RoutingDemoModels.java b/car/app/app-samples/showcase/common/src/main/java/androidx/car/app/sample/showcase/common/screens/navigationdemos/navigationtemplates/RoutingDemoModels.java
index b51619b..bdc3771 100644
--- a/car/app/app-samples/showcase/common/src/main/java/androidx/car/app/sample/showcase/common/screens/navigationdemos/navigationtemplates/RoutingDemoModels.java
+++ b/car/app/app-samples/showcase/common/src/main/java/androidx/car/app/sample/showcase/common/screens/navigationdemos/navigationtemplates/RoutingDemoModels.java
@@ -24,6 +24,7 @@
import android.text.SpannableString;
import android.text.Spanned;
+import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.car.app.AppManager;
import androidx.car.app.CarContext;
@@ -189,10 +190,14 @@
@NonNull CarContext carContext, @NonNull OnClickListener onStopNavigation) {
ActionStrip.Builder builder = new ActionStrip.Builder();
if (carContext.getCarAppApiLevel() >= CarAppApiLevels.LEVEL_5) {
+ @ColorInt int actionButtonRed = 0xffb40404;
builder.addAction(
new Action.Builder()
+ .setFlags(FLAG_PRIMARY)
+ .setBackgroundColor(
+ CarColor.createCustom(actionButtonRed, actionButtonRed))
.setOnClickListener(
- () -> carContext.getCarService(AppManager.class)
+ () -> carContext.getCarService(AppManager.class)
.showAlert(createAlert(carContext)))
.setIcon(new CarIcon.Builder(
IconCompat.createWithResource(
diff --git a/collection/collection-benchmark/src/androidUnitTest/java/androidx/collection/ObjectListBenchmarkTest.kt b/collection/collection-benchmark/src/androidUnitTest/java/androidx/collection/ObjectListBenchmarkTest.kt
new file mode 100644
index 0000000..a6ba28f
--- /dev/null
+++ b/collection/collection-benchmark/src/androidUnitTest/java/androidx/collection/ObjectListBenchmarkTest.kt
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package androidx.collection
+
+import androidx.benchmark.junit4.BenchmarkRule
+import androidx.benchmark.junit4.measureRepeated
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+@RunWith(JUnit4::class)
+class ObjectListBenchmarkTest {
+ val ObjectCount = 100
+ private val list: ObjectList<String> = MutableObjectList<String>(ObjectCount).also { list ->
+ repeat(ObjectCount) {
+ list += it.toString()
+ }
+ }
+
+ private val array = Array(ObjectCount) { it.toString() }
+
+ @get:Rule
+ val benchmark = BenchmarkRule()
+
+ @Test
+ fun forEach() {
+ benchmark.measureRepeated {
+ @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
+ var last: String
+ list.forEach { element ->
+ last = element
+ }
+ }
+ }
+
+ @Test
+ fun add() {
+ val mutableList = MutableObjectList<String>(ObjectCount)
+ benchmark.measureRepeated {
+ repeat(ObjectCount) {
+ mutableList += array[it]
+ }
+ mutableList.clear()
+ }
+ }
+
+ @Test
+ fun contains() {
+ benchmark.measureRepeated {
+ repeat(ObjectCount) {
+ list.contains(array[it])
+ }
+ }
+ }
+
+ @Test
+ fun get() {
+ benchmark.measureRepeated {
+ repeat(ObjectCount) {
+ list[it]
+ }
+ }
+ }
+
+ @Test
+ fun addAll() {
+ val mutableList = MutableObjectList<String>(ObjectCount)
+ benchmark.measureRepeated {
+ mutableList += list
+ mutableList.clear()
+ }
+ }
+
+ @Test
+ fun removeStart() {
+ val mutableList = MutableObjectList<String>(ObjectCount)
+ benchmark.measureRepeated {
+ mutableList += list
+ repeat(ObjectCount) {
+ mutableList.removeAt(0)
+ }
+ }
+ }
+
+ @Test
+ fun removeEnd() {
+ val mutableList = MutableObjectList<String>(ObjectCount)
+ benchmark.measureRepeated {
+ mutableList += list
+ for (i in ObjectCount - 1 downTo 0) {
+ mutableList.removeAt(i)
+ }
+ }
+ }
+}
diff --git a/collection/collection/api/current.txt b/collection/collection/api/current.txt
index ec619f8..4c78cef 100644
--- a/collection/collection/api/current.txt
+++ b/collection/collection/api/current.txt
@@ -121,9 +121,27 @@
public final class FloatFloatMapKt {
method public static androidx.collection.FloatFloatMap emptyFloatFloatMap();
method public static androidx.collection.FloatFloatMap floatFloatMapOf();
- method public static androidx.collection.FloatFloatMap floatFloatMapOf(kotlin.Pair<java.lang.Float,java.lang.Float>... pairs);
+ method public static androidx.collection.FloatFloatMap floatFloatMapOf(float key1, float value1);
+ method public static androidx.collection.FloatFloatMap floatFloatMapOf(float key1, float value1, float key2, float value2);
+ method public static androidx.collection.FloatFloatMap floatFloatMapOf(float key1, float value1, float key2, float value2, float key3, float value3);
+ method public static androidx.collection.FloatFloatMap floatFloatMapOf(float key1, float value1, float key2, float value2, float key3, float value3, float key4, float value4);
+ method public static androidx.collection.FloatFloatMap floatFloatMapOf(float key1, float value1, float key2, float value2, float key3, float value3, float key4, float value4, float key5, float value5);
method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf();
- method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf(kotlin.Pair<java.lang.Float,java.lang.Float>... pairs);
+ method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf(float key1, float value1);
+ method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf(float key1, float value1, float key2, float value2);
+ method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf(float key1, float value1, float key2, float value2, float key3, float value3);
+ method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf(float key1, float value1, float key2, float value2, float key3, float value3, float key4, float value4);
+ method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf(float key1, float value1, float key2, float value2, float key3, float value3, float key4, float value4, float key5, float value5);
+ }
+
+ @kotlin.jvm.JvmInline public final value class FloatFloatPair {
+ ctor public FloatFloatPair(float first, float second);
+ method public inline operator float component1();
+ method public inline operator float component2();
+ method public inline float getFirst();
+ method public inline float getSecond();
+ property public final inline float first;
+ property public final inline float second;
}
public abstract sealed class FloatIntMap {
@@ -153,9 +171,17 @@
public final class FloatIntMapKt {
method public static androidx.collection.FloatIntMap emptyFloatIntMap();
method public static androidx.collection.FloatIntMap floatIntMapOf();
- method public static androidx.collection.FloatIntMap floatIntMapOf(kotlin.Pair<java.lang.Float,java.lang.Integer>... pairs);
+ method public static androidx.collection.FloatIntMap floatIntMapOf(float key1, int value1);
+ method public static androidx.collection.FloatIntMap floatIntMapOf(float key1, int value1, float key2, int value2);
+ method public static androidx.collection.FloatIntMap floatIntMapOf(float key1, int value1, float key2, int value2, float key3, int value3);
+ method public static androidx.collection.FloatIntMap floatIntMapOf(float key1, int value1, float key2, int value2, float key3, int value3, float key4, int value4);
+ method public static androidx.collection.FloatIntMap floatIntMapOf(float key1, int value1, float key2, int value2, float key3, int value3, float key4, int value4, float key5, int value5);
method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf();
- method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf(kotlin.Pair<java.lang.Float,java.lang.Integer>... pairs);
+ method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf(float key1, int value1);
+ method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf(float key1, int value1, float key2, int value2);
+ method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf(float key1, int value1, float key2, int value2, float key3, int value3);
+ method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf(float key1, int value1, float key2, int value2, float key3, int value3, float key4, int value4);
+ method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf(float key1, int value1, float key2, int value2, float key3, int value3, float key4, int value4, float key5, int value5);
}
public abstract sealed class FloatList {
@@ -237,9 +263,17 @@
public final class FloatLongMapKt {
method public static androidx.collection.FloatLongMap emptyFloatLongMap();
method public static androidx.collection.FloatLongMap floatLongMapOf();
- method public static androidx.collection.FloatLongMap floatLongMapOf(kotlin.Pair<java.lang.Float,java.lang.Long>... pairs);
+ method public static androidx.collection.FloatLongMap floatLongMapOf(float key1, long value1);
+ method public static androidx.collection.FloatLongMap floatLongMapOf(float key1, long value1, float key2, long value2);
+ method public static androidx.collection.FloatLongMap floatLongMapOf(float key1, long value1, float key2, long value2, float key3, long value3);
+ method public static androidx.collection.FloatLongMap floatLongMapOf(float key1, long value1, float key2, long value2, float key3, long value3, float key4, long value4);
+ method public static androidx.collection.FloatLongMap floatLongMapOf(float key1, long value1, float key2, long value2, float key3, long value3, float key4, long value4, float key5, long value5);
method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf();
- method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf(kotlin.Pair<java.lang.Float,java.lang.Long>... pairs);
+ method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf(float key1, long value1);
+ method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf(float key1, long value1, float key2, long value2);
+ method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf(float key1, long value1, float key2, long value2, float key3, long value3);
+ method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf(float key1, long value1, float key2, long value2, float key3, long value3, float key4, long value4);
+ method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf(float key1, long value1, float key2, long value2, float key3, long value3, float key4, long value4, float key5, long value5);
}
public abstract sealed class FloatObjectMap<V> {
@@ -269,9 +303,17 @@
public final class FloatObjectMapKt {
method public static <V> androidx.collection.FloatObjectMap<V> emptyFloatObjectMap();
method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf();
- method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf(kotlin.Pair<java.lang.Float,? extends V>... pairs);
+ method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf(float key1, V value1);
+ method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf(float key1, V value1, float key2, V value2);
+ method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf(float key1, V value1, float key2, V value2, float key3, V value3);
+ method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf(float key1, V value1, float key2, V value2, float key3, V value3, float key4, V value4);
+ method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf(float key1, V value1, float key2, V value2, float key3, V value3, float key4, V value4, float key5, V value5);
method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf();
- method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf(kotlin.Pair<java.lang.Float,? extends V>... pairs);
+ method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf(float key1, V value1);
+ method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf(float key1, V value1, float key2, V value2);
+ method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf(float key1, V value1, float key2, V value2, float key3, V value3);
+ method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf(float key1, V value1, float key2, V value2, float key3, V value3, float key4, V value4);
+ method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf(float key1, V value1, float key2, V value2, float key3, V value3, float key4, V value4, float key5, V value5);
}
public abstract sealed class FloatSet {
@@ -334,9 +376,17 @@
public final class IntFloatMapKt {
method public static androidx.collection.IntFloatMap emptyIntFloatMap();
method public static androidx.collection.IntFloatMap intFloatMapOf();
- method public static androidx.collection.IntFloatMap intFloatMapOf(kotlin.Pair<java.lang.Integer,java.lang.Float>... pairs);
+ method public static androidx.collection.IntFloatMap intFloatMapOf(int key1, float value1);
+ method public static androidx.collection.IntFloatMap intFloatMapOf(int key1, float value1, int key2, float value2);
+ method public static androidx.collection.IntFloatMap intFloatMapOf(int key1, float value1, int key2, float value2, int key3, float value3);
+ method public static androidx.collection.IntFloatMap intFloatMapOf(int key1, float value1, int key2, float value2, int key3, float value3, int key4, float value4);
+ method public static androidx.collection.IntFloatMap intFloatMapOf(int key1, float value1, int key2, float value2, int key3, float value3, int key4, float value4, int key5, float value5);
method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf();
- method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf(kotlin.Pair<java.lang.Integer,java.lang.Float>... pairs);
+ method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf(int key1, float value1);
+ method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf(int key1, float value1, int key2, float value2);
+ method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf(int key1, float value1, int key2, float value2, int key3, float value3);
+ method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf(int key1, float value1, int key2, float value2, int key3, float value3, int key4, float value4);
+ method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf(int key1, float value1, int key2, float value2, int key3, float value3, int key4, float value4, int key5, float value5);
}
public abstract sealed class IntIntMap {
@@ -366,9 +416,27 @@
public final class IntIntMapKt {
method public static androidx.collection.IntIntMap emptyIntIntMap();
method public static androidx.collection.IntIntMap intIntMapOf();
- method public static androidx.collection.IntIntMap intIntMapOf(kotlin.Pair<java.lang.Integer,java.lang.Integer>... pairs);
+ method public static androidx.collection.IntIntMap intIntMapOf(int key1, int value1);
+ method public static androidx.collection.IntIntMap intIntMapOf(int key1, int value1, int key2, int value2);
+ method public static androidx.collection.IntIntMap intIntMapOf(int key1, int value1, int key2, int value2, int key3, int value3);
+ method public static androidx.collection.IntIntMap intIntMapOf(int key1, int value1, int key2, int value2, int key3, int value3, int key4, int value4);
+ method public static androidx.collection.IntIntMap intIntMapOf(int key1, int value1, int key2, int value2, int key3, int value3, int key4, int value4, int key5, int value5);
method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf();
- method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf(kotlin.Pair<java.lang.Integer,java.lang.Integer>... pairs);
+ method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf(int key1, int value1);
+ method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf(int key1, int value1, int key2, int value2);
+ method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf(int key1, int value1, int key2, int value2, int key3, int value3);
+ method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf(int key1, int value1, int key2, int value2, int key3, int value3, int key4, int value4);
+ method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf(int key1, int value1, int key2, int value2, int key3, int value3, int key4, int value4, int key5, int value5);
+ }
+
+ @kotlin.jvm.JvmInline public final value class IntIntPair {
+ ctor public IntIntPair(int first, int second);
+ method public inline operator int component1();
+ method public inline operator int component2();
+ method public int getFirst();
+ method public int getSecond();
+ property public final int first;
+ property public final int second;
}
public abstract sealed class IntList {
@@ -450,9 +518,17 @@
public final class IntLongMapKt {
method public static androidx.collection.IntLongMap emptyIntLongMap();
method public static androidx.collection.IntLongMap intLongMapOf();
- method public static androidx.collection.IntLongMap intLongMapOf(kotlin.Pair<java.lang.Integer,java.lang.Long>... pairs);
+ method public static androidx.collection.IntLongMap intLongMapOf(int key1, long value1);
+ method public static androidx.collection.IntLongMap intLongMapOf(int key1, long value1, int key2, long value2);
+ method public static androidx.collection.IntLongMap intLongMapOf(int key1, long value1, int key2, long value2, int key3, long value3);
+ method public static androidx.collection.IntLongMap intLongMapOf(int key1, long value1, int key2, long value2, int key3, long value3, int key4, long value4);
+ method public static androidx.collection.IntLongMap intLongMapOf(int key1, long value1, int key2, long value2, int key3, long value3, int key4, long value4, int key5, long value5);
method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf();
- method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf(kotlin.Pair<java.lang.Integer,java.lang.Long>... pairs);
+ method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf(int key1, long value1);
+ method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf(int key1, long value1, int key2, long value2);
+ method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf(int key1, long value1, int key2, long value2, int key3, long value3);
+ method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf(int key1, long value1, int key2, long value2, int key3, long value3, int key4, long value4);
+ method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf(int key1, long value1, int key2, long value2, int key3, long value3, int key4, long value4, int key5, long value5);
}
public abstract sealed class IntObjectMap<V> {
@@ -482,9 +558,17 @@
public final class IntObjectMapKt {
method public static <V> androidx.collection.IntObjectMap<V> emptyIntObjectMap();
method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf();
- method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf(kotlin.Pair<java.lang.Integer,? extends V>... pairs);
+ method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf(int key1, V value1);
+ method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf(int key1, V value1, int key2, V value2);
+ method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf(int key1, V value1, int key2, V value2, int key3, V value3);
+ method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf(int key1, V value1, int key2, V value2, int key3, V value3, int key4, V value4);
+ method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf(int key1, V value1, int key2, V value2, int key3, V value3, int key4, V value4, int key5, V value5);
method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf();
- method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf(kotlin.Pair<java.lang.Integer,? extends V>... pairs);
+ method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf(int key1, V value1);
+ method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf(int key1, V value1, int key2, V value2);
+ method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf(int key1, V value1, int key2, V value2, int key3, V value3);
+ method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf(int key1, V value1, int key2, V value2, int key3, V value3, int key4, V value4);
+ method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf(int key1, V value1, int key2, V value2, int key3, V value3, int key4, V value4, int key5, V value5);
}
public abstract sealed class IntSet {
@@ -547,9 +631,17 @@
public final class LongFloatMapKt {
method public static androidx.collection.LongFloatMap emptyLongFloatMap();
method public static androidx.collection.LongFloatMap longFloatMapOf();
- method public static androidx.collection.LongFloatMap longFloatMapOf(kotlin.Pair<java.lang.Long,java.lang.Float>... pairs);
+ method public static androidx.collection.LongFloatMap longFloatMapOf(long key1, float value1);
+ method public static androidx.collection.LongFloatMap longFloatMapOf(long key1, float value1, long key2, float value2);
+ method public static androidx.collection.LongFloatMap longFloatMapOf(long key1, float value1, long key2, float value2, long key3, float value3);
+ method public static androidx.collection.LongFloatMap longFloatMapOf(long key1, float value1, long key2, float value2, long key3, float value3, long key4, float value4);
+ method public static androidx.collection.LongFloatMap longFloatMapOf(long key1, float value1, long key2, float value2, long key3, float value3, long key4, float value4, long key5, float value5);
method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf();
- method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf(kotlin.Pair<java.lang.Long,java.lang.Float>... pairs);
+ method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf(long key1, float value1);
+ method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf(long key1, float value1, long key2, float value2);
+ method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf(long key1, float value1, long key2, float value2, long key3, float value3);
+ method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf(long key1, float value1, long key2, float value2, long key3, float value3, long key4, float value4);
+ method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf(long key1, float value1, long key2, float value2, long key3, float value3, long key4, float value4, long key5, float value5);
}
public abstract sealed class LongIntMap {
@@ -579,9 +671,17 @@
public final class LongIntMapKt {
method public static androidx.collection.LongIntMap emptyLongIntMap();
method public static androidx.collection.LongIntMap longIntMapOf();
- method public static androidx.collection.LongIntMap longIntMapOf(kotlin.Pair<java.lang.Long,java.lang.Integer>... pairs);
+ method public static androidx.collection.LongIntMap longIntMapOf(long key1, int value1);
+ method public static androidx.collection.LongIntMap longIntMapOf(long key1, int value1, long key2, int value2);
+ method public static androidx.collection.LongIntMap longIntMapOf(long key1, int value1, long key2, int value2, long key3, int value3);
+ method public static androidx.collection.LongIntMap longIntMapOf(long key1, int value1, long key2, int value2, long key3, int value3, long key4, int value4);
+ method public static androidx.collection.LongIntMap longIntMapOf(long key1, int value1, long key2, int value2, long key3, int value3, long key4, int value4, long key5, int value5);
method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf();
- method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf(kotlin.Pair<java.lang.Long,java.lang.Integer>... pairs);
+ method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf(long key1, int value1);
+ method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf(long key1, int value1, long key2, int value2);
+ method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf(long key1, int value1, long key2, int value2, long key3, int value3);
+ method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf(long key1, int value1, long key2, int value2, long key3, int value3, long key4, int value4);
+ method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf(long key1, int value1, long key2, int value2, long key3, int value3, long key4, int value4, long key5, int value5);
}
public abstract sealed class LongList {
@@ -663,9 +763,27 @@
public final class LongLongMapKt {
method public static androidx.collection.LongLongMap emptyLongLongMap();
method public static androidx.collection.LongLongMap longLongMapOf();
- method public static androidx.collection.LongLongMap longLongMapOf(kotlin.Pair<java.lang.Long,java.lang.Long>... pairs);
+ method public static androidx.collection.LongLongMap longLongMapOf(long key1, long value1);
+ method public static androidx.collection.LongLongMap longLongMapOf(long key1, long value1, long key2, long value2);
+ method public static androidx.collection.LongLongMap longLongMapOf(long key1, long value1, long key2, long value2, long key3, long value3);
+ method public static androidx.collection.LongLongMap longLongMapOf(long key1, long value1, long key2, long value2, long key3, long value3, long key4, long value4);
+ method public static androidx.collection.LongLongMap longLongMapOf(long key1, long value1, long key2, long value2, long key3, long value3, long key4, long value4, long key5, long value5);
method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf();
- method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf(kotlin.Pair<java.lang.Long,java.lang.Long>... pairs);
+ method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf(long key1, long value1);
+ method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf(long key1, long value1, long key2, long value2);
+ method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf(long key1, long value1, long key2, long value2, long key3, long value3);
+ method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf(long key1, long value1, long key2, long value2, long key3, long value3, long key4, long value4);
+ method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf(long key1, long value1, long key2, long value2, long key3, long value3, long key4, long value4, long key5, long value5);
+ }
+
+ public final class LongLongPair {
+ ctor public LongLongPair(long first, long second);
+ method public inline operator long component1();
+ method public inline operator long component2();
+ method public long getFirst();
+ method public long getSecond();
+ property public final long first;
+ property public final long second;
}
public abstract sealed class LongObjectMap<V> {
@@ -695,9 +813,17 @@
public final class LongObjectMapKt {
method public static <V> androidx.collection.LongObjectMap<V> emptyLongObjectMap();
method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf();
- method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf(kotlin.Pair<java.lang.Long,? extends V>... pairs);
+ method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf(long key1, V value1);
+ method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf(long key1, V value1, long key2, V value2);
+ method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf(long key1, V value1, long key2, V value2, long key3, V value3);
+ method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf(long key1, V value1, long key2, V value2, long key3, V value3, long key4, V value4);
+ method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf(long key1, V value1, long key2, V value2, long key3, V value3, long key4, V value4, long key5, V value5);
method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf();
- method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf(kotlin.Pair<java.lang.Long,? extends V>... pairs);
+ method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf(long key1, V value1);
+ method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf(long key1, V value1, long key2, V value2);
+ method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf(long key1, V value1, long key2, V value2, long key3, V value3);
+ method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf(long key1, V value1, long key2, V value2, long key3, V value3, long key4, V value4);
+ method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf(long key1, V value1, long key2, V value2, long key3, V value3, long key4, V value4, long key5, V value5);
}
public abstract sealed class LongSet {
@@ -809,11 +935,8 @@
method public inline operator void minusAssign(float key);
method public inline operator void minusAssign(float[] keys);
method public inline operator void plusAssign(androidx.collection.FloatFloatMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,java.lang.Float> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,java.lang.Float>![] pairs);
method public void put(float key, float value);
method public void putAll(androidx.collection.FloatFloatMap from);
- method public void putAll(kotlin.Pair<java.lang.Float,java.lang.Float>![] pairs);
method public void remove(float key);
method public boolean remove(float key, float value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Float,? super java.lang.Float,java.lang.Boolean> predicate);
@@ -830,11 +953,8 @@
method public inline operator void minusAssign(float key);
method public inline operator void minusAssign(float[] keys);
method public inline operator void plusAssign(androidx.collection.FloatIntMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,java.lang.Integer> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,java.lang.Integer>![] pairs);
method public void put(float key, int value);
method public void putAll(androidx.collection.FloatIntMap from);
- method public void putAll(kotlin.Pair<java.lang.Float,java.lang.Integer>![] pairs);
method public void remove(float key);
method public boolean remove(float key, int value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Float,? super java.lang.Integer,java.lang.Boolean> predicate);
@@ -882,11 +1002,8 @@
method public inline operator void minusAssign(float key);
method public inline operator void minusAssign(float[] keys);
method public inline operator void plusAssign(androidx.collection.FloatLongMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,java.lang.Long> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,java.lang.Long>![] pairs);
method public void put(float key, long value);
method public void putAll(androidx.collection.FloatLongMap from);
- method public void putAll(kotlin.Pair<java.lang.Float,java.lang.Long>![] pairs);
method public void remove(float key);
method public boolean remove(float key, long value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Float,? super java.lang.Long,java.lang.Boolean> predicate);
@@ -903,11 +1020,8 @@
method public inline operator void minusAssign(float key);
method public inline operator void minusAssign(float[] keys);
method public inline operator void plusAssign(androidx.collection.FloatObjectMap<V> from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,? extends V> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,? extends V>![] pairs);
method public V? put(float key, V value);
method public void putAll(androidx.collection.FloatObjectMap<V> from);
- method public void putAll(kotlin.Pair<java.lang.Float,? extends V>![] pairs);
method public V? remove(float key);
method public boolean remove(float key, V value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Float,? super V,java.lang.Boolean> predicate);
@@ -942,11 +1056,8 @@
method public inline operator void minusAssign(int key);
method public inline operator void minusAssign(int[] keys);
method public inline operator void plusAssign(androidx.collection.IntFloatMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,java.lang.Float> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,java.lang.Float>![] pairs);
method public void put(int key, float value);
method public void putAll(androidx.collection.IntFloatMap from);
- method public void putAll(kotlin.Pair<java.lang.Integer,java.lang.Float>![] pairs);
method public void remove(int key);
method public boolean remove(int key, float value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.Float,java.lang.Boolean> predicate);
@@ -963,11 +1074,8 @@
method public inline operator void minusAssign(int key);
method public inline operator void minusAssign(int[] keys);
method public inline operator void plusAssign(androidx.collection.IntIntMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,java.lang.Integer> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,java.lang.Integer>![] pairs);
method public void put(int key, int value);
method public void putAll(androidx.collection.IntIntMap from);
- method public void putAll(kotlin.Pair<java.lang.Integer,java.lang.Integer>![] pairs);
method public void remove(int key);
method public boolean remove(int key, int value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.Integer,java.lang.Boolean> predicate);
@@ -1015,11 +1123,8 @@
method public inline operator void minusAssign(int key);
method public inline operator void minusAssign(int[] keys);
method public inline operator void plusAssign(androidx.collection.IntLongMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,java.lang.Long> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,java.lang.Long>![] pairs);
method public void put(int key, long value);
method public void putAll(androidx.collection.IntLongMap from);
- method public void putAll(kotlin.Pair<java.lang.Integer,java.lang.Long>![] pairs);
method public void remove(int key);
method public boolean remove(int key, long value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.Long,java.lang.Boolean> predicate);
@@ -1036,11 +1141,8 @@
method public inline operator void minusAssign(int key);
method public inline operator void minusAssign(int[] keys);
method public inline operator void plusAssign(androidx.collection.IntObjectMap<V> from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,? extends V> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,? extends V>![] pairs);
method public V? put(int key, V value);
method public void putAll(androidx.collection.IntObjectMap<V> from);
- method public void putAll(kotlin.Pair<java.lang.Integer,? extends V>![] pairs);
method public V? remove(int key);
method public boolean remove(int key, V value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Integer,? super V,java.lang.Boolean> predicate);
@@ -1075,11 +1177,8 @@
method public inline operator void minusAssign(long key);
method public inline operator void minusAssign(long[] keys);
method public inline operator void plusAssign(androidx.collection.LongFloatMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,java.lang.Float> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,java.lang.Float>![] pairs);
method public void put(long key, float value);
method public void putAll(androidx.collection.LongFloatMap from);
- method public void putAll(kotlin.Pair<java.lang.Long,java.lang.Float>![] pairs);
method public void remove(long key);
method public boolean remove(long key, float value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Long,? super java.lang.Float,java.lang.Boolean> predicate);
@@ -1096,11 +1195,8 @@
method public inline operator void minusAssign(long key);
method public inline operator void minusAssign(long[] keys);
method public inline operator void plusAssign(androidx.collection.LongIntMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,java.lang.Integer> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,java.lang.Integer>![] pairs);
method public void put(long key, int value);
method public void putAll(androidx.collection.LongIntMap from);
- method public void putAll(kotlin.Pair<java.lang.Long,java.lang.Integer>![] pairs);
method public void remove(long key);
method public boolean remove(long key, int value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Long,? super java.lang.Integer,java.lang.Boolean> predicate);
@@ -1148,11 +1244,8 @@
method public inline operator void minusAssign(long key);
method public inline operator void minusAssign(long[] keys);
method public inline operator void plusAssign(androidx.collection.LongLongMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,java.lang.Long> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,java.lang.Long>![] pairs);
method public void put(long key, long value);
method public void putAll(androidx.collection.LongLongMap from);
- method public void putAll(kotlin.Pair<java.lang.Long,java.lang.Long>![] pairs);
method public void remove(long key);
method public boolean remove(long key, long value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Long,? super java.lang.Long,java.lang.Boolean> predicate);
@@ -1169,11 +1262,8 @@
method public inline operator void minusAssign(long key);
method public inline operator void minusAssign(long[] keys);
method public inline operator void plusAssign(androidx.collection.LongObjectMap<V> from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,? extends V> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,? extends V>![] pairs);
method public V? put(long key, V value);
method public void putAll(androidx.collection.LongObjectMap<V> from);
- method public void putAll(kotlin.Pair<java.lang.Long,? extends V>![] pairs);
method public V? remove(long key);
method public boolean remove(long key, V value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Long,? super V,java.lang.Boolean> predicate);
@@ -1209,11 +1299,8 @@
method public inline operator void minusAssign(K![] keys);
method public inline operator void minusAssign(kotlin.sequences.Sequence<? extends K> keys);
method public inline operator void plusAssign(androidx.collection.ObjectFloatMap<K> from);
- method public inline operator void plusAssign(kotlin.Pair<? extends K,java.lang.Float> pair);
- method public inline operator void plusAssign(kotlin.Pair<? extends K,java.lang.Float>![] pairs);
method public void put(K key, float value);
method public void putAll(androidx.collection.ObjectFloatMap<K> from);
- method public void putAll(kotlin.Pair<? extends K,java.lang.Float>![] pairs);
method public void remove(K key);
method public boolean remove(K key, float value);
method public void removeIf(kotlin.jvm.functions.Function2<? super K,? super java.lang.Float,java.lang.Boolean> predicate);
@@ -1231,11 +1318,8 @@
method public inline operator void minusAssign(K![] keys);
method public inline operator void minusAssign(kotlin.sequences.Sequence<? extends K> keys);
method public inline operator void plusAssign(androidx.collection.ObjectIntMap<K> from);
- method public inline operator void plusAssign(kotlin.Pair<? extends K,java.lang.Integer> pair);
- method public inline operator void plusAssign(kotlin.Pair<? extends K,java.lang.Integer>![] pairs);
method public void put(K key, int value);
method public void putAll(androidx.collection.ObjectIntMap<K> from);
- method public void putAll(kotlin.Pair<? extends K,java.lang.Integer>![] pairs);
method public void remove(K key);
method public boolean remove(K key, int value);
method public void removeIf(kotlin.jvm.functions.Function2<? super K,? super java.lang.Integer,java.lang.Boolean> predicate);
@@ -1305,11 +1389,8 @@
method public inline operator void minusAssign(K![] keys);
method public inline operator void minusAssign(kotlin.sequences.Sequence<? extends K> keys);
method public inline operator void plusAssign(androidx.collection.ObjectLongMap<K> from);
- method public inline operator void plusAssign(kotlin.Pair<? extends K,java.lang.Long> pair);
- method public inline operator void plusAssign(kotlin.Pair<? extends K,java.lang.Long>![] pairs);
method public void put(K key, long value);
method public void putAll(androidx.collection.ObjectLongMap<K> from);
- method public void putAll(kotlin.Pair<? extends K,java.lang.Long>![] pairs);
method public void remove(K key);
method public boolean remove(K key, long value);
method public void removeIf(kotlin.jvm.functions.Function2<? super K,? super java.lang.Long,java.lang.Boolean> predicate);
@@ -1322,6 +1403,8 @@
method public java.util.Map<K,V> asMutableMap();
method public void clear();
method public inline V getOrPut(K key, kotlin.jvm.functions.Function0<? extends V> defaultValue);
+ method public inline operator void minusAssign(androidx.collection.ObjectList<K> keys);
+ method public inline operator void minusAssign(androidx.collection.ScatterSet<K> keys);
method public inline operator void minusAssign(Iterable<? extends K> keys);
method public inline operator void minusAssign(K key);
method public inline operator void minusAssign(K![] keys);
@@ -1348,23 +1431,27 @@
public final class MutableScatterSet<E> extends androidx.collection.ScatterSet<E> {
ctor public MutableScatterSet(optional int initialCapacity);
method public boolean add(E element);
+ method public boolean addAll(androidx.collection.ObjectList<E> elements);
method public boolean addAll(androidx.collection.ScatterSet<E> elements);
method public boolean addAll(E![] elements);
method public boolean addAll(Iterable<? extends E> elements);
method public boolean addAll(kotlin.sequences.Sequence<? extends E> elements);
method public java.util.Set<E> asMutableSet();
method public void clear();
+ method public operator void minusAssign(androidx.collection.ObjectList<E> elements);
method public operator void minusAssign(androidx.collection.ScatterSet<E> elements);
method public operator void minusAssign(E element);
method public operator void minusAssign(E![] elements);
method public operator void minusAssign(Iterable<? extends E> elements);
method public operator void minusAssign(kotlin.sequences.Sequence<? extends E> elements);
+ method public operator void plusAssign(androidx.collection.ObjectList<E> elements);
method public operator void plusAssign(androidx.collection.ScatterSet<E> elements);
method public operator void plusAssign(E element);
method public operator void plusAssign(E![] elements);
method public operator void plusAssign(Iterable<? extends E> elements);
method public operator void plusAssign(kotlin.sequences.Sequence<? extends E> elements);
method public boolean remove(E element);
+ method public boolean removeAll(androidx.collection.ObjectList<E> elements);
method public boolean removeAll(androidx.collection.ScatterSet<E> elements);
method public boolean removeAll(E![] elements);
method public boolean removeAll(Iterable<? extends E> elements);
@@ -1400,9 +1487,17 @@
public final class ObjectFloatMapKt {
method public static <K> androidx.collection.ObjectFloatMap<K> emptyObjectFloatMap();
method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf();
- method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf(kotlin.Pair<? extends K,java.lang.Float>... pairs);
+ method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf(K key1, float value1);
+ method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf(K key1, float value1, K key2, float value2);
+ method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf(K key1, float value1, K key2, float value2, K key3, float value3);
+ method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf(K key1, float value1, K key2, float value2, K key3, float value3, K key4, float value4);
+ method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf(K key1, float value1, K key2, float value2, K key3, float value3, K key4, float value4, K key5, float value5);
method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMap();
- method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMapOf(kotlin.Pair<? extends K,java.lang.Float>... pairs);
+ method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMapOf(K key1, float value1);
+ method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMapOf(K key1, float value1, K key2, float value2);
+ method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMapOf(K key1, float value1, K key2, float value2, K key3, float value3);
+ method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMapOf(K key1, float value1, K key2, float value2, K key3, float value3, K key4, float value4);
+ method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMapOf(K key1, float value1, K key2, float value2, K key3, float value3, K key4, float value4, K key5, float value5);
}
public abstract sealed class ObjectIntMap<K> {
@@ -1432,9 +1527,17 @@
public final class ObjectIntMapKt {
method public static <K> androidx.collection.ObjectIntMap<K> emptyObjectIntMap();
method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf();
- method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf(kotlin.Pair<? extends K,java.lang.Integer>... pairs);
+ method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf(K key1, int value1);
+ method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf(K key1, int value1, K key2, int value2);
+ method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf(K key1, int value1, K key2, int value2, K key3, int value3);
+ method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf(K key1, int value1, K key2, int value2, K key3, int value3, K key4, int value4);
+ method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf(K key1, int value1, K key2, int value2, K key3, int value3, K key4, int value4, K key5, int value5);
method public static <K> androidx.collection.ObjectIntMap<K> objectIntMap();
- method public static <K> androidx.collection.ObjectIntMap<K> objectIntMapOf(kotlin.Pair<? extends K,java.lang.Integer>... pairs);
+ method public static <K> androidx.collection.ObjectIntMap<K> objectIntMapOf(K key1, int value1);
+ method public static <K> androidx.collection.ObjectIntMap<K> objectIntMapOf(K key1, int value1, K key2, int value2);
+ method public static <K> androidx.collection.ObjectIntMap<K> objectIntMapOf(K key1, int value1, K key2, int value2, K key3, int value3);
+ method public static <K> androidx.collection.ObjectIntMap<K> objectIntMapOf(K key1, int value1, K key2, int value2, K key3, int value3, K key4, int value4);
+ method public static <K> androidx.collection.ObjectIntMap<K> objectIntMapOf(K key1, int value1, K key2, int value2, K key3, int value3, K key4, int value4, K key5, int value5);
}
public abstract sealed class ObjectList<E> {
@@ -1524,39 +1627,17 @@
public final class ObjectLongMapKt {
method public static <K> androidx.collection.ObjectLongMap<K> emptyObjectLongMap();
method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf();
- method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf(kotlin.Pair<? extends K,java.lang.Long>... pairs);
+ method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf(K key1, long value1);
+ method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf(K key1, long value1, K key2, long value2);
+ method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf(K key1, long value1, K key2, long value2, K key3, long value3);
+ method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf(K key1, long value1, K key2, long value2, K key3, long value3, K key4, long value4);
+ method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf(K key1, long value1, K key2, long value2, K key3, long value3, K key4, long value4, K key5, long value5);
method public static <K> androidx.collection.ObjectLongMap<K> objectLongMap();
- method public static <K> androidx.collection.ObjectLongMap<K> objectLongMapOf(kotlin.Pair<? extends K,java.lang.Long>... pairs);
- }
-
- @kotlin.jvm.JvmInline public final value class PairFloatFloat {
- ctor public PairFloatFloat(float first, float second);
- method public inline operator float component1();
- method public inline operator float component2();
- method public inline float getFirst();
- method public inline float getSecond();
- property public final inline float first;
- property public final inline float second;
- }
-
- @kotlin.jvm.JvmInline public final value class PairIntInt {
- ctor public PairIntInt(int first, int second);
- method public inline operator int component1();
- method public inline operator int component2();
- method public int getFirst();
- method public int getSecond();
- property public final int first;
- property public final int second;
- }
-
- public final class PairLongLong {
- ctor public PairLongLong(long first, long second);
- method public inline operator long component1();
- method public inline operator long component2();
- method public long getFirst();
- method public long getSecond();
- property public final long first;
- property public final long second;
+ method public static <K> androidx.collection.ObjectLongMap<K> objectLongMapOf(K key1, long value1);
+ method public static <K> androidx.collection.ObjectLongMap<K> objectLongMapOf(K key1, long value1, K key2, long value2);
+ method public static <K> androidx.collection.ObjectLongMap<K> objectLongMapOf(K key1, long value1, K key2, long value2, K key3, long value3);
+ method public static <K> androidx.collection.ObjectLongMap<K> objectLongMapOf(K key1, long value1, K key2, long value2, K key3, long value3, K key4, long value4);
+ method public static <K> androidx.collection.ObjectLongMap<K> objectLongMapOf(K key1, long value1, K key2, long value2, K key3, long value3, K key4, long value4, K key5, long value5);
}
public abstract sealed class ScatterMap<K, V> {
diff --git a/collection/collection/api/restricted_current.txt b/collection/collection/api/restricted_current.txt
index 098c0eb..48a12f4 100644
--- a/collection/collection/api/restricted_current.txt
+++ b/collection/collection/api/restricted_current.txt
@@ -126,9 +126,27 @@
public final class FloatFloatMapKt {
method public static androidx.collection.FloatFloatMap emptyFloatFloatMap();
method public static androidx.collection.FloatFloatMap floatFloatMapOf();
- method public static androidx.collection.FloatFloatMap floatFloatMapOf(kotlin.Pair<java.lang.Float,java.lang.Float>... pairs);
+ method public static androidx.collection.FloatFloatMap floatFloatMapOf(float key1, float value1);
+ method public static androidx.collection.FloatFloatMap floatFloatMapOf(float key1, float value1, float key2, float value2);
+ method public static androidx.collection.FloatFloatMap floatFloatMapOf(float key1, float value1, float key2, float value2, float key3, float value3);
+ method public static androidx.collection.FloatFloatMap floatFloatMapOf(float key1, float value1, float key2, float value2, float key3, float value3, float key4, float value4);
+ method public static androidx.collection.FloatFloatMap floatFloatMapOf(float key1, float value1, float key2, float value2, float key3, float value3, float key4, float value4, float key5, float value5);
method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf();
- method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf(kotlin.Pair<java.lang.Float,java.lang.Float>... pairs);
+ method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf(float key1, float value1);
+ method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf(float key1, float value1, float key2, float value2);
+ method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf(float key1, float value1, float key2, float value2, float key3, float value3);
+ method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf(float key1, float value1, float key2, float value2, float key3, float value3, float key4, float value4);
+ method public static androidx.collection.MutableFloatFloatMap mutableFloatFloatMapOf(float key1, float value1, float key2, float value2, float key3, float value3, float key4, float value4, float key5, float value5);
+ }
+
+ @kotlin.jvm.JvmInline public final value class FloatFloatPair {
+ ctor public FloatFloatPair(float first, float second);
+ method public inline operator float component1();
+ method public inline operator float component2();
+ method public inline float getFirst();
+ method public inline float getSecond();
+ property public final inline float first;
+ property public final inline float second;
}
public abstract sealed class FloatIntMap {
@@ -163,9 +181,17 @@
public final class FloatIntMapKt {
method public static androidx.collection.FloatIntMap emptyFloatIntMap();
method public static androidx.collection.FloatIntMap floatIntMapOf();
- method public static androidx.collection.FloatIntMap floatIntMapOf(kotlin.Pair<java.lang.Float,java.lang.Integer>... pairs);
+ method public static androidx.collection.FloatIntMap floatIntMapOf(float key1, int value1);
+ method public static androidx.collection.FloatIntMap floatIntMapOf(float key1, int value1, float key2, int value2);
+ method public static androidx.collection.FloatIntMap floatIntMapOf(float key1, int value1, float key2, int value2, float key3, int value3);
+ method public static androidx.collection.FloatIntMap floatIntMapOf(float key1, int value1, float key2, int value2, float key3, int value3, float key4, int value4);
+ method public static androidx.collection.FloatIntMap floatIntMapOf(float key1, int value1, float key2, int value2, float key3, int value3, float key4, int value4, float key5, int value5);
method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf();
- method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf(kotlin.Pair<java.lang.Float,java.lang.Integer>... pairs);
+ method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf(float key1, int value1);
+ method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf(float key1, int value1, float key2, int value2);
+ method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf(float key1, int value1, float key2, int value2, float key3, int value3);
+ method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf(float key1, int value1, float key2, int value2, float key3, int value3, float key4, int value4);
+ method public static androidx.collection.MutableFloatIntMap mutableFloatIntMapOf(float key1, int value1, float key2, int value2, float key3, int value3, float key4, int value4, float key5, int value5);
}
public abstract sealed class FloatList {
@@ -254,9 +280,17 @@
public final class FloatLongMapKt {
method public static androidx.collection.FloatLongMap emptyFloatLongMap();
method public static androidx.collection.FloatLongMap floatLongMapOf();
- method public static androidx.collection.FloatLongMap floatLongMapOf(kotlin.Pair<java.lang.Float,java.lang.Long>... pairs);
+ method public static androidx.collection.FloatLongMap floatLongMapOf(float key1, long value1);
+ method public static androidx.collection.FloatLongMap floatLongMapOf(float key1, long value1, float key2, long value2);
+ method public static androidx.collection.FloatLongMap floatLongMapOf(float key1, long value1, float key2, long value2, float key3, long value3);
+ method public static androidx.collection.FloatLongMap floatLongMapOf(float key1, long value1, float key2, long value2, float key3, long value3, float key4, long value4);
+ method public static androidx.collection.FloatLongMap floatLongMapOf(float key1, long value1, float key2, long value2, float key3, long value3, float key4, long value4, float key5, long value5);
method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf();
- method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf(kotlin.Pair<java.lang.Float,java.lang.Long>... pairs);
+ method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf(float key1, long value1);
+ method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf(float key1, long value1, float key2, long value2);
+ method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf(float key1, long value1, float key2, long value2, float key3, long value3);
+ method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf(float key1, long value1, float key2, long value2, float key3, long value3, float key4, long value4);
+ method public static androidx.collection.MutableFloatLongMap mutableFloatLongMapOf(float key1, long value1, float key2, long value2, float key3, long value3, float key4, long value4, float key5, long value5);
}
public abstract sealed class FloatObjectMap<V> {
@@ -290,9 +324,17 @@
public final class FloatObjectMapKt {
method public static <V> androidx.collection.FloatObjectMap<V> emptyFloatObjectMap();
method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf();
- method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf(kotlin.Pair<java.lang.Float,? extends V>... pairs);
+ method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf(float key1, V value1);
+ method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf(float key1, V value1, float key2, V value2);
+ method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf(float key1, V value1, float key2, V value2, float key3, V value3);
+ method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf(float key1, V value1, float key2, V value2, float key3, V value3, float key4, V value4);
+ method public static <V> androidx.collection.FloatObjectMap<V> floatObjectMapOf(float key1, V value1, float key2, V value2, float key3, V value3, float key4, V value4, float key5, V value5);
method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf();
- method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf(kotlin.Pair<java.lang.Float,? extends V>... pairs);
+ method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf(float key1, V value1);
+ method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf(float key1, V value1, float key2, V value2);
+ method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf(float key1, V value1, float key2, V value2, float key3, V value3);
+ method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf(float key1, V value1, float key2, V value2, float key3, V value3, float key4, V value4);
+ method public static <V> androidx.collection.MutableFloatObjectMap<V> mutableFloatObjectMapOf(float key1, V value1, float key2, V value2, float key3, V value3, float key4, V value4, float key5, V value5);
}
public abstract sealed class FloatSet {
@@ -363,9 +405,17 @@
public final class IntFloatMapKt {
method public static androidx.collection.IntFloatMap emptyIntFloatMap();
method public static androidx.collection.IntFloatMap intFloatMapOf();
- method public static androidx.collection.IntFloatMap intFloatMapOf(kotlin.Pair<java.lang.Integer,java.lang.Float>... pairs);
+ method public static androidx.collection.IntFloatMap intFloatMapOf(int key1, float value1);
+ method public static androidx.collection.IntFloatMap intFloatMapOf(int key1, float value1, int key2, float value2);
+ method public static androidx.collection.IntFloatMap intFloatMapOf(int key1, float value1, int key2, float value2, int key3, float value3);
+ method public static androidx.collection.IntFloatMap intFloatMapOf(int key1, float value1, int key2, float value2, int key3, float value3, int key4, float value4);
+ method public static androidx.collection.IntFloatMap intFloatMapOf(int key1, float value1, int key2, float value2, int key3, float value3, int key4, float value4, int key5, float value5);
method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf();
- method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf(kotlin.Pair<java.lang.Integer,java.lang.Float>... pairs);
+ method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf(int key1, float value1);
+ method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf(int key1, float value1, int key2, float value2);
+ method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf(int key1, float value1, int key2, float value2, int key3, float value3);
+ method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf(int key1, float value1, int key2, float value2, int key3, float value3, int key4, float value4);
+ method public static androidx.collection.MutableIntFloatMap mutableIntFloatMapOf(int key1, float value1, int key2, float value2, int key3, float value3, int key4, float value4, int key5, float value5);
}
public abstract sealed class IntIntMap {
@@ -400,9 +450,27 @@
public final class IntIntMapKt {
method public static androidx.collection.IntIntMap emptyIntIntMap();
method public static androidx.collection.IntIntMap intIntMapOf();
- method public static androidx.collection.IntIntMap intIntMapOf(kotlin.Pair<java.lang.Integer,java.lang.Integer>... pairs);
+ method public static androidx.collection.IntIntMap intIntMapOf(int key1, int value1);
+ method public static androidx.collection.IntIntMap intIntMapOf(int key1, int value1, int key2, int value2);
+ method public static androidx.collection.IntIntMap intIntMapOf(int key1, int value1, int key2, int value2, int key3, int value3);
+ method public static androidx.collection.IntIntMap intIntMapOf(int key1, int value1, int key2, int value2, int key3, int value3, int key4, int value4);
+ method public static androidx.collection.IntIntMap intIntMapOf(int key1, int value1, int key2, int value2, int key3, int value3, int key4, int value4, int key5, int value5);
method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf();
- method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf(kotlin.Pair<java.lang.Integer,java.lang.Integer>... pairs);
+ method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf(int key1, int value1);
+ method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf(int key1, int value1, int key2, int value2);
+ method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf(int key1, int value1, int key2, int value2, int key3, int value3);
+ method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf(int key1, int value1, int key2, int value2, int key3, int value3, int key4, int value4);
+ method public static androidx.collection.MutableIntIntMap mutableIntIntMapOf(int key1, int value1, int key2, int value2, int key3, int value3, int key4, int value4, int key5, int value5);
+ }
+
+ @kotlin.jvm.JvmInline public final value class IntIntPair {
+ ctor public IntIntPair(int first, int second);
+ method public inline operator int component1();
+ method public inline operator int component2();
+ method public int getFirst();
+ method public int getSecond();
+ property public final int first;
+ property public final int second;
}
public abstract sealed class IntList {
@@ -491,9 +559,17 @@
public final class IntLongMapKt {
method public static androidx.collection.IntLongMap emptyIntLongMap();
method public static androidx.collection.IntLongMap intLongMapOf();
- method public static androidx.collection.IntLongMap intLongMapOf(kotlin.Pair<java.lang.Integer,java.lang.Long>... pairs);
+ method public static androidx.collection.IntLongMap intLongMapOf(int key1, long value1);
+ method public static androidx.collection.IntLongMap intLongMapOf(int key1, long value1, int key2, long value2);
+ method public static androidx.collection.IntLongMap intLongMapOf(int key1, long value1, int key2, long value2, int key3, long value3);
+ method public static androidx.collection.IntLongMap intLongMapOf(int key1, long value1, int key2, long value2, int key3, long value3, int key4, long value4);
+ method public static androidx.collection.IntLongMap intLongMapOf(int key1, long value1, int key2, long value2, int key3, long value3, int key4, long value4, int key5, long value5);
method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf();
- method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf(kotlin.Pair<java.lang.Integer,java.lang.Long>... pairs);
+ method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf(int key1, long value1);
+ method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf(int key1, long value1, int key2, long value2);
+ method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf(int key1, long value1, int key2, long value2, int key3, long value3);
+ method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf(int key1, long value1, int key2, long value2, int key3, long value3, int key4, long value4);
+ method public static androidx.collection.MutableIntLongMap mutableIntLongMapOf(int key1, long value1, int key2, long value2, int key3, long value3, int key4, long value4, int key5, long value5);
}
public abstract sealed class IntObjectMap<V> {
@@ -527,9 +603,17 @@
public final class IntObjectMapKt {
method public static <V> androidx.collection.IntObjectMap<V> emptyIntObjectMap();
method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf();
- method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf(kotlin.Pair<java.lang.Integer,? extends V>... pairs);
+ method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf(int key1, V value1);
+ method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf(int key1, V value1, int key2, V value2);
+ method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf(int key1, V value1, int key2, V value2, int key3, V value3);
+ method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf(int key1, V value1, int key2, V value2, int key3, V value3, int key4, V value4);
+ method public static <V> androidx.collection.IntObjectMap<V> intObjectMapOf(int key1, V value1, int key2, V value2, int key3, V value3, int key4, V value4, int key5, V value5);
method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf();
- method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf(kotlin.Pair<java.lang.Integer,? extends V>... pairs);
+ method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf(int key1, V value1);
+ method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf(int key1, V value1, int key2, V value2);
+ method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf(int key1, V value1, int key2, V value2, int key3, V value3);
+ method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf(int key1, V value1, int key2, V value2, int key3, V value3, int key4, V value4);
+ method public static <V> androidx.collection.MutableIntObjectMap<V> mutableIntObjectMapOf(int key1, V value1, int key2, V value2, int key3, V value3, int key4, V value4, int key5, V value5);
}
public abstract sealed class IntSet {
@@ -600,9 +684,17 @@
public final class LongFloatMapKt {
method public static androidx.collection.LongFloatMap emptyLongFloatMap();
method public static androidx.collection.LongFloatMap longFloatMapOf();
- method public static androidx.collection.LongFloatMap longFloatMapOf(kotlin.Pair<java.lang.Long,java.lang.Float>... pairs);
+ method public static androidx.collection.LongFloatMap longFloatMapOf(long key1, float value1);
+ method public static androidx.collection.LongFloatMap longFloatMapOf(long key1, float value1, long key2, float value2);
+ method public static androidx.collection.LongFloatMap longFloatMapOf(long key1, float value1, long key2, float value2, long key3, float value3);
+ method public static androidx.collection.LongFloatMap longFloatMapOf(long key1, float value1, long key2, float value2, long key3, float value3, long key4, float value4);
+ method public static androidx.collection.LongFloatMap longFloatMapOf(long key1, float value1, long key2, float value2, long key3, float value3, long key4, float value4, long key5, float value5);
method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf();
- method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf(kotlin.Pair<java.lang.Long,java.lang.Float>... pairs);
+ method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf(long key1, float value1);
+ method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf(long key1, float value1, long key2, float value2);
+ method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf(long key1, float value1, long key2, float value2, long key3, float value3);
+ method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf(long key1, float value1, long key2, float value2, long key3, float value3, long key4, float value4);
+ method public static androidx.collection.MutableLongFloatMap mutableLongFloatMapOf(long key1, float value1, long key2, float value2, long key3, float value3, long key4, float value4, long key5, float value5);
}
public abstract sealed class LongIntMap {
@@ -637,9 +729,17 @@
public final class LongIntMapKt {
method public static androidx.collection.LongIntMap emptyLongIntMap();
method public static androidx.collection.LongIntMap longIntMapOf();
- method public static androidx.collection.LongIntMap longIntMapOf(kotlin.Pair<java.lang.Long,java.lang.Integer>... pairs);
+ method public static androidx.collection.LongIntMap longIntMapOf(long key1, int value1);
+ method public static androidx.collection.LongIntMap longIntMapOf(long key1, int value1, long key2, int value2);
+ method public static androidx.collection.LongIntMap longIntMapOf(long key1, int value1, long key2, int value2, long key3, int value3);
+ method public static androidx.collection.LongIntMap longIntMapOf(long key1, int value1, long key2, int value2, long key3, int value3, long key4, int value4);
+ method public static androidx.collection.LongIntMap longIntMapOf(long key1, int value1, long key2, int value2, long key3, int value3, long key4, int value4, long key5, int value5);
method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf();
- method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf(kotlin.Pair<java.lang.Long,java.lang.Integer>... pairs);
+ method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf(long key1, int value1);
+ method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf(long key1, int value1, long key2, int value2);
+ method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf(long key1, int value1, long key2, int value2, long key3, int value3);
+ method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf(long key1, int value1, long key2, int value2, long key3, int value3, long key4, int value4);
+ method public static androidx.collection.MutableLongIntMap mutableLongIntMapOf(long key1, int value1, long key2, int value2, long key3, int value3, long key4, int value4, long key5, int value5);
}
public abstract sealed class LongList {
@@ -728,9 +828,27 @@
public final class LongLongMapKt {
method public static androidx.collection.LongLongMap emptyLongLongMap();
method public static androidx.collection.LongLongMap longLongMapOf();
- method public static androidx.collection.LongLongMap longLongMapOf(kotlin.Pair<java.lang.Long,java.lang.Long>... pairs);
+ method public static androidx.collection.LongLongMap longLongMapOf(long key1, long value1);
+ method public static androidx.collection.LongLongMap longLongMapOf(long key1, long value1, long key2, long value2);
+ method public static androidx.collection.LongLongMap longLongMapOf(long key1, long value1, long key2, long value2, long key3, long value3);
+ method public static androidx.collection.LongLongMap longLongMapOf(long key1, long value1, long key2, long value2, long key3, long value3, long key4, long value4);
+ method public static androidx.collection.LongLongMap longLongMapOf(long key1, long value1, long key2, long value2, long key3, long value3, long key4, long value4, long key5, long value5);
method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf();
- method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf(kotlin.Pair<java.lang.Long,java.lang.Long>... pairs);
+ method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf(long key1, long value1);
+ method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf(long key1, long value1, long key2, long value2);
+ method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf(long key1, long value1, long key2, long value2, long key3, long value3);
+ method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf(long key1, long value1, long key2, long value2, long key3, long value3, long key4, long value4);
+ method public static androidx.collection.MutableLongLongMap mutableLongLongMapOf(long key1, long value1, long key2, long value2, long key3, long value3, long key4, long value4, long key5, long value5);
+ }
+
+ public final class LongLongPair {
+ ctor public LongLongPair(long first, long second);
+ method public inline operator long component1();
+ method public inline operator long component2();
+ method public long getFirst();
+ method public long getSecond();
+ property public final long first;
+ property public final long second;
}
public abstract sealed class LongObjectMap<V> {
@@ -764,9 +882,17 @@
public final class LongObjectMapKt {
method public static <V> androidx.collection.LongObjectMap<V> emptyLongObjectMap();
method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf();
- method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf(kotlin.Pair<java.lang.Long,? extends V>... pairs);
+ method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf(long key1, V value1);
+ method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf(long key1, V value1, long key2, V value2);
+ method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf(long key1, V value1, long key2, V value2, long key3, V value3);
+ method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf(long key1, V value1, long key2, V value2, long key3, V value3, long key4, V value4);
+ method public static <V> androidx.collection.LongObjectMap<V> longObjectMapOf(long key1, V value1, long key2, V value2, long key3, V value3, long key4, V value4, long key5, V value5);
method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf();
- method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf(kotlin.Pair<java.lang.Long,? extends V>... pairs);
+ method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf(long key1, V value1);
+ method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf(long key1, V value1, long key2, V value2);
+ method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf(long key1, V value1, long key2, V value2, long key3, V value3);
+ method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf(long key1, V value1, long key2, V value2, long key3, V value3, long key4, V value4);
+ method public static <V> androidx.collection.MutableLongObjectMap<V> mutableLongObjectMapOf(long key1, V value1, long key2, V value2, long key3, V value3, long key4, V value4, long key5, V value5);
}
public abstract sealed class LongSet {
@@ -881,11 +1007,8 @@
method public inline operator void minusAssign(float key);
method public inline operator void minusAssign(float[] keys);
method public inline operator void plusAssign(androidx.collection.FloatFloatMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,java.lang.Float> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,java.lang.Float>![] pairs);
method public void put(float key, float value);
method public void putAll(androidx.collection.FloatFloatMap from);
- method public void putAll(kotlin.Pair<java.lang.Float,java.lang.Float>![] pairs);
method public void remove(float key);
method public boolean remove(float key, float value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Float,? super java.lang.Float,java.lang.Boolean> predicate);
@@ -902,11 +1025,8 @@
method public inline operator void minusAssign(float key);
method public inline operator void minusAssign(float[] keys);
method public inline operator void plusAssign(androidx.collection.FloatIntMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,java.lang.Integer> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,java.lang.Integer>![] pairs);
method public void put(float key, int value);
method public void putAll(androidx.collection.FloatIntMap from);
- method public void putAll(kotlin.Pair<java.lang.Float,java.lang.Integer>![] pairs);
method public void remove(float key);
method public boolean remove(float key, int value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Float,? super java.lang.Integer,java.lang.Boolean> predicate);
@@ -954,11 +1074,8 @@
method public inline operator void minusAssign(float key);
method public inline operator void minusAssign(float[] keys);
method public inline operator void plusAssign(androidx.collection.FloatLongMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,java.lang.Long> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,java.lang.Long>![] pairs);
method public void put(float key, long value);
method public void putAll(androidx.collection.FloatLongMap from);
- method public void putAll(kotlin.Pair<java.lang.Float,java.lang.Long>![] pairs);
method public void remove(float key);
method public boolean remove(float key, long value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Float,? super java.lang.Long,java.lang.Boolean> predicate);
@@ -975,11 +1092,8 @@
method public inline operator void minusAssign(float key);
method public inline operator void minusAssign(float[] keys);
method public inline operator void plusAssign(androidx.collection.FloatObjectMap<V> from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,? extends V> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Float,? extends V>![] pairs);
method public V? put(float key, V value);
method public void putAll(androidx.collection.FloatObjectMap<V> from);
- method public void putAll(kotlin.Pair<java.lang.Float,? extends V>![] pairs);
method public V? remove(float key);
method public boolean remove(float key, V value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Float,? super V,java.lang.Boolean> predicate);
@@ -1014,11 +1128,8 @@
method public inline operator void minusAssign(int key);
method public inline operator void minusAssign(int[] keys);
method public inline operator void plusAssign(androidx.collection.IntFloatMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,java.lang.Float> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,java.lang.Float>![] pairs);
method public void put(int key, float value);
method public void putAll(androidx.collection.IntFloatMap from);
- method public void putAll(kotlin.Pair<java.lang.Integer,java.lang.Float>![] pairs);
method public void remove(int key);
method public boolean remove(int key, float value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.Float,java.lang.Boolean> predicate);
@@ -1035,11 +1146,8 @@
method public inline operator void minusAssign(int key);
method public inline operator void minusAssign(int[] keys);
method public inline operator void plusAssign(androidx.collection.IntIntMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,java.lang.Integer> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,java.lang.Integer>![] pairs);
method public void put(int key, int value);
method public void putAll(androidx.collection.IntIntMap from);
- method public void putAll(kotlin.Pair<java.lang.Integer,java.lang.Integer>![] pairs);
method public void remove(int key);
method public boolean remove(int key, int value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.Integer,java.lang.Boolean> predicate);
@@ -1087,11 +1195,8 @@
method public inline operator void minusAssign(int key);
method public inline operator void minusAssign(int[] keys);
method public inline operator void plusAssign(androidx.collection.IntLongMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,java.lang.Long> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,java.lang.Long>![] pairs);
method public void put(int key, long value);
method public void putAll(androidx.collection.IntLongMap from);
- method public void putAll(kotlin.Pair<java.lang.Integer,java.lang.Long>![] pairs);
method public void remove(int key);
method public boolean remove(int key, long value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Integer,? super java.lang.Long,java.lang.Boolean> predicate);
@@ -1108,11 +1213,8 @@
method public inline operator void minusAssign(int key);
method public inline operator void minusAssign(int[] keys);
method public inline operator void plusAssign(androidx.collection.IntObjectMap<V> from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,? extends V> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Integer,? extends V>![] pairs);
method public V? put(int key, V value);
method public void putAll(androidx.collection.IntObjectMap<V> from);
- method public void putAll(kotlin.Pair<java.lang.Integer,? extends V>![] pairs);
method public V? remove(int key);
method public boolean remove(int key, V value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Integer,? super V,java.lang.Boolean> predicate);
@@ -1147,11 +1249,8 @@
method public inline operator void minusAssign(long key);
method public inline operator void minusAssign(long[] keys);
method public inline operator void plusAssign(androidx.collection.LongFloatMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,java.lang.Float> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,java.lang.Float>![] pairs);
method public void put(long key, float value);
method public void putAll(androidx.collection.LongFloatMap from);
- method public void putAll(kotlin.Pair<java.lang.Long,java.lang.Float>![] pairs);
method public void remove(long key);
method public boolean remove(long key, float value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Long,? super java.lang.Float,java.lang.Boolean> predicate);
@@ -1168,11 +1267,8 @@
method public inline operator void minusAssign(long key);
method public inline operator void minusAssign(long[] keys);
method public inline operator void plusAssign(androidx.collection.LongIntMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,java.lang.Integer> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,java.lang.Integer>![] pairs);
method public void put(long key, int value);
method public void putAll(androidx.collection.LongIntMap from);
- method public void putAll(kotlin.Pair<java.lang.Long,java.lang.Integer>![] pairs);
method public void remove(long key);
method public boolean remove(long key, int value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Long,? super java.lang.Integer,java.lang.Boolean> predicate);
@@ -1220,11 +1316,8 @@
method public inline operator void minusAssign(long key);
method public inline operator void minusAssign(long[] keys);
method public inline operator void plusAssign(androidx.collection.LongLongMap from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,java.lang.Long> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,java.lang.Long>![] pairs);
method public void put(long key, long value);
method public void putAll(androidx.collection.LongLongMap from);
- method public void putAll(kotlin.Pair<java.lang.Long,java.lang.Long>![] pairs);
method public void remove(long key);
method public boolean remove(long key, long value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Long,? super java.lang.Long,java.lang.Boolean> predicate);
@@ -1241,11 +1334,8 @@
method public inline operator void minusAssign(long key);
method public inline operator void minusAssign(long[] keys);
method public inline operator void plusAssign(androidx.collection.LongObjectMap<V> from);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,? extends V> pair);
- method public inline operator void plusAssign(kotlin.Pair<java.lang.Long,? extends V>![] pairs);
method public V? put(long key, V value);
method public void putAll(androidx.collection.LongObjectMap<V> from);
- method public void putAll(kotlin.Pair<java.lang.Long,? extends V>![] pairs);
method public V? remove(long key);
method public boolean remove(long key, V value);
method public void removeIf(kotlin.jvm.functions.Function2<? super java.lang.Long,? super V,java.lang.Boolean> predicate);
@@ -1281,11 +1371,8 @@
method public inline operator void minusAssign(K![] keys);
method public inline operator void minusAssign(kotlin.sequences.Sequence<? extends K> keys);
method public inline operator void plusAssign(androidx.collection.ObjectFloatMap<K> from);
- method public inline operator void plusAssign(kotlin.Pair<? extends K,java.lang.Float> pair);
- method public inline operator void plusAssign(kotlin.Pair<? extends K,java.lang.Float>![] pairs);
method public void put(K key, float value);
method public void putAll(androidx.collection.ObjectFloatMap<K> from);
- method public void putAll(kotlin.Pair<? extends K,java.lang.Float>![] pairs);
method public void remove(K key);
method public boolean remove(K key, float value);
method public void removeIf(kotlin.jvm.functions.Function2<? super K,? super java.lang.Float,java.lang.Boolean> predicate);
@@ -1303,11 +1390,8 @@
method public inline operator void minusAssign(K![] keys);
method public inline operator void minusAssign(kotlin.sequences.Sequence<? extends K> keys);
method public inline operator void plusAssign(androidx.collection.ObjectIntMap<K> from);
- method public inline operator void plusAssign(kotlin.Pair<? extends K,java.lang.Integer> pair);
- method public inline operator void plusAssign(kotlin.Pair<? extends K,java.lang.Integer>![] pairs);
method public void put(K key, int value);
method public void putAll(androidx.collection.ObjectIntMap<K> from);
- method public void putAll(kotlin.Pair<? extends K,java.lang.Integer>![] pairs);
method public void remove(K key);
method public boolean remove(K key, int value);
method public void removeIf(kotlin.jvm.functions.Function2<? super K,? super java.lang.Integer,java.lang.Boolean> predicate);
@@ -1377,11 +1461,8 @@
method public inline operator void minusAssign(K![] keys);
method public inline operator void minusAssign(kotlin.sequences.Sequence<? extends K> keys);
method public inline operator void plusAssign(androidx.collection.ObjectLongMap<K> from);
- method public inline operator void plusAssign(kotlin.Pair<? extends K,java.lang.Long> pair);
- method public inline operator void plusAssign(kotlin.Pair<? extends K,java.lang.Long>![] pairs);
method public void put(K key, long value);
method public void putAll(androidx.collection.ObjectLongMap<K> from);
- method public void putAll(kotlin.Pair<? extends K,java.lang.Long>![] pairs);
method public void remove(K key);
method public boolean remove(K key, long value);
method public void removeIf(kotlin.jvm.functions.Function2<? super K,? super java.lang.Long,java.lang.Boolean> predicate);
@@ -1394,6 +1475,8 @@
method public java.util.Map<K,V> asMutableMap();
method public void clear();
method public inline V getOrPut(K key, kotlin.jvm.functions.Function0<? extends V> defaultValue);
+ method public inline operator void minusAssign(androidx.collection.ObjectList<K> keys);
+ method public inline operator void minusAssign(androidx.collection.ScatterSet<K> keys);
method public inline operator void minusAssign(Iterable<? extends K> keys);
method public inline operator void minusAssign(K key);
method public inline operator void minusAssign(K![] keys);
@@ -1420,23 +1503,27 @@
public final class MutableScatterSet<E> extends androidx.collection.ScatterSet<E> {
ctor public MutableScatterSet(optional int initialCapacity);
method public boolean add(E element);
+ method public boolean addAll(androidx.collection.ObjectList<E> elements);
method public boolean addAll(androidx.collection.ScatterSet<E> elements);
method public boolean addAll(E![] elements);
method public boolean addAll(Iterable<? extends E> elements);
method public boolean addAll(kotlin.sequences.Sequence<? extends E> elements);
method public java.util.Set<E> asMutableSet();
method public void clear();
+ method public operator void minusAssign(androidx.collection.ObjectList<E> elements);
method public operator void minusAssign(androidx.collection.ScatterSet<E> elements);
method public operator void minusAssign(E element);
method public operator void minusAssign(E![] elements);
method public operator void minusAssign(Iterable<? extends E> elements);
method public operator void minusAssign(kotlin.sequences.Sequence<? extends E> elements);
+ method public operator void plusAssign(androidx.collection.ObjectList<E> elements);
method public operator void plusAssign(androidx.collection.ScatterSet<E> elements);
method public operator void plusAssign(E element);
method public operator void plusAssign(E![] elements);
method public operator void plusAssign(Iterable<? extends E> elements);
method public operator void plusAssign(kotlin.sequences.Sequence<? extends E> elements);
method public boolean remove(E element);
+ method public boolean removeAll(androidx.collection.ObjectList<E> elements);
method public boolean removeAll(androidx.collection.ScatterSet<E> elements);
method public boolean removeAll(E![] elements);
method public boolean removeAll(Iterable<? extends E> elements);
@@ -1478,9 +1565,17 @@
public final class ObjectFloatMapKt {
method public static <K> androidx.collection.ObjectFloatMap<K> emptyObjectFloatMap();
method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf();
- method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf(kotlin.Pair<? extends K,java.lang.Float>... pairs);
+ method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf(K key1, float value1);
+ method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf(K key1, float value1, K key2, float value2);
+ method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf(K key1, float value1, K key2, float value2, K key3, float value3);
+ method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf(K key1, float value1, K key2, float value2, K key3, float value3, K key4, float value4);
+ method public static <K> androidx.collection.MutableObjectFloatMap<K> mutableObjectFloatMapOf(K key1, float value1, K key2, float value2, K key3, float value3, K key4, float value4, K key5, float value5);
method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMap();
- method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMapOf(kotlin.Pair<? extends K,java.lang.Float>... pairs);
+ method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMapOf(K key1, float value1);
+ method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMapOf(K key1, float value1, K key2, float value2);
+ method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMapOf(K key1, float value1, K key2, float value2, K key3, float value3);
+ method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMapOf(K key1, float value1, K key2, float value2, K key3, float value3, K key4, float value4);
+ method public static <K> androidx.collection.ObjectFloatMap<K> objectFloatMapOf(K key1, float value1, K key2, float value2, K key3, float value3, K key4, float value4, K key5, float value5);
}
public abstract sealed class ObjectIntMap<K> {
@@ -1515,9 +1610,17 @@
public final class ObjectIntMapKt {
method public static <K> androidx.collection.ObjectIntMap<K> emptyObjectIntMap();
method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf();
- method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf(kotlin.Pair<? extends K,java.lang.Integer>... pairs);
+ method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf(K key1, int value1);
+ method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf(K key1, int value1, K key2, int value2);
+ method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf(K key1, int value1, K key2, int value2, K key3, int value3);
+ method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf(K key1, int value1, K key2, int value2, K key3, int value3, K key4, int value4);
+ method public static <K> androidx.collection.MutableObjectIntMap<K> mutableObjectIntMapOf(K key1, int value1, K key2, int value2, K key3, int value3, K key4, int value4, K key5, int value5);
method public static <K> androidx.collection.ObjectIntMap<K> objectIntMap();
- method public static <K> androidx.collection.ObjectIntMap<K> objectIntMapOf(kotlin.Pair<? extends K,java.lang.Integer>... pairs);
+ method public static <K> androidx.collection.ObjectIntMap<K> objectIntMapOf(K key1, int value1);
+ method public static <K> androidx.collection.ObjectIntMap<K> objectIntMapOf(K key1, int value1, K key2, int value2);
+ method public static <K> androidx.collection.ObjectIntMap<K> objectIntMapOf(K key1, int value1, K key2, int value2, K key3, int value3);
+ method public static <K> androidx.collection.ObjectIntMap<K> objectIntMapOf(K key1, int value1, K key2, int value2, K key3, int value3, K key4, int value4);
+ method public static <K> androidx.collection.ObjectIntMap<K> objectIntMapOf(K key1, int value1, K key2, int value2, K key3, int value3, K key4, int value4, K key5, int value5);
}
public abstract sealed class ObjectList<E> {
@@ -1614,39 +1717,17 @@
public final class ObjectLongMapKt {
method public static <K> androidx.collection.ObjectLongMap<K> emptyObjectLongMap();
method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf();
- method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf(kotlin.Pair<? extends K,java.lang.Long>... pairs);
+ method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf(K key1, long value1);
+ method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf(K key1, long value1, K key2, long value2);
+ method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf(K key1, long value1, K key2, long value2, K key3, long value3);
+ method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf(K key1, long value1, K key2, long value2, K key3, long value3, K key4, long value4);
+ method public static <K> androidx.collection.MutableObjectLongMap<K> mutableObjectLongMapOf(K key1, long value1, K key2, long value2, K key3, long value3, K key4, long value4, K key5, long value5);
method public static <K> androidx.collection.ObjectLongMap<K> objectLongMap();
- method public static <K> androidx.collection.ObjectLongMap<K> objectLongMapOf(kotlin.Pair<? extends K,java.lang.Long>... pairs);
- }
-
- @kotlin.jvm.JvmInline public final value class PairFloatFloat {
- ctor public PairFloatFloat(float first, float second);
- method public inline operator float component1();
- method public inline operator float component2();
- method public inline float getFirst();
- method public inline float getSecond();
- property public final inline float first;
- property public final inline float second;
- }
-
- @kotlin.jvm.JvmInline public final value class PairIntInt {
- ctor public PairIntInt(int first, int second);
- method public inline operator int component1();
- method public inline operator int component2();
- method public int getFirst();
- method public int getSecond();
- property public final int first;
- property public final int second;
- }
-
- public final class PairLongLong {
- ctor public PairLongLong(long first, long second);
- method public inline operator long component1();
- method public inline operator long component2();
- method public long getFirst();
- method public long getSecond();
- property public final long first;
- property public final long second;
+ method public static <K> androidx.collection.ObjectLongMap<K> objectLongMapOf(K key1, long value1);
+ method public static <K> androidx.collection.ObjectLongMap<K> objectLongMapOf(K key1, long value1, K key2, long value2);
+ method public static <K> androidx.collection.ObjectLongMap<K> objectLongMapOf(K key1, long value1, K key2, long value2, K key3, long value3);
+ method public static <K> androidx.collection.ObjectLongMap<K> objectLongMapOf(K key1, long value1, K key2, long value2, K key3, long value3, K key4, long value4);
+ method public static <K> androidx.collection.ObjectLongMap<K> objectLongMapOf(K key1, long value1, K key2, long value2, K key3, long value3, K key4, long value4, K key5, long value5);
}
public abstract sealed class ScatterMap<K, V> {
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/FloatFloatMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/FloatFloatMap.kt
index bca375a..0c95647 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/FloatFloatMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/FloatFloatMap.kt
@@ -41,7 +41,6 @@
/**
* Returns an empty, read-only [FloatFloatMap].
*/
-@Suppress("UNCHECKED_CAST")
public fun emptyFloatFloatMap(): FloatFloatMap = EmptyFloatFloatMap
/**
@@ -50,18 +49,87 @@
public fun floatFloatMapOf(): FloatFloatMap = EmptyFloatFloatMap
/**
- * Returns a new [FloatFloatMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Float] key and [Float] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [FloatFloatMap] with [key1] associated with [value1].
*/
-public fun floatFloatMapOf(vararg pairs: Pair<Float, Float>): FloatFloatMap =
- MutableFloatFloatMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun floatFloatMapOf(
+ key1: Float,
+ value1: Float
+): FloatFloatMap = MutableFloatFloatMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [FloatFloatMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun floatFloatMapOf(
+ key1: Float,
+ value1: Float,
+ key2: Float,
+ value2: Float,
+): FloatFloatMap = MutableFloatFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [FloatFloatMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun floatFloatMapOf(
+ key1: Float,
+ value1: Float,
+ key2: Float,
+ value2: Float,
+ key3: Float,
+ value3: Float,
+): FloatFloatMap = MutableFloatFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [FloatFloatMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun floatFloatMapOf(
+ key1: Float,
+ value1: Float,
+ key2: Float,
+ value2: Float,
+ key3: Float,
+ value3: Float,
+ key4: Float,
+ value4: Float,
+): FloatFloatMap = MutableFloatFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [FloatFloatMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun floatFloatMapOf(
+ key1: Float,
+ value1: Float,
+ key2: Float,
+ value2: Float,
+ key3: Float,
+ value3: Float,
+ key4: Float,
+ value4: Float,
+ key5: Float,
+ value5: Float,
+): FloatFloatMap = MutableFloatFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -70,18 +138,87 @@
public fun mutableFloatFloatMapOf(): MutableFloatFloatMap = MutableFloatFloatMap()
/**
- * Returns a new [MutableFloatFloatMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Float] key and [Float] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [MutableFloatFloatMap] with [key1] associated with [value1].
*/
-public fun mutableFloatFloatMapOf(vararg pairs: Pair<Float, Float>): MutableFloatFloatMap =
- MutableFloatFloatMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun mutableFloatFloatMapOf(
+ key1: Float,
+ value1: Float
+): MutableFloatFloatMap = MutableFloatFloatMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutableFloatFloatMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun mutableFloatFloatMapOf(
+ key1: Float,
+ value1: Float,
+ key2: Float,
+ value2: Float,
+): MutableFloatFloatMap = MutableFloatFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableFloatFloatMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun mutableFloatFloatMapOf(
+ key1: Float,
+ value1: Float,
+ key2: Float,
+ value2: Float,
+ key3: Float,
+ value3: Float,
+): MutableFloatFloatMap = MutableFloatFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableFloatFloatMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun mutableFloatFloatMapOf(
+ key1: Float,
+ value1: Float,
+ key2: Float,
+ value2: Float,
+ key3: Float,
+ value3: Float,
+ key4: Float,
+ value4: Float,
+): MutableFloatFloatMap = MutableFloatFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableFloatFloatMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun mutableFloatFloatMapOf(
+ key1: Float,
+ value1: Float,
+ key2: Float,
+ value2: Float,
+ key3: Float,
+ value3: Float,
+ key4: Float,
+ value4: Float,
+ key5: Float,
+ value5: Float,
+): MutableFloatFloatMap = MutableFloatFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +691,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Float] key and [Float] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<Pair<Float, Float>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: FloatFloatMap) {
@@ -577,29 +700,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that [pair] allocated and both the [Float] key and [Float] value are
- * boxed. Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<Float, Float>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Float] key and [Float] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<Pair<Float, Float>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: FloatFloatMap): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/PairFloatFloat.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/FloatFloatPair.kt
similarity index 93%
rename from collection/collection/src/commonMain/kotlin/androidx/collection/PairFloatFloat.kt
rename to collection/collection/src/commonMain/kotlin/androidx/collection/FloatFloatPair.kt
index aac435a..602efb3 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/PairFloatFloat.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/FloatFloatPair.kt
@@ -26,14 +26,14 @@
* *Note*: This class is optimized by using a value class, a Kotlin language featured
* not available from Java code. Java developers can get the same functionality by
* using [Pair] or by constructing a custom implementation using Float parameters
- * directly (see [PairLongLong] for an example).
+ * directly (see [LongLongPair] for an example).
*/
@JvmInline
-public value class PairFloatFloat internal constructor(
+public value class FloatFloatPair internal constructor(
@PublishedApi @JvmField internal val packedValue: Long
) {
/**
- * Constructs a [PairFloatFloat] with two [Float] values.
+ * Constructs a [FloatFloatPair] with two [Float] values.
*
* @param first the first value in the pair
* @param second the second value in the pair
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/FloatIntMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/FloatIntMap.kt
index 29adea3..0dc9f6e 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/FloatIntMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/FloatIntMap.kt
@@ -41,7 +41,6 @@
/**
* Returns an empty, read-only [FloatIntMap].
*/
-@Suppress("UNCHECKED_CAST")
public fun emptyFloatIntMap(): FloatIntMap = EmptyFloatIntMap
/**
@@ -50,18 +49,87 @@
public fun floatIntMapOf(): FloatIntMap = EmptyFloatIntMap
/**
- * Returns a new [FloatIntMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Float] key and [Int] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [FloatIntMap] with [key1] associated with [value1].
*/
-public fun floatIntMapOf(vararg pairs: Pair<Float, Int>): FloatIntMap =
- MutableFloatIntMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun floatIntMapOf(
+ key1: Float,
+ value1: Int
+): FloatIntMap = MutableFloatIntMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [FloatIntMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun floatIntMapOf(
+ key1: Float,
+ value1: Int,
+ key2: Float,
+ value2: Int,
+): FloatIntMap = MutableFloatIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [FloatIntMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun floatIntMapOf(
+ key1: Float,
+ value1: Int,
+ key2: Float,
+ value2: Int,
+ key3: Float,
+ value3: Int,
+): FloatIntMap = MutableFloatIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [FloatIntMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun floatIntMapOf(
+ key1: Float,
+ value1: Int,
+ key2: Float,
+ value2: Int,
+ key3: Float,
+ value3: Int,
+ key4: Float,
+ value4: Int,
+): FloatIntMap = MutableFloatIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [FloatIntMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun floatIntMapOf(
+ key1: Float,
+ value1: Int,
+ key2: Float,
+ value2: Int,
+ key3: Float,
+ value3: Int,
+ key4: Float,
+ value4: Int,
+ key5: Float,
+ value5: Int,
+): FloatIntMap = MutableFloatIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -70,18 +138,87 @@
public fun mutableFloatIntMapOf(): MutableFloatIntMap = MutableFloatIntMap()
/**
- * Returns a new [MutableFloatIntMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Float] key and [Int] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [MutableFloatIntMap] with [key1] associated with [value1].
*/
-public fun mutableFloatIntMapOf(vararg pairs: Pair<Float, Int>): MutableFloatIntMap =
- MutableFloatIntMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun mutableFloatIntMapOf(
+ key1: Float,
+ value1: Int
+): MutableFloatIntMap = MutableFloatIntMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutableFloatIntMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun mutableFloatIntMapOf(
+ key1: Float,
+ value1: Int,
+ key2: Float,
+ value2: Int,
+): MutableFloatIntMap = MutableFloatIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableFloatIntMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun mutableFloatIntMapOf(
+ key1: Float,
+ value1: Int,
+ key2: Float,
+ value2: Int,
+ key3: Float,
+ value3: Int,
+): MutableFloatIntMap = MutableFloatIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableFloatIntMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun mutableFloatIntMapOf(
+ key1: Float,
+ value1: Int,
+ key2: Float,
+ value2: Int,
+ key3: Float,
+ value3: Int,
+ key4: Float,
+ value4: Int,
+): MutableFloatIntMap = MutableFloatIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableFloatIntMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun mutableFloatIntMapOf(
+ key1: Float,
+ value1: Int,
+ key2: Float,
+ value2: Int,
+ key3: Float,
+ value3: Int,
+ key4: Float,
+ value4: Int,
+ key5: Float,
+ value5: Int,
+): MutableFloatIntMap = MutableFloatIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +691,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Float] key and [Int] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<Pair<Float, Int>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: FloatIntMap) {
@@ -577,29 +700,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that [pair] allocated and both the [Float] key and [Int] value are
- * boxed. Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<Float, Int>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Float] key and [Int] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<Pair<Float, Int>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: FloatIntMap): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/FloatLongMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/FloatLongMap.kt
index ac71a3e..6b5bf9f 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/FloatLongMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/FloatLongMap.kt
@@ -41,7 +41,6 @@
/**
* Returns an empty, read-only [FloatLongMap].
*/
-@Suppress("UNCHECKED_CAST")
public fun emptyFloatLongMap(): FloatLongMap = EmptyFloatLongMap
/**
@@ -50,18 +49,87 @@
public fun floatLongMapOf(): FloatLongMap = EmptyFloatLongMap
/**
- * Returns a new [FloatLongMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Float] key and [Long] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [FloatLongMap] with [key1] associated with [value1].
*/
-public fun floatLongMapOf(vararg pairs: Pair<Float, Long>): FloatLongMap =
- MutableFloatLongMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun floatLongMapOf(
+ key1: Float,
+ value1: Long
+): FloatLongMap = MutableFloatLongMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [FloatLongMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun floatLongMapOf(
+ key1: Float,
+ value1: Long,
+ key2: Float,
+ value2: Long,
+): FloatLongMap = MutableFloatLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [FloatLongMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun floatLongMapOf(
+ key1: Float,
+ value1: Long,
+ key2: Float,
+ value2: Long,
+ key3: Float,
+ value3: Long,
+): FloatLongMap = MutableFloatLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [FloatLongMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun floatLongMapOf(
+ key1: Float,
+ value1: Long,
+ key2: Float,
+ value2: Long,
+ key3: Float,
+ value3: Long,
+ key4: Float,
+ value4: Long,
+): FloatLongMap = MutableFloatLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [FloatLongMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun floatLongMapOf(
+ key1: Float,
+ value1: Long,
+ key2: Float,
+ value2: Long,
+ key3: Float,
+ value3: Long,
+ key4: Float,
+ value4: Long,
+ key5: Float,
+ value5: Long,
+): FloatLongMap = MutableFloatLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -70,18 +138,87 @@
public fun mutableFloatLongMapOf(): MutableFloatLongMap = MutableFloatLongMap()
/**
- * Returns a new [MutableFloatLongMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Float] key and [Long] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [MutableFloatLongMap] with [key1] associated with [value1].
*/
-public fun mutableFloatLongMapOf(vararg pairs: Pair<Float, Long>): MutableFloatLongMap =
- MutableFloatLongMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun mutableFloatLongMapOf(
+ key1: Float,
+ value1: Long
+): MutableFloatLongMap = MutableFloatLongMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutableFloatLongMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun mutableFloatLongMapOf(
+ key1: Float,
+ value1: Long,
+ key2: Float,
+ value2: Long,
+): MutableFloatLongMap = MutableFloatLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableFloatLongMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun mutableFloatLongMapOf(
+ key1: Float,
+ value1: Long,
+ key2: Float,
+ value2: Long,
+ key3: Float,
+ value3: Long,
+): MutableFloatLongMap = MutableFloatLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableFloatLongMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun mutableFloatLongMapOf(
+ key1: Float,
+ value1: Long,
+ key2: Float,
+ value2: Long,
+ key3: Float,
+ value3: Long,
+ key4: Float,
+ value4: Long,
+): MutableFloatLongMap = MutableFloatLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableFloatLongMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun mutableFloatLongMapOf(
+ key1: Float,
+ value1: Long,
+ key2: Float,
+ value2: Long,
+ key3: Float,
+ value3: Long,
+ key4: Float,
+ value4: Long,
+ key5: Float,
+ value5: Long,
+): MutableFloatLongMap = MutableFloatLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +691,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Float] key and [Long] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<Pair<Float, Long>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: FloatLongMap) {
@@ -577,29 +700,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that [pair] allocated and both the [Float] key and [Long] value are
- * boxed. Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<Float, Long>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Float] key and [Long] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<Pair<Float, Long>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: FloatLongMap): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/FloatObjectMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/FloatObjectMap.kt
index 292347f..101790d 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/FloatObjectMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/FloatObjectMap.kt
@@ -52,18 +52,87 @@
public fun <V> floatObjectMapOf(): FloatObjectMap<V> = EmptyFloatObjectMap as FloatObjectMap<V>
/**
- * Returns a new [FloatObjectMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Float] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [FloatObjectMap] with [key1] associated with [value1].
*/
-public fun <V> floatObjectMapOf(vararg pairs: Pair<Float, V>): FloatObjectMap<V> =
- MutableFloatObjectMap<V>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <V> floatObjectMapOf(
+ key1: Float,
+ value1: V
+): FloatObjectMap<V> = MutableFloatObjectMap<V>().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [FloatObjectMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun <V> floatObjectMapOf(
+ key1: Float,
+ value1: V,
+ key2: Float,
+ value2: V,
+): FloatObjectMap<V> = MutableFloatObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [FloatObjectMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun <V> floatObjectMapOf(
+ key1: Float,
+ value1: V,
+ key2: Float,
+ value2: V,
+ key3: Float,
+ value3: V,
+): FloatObjectMap<V> = MutableFloatObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [FloatObjectMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <V> floatObjectMapOf(
+ key1: Float,
+ value1: V,
+ key2: Float,
+ value2: V,
+ key3: Float,
+ value3: V,
+ key4: Float,
+ value4: V,
+): FloatObjectMap<V> = MutableFloatObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [FloatObjectMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <V> floatObjectMapOf(
+ key1: Float,
+ value1: V,
+ key2: Float,
+ value2: V,
+ key3: Float,
+ value3: V,
+ key4: Float,
+ value4: V,
+ key5: Float,
+ value5: V,
+): FloatObjectMap<V> = MutableFloatObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -72,18 +141,87 @@
public fun <V> mutableFloatObjectMapOf(): MutableFloatObjectMap<V> = MutableFloatObjectMap()
/**
- * Returns a new [MutableFloatObjectMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Float] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [MutableFloatObjectMap] with [key1] associated with [value1].
*/
-public fun <V> mutableFloatObjectMapOf(vararg pairs: Pair<Float, V>): MutableFloatObjectMap<V> =
- MutableFloatObjectMap<V>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <V> mutableFloatObjectMapOf(
+ key1: Float,
+ value1: V
+): MutableFloatObjectMap<V> = MutableFloatObjectMap<V>().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutableFloatObjectMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun <V> mutableFloatObjectMapOf(
+ key1: Float,
+ value1: V,
+ key2: Float,
+ value2: V,
+): MutableFloatObjectMap<V> = MutableFloatObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableFloatObjectMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun <V> mutableFloatObjectMapOf(
+ key1: Float,
+ value1: V,
+ key2: Float,
+ value2: V,
+ key3: Float,
+ value3: V,
+): MutableFloatObjectMap<V> = MutableFloatObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableFloatObjectMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <V> mutableFloatObjectMapOf(
+ key1: Float,
+ value1: V,
+ key2: Float,
+ value2: V,
+ key3: Float,
+ value3: V,
+ key4: Float,
+ value4: V,
+): MutableFloatObjectMap<V> = MutableFloatObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableFloatObjectMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <V> mutableFloatObjectMapOf(
+ key1: Float,
+ value1: V,
+ key2: Float,
+ value2: V,
+ key3: Float,
+ value3: V,
+ key4: Float,
+ value4: V,
+ key5: Float,
+ value5: V,
+): MutableFloatObjectMap<V> = MutableFloatObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +692,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Float] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<out Pair<Float, V>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: FloatObjectMap<V>) {
@@ -577,29 +701,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that the [Pair] is allocated and the [Float] key is boxed.
- * Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<Float, V>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Float] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<out Pair<Float, V>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: FloatObjectMap<V>): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/IntFloatMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/IntFloatMap.kt
index b9151ff7..a95dc1a 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/IntFloatMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/IntFloatMap.kt
@@ -41,7 +41,6 @@
/**
* Returns an empty, read-only [IntFloatMap].
*/
-@Suppress("UNCHECKED_CAST")
public fun emptyIntFloatMap(): IntFloatMap = EmptyIntFloatMap
/**
@@ -50,18 +49,87 @@
public fun intFloatMapOf(): IntFloatMap = EmptyIntFloatMap
/**
- * Returns a new [IntFloatMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Int] key and [Float] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [IntFloatMap] with [key1] associated with [value1].
*/
-public fun intFloatMapOf(vararg pairs: Pair<Int, Float>): IntFloatMap =
- MutableIntFloatMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun intFloatMapOf(
+ key1: Int,
+ value1: Float
+): IntFloatMap = MutableIntFloatMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [IntFloatMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun intFloatMapOf(
+ key1: Int,
+ value1: Float,
+ key2: Int,
+ value2: Float,
+): IntFloatMap = MutableIntFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [IntFloatMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun intFloatMapOf(
+ key1: Int,
+ value1: Float,
+ key2: Int,
+ value2: Float,
+ key3: Int,
+ value3: Float,
+): IntFloatMap = MutableIntFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [IntFloatMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun intFloatMapOf(
+ key1: Int,
+ value1: Float,
+ key2: Int,
+ value2: Float,
+ key3: Int,
+ value3: Float,
+ key4: Int,
+ value4: Float,
+): IntFloatMap = MutableIntFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [IntFloatMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun intFloatMapOf(
+ key1: Int,
+ value1: Float,
+ key2: Int,
+ value2: Float,
+ key3: Int,
+ value3: Float,
+ key4: Int,
+ value4: Float,
+ key5: Int,
+ value5: Float,
+): IntFloatMap = MutableIntFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -70,18 +138,87 @@
public fun mutableIntFloatMapOf(): MutableIntFloatMap = MutableIntFloatMap()
/**
- * Returns a new [MutableIntFloatMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Int] key and [Float] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [MutableIntFloatMap] with [key1] associated with [value1].
*/
-public fun mutableIntFloatMapOf(vararg pairs: Pair<Int, Float>): MutableIntFloatMap =
- MutableIntFloatMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun mutableIntFloatMapOf(
+ key1: Int,
+ value1: Float
+): MutableIntFloatMap = MutableIntFloatMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutableIntFloatMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun mutableIntFloatMapOf(
+ key1: Int,
+ value1: Float,
+ key2: Int,
+ value2: Float,
+): MutableIntFloatMap = MutableIntFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableIntFloatMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun mutableIntFloatMapOf(
+ key1: Int,
+ value1: Float,
+ key2: Int,
+ value2: Float,
+ key3: Int,
+ value3: Float,
+): MutableIntFloatMap = MutableIntFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableIntFloatMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun mutableIntFloatMapOf(
+ key1: Int,
+ value1: Float,
+ key2: Int,
+ value2: Float,
+ key3: Int,
+ value3: Float,
+ key4: Int,
+ value4: Float,
+): MutableIntFloatMap = MutableIntFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableIntFloatMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun mutableIntFloatMapOf(
+ key1: Int,
+ value1: Float,
+ key2: Int,
+ value2: Float,
+ key3: Int,
+ value3: Float,
+ key4: Int,
+ value4: Float,
+ key5: Int,
+ value5: Float,
+): MutableIntFloatMap = MutableIntFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +691,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Int] key and [Float] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<Pair<Int, Float>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: IntFloatMap) {
@@ -577,29 +700,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that [pair] allocated and both the [Int] key and [Float] value are
- * boxed. Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<Int, Float>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Int] key and [Float] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<Pair<Int, Float>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: IntFloatMap): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/IntIntMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/IntIntMap.kt
index 5d288b2..4984f29 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/IntIntMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/IntIntMap.kt
@@ -41,7 +41,6 @@
/**
* Returns an empty, read-only [IntIntMap].
*/
-@Suppress("UNCHECKED_CAST")
public fun emptyIntIntMap(): IntIntMap = EmptyIntIntMap
/**
@@ -50,18 +49,87 @@
public fun intIntMapOf(): IntIntMap = EmptyIntIntMap
/**
- * Returns a new [IntIntMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Int] key and [Int] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [IntIntMap] with [key1] associated with [value1].
*/
-public fun intIntMapOf(vararg pairs: Pair<Int, Int>): IntIntMap =
- MutableIntIntMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun intIntMapOf(
+ key1: Int,
+ value1: Int
+): IntIntMap = MutableIntIntMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [IntIntMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun intIntMapOf(
+ key1: Int,
+ value1: Int,
+ key2: Int,
+ value2: Int,
+): IntIntMap = MutableIntIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [IntIntMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun intIntMapOf(
+ key1: Int,
+ value1: Int,
+ key2: Int,
+ value2: Int,
+ key3: Int,
+ value3: Int,
+): IntIntMap = MutableIntIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [IntIntMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun intIntMapOf(
+ key1: Int,
+ value1: Int,
+ key2: Int,
+ value2: Int,
+ key3: Int,
+ value3: Int,
+ key4: Int,
+ value4: Int,
+): IntIntMap = MutableIntIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [IntIntMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun intIntMapOf(
+ key1: Int,
+ value1: Int,
+ key2: Int,
+ value2: Int,
+ key3: Int,
+ value3: Int,
+ key4: Int,
+ value4: Int,
+ key5: Int,
+ value5: Int,
+): IntIntMap = MutableIntIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -70,18 +138,87 @@
public fun mutableIntIntMapOf(): MutableIntIntMap = MutableIntIntMap()
/**
- * Returns a new [MutableIntIntMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Int] key and [Int] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [MutableIntIntMap] with [key1] associated with [value1].
*/
-public fun mutableIntIntMapOf(vararg pairs: Pair<Int, Int>): MutableIntIntMap =
- MutableIntIntMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun mutableIntIntMapOf(
+ key1: Int,
+ value1: Int
+): MutableIntIntMap = MutableIntIntMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutableIntIntMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun mutableIntIntMapOf(
+ key1: Int,
+ value1: Int,
+ key2: Int,
+ value2: Int,
+): MutableIntIntMap = MutableIntIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableIntIntMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun mutableIntIntMapOf(
+ key1: Int,
+ value1: Int,
+ key2: Int,
+ value2: Int,
+ key3: Int,
+ value3: Int,
+): MutableIntIntMap = MutableIntIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableIntIntMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun mutableIntIntMapOf(
+ key1: Int,
+ value1: Int,
+ key2: Int,
+ value2: Int,
+ key3: Int,
+ value3: Int,
+ key4: Int,
+ value4: Int,
+): MutableIntIntMap = MutableIntIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableIntIntMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun mutableIntIntMapOf(
+ key1: Int,
+ value1: Int,
+ key2: Int,
+ value2: Int,
+ key3: Int,
+ value3: Int,
+ key4: Int,
+ value4: Int,
+ key5: Int,
+ value5: Int,
+): MutableIntIntMap = MutableIntIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +691,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Int] key and [Int] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<Pair<Int, Int>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: IntIntMap) {
@@ -577,29 +700,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that [pair] allocated and both the [Int] key and [Int] value are
- * boxed. Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<Int, Int>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Int] key and [Int] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<Pair<Int, Int>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: IntIntMap): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/PairIntInt.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/IntIntPair.kt
similarity index 94%
rename from collection/collection/src/commonMain/kotlin/androidx/collection/PairIntInt.kt
rename to collection/collection/src/commonMain/kotlin/androidx/collection/IntIntPair.kt
index 0c7df8f..f192d1e 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/PairIntInt.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/IntIntPair.kt
@@ -26,14 +26,14 @@
* *Note*: This class is optimized by using a value class, a Kotlin language featured
* not available from Java code. Java developers can get the same functionality by
* using [Pair] or by constructing a custom implementation using Int parameters
- * directly (see [PairLongLong] for an example).
+ * directly (see [LongLongPair] for an example).
*/
@JvmInline
-public value class PairIntInt internal constructor(
+public value class IntIntPair internal constructor(
@PublishedApi @JvmField internal val packedValue: Long
) {
/**
- * Constructs a [PairIntInt] with two [Int] values.
+ * Constructs a [IntIntPair] with two [Int] values.
*
* @param first the first value in the pair
* @param second the second value in the pair
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/IntLongMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/IntLongMap.kt
index ce4455a..4812905 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/IntLongMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/IntLongMap.kt
@@ -41,7 +41,6 @@
/**
* Returns an empty, read-only [IntLongMap].
*/
-@Suppress("UNCHECKED_CAST")
public fun emptyIntLongMap(): IntLongMap = EmptyIntLongMap
/**
@@ -50,18 +49,87 @@
public fun intLongMapOf(): IntLongMap = EmptyIntLongMap
/**
- * Returns a new [IntLongMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Int] key and [Long] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [IntLongMap] with [key1] associated with [value1].
*/
-public fun intLongMapOf(vararg pairs: Pair<Int, Long>): IntLongMap =
- MutableIntLongMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun intLongMapOf(
+ key1: Int,
+ value1: Long
+): IntLongMap = MutableIntLongMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [IntLongMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun intLongMapOf(
+ key1: Int,
+ value1: Long,
+ key2: Int,
+ value2: Long,
+): IntLongMap = MutableIntLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [IntLongMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun intLongMapOf(
+ key1: Int,
+ value1: Long,
+ key2: Int,
+ value2: Long,
+ key3: Int,
+ value3: Long,
+): IntLongMap = MutableIntLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [IntLongMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun intLongMapOf(
+ key1: Int,
+ value1: Long,
+ key2: Int,
+ value2: Long,
+ key3: Int,
+ value3: Long,
+ key4: Int,
+ value4: Long,
+): IntLongMap = MutableIntLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [IntLongMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun intLongMapOf(
+ key1: Int,
+ value1: Long,
+ key2: Int,
+ value2: Long,
+ key3: Int,
+ value3: Long,
+ key4: Int,
+ value4: Long,
+ key5: Int,
+ value5: Long,
+): IntLongMap = MutableIntLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -70,18 +138,87 @@
public fun mutableIntLongMapOf(): MutableIntLongMap = MutableIntLongMap()
/**
- * Returns a new [MutableIntLongMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Int] key and [Long] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [MutableIntLongMap] with [key1] associated with [value1].
*/
-public fun mutableIntLongMapOf(vararg pairs: Pair<Int, Long>): MutableIntLongMap =
- MutableIntLongMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun mutableIntLongMapOf(
+ key1: Int,
+ value1: Long
+): MutableIntLongMap = MutableIntLongMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutableIntLongMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun mutableIntLongMapOf(
+ key1: Int,
+ value1: Long,
+ key2: Int,
+ value2: Long,
+): MutableIntLongMap = MutableIntLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableIntLongMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun mutableIntLongMapOf(
+ key1: Int,
+ value1: Long,
+ key2: Int,
+ value2: Long,
+ key3: Int,
+ value3: Long,
+): MutableIntLongMap = MutableIntLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableIntLongMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun mutableIntLongMapOf(
+ key1: Int,
+ value1: Long,
+ key2: Int,
+ value2: Long,
+ key3: Int,
+ value3: Long,
+ key4: Int,
+ value4: Long,
+): MutableIntLongMap = MutableIntLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableIntLongMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun mutableIntLongMapOf(
+ key1: Int,
+ value1: Long,
+ key2: Int,
+ value2: Long,
+ key3: Int,
+ value3: Long,
+ key4: Int,
+ value4: Long,
+ key5: Int,
+ value5: Long,
+): MutableIntLongMap = MutableIntLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +691,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Int] key and [Long] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<Pair<Int, Long>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: IntLongMap) {
@@ -577,29 +700,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that [pair] allocated and both the [Int] key and [Long] value are
- * boxed. Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<Int, Long>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Int] key and [Long] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<Pair<Int, Long>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: IntLongMap): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/IntObjectMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/IntObjectMap.kt
index 1626d89..7ed1e7e 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/IntObjectMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/IntObjectMap.kt
@@ -52,18 +52,87 @@
public fun <V> intObjectMapOf(): IntObjectMap<V> = EmptyIntObjectMap as IntObjectMap<V>
/**
- * Returns a new [IntObjectMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Int] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [IntObjectMap] with [key1] associated with [value1].
*/
-public fun <V> intObjectMapOf(vararg pairs: Pair<Int, V>): IntObjectMap<V> =
- MutableIntObjectMap<V>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <V> intObjectMapOf(
+ key1: Int,
+ value1: V
+): IntObjectMap<V> = MutableIntObjectMap<V>().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [IntObjectMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun <V> intObjectMapOf(
+ key1: Int,
+ value1: V,
+ key2: Int,
+ value2: V,
+): IntObjectMap<V> = MutableIntObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [IntObjectMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun <V> intObjectMapOf(
+ key1: Int,
+ value1: V,
+ key2: Int,
+ value2: V,
+ key3: Int,
+ value3: V,
+): IntObjectMap<V> = MutableIntObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [IntObjectMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <V> intObjectMapOf(
+ key1: Int,
+ value1: V,
+ key2: Int,
+ value2: V,
+ key3: Int,
+ value3: V,
+ key4: Int,
+ value4: V,
+): IntObjectMap<V> = MutableIntObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [IntObjectMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <V> intObjectMapOf(
+ key1: Int,
+ value1: V,
+ key2: Int,
+ value2: V,
+ key3: Int,
+ value3: V,
+ key4: Int,
+ value4: V,
+ key5: Int,
+ value5: V,
+): IntObjectMap<V> = MutableIntObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -72,18 +141,87 @@
public fun <V> mutableIntObjectMapOf(): MutableIntObjectMap<V> = MutableIntObjectMap()
/**
- * Returns a new [MutableIntObjectMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Int] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [MutableIntObjectMap] with [key1] associated with [value1].
*/
-public fun <V> mutableIntObjectMapOf(vararg pairs: Pair<Int, V>): MutableIntObjectMap<V> =
- MutableIntObjectMap<V>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <V> mutableIntObjectMapOf(
+ key1: Int,
+ value1: V
+): MutableIntObjectMap<V> = MutableIntObjectMap<V>().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutableIntObjectMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun <V> mutableIntObjectMapOf(
+ key1: Int,
+ value1: V,
+ key2: Int,
+ value2: V,
+): MutableIntObjectMap<V> = MutableIntObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableIntObjectMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun <V> mutableIntObjectMapOf(
+ key1: Int,
+ value1: V,
+ key2: Int,
+ value2: V,
+ key3: Int,
+ value3: V,
+): MutableIntObjectMap<V> = MutableIntObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableIntObjectMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <V> mutableIntObjectMapOf(
+ key1: Int,
+ value1: V,
+ key2: Int,
+ value2: V,
+ key3: Int,
+ value3: V,
+ key4: Int,
+ value4: V,
+): MutableIntObjectMap<V> = MutableIntObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableIntObjectMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <V> mutableIntObjectMapOf(
+ key1: Int,
+ value1: V,
+ key2: Int,
+ value2: V,
+ key3: Int,
+ value3: V,
+ key4: Int,
+ value4: V,
+ key5: Int,
+ value5: V,
+): MutableIntObjectMap<V> = MutableIntObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +692,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Int] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<out Pair<Int, V>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: IntObjectMap<V>) {
@@ -577,29 +701,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that the [Pair] is allocated and the [Int] key is boxed.
- * Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<Int, V>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Int] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<out Pair<Int, V>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: IntObjectMap<V>): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/LongFloatMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/LongFloatMap.kt
index 797b7fb..f9eb698 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/LongFloatMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/LongFloatMap.kt
@@ -41,7 +41,6 @@
/**
* Returns an empty, read-only [LongFloatMap].
*/
-@Suppress("UNCHECKED_CAST")
public fun emptyLongFloatMap(): LongFloatMap = EmptyLongFloatMap
/**
@@ -50,18 +49,87 @@
public fun longFloatMapOf(): LongFloatMap = EmptyLongFloatMap
/**
- * Returns a new [LongFloatMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Long] key and [Float] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [LongFloatMap] with [key1] associated with [value1].
*/
-public fun longFloatMapOf(vararg pairs: Pair<Long, Float>): LongFloatMap =
- MutableLongFloatMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun longFloatMapOf(
+ key1: Long,
+ value1: Float
+): LongFloatMap = MutableLongFloatMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [LongFloatMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun longFloatMapOf(
+ key1: Long,
+ value1: Float,
+ key2: Long,
+ value2: Float,
+): LongFloatMap = MutableLongFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [LongFloatMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun longFloatMapOf(
+ key1: Long,
+ value1: Float,
+ key2: Long,
+ value2: Float,
+ key3: Long,
+ value3: Float,
+): LongFloatMap = MutableLongFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [LongFloatMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun longFloatMapOf(
+ key1: Long,
+ value1: Float,
+ key2: Long,
+ value2: Float,
+ key3: Long,
+ value3: Float,
+ key4: Long,
+ value4: Float,
+): LongFloatMap = MutableLongFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [LongFloatMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun longFloatMapOf(
+ key1: Long,
+ value1: Float,
+ key2: Long,
+ value2: Float,
+ key3: Long,
+ value3: Float,
+ key4: Long,
+ value4: Float,
+ key5: Long,
+ value5: Float,
+): LongFloatMap = MutableLongFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -70,18 +138,87 @@
public fun mutableLongFloatMapOf(): MutableLongFloatMap = MutableLongFloatMap()
/**
- * Returns a new [MutableLongFloatMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Long] key and [Float] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [MutableLongFloatMap] with [key1] associated with [value1].
*/
-public fun mutableLongFloatMapOf(vararg pairs: Pair<Long, Float>): MutableLongFloatMap =
- MutableLongFloatMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun mutableLongFloatMapOf(
+ key1: Long,
+ value1: Float
+): MutableLongFloatMap = MutableLongFloatMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutableLongFloatMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun mutableLongFloatMapOf(
+ key1: Long,
+ value1: Float,
+ key2: Long,
+ value2: Float,
+): MutableLongFloatMap = MutableLongFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableLongFloatMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun mutableLongFloatMapOf(
+ key1: Long,
+ value1: Float,
+ key2: Long,
+ value2: Float,
+ key3: Long,
+ value3: Float,
+): MutableLongFloatMap = MutableLongFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableLongFloatMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun mutableLongFloatMapOf(
+ key1: Long,
+ value1: Float,
+ key2: Long,
+ value2: Float,
+ key3: Long,
+ value3: Float,
+ key4: Long,
+ value4: Float,
+): MutableLongFloatMap = MutableLongFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableLongFloatMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun mutableLongFloatMapOf(
+ key1: Long,
+ value1: Float,
+ key2: Long,
+ value2: Float,
+ key3: Long,
+ value3: Float,
+ key4: Long,
+ value4: Float,
+ key5: Long,
+ value5: Float,
+): MutableLongFloatMap = MutableLongFloatMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +691,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Long] key and [Float] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<Pair<Long, Float>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: LongFloatMap) {
@@ -577,29 +700,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that [pair] allocated and both the [Long] key and [Float] value are
- * boxed. Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<Long, Float>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Long] key and [Float] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<Pair<Long, Float>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: LongFloatMap): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/LongIntMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/LongIntMap.kt
index c9c5ef6..082b076 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/LongIntMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/LongIntMap.kt
@@ -41,7 +41,6 @@
/**
* Returns an empty, read-only [LongIntMap].
*/
-@Suppress("UNCHECKED_CAST")
public fun emptyLongIntMap(): LongIntMap = EmptyLongIntMap
/**
@@ -50,18 +49,87 @@
public fun longIntMapOf(): LongIntMap = EmptyLongIntMap
/**
- * Returns a new [LongIntMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Long] key and [Int] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [LongIntMap] with [key1] associated with [value1].
*/
-public fun longIntMapOf(vararg pairs: Pair<Long, Int>): LongIntMap =
- MutableLongIntMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun longIntMapOf(
+ key1: Long,
+ value1: Int
+): LongIntMap = MutableLongIntMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [LongIntMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun longIntMapOf(
+ key1: Long,
+ value1: Int,
+ key2: Long,
+ value2: Int,
+): LongIntMap = MutableLongIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [LongIntMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun longIntMapOf(
+ key1: Long,
+ value1: Int,
+ key2: Long,
+ value2: Int,
+ key3: Long,
+ value3: Int,
+): LongIntMap = MutableLongIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [LongIntMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun longIntMapOf(
+ key1: Long,
+ value1: Int,
+ key2: Long,
+ value2: Int,
+ key3: Long,
+ value3: Int,
+ key4: Long,
+ value4: Int,
+): LongIntMap = MutableLongIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [LongIntMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun longIntMapOf(
+ key1: Long,
+ value1: Int,
+ key2: Long,
+ value2: Int,
+ key3: Long,
+ value3: Int,
+ key4: Long,
+ value4: Int,
+ key5: Long,
+ value5: Int,
+): LongIntMap = MutableLongIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -70,18 +138,87 @@
public fun mutableLongIntMapOf(): MutableLongIntMap = MutableLongIntMap()
/**
- * Returns a new [MutableLongIntMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Long] key and [Int] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [MutableLongIntMap] with [key1] associated with [value1].
*/
-public fun mutableLongIntMapOf(vararg pairs: Pair<Long, Int>): MutableLongIntMap =
- MutableLongIntMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun mutableLongIntMapOf(
+ key1: Long,
+ value1: Int
+): MutableLongIntMap = MutableLongIntMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutableLongIntMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun mutableLongIntMapOf(
+ key1: Long,
+ value1: Int,
+ key2: Long,
+ value2: Int,
+): MutableLongIntMap = MutableLongIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableLongIntMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun mutableLongIntMapOf(
+ key1: Long,
+ value1: Int,
+ key2: Long,
+ value2: Int,
+ key3: Long,
+ value3: Int,
+): MutableLongIntMap = MutableLongIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableLongIntMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun mutableLongIntMapOf(
+ key1: Long,
+ value1: Int,
+ key2: Long,
+ value2: Int,
+ key3: Long,
+ value3: Int,
+ key4: Long,
+ value4: Int,
+): MutableLongIntMap = MutableLongIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableLongIntMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun mutableLongIntMapOf(
+ key1: Long,
+ value1: Int,
+ key2: Long,
+ value2: Int,
+ key3: Long,
+ value3: Int,
+ key4: Long,
+ value4: Int,
+ key5: Long,
+ value5: Int,
+): MutableLongIntMap = MutableLongIntMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +691,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Long] key and [Int] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<Pair<Long, Int>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: LongIntMap) {
@@ -577,29 +700,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that [pair] allocated and both the [Long] key and [Int] value are
- * boxed. Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<Long, Int>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Long] key and [Int] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<Pair<Long, Int>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: LongIntMap): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/LongLongMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/LongLongMap.kt
index e61a7a0..bc18e9b 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/LongLongMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/LongLongMap.kt
@@ -41,7 +41,6 @@
/**
* Returns an empty, read-only [LongLongMap].
*/
-@Suppress("UNCHECKED_CAST")
public fun emptyLongLongMap(): LongLongMap = EmptyLongLongMap
/**
@@ -50,18 +49,87 @@
public fun longLongMapOf(): LongLongMap = EmptyLongLongMap
/**
- * Returns a new [LongLongMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Long] key and [Long] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [LongLongMap] with [key1] associated with [value1].
*/
-public fun longLongMapOf(vararg pairs: Pair<Long, Long>): LongLongMap =
- MutableLongLongMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun longLongMapOf(
+ key1: Long,
+ value1: Long
+): LongLongMap = MutableLongLongMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [LongLongMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun longLongMapOf(
+ key1: Long,
+ value1: Long,
+ key2: Long,
+ value2: Long,
+): LongLongMap = MutableLongLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [LongLongMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun longLongMapOf(
+ key1: Long,
+ value1: Long,
+ key2: Long,
+ value2: Long,
+ key3: Long,
+ value3: Long,
+): LongLongMap = MutableLongLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [LongLongMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun longLongMapOf(
+ key1: Long,
+ value1: Long,
+ key2: Long,
+ value2: Long,
+ key3: Long,
+ value3: Long,
+ key4: Long,
+ value4: Long,
+): LongLongMap = MutableLongLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [LongLongMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun longLongMapOf(
+ key1: Long,
+ value1: Long,
+ key2: Long,
+ value2: Long,
+ key3: Long,
+ value3: Long,
+ key4: Long,
+ value4: Long,
+ key5: Long,
+ value5: Long,
+): LongLongMap = MutableLongLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -70,18 +138,87 @@
public fun mutableLongLongMapOf(): MutableLongLongMap = MutableLongLongMap()
/**
- * Returns a new [MutableLongLongMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Long] key and [Long] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [MutableLongLongMap] with [key1] associated with [value1].
*/
-public fun mutableLongLongMapOf(vararg pairs: Pair<Long, Long>): MutableLongLongMap =
- MutableLongLongMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun mutableLongLongMapOf(
+ key1: Long,
+ value1: Long
+): MutableLongLongMap = MutableLongLongMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutableLongLongMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun mutableLongLongMapOf(
+ key1: Long,
+ value1: Long,
+ key2: Long,
+ value2: Long,
+): MutableLongLongMap = MutableLongLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableLongLongMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun mutableLongLongMapOf(
+ key1: Long,
+ value1: Long,
+ key2: Long,
+ value2: Long,
+ key3: Long,
+ value3: Long,
+): MutableLongLongMap = MutableLongLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableLongLongMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun mutableLongLongMapOf(
+ key1: Long,
+ value1: Long,
+ key2: Long,
+ value2: Long,
+ key3: Long,
+ value3: Long,
+ key4: Long,
+ value4: Long,
+): MutableLongLongMap = MutableLongLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableLongLongMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun mutableLongLongMapOf(
+ key1: Long,
+ value1: Long,
+ key2: Long,
+ value2: Long,
+ key3: Long,
+ value3: Long,
+ key4: Long,
+ value4: Long,
+ key5: Long,
+ value5: Long,
+): MutableLongLongMap = MutableLongLongMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +691,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Long] key and [Long] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<Pair<Long, Long>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: LongLongMap) {
@@ -577,29 +700,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that [pair] allocated and both the [Long] key and [Long] value are
- * boxed. Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<Long, Long>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [Long] key and [Long] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<Pair<Long, Long>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: LongLongMap): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/PairLongLong.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/LongLongPair.kt
similarity index 87%
rename from collection/collection/src/commonMain/kotlin/androidx/collection/PairLongLong.kt
rename to collection/collection/src/commonMain/kotlin/androidx/collection/LongLongPair.kt
index 7184f9a..ce84157 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/PairLongLong.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/LongLongPair.kt
@@ -23,7 +23,7 @@
* @param first the first value in the pair
* @param second the second value in the pair
*/
-public class PairLongLong public constructor(public val first: Long, public val second: Long) {
+public class LongLongPair public constructor(public val first: Long, public val second: Long) {
/**
* Returns the [first] component of the pair. For instance, the first component
* of `PairLongLong(3, 4)` is `3`.
@@ -51,11 +51,11 @@
/**
* Checks the two values for equality.
*
- * @param other the [PairLongLong] to which this one is to be checked for equality
- * @return true if the underlying values of the [PairLongLong] are both considered equal
+ * @param other the [LongLongPair] to which this one is to be checked for equality
+ * @return true if the underlying values of the [LongLongPair] are both considered equal
*/
override fun equals(other: Any?): Boolean {
- if (!(other is PairLongLong)) {
+ if (!(other is LongLongPair)) {
return false
}
return other.first == first && other.second == second
@@ -64,7 +64,7 @@
/**
* Compute a hash code using the hash codes of the underlying values
*
- * @return a hashcode of the [PairLongLong]
+ * @return a hashcode of the [LongLongPair]
*/
override fun hashCode(): Int {
return first.hashCode() xor second.hashCode()
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/LongObjectMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/LongObjectMap.kt
index f01c754..7d8ae9f 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/LongObjectMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/LongObjectMap.kt
@@ -52,18 +52,87 @@
public fun <V> longObjectMapOf(): LongObjectMap<V> = EmptyLongObjectMap as LongObjectMap<V>
/**
- * Returns a new [LongObjectMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Long] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [LongObjectMap] with [key1] associated with [value1].
*/
-public fun <V> longObjectMapOf(vararg pairs: Pair<Long, V>): LongObjectMap<V> =
- MutableLongObjectMap<V>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <V> longObjectMapOf(
+ key1: Long,
+ value1: V
+): LongObjectMap<V> = MutableLongObjectMap<V>().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [LongObjectMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun <V> longObjectMapOf(
+ key1: Long,
+ value1: V,
+ key2: Long,
+ value2: V,
+): LongObjectMap<V> = MutableLongObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [LongObjectMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun <V> longObjectMapOf(
+ key1: Long,
+ value1: V,
+ key2: Long,
+ value2: V,
+ key3: Long,
+ value3: V,
+): LongObjectMap<V> = MutableLongObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [LongObjectMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <V> longObjectMapOf(
+ key1: Long,
+ value1: V,
+ key2: Long,
+ value2: V,
+ key3: Long,
+ value3: V,
+ key4: Long,
+ value4: V,
+): LongObjectMap<V> = MutableLongObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [LongObjectMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <V> longObjectMapOf(
+ key1: Long,
+ value1: V,
+ key2: Long,
+ value2: V,
+ key3: Long,
+ value3: V,
+ key4: Long,
+ value4: V,
+ key5: Long,
+ value5: V,
+): LongObjectMap<V> = MutableLongObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -72,18 +141,87 @@
public fun <V> mutableLongObjectMapOf(): MutableLongObjectMap<V> = MutableLongObjectMap()
/**
- * Returns a new [MutableLongObjectMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Long] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [MutableLongObjectMap] with [key1] associated with [value1].
*/
-public fun <V> mutableLongObjectMapOf(vararg pairs: Pair<Long, V>): MutableLongObjectMap<V> =
- MutableLongObjectMap<V>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <V> mutableLongObjectMapOf(
+ key1: Long,
+ value1: V
+): MutableLongObjectMap<V> = MutableLongObjectMap<V>().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutableLongObjectMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun <V> mutableLongObjectMapOf(
+ key1: Long,
+ value1: V,
+ key2: Long,
+ value2: V,
+): MutableLongObjectMap<V> = MutableLongObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableLongObjectMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun <V> mutableLongObjectMapOf(
+ key1: Long,
+ value1: V,
+ key2: Long,
+ value2: V,
+ key3: Long,
+ value3: V,
+): MutableLongObjectMap<V> = MutableLongObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableLongObjectMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <V> mutableLongObjectMapOf(
+ key1: Long,
+ value1: V,
+ key2: Long,
+ value2: V,
+ key3: Long,
+ value3: V,
+ key4: Long,
+ value4: V,
+): MutableLongObjectMap<V> = MutableLongObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableLongObjectMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <V> mutableLongObjectMapOf(
+ key1: Long,
+ value1: V,
+ key2: Long,
+ value2: V,
+ key3: Long,
+ value3: V,
+ key4: Long,
+ value4: V,
+ key5: Long,
+ value5: V,
+): MutableLongObjectMap<V> = MutableLongObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +692,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Long] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<out Pair<Long, V>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: LongObjectMap<V>) {
@@ -577,29 +701,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that the [Pair] is allocated and the [Long] key is boxed.
- * Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<Long, V>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Long] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<out Pair<Long, V>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: LongObjectMap<V>): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectFloatMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectFloatMap.kt
index 95c1a3d..8b2b52d 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectFloatMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectFloatMap.kt
@@ -54,38 +54,186 @@
EmptyObjectFloatMap as ObjectFloatMap<K>
/**
- * Returns a new [MutableObjectFloatMap].
+ * Returns a new [ObjectFloatMap] with only [key1] associated with [value1].
+ */
+public fun <K> objectFloatMapOf(
+ key1: K,
+ value1: Float
+): ObjectFloatMap<K> =
+ MutableObjectFloatMap<K>().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [ObjectFloatMap] with only [key1] and [key2] associated with
+ * [value1] and [value2], respectively.
+ */
+public fun <K> objectFloatMapOf(
+ key1: K,
+ value1: Float,
+ key2: K,
+ value2: Float,
+): ObjectFloatMap<K> =
+ MutableObjectFloatMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [ObjectFloatMap] with only [key1], [key2], and [key3] associated with
+ * [value1], [value2], and [value3], respectively.
+ */
+public fun <K> objectFloatMapOf(
+ key1: K,
+ value1: Float,
+ key2: K,
+ value2: Float,
+ key3: K,
+ value3: Float,
+): ObjectFloatMap<K> =
+ MutableObjectFloatMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [ObjectFloatMap] with only [key1], [key2], [key3], and [key4] associated with
+ * [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <K> objectFloatMapOf(
+ key1: K,
+ value1: Float,
+ key2: K,
+ value2: Float,
+ key3: K,
+ value3: Float,
+ key4: K,
+ value4: Float,
+): ObjectFloatMap<K> =
+ MutableObjectFloatMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [ObjectFloatMap] with only [key1], [key2], [key3], [key4], and [key5] associated
+ * with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <K> objectFloatMapOf(
+ key1: K,
+ value1: Float,
+ key2: K,
+ value2: Float,
+ key3: K,
+ value3: Float,
+ key4: K,
+ value4: Float,
+ key5: K,
+ value5: Float,
+): ObjectFloatMap<K> =
+ MutableObjectFloatMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
+ }
+
+/**
+ * Returns a new empty [MutableObjectFloatMap].
*/
public fun <K> mutableObjectFloatMapOf(): MutableObjectFloatMap<K> = MutableObjectFloatMap()
/**
- * Returns a new [MutableObjectFloatMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Float] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [MutableObjectFloatMap] with only [key1] associated with [value1].
*/
-public fun <K> objectFloatMapOf(vararg pairs: Pair<K, Float>): ObjectFloatMap<K> =
- MutableObjectFloatMap<K>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <K> mutableObjectFloatMapOf(
+ key1: K,
+ value1: Float,
+): MutableObjectFloatMap<K> =
+ MutableObjectFloatMap<K>().also { map ->
+ map[key1] = value1
}
/**
- * Returns a new [MutableObjectFloatMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Float] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [MutableObjectFloatMap] with only [key1] and [key2] associated with
+ * [value1] and [value2], respectively.
*/
-public fun <K> mutableObjectFloatMapOf(vararg pairs: Pair<K, Float>): MutableObjectFloatMap<K> =
- MutableObjectFloatMap<K>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <K> mutableObjectFloatMapOf(
+ key1: K,
+ value1: Float,
+ key2: K,
+ value2: Float,
+): MutableObjectFloatMap<K> =
+ MutableObjectFloatMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableObjectFloatMap] with only [key1], [key2], and [key3] associated with
+ * [value1], [value2], and [value3], respectively.
+ */
+public fun <K> mutableObjectFloatMapOf(
+ key1: K,
+ value1: Float,
+ key2: K,
+ value2: Float,
+ key3: K,
+ value3: Float,
+): MutableObjectFloatMap<K> =
+ MutableObjectFloatMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableObjectFloatMap] with only [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <K> mutableObjectFloatMapOf(
+ key1: K,
+ value1: Float,
+ key2: K,
+ value2: Float,
+ key3: K,
+ value3: Float,
+ key4: K,
+ value4: Float,
+): MutableObjectFloatMap<K> =
+ MutableObjectFloatMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableObjectFloatMap] with only [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <K> mutableObjectFloatMapOf(
+ key1: K,
+ value1: Float,
+ key2: K,
+ value2: Float,
+ key3: K,
+ value3: Float,
+ key4: K,
+ value4: Float,
+ key5: K,
+ value5: Float,
+): MutableObjectFloatMap<K> =
+ MutableObjectFloatMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -560,20 +708,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Float] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<out Pair<K, Float>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: ObjectFloatMap<K>) {
@@ -583,29 +717,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that the [Pair] is allocated and the [Float] value is boxed.
- * Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<K, Float>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Float] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<out Pair<K, Float>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: ObjectFloatMap<K>): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectIntMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectIntMap.kt
index 697f1b0..06130a1 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectIntMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectIntMap.kt
@@ -54,38 +54,186 @@
EmptyObjectIntMap as ObjectIntMap<K>
/**
- * Returns a new [MutableObjectIntMap].
+ * Returns a new [ObjectIntMap] with only [key1] associated with [value1].
+ */
+public fun <K> objectIntMapOf(
+ key1: K,
+ value1: Int
+): ObjectIntMap<K> =
+ MutableObjectIntMap<K>().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [ObjectIntMap] with only [key1] and [key2] associated with
+ * [value1] and [value2], respectively.
+ */
+public fun <K> objectIntMapOf(
+ key1: K,
+ value1: Int,
+ key2: K,
+ value2: Int,
+): ObjectIntMap<K> =
+ MutableObjectIntMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [ObjectIntMap] with only [key1], [key2], and [key3] associated with
+ * [value1], [value2], and [value3], respectively.
+ */
+public fun <K> objectIntMapOf(
+ key1: K,
+ value1: Int,
+ key2: K,
+ value2: Int,
+ key3: K,
+ value3: Int,
+): ObjectIntMap<K> =
+ MutableObjectIntMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [ObjectIntMap] with only [key1], [key2], [key3], and [key4] associated with
+ * [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <K> objectIntMapOf(
+ key1: K,
+ value1: Int,
+ key2: K,
+ value2: Int,
+ key3: K,
+ value3: Int,
+ key4: K,
+ value4: Int,
+): ObjectIntMap<K> =
+ MutableObjectIntMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [ObjectIntMap] with only [key1], [key2], [key3], [key4], and [key5] associated
+ * with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <K> objectIntMapOf(
+ key1: K,
+ value1: Int,
+ key2: K,
+ value2: Int,
+ key3: K,
+ value3: Int,
+ key4: K,
+ value4: Int,
+ key5: K,
+ value5: Int,
+): ObjectIntMap<K> =
+ MutableObjectIntMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
+ }
+
+/**
+ * Returns a new empty [MutableObjectIntMap].
*/
public fun <K> mutableObjectIntMapOf(): MutableObjectIntMap<K> = MutableObjectIntMap()
/**
- * Returns a new [MutableObjectIntMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Int] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [MutableObjectIntMap] with only [key1] associated with [value1].
*/
-public fun <K> objectIntMapOf(vararg pairs: Pair<K, Int>): ObjectIntMap<K> =
- MutableObjectIntMap<K>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <K> mutableObjectIntMapOf(
+ key1: K,
+ value1: Int,
+): MutableObjectIntMap<K> =
+ MutableObjectIntMap<K>().also { map ->
+ map[key1] = value1
}
/**
- * Returns a new [MutableObjectIntMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Int] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [MutableObjectIntMap] with only [key1] and [key2] associated with
+ * [value1] and [value2], respectively.
*/
-public fun <K> mutableObjectIntMapOf(vararg pairs: Pair<K, Int>): MutableObjectIntMap<K> =
- MutableObjectIntMap<K>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <K> mutableObjectIntMapOf(
+ key1: K,
+ value1: Int,
+ key2: K,
+ value2: Int,
+): MutableObjectIntMap<K> =
+ MutableObjectIntMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableObjectIntMap] with only [key1], [key2], and [key3] associated with
+ * [value1], [value2], and [value3], respectively.
+ */
+public fun <K> mutableObjectIntMapOf(
+ key1: K,
+ value1: Int,
+ key2: K,
+ value2: Int,
+ key3: K,
+ value3: Int,
+): MutableObjectIntMap<K> =
+ MutableObjectIntMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableObjectIntMap] with only [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <K> mutableObjectIntMapOf(
+ key1: K,
+ value1: Int,
+ key2: K,
+ value2: Int,
+ key3: K,
+ value3: Int,
+ key4: K,
+ value4: Int,
+): MutableObjectIntMap<K> =
+ MutableObjectIntMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableObjectIntMap] with only [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <K> mutableObjectIntMapOf(
+ key1: K,
+ value1: Int,
+ key2: K,
+ value2: Int,
+ key3: K,
+ value3: Int,
+ key4: K,
+ value4: Int,
+ key5: K,
+ value5: Int,
+): MutableObjectIntMap<K> =
+ MutableObjectIntMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -560,20 +708,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Int] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<out Pair<K, Int>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: ObjectIntMap<K>) {
@@ -583,29 +717,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that the [Pair] is allocated and the [Int] value is boxed.
- * Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<K, Int>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Int] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<out Pair<K, Int>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: ObjectIntMap<K>): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectList.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectList.kt
index 105ebaf..fd01faa 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectList.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectList.kt
@@ -36,6 +36,11 @@
* **Note** [List] access is available through [asList] when developers need access to the
* common API.
*
+ * It is best to use this for all internal implementations where a list of reference types
+ * is needed. Use [List] in public API to take advantage of the commonly-used interface.
+ * It is common to use [ObjectList] internally and use [asList] to get a [List] interface
+ * for interacting with public APIs.
+ *
* @see MutableObjectList
* @see FloatList
* @see IntList
@@ -118,12 +123,7 @@
* Returns `true` if the [ObjectList] contains [element] or `false` otherwise.
*/
public operator fun contains(element: E): Boolean {
- forEach {
- if (it == element) {
- return true
- }
- }
- return false
+ return indexOf(element) >= 0
}
/**
@@ -391,9 +391,21 @@
* Returns the index of [element] in the [ObjectList] or `-1` if [element] is not there.
*/
public fun indexOf(element: E): Int {
- forEachIndexed { i, item ->
- if (element == item) {
- return i
+ // Comparing with == for each element is slower than comparing with .equals().
+ // We split the iteration for null and for non-null to speed it up.
+ // See ObjectListBenchmarkTest.contains()
+ if (element == null) {
+ forEachIndexed { i, item ->
+ if (item == null) {
+ return i
+ }
+ }
+ } else {
+ forEachIndexed { i, item ->
+ @Suppress("ReplaceCallWithBinaryOperator")
+ if (element.equals(item)) {
+ return i
+ }
}
}
return -1
@@ -489,9 +501,21 @@
* [element] or `-1` if no elements match.
*/
public fun lastIndexOf(element: E): Int {
- forEachReversedIndexed { i, item ->
- if (element == item) {
- return i
+ // Comparing with == for each element is slower than comparing with .equals().
+ // We split the iteration for null and for non-null to speed it up.
+ // See ObjectListBenchmarkTest.contains()
+ if (element == null) {
+ forEachReversedIndexed { i, item ->
+ if (item == null) {
+ return i
+ }
+ }
+ } else {
+ forEachReversedIndexed { i, item ->
+ @Suppress("ReplaceCallWithBinaryOperator")
+ if (element.equals(item)) {
+ return i
+ }
}
}
return -1
@@ -575,6 +599,11 @@
* **Note** [MutableList] access is available through [asMutableList] when developers need
* access to the common API.
*
+ * It is best to use this for all internal implementations where a list of reference types
+ * is needed. Use [MutableList] in public API to take advantage of the commonly-used interface.
+ * It is common to use [MutableObjectList] internally and use [asMutableList] or [asList]
+ * to get a [MutableList] or [List] interface for interacting with public APIs.
+ *
* @see ObjectList
* @see MutableFloatList
* @see MutableIntList
@@ -1101,7 +1130,7 @@
val content = content
for (i in lastIndex downTo 0) {
val element = content[i]
- if (elements.indexOfFirst { it == element } < 0) {
+ if (elements.indexOf(element) < 0) {
removeAt(i)
}
}
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectLongMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectLongMap.kt
index 092855b..ebe3595 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectLongMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/ObjectLongMap.kt
@@ -54,38 +54,186 @@
EmptyObjectLongMap as ObjectLongMap<K>
/**
- * Returns a new [MutableObjectLongMap].
+ * Returns a new [ObjectLongMap] with only [key1] associated with [value1].
+ */
+public fun <K> objectLongMapOf(
+ key1: K,
+ value1: Long
+): ObjectLongMap<K> =
+ MutableObjectLongMap<K>().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [ObjectLongMap] with only [key1] and [key2] associated with
+ * [value1] and [value2], respectively.
+ */
+public fun <K> objectLongMapOf(
+ key1: K,
+ value1: Long,
+ key2: K,
+ value2: Long,
+): ObjectLongMap<K> =
+ MutableObjectLongMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [ObjectLongMap] with only [key1], [key2], and [key3] associated with
+ * [value1], [value2], and [value3], respectively.
+ */
+public fun <K> objectLongMapOf(
+ key1: K,
+ value1: Long,
+ key2: K,
+ value2: Long,
+ key3: K,
+ value3: Long,
+): ObjectLongMap<K> =
+ MutableObjectLongMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [ObjectLongMap] with only [key1], [key2], [key3], and [key4] associated with
+ * [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <K> objectLongMapOf(
+ key1: K,
+ value1: Long,
+ key2: K,
+ value2: Long,
+ key3: K,
+ value3: Long,
+ key4: K,
+ value4: Long,
+): ObjectLongMap<K> =
+ MutableObjectLongMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [ObjectLongMap] with only [key1], [key2], [key3], [key4], and [key5] associated
+ * with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <K> objectLongMapOf(
+ key1: K,
+ value1: Long,
+ key2: K,
+ value2: Long,
+ key3: K,
+ value3: Long,
+ key4: K,
+ value4: Long,
+ key5: K,
+ value5: Long,
+): ObjectLongMap<K> =
+ MutableObjectLongMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
+ }
+
+/**
+ * Returns a new empty [MutableObjectLongMap].
*/
public fun <K> mutableObjectLongMapOf(): MutableObjectLongMap<K> = MutableObjectLongMap()
/**
- * Returns a new [MutableObjectLongMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Long] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [MutableObjectLongMap] with only [key1] associated with [value1].
*/
-public fun <K> objectLongMapOf(vararg pairs: Pair<K, Long>): ObjectLongMap<K> =
- MutableObjectLongMap<K>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <K> mutableObjectLongMapOf(
+ key1: K,
+ value1: Long,
+): MutableObjectLongMap<K> =
+ MutableObjectLongMap<K>().also { map ->
+ map[key1] = value1
}
/**
- * Returns a new [MutableObjectLongMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Long] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [MutableObjectLongMap] with only [key1] and [key2] associated with
+ * [value1] and [value2], respectively.
*/
-public fun <K> mutableObjectLongMapOf(vararg pairs: Pair<K, Long>): MutableObjectLongMap<K> =
- MutableObjectLongMap<K>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <K> mutableObjectLongMapOf(
+ key1: K,
+ value1: Long,
+ key2: K,
+ value2: Long,
+): MutableObjectLongMap<K> =
+ MutableObjectLongMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableObjectLongMap] with only [key1], [key2], and [key3] associated with
+ * [value1], [value2], and [value3], respectively.
+ */
+public fun <K> mutableObjectLongMapOf(
+ key1: K,
+ value1: Long,
+ key2: K,
+ value2: Long,
+ key3: K,
+ value3: Long,
+): MutableObjectLongMap<K> =
+ MutableObjectLongMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableObjectLongMap] with only [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <K> mutableObjectLongMapOf(
+ key1: K,
+ value1: Long,
+ key2: K,
+ value2: Long,
+ key3: K,
+ value3: Long,
+ key4: K,
+ value4: Long,
+): MutableObjectLongMap<K> =
+ MutableObjectLongMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableObjectLongMap] with only [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <K> mutableObjectLongMapOf(
+ key1: K,
+ value1: Long,
+ key2: K,
+ value2: Long,
+ key3: K,
+ value3: Long,
+ key4: K,
+ value4: Long,
+ key5: K,
+ value5: Long,
+): MutableObjectLongMap<K> =
+ MutableObjectLongMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -560,20 +708,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Long] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<out Pair<K, Long>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: ObjectLongMap<K>) {
@@ -583,29 +717,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that the [Pair] is allocated and the [Long] value is boxed.
- * Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<K, Long>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [Long] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<out Pair<K, Long>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: ObjectLongMap<K>): Unit = putAll(from)
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/ScatterMap.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/ScatterMap.kt
index 37be5a5..7f3ea33 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/ScatterMap.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/ScatterMap.kt
@@ -988,6 +988,24 @@
}
}
+ /**
+ * Removes the specified [keys] and their associated value from the map.
+ */
+ public inline operator fun minusAssign(keys: ScatterSet<K>) {
+ keys.forEach { key ->
+ remove(key)
+ }
+ }
+
+ /**
+ * Removes the specified [keys] and their associated value from the map.
+ */
+ public inline operator fun minusAssign(keys: ObjectList<K>) {
+ keys.forEach { key ->
+ remove(key)
+ }
+ }
+
private fun removeValueAt(index: Int): V? {
_size -= 1
diff --git a/collection/collection/src/commonMain/kotlin/androidx/collection/ScatterSet.kt b/collection/collection/src/commonMain/kotlin/androidx/collection/ScatterSet.kt
index fe0cfd4..8299a1b 100644
--- a/collection/collection/src/commonMain/kotlin/androidx/collection/ScatterSet.kt
+++ b/collection/collection/src/commonMain/kotlin/androidx/collection/ScatterSet.kt
@@ -613,6 +613,18 @@
}
/**
+ * Adds all the elements in the [elements] set into this set.
+ * @param elements An [ObjectList] whose elements are to be added to the set
+ * @return `true` if any of the specified elements were added to the collection,
+ * `false` if the collection was not modified.
+ */
+ public fun addAll(elements: ObjectList<E>): Boolean {
+ val oldSize = size
+ plusAssign(elements)
+ return oldSize != size
+ }
+
+ /**
* Adds all the [elements] into this set.
* @param elements An array of elements to add to the set.
*/
@@ -653,6 +665,16 @@
}
/**
+ * Adds all the elements in the [elements] set into this set.
+ * @param elements An [ObjectList] whose elements are to be added to the set
+ */
+ public operator fun plusAssign(elements: ObjectList<E>) {
+ elements.forEach { element ->
+ plusAssign(element)
+ }
+ }
+
+ /**
* Removes the specified [element] from the set.
* @param element The element to be removed from the set.
* @return `true` if the [element] was present in the set, or `false` if it wasn't
@@ -724,6 +746,17 @@
/**
* Removes the specified [elements] from the set, if present.
+ * @param elements An [ObjectList] whose elements should be removed from the set.
+ * @return `true` if the set was changed or `false` if none of the elements were present.
+ */
+ public fun removeAll(elements: ObjectList<E>): Boolean {
+ val oldSize = size
+ minusAssign(elements)
+ return oldSize != size
+ }
+
+ /**
+ * Removes the specified [elements] from the set, if present.
* @param elements An array of elements to be removed from the set.
*/
public operator fun minusAssign(@Suppress("ArrayReturn") elements: Array<out E>) {
@@ -763,6 +796,16 @@
}
/**
+ * Removes the specified [elements] from the set, if present.
+ * @param elements An [ObjectList] whose elements should be removed from the set.
+ */
+ public operator fun minusAssign(elements: ObjectList<E>) {
+ elements.forEach { element ->
+ minusAssign(element)
+ }
+ }
+
+ /**
* Removes any values for which the specified [predicate] returns true.
*/
public inline fun removeIf(predicate: (E) -> Boolean) {
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/FloatFloatMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/FloatFloatMapTest.kt
index fa56a25..c574f15 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/FloatFloatMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/FloatFloatMapTest.kt
@@ -78,14 +78,113 @@
}
@Test
- fun floatFloatMapPairsFunction() {
- val map = mutableFloatFloatMapOf(
- 1f to 1f,
- 2f to 2f
+ fun floatFloatMapInitFunction() {
+ val map1 = floatFloatMapOf(
+ 1f, 1f,
)
- assertEquals(2, map.size)
- assertEquals(1f, map[1f])
- assertEquals(2f, map[2f])
+ assertEquals(1, map1.size)
+ assertEquals(1f, map1[1f])
+
+ val map2 = floatFloatMapOf(
+ 1f, 1f,
+ 2f, 2f,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1f, map2[1f])
+ assertEquals(2f, map2[2f])
+
+ val map3 = floatFloatMapOf(
+ 1f, 1f,
+ 2f, 2f,
+ 3f, 3f,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1f, map3[1f])
+ assertEquals(2f, map3[2f])
+ assertEquals(3f, map3[3f])
+
+ val map4 = floatFloatMapOf(
+ 1f, 1f,
+ 2f, 2f,
+ 3f, 3f,
+ 4f, 4f,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1f, map4[1f])
+ assertEquals(2f, map4[2f])
+ assertEquals(3f, map4[3f])
+ assertEquals(4f, map4[4f])
+
+ val map5 = floatFloatMapOf(
+ 1f, 1f,
+ 2f, 2f,
+ 3f, 3f,
+ 4f, 4f,
+ 5f, 5f,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1f, map5[1f])
+ assertEquals(2f, map5[2f])
+ assertEquals(3f, map5[3f])
+ assertEquals(4f, map5[4f])
+ assertEquals(5f, map5[5f])
+ }
+
+ @Test
+ fun mutableFloatFloatMapInitFunction() {
+ val map1 = mutableFloatFloatMapOf(
+ 1f, 1f,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1f, map1[1f])
+
+ val map2 = mutableFloatFloatMapOf(
+ 1f, 1f,
+ 2f, 2f,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1f, map2[1f])
+ assertEquals(2f, map2[2f])
+
+ val map3 = mutableFloatFloatMapOf(
+ 1f, 1f,
+ 2f, 2f,
+ 3f, 3f,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1f, map3[1f])
+ assertEquals(2f, map3[2f])
+ assertEquals(3f, map3[3f])
+
+ val map4 = mutableFloatFloatMapOf(
+ 1f, 1f,
+ 2f, 2f,
+ 3f, 3f,
+ 4f, 4f,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1f, map4[1f])
+ assertEquals(2f, map4[2f])
+ assertEquals(3f, map4[3f])
+ assertEquals(4f, map4[4f])
+
+ val map5 = mutableFloatFloatMapOf(
+ 1f, 1f,
+ 2f, 2f,
+ 3f, 3f,
+ 4f, 4f,
+ 5f, 5f,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1f, map5[1f])
+ assertEquals(2f, map5[2f])
+ assertEquals(3f, map5[3f])
+ assertEquals(4f, map5[4f])
+ assertEquals(5f, map5[5f])
}
@Test
@@ -146,38 +245,6 @@
}
@Test
- fun putAllArray() {
- val map = MutableFloatFloatMap()
- map[1f] = 1f
- map[2f] = 2f
-
- map.putAll(arrayOf(3f to 3f, 7f to 7f))
-
- assertEquals(4, map.size)
- assertEquals(3f, map[3f])
- assertEquals(7f, map[7f])
- }
-
- @Test
- fun plus() {
- val map = MutableFloatFloatMap()
- map += 1f to 1f
-
- assertEquals(1, map.size)
- assertEquals(1f, map[1f])
- }
-
- @Test
- fun plusArray() {
- val map = MutableFloatFloatMap()
- map += arrayOf(3f to 3f, 7f to 7f)
-
- assertEquals(2, map.size)
- assertEquals(3f, map[3f])
- assertEquals(7f, map[7f])
- }
-
- @Test
fun findNonExistingKey() {
val map = MutableFloatFloatMap()
map[1f] = 1f
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/FloatIntMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/FloatIntMapTest.kt
index 9d24ffc..4dd5f29 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/FloatIntMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/FloatIntMapTest.kt
@@ -78,14 +78,113 @@
}
@Test
- fun floatIntMapPairsFunction() {
- val map = mutableFloatIntMapOf(
- 1f to 1,
- 2f to 2
+ fun floatIntMapInitFunction() {
+ val map1 = floatIntMapOf(
+ 1f, 1,
)
- assertEquals(2, map.size)
- assertEquals(1, map[1f])
- assertEquals(2, map[2f])
+ assertEquals(1, map1.size)
+ assertEquals(1, map1[1f])
+
+ val map2 = floatIntMapOf(
+ 1f, 1,
+ 2f, 2,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1, map2[1f])
+ assertEquals(2, map2[2f])
+
+ val map3 = floatIntMapOf(
+ 1f, 1,
+ 2f, 2,
+ 3f, 3,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1, map3[1f])
+ assertEquals(2, map3[2f])
+ assertEquals(3, map3[3f])
+
+ val map4 = floatIntMapOf(
+ 1f, 1,
+ 2f, 2,
+ 3f, 3,
+ 4f, 4,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1, map4[1f])
+ assertEquals(2, map4[2f])
+ assertEquals(3, map4[3f])
+ assertEquals(4, map4[4f])
+
+ val map5 = floatIntMapOf(
+ 1f, 1,
+ 2f, 2,
+ 3f, 3,
+ 4f, 4,
+ 5f, 5,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1, map5[1f])
+ assertEquals(2, map5[2f])
+ assertEquals(3, map5[3f])
+ assertEquals(4, map5[4f])
+ assertEquals(5, map5[5f])
+ }
+
+ @Test
+ fun mutableFloatIntMapInitFunction() {
+ val map1 = mutableFloatIntMapOf(
+ 1f, 1,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1, map1[1f])
+
+ val map2 = mutableFloatIntMapOf(
+ 1f, 1,
+ 2f, 2,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1, map2[1f])
+ assertEquals(2, map2[2f])
+
+ val map3 = mutableFloatIntMapOf(
+ 1f, 1,
+ 2f, 2,
+ 3f, 3,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1, map3[1f])
+ assertEquals(2, map3[2f])
+ assertEquals(3, map3[3f])
+
+ val map4 = mutableFloatIntMapOf(
+ 1f, 1,
+ 2f, 2,
+ 3f, 3,
+ 4f, 4,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1, map4[1f])
+ assertEquals(2, map4[2f])
+ assertEquals(3, map4[3f])
+ assertEquals(4, map4[4f])
+
+ val map5 = mutableFloatIntMapOf(
+ 1f, 1,
+ 2f, 2,
+ 3f, 3,
+ 4f, 4,
+ 5f, 5,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1, map5[1f])
+ assertEquals(2, map5[2f])
+ assertEquals(3, map5[3f])
+ assertEquals(4, map5[4f])
+ assertEquals(5, map5[5f])
}
@Test
@@ -146,38 +245,6 @@
}
@Test
- fun putAllArray() {
- val map = MutableFloatIntMap()
- map[1f] = 1
- map[2f] = 2
-
- map.putAll(arrayOf(3f to 3, 7f to 7))
-
- assertEquals(4, map.size)
- assertEquals(3, map[3f])
- assertEquals(7, map[7f])
- }
-
- @Test
- fun plus() {
- val map = MutableFloatIntMap()
- map += 1f to 1
-
- assertEquals(1, map.size)
- assertEquals(1, map[1f])
- }
-
- @Test
- fun plusArray() {
- val map = MutableFloatIntMap()
- map += arrayOf(3f to 3, 7f to 7)
-
- assertEquals(2, map.size)
- assertEquals(3, map[3f])
- assertEquals(7, map[7f])
- }
-
- @Test
fun findNonExistingKey() {
val map = MutableFloatIntMap()
map[1f] = 1
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/FloatLongMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/FloatLongMapTest.kt
index cc90959..66b8b57 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/FloatLongMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/FloatLongMapTest.kt
@@ -78,14 +78,113 @@
}
@Test
- fun floatLongMapPairsFunction() {
- val map = mutableFloatLongMapOf(
- 1f to 1L,
- 2f to 2L
+ fun floatLongMapInitFunction() {
+ val map1 = floatLongMapOf(
+ 1f, 1L,
)
- assertEquals(2, map.size)
- assertEquals(1L, map[1f])
- assertEquals(2L, map[2f])
+ assertEquals(1, map1.size)
+ assertEquals(1L, map1[1f])
+
+ val map2 = floatLongMapOf(
+ 1f, 1L,
+ 2f, 2L,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1L, map2[1f])
+ assertEquals(2L, map2[2f])
+
+ val map3 = floatLongMapOf(
+ 1f, 1L,
+ 2f, 2L,
+ 3f, 3L,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1L, map3[1f])
+ assertEquals(2L, map3[2f])
+ assertEquals(3L, map3[3f])
+
+ val map4 = floatLongMapOf(
+ 1f, 1L,
+ 2f, 2L,
+ 3f, 3L,
+ 4f, 4L,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1L, map4[1f])
+ assertEquals(2L, map4[2f])
+ assertEquals(3L, map4[3f])
+ assertEquals(4L, map4[4f])
+
+ val map5 = floatLongMapOf(
+ 1f, 1L,
+ 2f, 2L,
+ 3f, 3L,
+ 4f, 4L,
+ 5f, 5L,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1L, map5[1f])
+ assertEquals(2L, map5[2f])
+ assertEquals(3L, map5[3f])
+ assertEquals(4L, map5[4f])
+ assertEquals(5L, map5[5f])
+ }
+
+ @Test
+ fun mutableFloatLongMapInitFunction() {
+ val map1 = mutableFloatLongMapOf(
+ 1f, 1L,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1L, map1[1f])
+
+ val map2 = mutableFloatLongMapOf(
+ 1f, 1L,
+ 2f, 2L,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1L, map2[1f])
+ assertEquals(2L, map2[2f])
+
+ val map3 = mutableFloatLongMapOf(
+ 1f, 1L,
+ 2f, 2L,
+ 3f, 3L,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1L, map3[1f])
+ assertEquals(2L, map3[2f])
+ assertEquals(3L, map3[3f])
+
+ val map4 = mutableFloatLongMapOf(
+ 1f, 1L,
+ 2f, 2L,
+ 3f, 3L,
+ 4f, 4L,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1L, map4[1f])
+ assertEquals(2L, map4[2f])
+ assertEquals(3L, map4[3f])
+ assertEquals(4L, map4[4f])
+
+ val map5 = mutableFloatLongMapOf(
+ 1f, 1L,
+ 2f, 2L,
+ 3f, 3L,
+ 4f, 4L,
+ 5f, 5L,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1L, map5[1f])
+ assertEquals(2L, map5[2f])
+ assertEquals(3L, map5[3f])
+ assertEquals(4L, map5[4f])
+ assertEquals(5L, map5[5f])
}
@Test
@@ -146,38 +245,6 @@
}
@Test
- fun putAllArray() {
- val map = MutableFloatLongMap()
- map[1f] = 1L
- map[2f] = 2L
-
- map.putAll(arrayOf(3f to 3L, 7f to 7L))
-
- assertEquals(4, map.size)
- assertEquals(3L, map[3f])
- assertEquals(7L, map[7f])
- }
-
- @Test
- fun plus() {
- val map = MutableFloatLongMap()
- map += 1f to 1L
-
- assertEquals(1, map.size)
- assertEquals(1L, map[1f])
- }
-
- @Test
- fun plusArray() {
- val map = MutableFloatLongMap()
- map += arrayOf(3f to 3L, 7f to 7L)
-
- assertEquals(2, map.size)
- assertEquals(3L, map[3f])
- assertEquals(7L, map[7f])
- }
-
- @Test
fun findNonExistingKey() {
val map = MutableFloatLongMap()
map[1f] = 1L
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/FloatObjectMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/FloatObjectMapTest.kt
index 4a10fc7b..c0aca75 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/FloatObjectMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/FloatObjectMapTest.kt
@@ -78,14 +78,113 @@
}
@Test
- fun floatObjectMapPairsFunction() {
- val map = mutableFloatObjectMapOf(
- 1f to "World",
- 2f to "Monde"
+ fun floatObjectMapInitFunction() {
+ val map1 = floatObjectMapOf(
+ 1f, "World",
)
- assertEquals(2, map.size)
- assertEquals("World", map[1f])
- assertEquals("Monde", map[2f])
+ assertEquals(1, map1.size)
+ assertEquals("World", map1[1f])
+
+ val map2 = floatObjectMapOf(
+ 1f, "World",
+ 2f, "Monde",
+ )
+ assertEquals(2, map2.size)
+ assertEquals("World", map2[1f])
+ assertEquals("Monde", map2[2f])
+
+ val map3 = floatObjectMapOf(
+ 1f, "World",
+ 2f, "Monde",
+ 3f, "Welt",
+ )
+ assertEquals(3, map3.size)
+ assertEquals("World", map3[1f])
+ assertEquals("Monde", map3[2f])
+ assertEquals("Welt", map3[3f])
+
+ val map4 = floatObjectMapOf(
+ 1f, "World",
+ 2f, "Monde",
+ 3f, "Welt",
+ 4f, "Sekai",
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals("World", map4[1f])
+ assertEquals("Monde", map4[2f])
+ assertEquals("Welt", map4[3f])
+ assertEquals("Sekai", map4[4f])
+
+ val map5 = floatObjectMapOf(
+ 1f, "World",
+ 2f, "Monde",
+ 3f, "Welt",
+ 4f, "Sekai",
+ 5f, "Mondo",
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals("World", map5[1f])
+ assertEquals("Monde", map5[2f])
+ assertEquals("Welt", map5[3f])
+ assertEquals("Sekai", map5[4f])
+ assertEquals("Mondo", map5[5f])
+ }
+
+ @Test
+ fun mutableFloatObjectMapInitFunction() {
+ val map1 = mutableFloatObjectMapOf(
+ 1f, "World",
+ )
+ assertEquals(1, map1.size)
+ assertEquals("World", map1[1f])
+
+ val map2 = mutableFloatObjectMapOf(
+ 1f, "World",
+ 2f, "Monde",
+ )
+ assertEquals(2, map2.size)
+ assertEquals("World", map2[1f])
+ assertEquals("Monde", map2[2f])
+
+ val map3 = mutableFloatObjectMapOf(
+ 1f, "World",
+ 2f, "Monde",
+ 3f, "Welt",
+ )
+ assertEquals(3, map3.size)
+ assertEquals("World", map3[1f])
+ assertEquals("Monde", map3[2f])
+ assertEquals("Welt", map3[3f])
+
+ val map4 = mutableFloatObjectMapOf(
+ 1f, "World",
+ 2f, "Monde",
+ 3f, "Welt",
+ 4f, "Sekai",
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals("World", map4[1f])
+ assertEquals("Monde", map4[2f])
+ assertEquals("Welt", map4[3f])
+ assertEquals("Sekai", map4[4f])
+
+ val map5 = mutableFloatObjectMapOf(
+ 1f, "World",
+ 2f, "Monde",
+ 3f, "Welt",
+ 4f, "Sekai",
+ 5f, "Mondo",
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals("World", map5[1f])
+ assertEquals("Monde", map5[2f])
+ assertEquals("Welt", map5[3f])
+ assertEquals("Sekai", map5[4f])
+ assertEquals("Mondo", map5[5f])
}
@Test
@@ -153,25 +252,12 @@
}
@Test
- fun putAllArray() {
- val map = MutableFloatObjectMap<String?>()
- map[1f] = "World"
- map[2f] = null
-
- map.putAll(arrayOf(3f to "Welt", 7f to "Mundo"))
-
- assertEquals(4, map.size)
- assertEquals("Welt", map[3f])
- assertEquals("Mundo", map[7f])
- }
-
- @Test
fun putAllMap() {
val map = MutableFloatObjectMap<String?>()
map[1f] = "World"
map[2f] = null
- map.putAll(mutableFloatObjectMapOf(3f to "Welt", 7f to "Mundo"))
+ map.putAll(mutableFloatObjectMapOf(3f, "Welt", 7f, "Mundo"))
assertEquals(4, map.size)
assertEquals("Welt", map[3f])
@@ -179,28 +265,9 @@
}
@Test
- fun plus() {
- val map = MutableFloatObjectMap<String>()
- map += 1f to "World"
-
- assertEquals(1, map.size)
- assertEquals("World", map[1f])
- }
-
- @Test
fun plusMap() {
val map = MutableFloatObjectMap<String>()
- map += floatObjectMapOf(3f to "Welt", 7f to "Mundo")
-
- assertEquals(2, map.size)
- assertEquals("Welt", map[3f])
- assertEquals("Mundo", map[7f])
- }
-
- @Test
- fun plusArray() {
- val map = MutableFloatObjectMap<String>()
- map += arrayOf(3f to "Welt", 7f to "Mundo")
+ map += floatObjectMapOf(3f, "Welt", 7f, "Mundo")
assertEquals(2, map.size)
assertEquals("Welt", map[3f])
@@ -626,7 +693,7 @@
map[5f] = "Mondo"
map[6f] = "Sesang"
- assertTrue(map.all { key, value -> key < 7f && value.length > 0 })
+ assertTrue(map.all { key, value -> key < 7f && value.isNotEmpty() })
assertFalse(map.all { key, _ -> key < 6f })
}
}
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/IntFloatMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/IntFloatMapTest.kt
index 94c8ec2..99b7411 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/IntFloatMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/IntFloatMapTest.kt
@@ -78,14 +78,113 @@
}
@Test
- fun intFloatMapPairsFunction() {
- val map = mutableIntFloatMapOf(
- 1 to 1f,
- 2 to 2f
+ fun intFloatMapInitFunction() {
+ val map1 = intFloatMapOf(
+ 1, 1f,
)
- assertEquals(2, map.size)
- assertEquals(1f, map[1])
- assertEquals(2f, map[2])
+ assertEquals(1, map1.size)
+ assertEquals(1f, map1[1])
+
+ val map2 = intFloatMapOf(
+ 1, 1f,
+ 2, 2f,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1f, map2[1])
+ assertEquals(2f, map2[2])
+
+ val map3 = intFloatMapOf(
+ 1, 1f,
+ 2, 2f,
+ 3, 3f,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1f, map3[1])
+ assertEquals(2f, map3[2])
+ assertEquals(3f, map3[3])
+
+ val map4 = intFloatMapOf(
+ 1, 1f,
+ 2, 2f,
+ 3, 3f,
+ 4, 4f,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1f, map4[1])
+ assertEquals(2f, map4[2])
+ assertEquals(3f, map4[3])
+ assertEquals(4f, map4[4])
+
+ val map5 = intFloatMapOf(
+ 1, 1f,
+ 2, 2f,
+ 3, 3f,
+ 4, 4f,
+ 5, 5f,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1f, map5[1])
+ assertEquals(2f, map5[2])
+ assertEquals(3f, map5[3])
+ assertEquals(4f, map5[4])
+ assertEquals(5f, map5[5])
+ }
+
+ @Test
+ fun mutableIntFloatMapInitFunction() {
+ val map1 = mutableIntFloatMapOf(
+ 1, 1f,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1f, map1[1])
+
+ val map2 = mutableIntFloatMapOf(
+ 1, 1f,
+ 2, 2f,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1f, map2[1])
+ assertEquals(2f, map2[2])
+
+ val map3 = mutableIntFloatMapOf(
+ 1, 1f,
+ 2, 2f,
+ 3, 3f,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1f, map3[1])
+ assertEquals(2f, map3[2])
+ assertEquals(3f, map3[3])
+
+ val map4 = mutableIntFloatMapOf(
+ 1, 1f,
+ 2, 2f,
+ 3, 3f,
+ 4, 4f,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1f, map4[1])
+ assertEquals(2f, map4[2])
+ assertEquals(3f, map4[3])
+ assertEquals(4f, map4[4])
+
+ val map5 = mutableIntFloatMapOf(
+ 1, 1f,
+ 2, 2f,
+ 3, 3f,
+ 4, 4f,
+ 5, 5f,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1f, map5[1])
+ assertEquals(2f, map5[2])
+ assertEquals(3f, map5[3])
+ assertEquals(4f, map5[4])
+ assertEquals(5f, map5[5])
}
@Test
@@ -146,38 +245,6 @@
}
@Test
- fun putAllArray() {
- val map = MutableIntFloatMap()
- map[1] = 1f
- map[2] = 2f
-
- map.putAll(arrayOf(3 to 3f, 7 to 7f))
-
- assertEquals(4, map.size)
- assertEquals(3f, map[3])
- assertEquals(7f, map[7])
- }
-
- @Test
- fun plus() {
- val map = MutableIntFloatMap()
- map += 1 to 1f
-
- assertEquals(1, map.size)
- assertEquals(1f, map[1])
- }
-
- @Test
- fun plusArray() {
- val map = MutableIntFloatMap()
- map += arrayOf(3 to 3f, 7 to 7f)
-
- assertEquals(2, map.size)
- assertEquals(3f, map[3])
- assertEquals(7f, map[7])
- }
-
- @Test
fun findNonExistingKey() {
val map = MutableIntFloatMap()
map[1] = 1f
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/IntIntMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/IntIntMapTest.kt
index 933c5ba..e64d2ed 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/IntIntMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/IntIntMapTest.kt
@@ -78,14 +78,113 @@
}
@Test
- fun intIntMapPairsFunction() {
- val map = mutableIntIntMapOf(
- 1 to 1,
- 2 to 2
+ fun intIntMapInitFunction() {
+ val map1 = intIntMapOf(
+ 1, 1,
)
- assertEquals(2, map.size)
- assertEquals(1, map[1])
- assertEquals(2, map[2])
+ assertEquals(1, map1.size)
+ assertEquals(1, map1[1])
+
+ val map2 = intIntMapOf(
+ 1, 1,
+ 2, 2,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1, map2[1])
+ assertEquals(2, map2[2])
+
+ val map3 = intIntMapOf(
+ 1, 1,
+ 2, 2,
+ 3, 3,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1, map3[1])
+ assertEquals(2, map3[2])
+ assertEquals(3, map3[3])
+
+ val map4 = intIntMapOf(
+ 1, 1,
+ 2, 2,
+ 3, 3,
+ 4, 4,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1, map4[1])
+ assertEquals(2, map4[2])
+ assertEquals(3, map4[3])
+ assertEquals(4, map4[4])
+
+ val map5 = intIntMapOf(
+ 1, 1,
+ 2, 2,
+ 3, 3,
+ 4, 4,
+ 5, 5,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1, map5[1])
+ assertEquals(2, map5[2])
+ assertEquals(3, map5[3])
+ assertEquals(4, map5[4])
+ assertEquals(5, map5[5])
+ }
+
+ @Test
+ fun mutableIntIntMapInitFunction() {
+ val map1 = mutableIntIntMapOf(
+ 1, 1,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1, map1[1])
+
+ val map2 = mutableIntIntMapOf(
+ 1, 1,
+ 2, 2,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1, map2[1])
+ assertEquals(2, map2[2])
+
+ val map3 = mutableIntIntMapOf(
+ 1, 1,
+ 2, 2,
+ 3, 3,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1, map3[1])
+ assertEquals(2, map3[2])
+ assertEquals(3, map3[3])
+
+ val map4 = mutableIntIntMapOf(
+ 1, 1,
+ 2, 2,
+ 3, 3,
+ 4, 4,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1, map4[1])
+ assertEquals(2, map4[2])
+ assertEquals(3, map4[3])
+ assertEquals(4, map4[4])
+
+ val map5 = mutableIntIntMapOf(
+ 1, 1,
+ 2, 2,
+ 3, 3,
+ 4, 4,
+ 5, 5,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1, map5[1])
+ assertEquals(2, map5[2])
+ assertEquals(3, map5[3])
+ assertEquals(4, map5[4])
+ assertEquals(5, map5[5])
}
@Test
@@ -146,38 +245,6 @@
}
@Test
- fun putAllArray() {
- val map = MutableIntIntMap()
- map[1] = 1
- map[2] = 2
-
- map.putAll(arrayOf(3 to 3, 7 to 7))
-
- assertEquals(4, map.size)
- assertEquals(3, map[3])
- assertEquals(7, map[7])
- }
-
- @Test
- fun plus() {
- val map = MutableIntIntMap()
- map += 1 to 1
-
- assertEquals(1, map.size)
- assertEquals(1, map[1])
- }
-
- @Test
- fun plusArray() {
- val map = MutableIntIntMap()
- map += arrayOf(3 to 3, 7 to 7)
-
- assertEquals(2, map.size)
- assertEquals(3, map[3])
- assertEquals(7, map[7])
- }
-
- @Test
fun findNonExistingKey() {
val map = MutableIntIntMap()
map[1] = 1
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/IntLongMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/IntLongMapTest.kt
index 734fb05..37bb0ff 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/IntLongMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/IntLongMapTest.kt
@@ -78,14 +78,113 @@
}
@Test
- fun intLongMapPairsFunction() {
- val map = mutableIntLongMapOf(
- 1 to 1L,
- 2 to 2L
+ fun intLongMapInitFunction() {
+ val map1 = intLongMapOf(
+ 1, 1L,
)
- assertEquals(2, map.size)
- assertEquals(1L, map[1])
- assertEquals(2L, map[2])
+ assertEquals(1, map1.size)
+ assertEquals(1L, map1[1])
+
+ val map2 = intLongMapOf(
+ 1, 1L,
+ 2, 2L,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1L, map2[1])
+ assertEquals(2L, map2[2])
+
+ val map3 = intLongMapOf(
+ 1, 1L,
+ 2, 2L,
+ 3, 3L,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1L, map3[1])
+ assertEquals(2L, map3[2])
+ assertEquals(3L, map3[3])
+
+ val map4 = intLongMapOf(
+ 1, 1L,
+ 2, 2L,
+ 3, 3L,
+ 4, 4L,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1L, map4[1])
+ assertEquals(2L, map4[2])
+ assertEquals(3L, map4[3])
+ assertEquals(4L, map4[4])
+
+ val map5 = intLongMapOf(
+ 1, 1L,
+ 2, 2L,
+ 3, 3L,
+ 4, 4L,
+ 5, 5L,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1L, map5[1])
+ assertEquals(2L, map5[2])
+ assertEquals(3L, map5[3])
+ assertEquals(4L, map5[4])
+ assertEquals(5L, map5[5])
+ }
+
+ @Test
+ fun mutableIntLongMapInitFunction() {
+ val map1 = mutableIntLongMapOf(
+ 1, 1L,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1L, map1[1])
+
+ val map2 = mutableIntLongMapOf(
+ 1, 1L,
+ 2, 2L,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1L, map2[1])
+ assertEquals(2L, map2[2])
+
+ val map3 = mutableIntLongMapOf(
+ 1, 1L,
+ 2, 2L,
+ 3, 3L,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1L, map3[1])
+ assertEquals(2L, map3[2])
+ assertEquals(3L, map3[3])
+
+ val map4 = mutableIntLongMapOf(
+ 1, 1L,
+ 2, 2L,
+ 3, 3L,
+ 4, 4L,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1L, map4[1])
+ assertEquals(2L, map4[2])
+ assertEquals(3L, map4[3])
+ assertEquals(4L, map4[4])
+
+ val map5 = mutableIntLongMapOf(
+ 1, 1L,
+ 2, 2L,
+ 3, 3L,
+ 4, 4L,
+ 5, 5L,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1L, map5[1])
+ assertEquals(2L, map5[2])
+ assertEquals(3L, map5[3])
+ assertEquals(4L, map5[4])
+ assertEquals(5L, map5[5])
}
@Test
@@ -146,38 +245,6 @@
}
@Test
- fun putAllArray() {
- val map = MutableIntLongMap()
- map[1] = 1L
- map[2] = 2L
-
- map.putAll(arrayOf(3 to 3L, 7 to 7L))
-
- assertEquals(4, map.size)
- assertEquals(3L, map[3])
- assertEquals(7L, map[7])
- }
-
- @Test
- fun plus() {
- val map = MutableIntLongMap()
- map += 1 to 1L
-
- assertEquals(1, map.size)
- assertEquals(1L, map[1])
- }
-
- @Test
- fun plusArray() {
- val map = MutableIntLongMap()
- map += arrayOf(3 to 3L, 7 to 7L)
-
- assertEquals(2, map.size)
- assertEquals(3L, map[3])
- assertEquals(7L, map[7])
- }
-
- @Test
fun findNonExistingKey() {
val map = MutableIntLongMap()
map[1] = 1L
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/IntObjectMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/IntObjectMapTest.kt
index 40038d2..9144ed6 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/IntObjectMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/IntObjectMapTest.kt
@@ -78,14 +78,113 @@
}
@Test
- fun intObjectMapPairsFunction() {
- val map = mutableIntObjectMapOf(
- 1 to "World",
- 2 to "Monde"
+ fun intObjectMapInitFunction() {
+ val map1 = intObjectMapOf(
+ 1, "World",
)
- assertEquals(2, map.size)
- assertEquals("World", map[1])
- assertEquals("Monde", map[2])
+ assertEquals(1, map1.size)
+ assertEquals("World", map1[1])
+
+ val map2 = intObjectMapOf(
+ 1, "World",
+ 2, "Monde",
+ )
+ assertEquals(2, map2.size)
+ assertEquals("World", map2[1])
+ assertEquals("Monde", map2[2])
+
+ val map3 = intObjectMapOf(
+ 1, "World",
+ 2, "Monde",
+ 3, "Welt",
+ )
+ assertEquals(3, map3.size)
+ assertEquals("World", map3[1])
+ assertEquals("Monde", map3[2])
+ assertEquals("Welt", map3[3])
+
+ val map4 = intObjectMapOf(
+ 1, "World",
+ 2, "Monde",
+ 3, "Welt",
+ 4, "Sekai",
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals("World", map4[1])
+ assertEquals("Monde", map4[2])
+ assertEquals("Welt", map4[3])
+ assertEquals("Sekai", map4[4])
+
+ val map5 = intObjectMapOf(
+ 1, "World",
+ 2, "Monde",
+ 3, "Welt",
+ 4, "Sekai",
+ 5, "Mondo",
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals("World", map5[1])
+ assertEquals("Monde", map5[2])
+ assertEquals("Welt", map5[3])
+ assertEquals("Sekai", map5[4])
+ assertEquals("Mondo", map5[5])
+ }
+
+ @Test
+ fun mutableIntObjectMapInitFunction() {
+ val map1 = mutableIntObjectMapOf(
+ 1, "World",
+ )
+ assertEquals(1, map1.size)
+ assertEquals("World", map1[1])
+
+ val map2 = mutableIntObjectMapOf(
+ 1, "World",
+ 2, "Monde",
+ )
+ assertEquals(2, map2.size)
+ assertEquals("World", map2[1])
+ assertEquals("Monde", map2[2])
+
+ val map3 = mutableIntObjectMapOf(
+ 1, "World",
+ 2, "Monde",
+ 3, "Welt",
+ )
+ assertEquals(3, map3.size)
+ assertEquals("World", map3[1])
+ assertEquals("Monde", map3[2])
+ assertEquals("Welt", map3[3])
+
+ val map4 = mutableIntObjectMapOf(
+ 1, "World",
+ 2, "Monde",
+ 3, "Welt",
+ 4, "Sekai",
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals("World", map4[1])
+ assertEquals("Monde", map4[2])
+ assertEquals("Welt", map4[3])
+ assertEquals("Sekai", map4[4])
+
+ val map5 = mutableIntObjectMapOf(
+ 1, "World",
+ 2, "Monde",
+ 3, "Welt",
+ 4, "Sekai",
+ 5, "Mondo",
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals("World", map5[1])
+ assertEquals("Monde", map5[2])
+ assertEquals("Welt", map5[3])
+ assertEquals("Sekai", map5[4])
+ assertEquals("Mondo", map5[5])
}
@Test
@@ -153,25 +252,12 @@
}
@Test
- fun putAllArray() {
- val map = MutableIntObjectMap<String?>()
- map[1] = "World"
- map[2] = null
-
- map.putAll(arrayOf(3 to "Welt", 7 to "Mundo"))
-
- assertEquals(4, map.size)
- assertEquals("Welt", map[3])
- assertEquals("Mundo", map[7])
- }
-
- @Test
fun putAllMap() {
val map = MutableIntObjectMap<String?>()
map[1] = "World"
map[2] = null
- map.putAll(mutableIntObjectMapOf(3 to "Welt", 7 to "Mundo"))
+ map.putAll(mutableIntObjectMapOf(3, "Welt", 7, "Mundo"))
assertEquals(4, map.size)
assertEquals("Welt", map[3])
@@ -179,28 +265,9 @@
}
@Test
- fun plus() {
- val map = MutableIntObjectMap<String>()
- map += 1 to "World"
-
- assertEquals(1, map.size)
- assertEquals("World", map[1])
- }
-
- @Test
fun plusMap() {
val map = MutableIntObjectMap<String>()
- map += intObjectMapOf(3 to "Welt", 7 to "Mundo")
-
- assertEquals(2, map.size)
- assertEquals("Welt", map[3])
- assertEquals("Mundo", map[7])
- }
-
- @Test
- fun plusArray() {
- val map = MutableIntObjectMap<String>()
- map += arrayOf(3 to "Welt", 7 to "Mundo")
+ map += intObjectMapOf(3, "Welt", 7, "Mundo")
assertEquals(2, map.size)
assertEquals("Welt", map[3])
@@ -626,7 +693,7 @@
map[5] = "Mondo"
map[6] = "Sesang"
- assertTrue(map.all { key, value -> key < 7 && value.length > 0 })
+ assertTrue(map.all { key, value -> key < 7 && value.isNotEmpty() })
assertFalse(map.all { key, _ -> key < 6 })
}
}
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/LongFloatMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/LongFloatMapTest.kt
index b395753..f187101 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/LongFloatMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/LongFloatMapTest.kt
@@ -78,14 +78,113 @@
}
@Test
- fun longFloatMapPairsFunction() {
- val map = mutableLongFloatMapOf(
- 1L to 1f,
- 2L to 2f
+ fun longFloatMapInitFunction() {
+ val map1 = longFloatMapOf(
+ 1L, 1f,
)
- assertEquals(2, map.size)
- assertEquals(1f, map[1L])
- assertEquals(2f, map[2L])
+ assertEquals(1, map1.size)
+ assertEquals(1f, map1[1L])
+
+ val map2 = longFloatMapOf(
+ 1L, 1f,
+ 2L, 2f,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1f, map2[1L])
+ assertEquals(2f, map2[2L])
+
+ val map3 = longFloatMapOf(
+ 1L, 1f,
+ 2L, 2f,
+ 3L, 3f,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1f, map3[1L])
+ assertEquals(2f, map3[2L])
+ assertEquals(3f, map3[3L])
+
+ val map4 = longFloatMapOf(
+ 1L, 1f,
+ 2L, 2f,
+ 3L, 3f,
+ 4L, 4f,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1f, map4[1L])
+ assertEquals(2f, map4[2L])
+ assertEquals(3f, map4[3L])
+ assertEquals(4f, map4[4L])
+
+ val map5 = longFloatMapOf(
+ 1L, 1f,
+ 2L, 2f,
+ 3L, 3f,
+ 4L, 4f,
+ 5L, 5f,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1f, map5[1L])
+ assertEquals(2f, map5[2L])
+ assertEquals(3f, map5[3L])
+ assertEquals(4f, map5[4L])
+ assertEquals(5f, map5[5L])
+ }
+
+ @Test
+ fun mutableLongFloatMapInitFunction() {
+ val map1 = mutableLongFloatMapOf(
+ 1L, 1f,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1f, map1[1L])
+
+ val map2 = mutableLongFloatMapOf(
+ 1L, 1f,
+ 2L, 2f,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1f, map2[1L])
+ assertEquals(2f, map2[2L])
+
+ val map3 = mutableLongFloatMapOf(
+ 1L, 1f,
+ 2L, 2f,
+ 3L, 3f,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1f, map3[1L])
+ assertEquals(2f, map3[2L])
+ assertEquals(3f, map3[3L])
+
+ val map4 = mutableLongFloatMapOf(
+ 1L, 1f,
+ 2L, 2f,
+ 3L, 3f,
+ 4L, 4f,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1f, map4[1L])
+ assertEquals(2f, map4[2L])
+ assertEquals(3f, map4[3L])
+ assertEquals(4f, map4[4L])
+
+ val map5 = mutableLongFloatMapOf(
+ 1L, 1f,
+ 2L, 2f,
+ 3L, 3f,
+ 4L, 4f,
+ 5L, 5f,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1f, map5[1L])
+ assertEquals(2f, map5[2L])
+ assertEquals(3f, map5[3L])
+ assertEquals(4f, map5[4L])
+ assertEquals(5f, map5[5L])
}
@Test
@@ -146,38 +245,6 @@
}
@Test
- fun putAllArray() {
- val map = MutableLongFloatMap()
- map[1L] = 1f
- map[2L] = 2f
-
- map.putAll(arrayOf(3L to 3f, 7L to 7f))
-
- assertEquals(4, map.size)
- assertEquals(3f, map[3L])
- assertEquals(7f, map[7L])
- }
-
- @Test
- fun plus() {
- val map = MutableLongFloatMap()
- map += 1L to 1f
-
- assertEquals(1, map.size)
- assertEquals(1f, map[1L])
- }
-
- @Test
- fun plusArray() {
- val map = MutableLongFloatMap()
- map += arrayOf(3L to 3f, 7L to 7f)
-
- assertEquals(2, map.size)
- assertEquals(3f, map[3L])
- assertEquals(7f, map[7L])
- }
-
- @Test
fun findNonExistingKey() {
val map = MutableLongFloatMap()
map[1L] = 1f
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/LongIntMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/LongIntMapTest.kt
index cf64c64..56b066a 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/LongIntMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/LongIntMapTest.kt
@@ -78,14 +78,113 @@
}
@Test
- fun longIntMapPairsFunction() {
- val map = mutableLongIntMapOf(
- 1L to 1,
- 2L to 2
+ fun longIntMapInitFunction() {
+ val map1 = longIntMapOf(
+ 1L, 1,
)
- assertEquals(2, map.size)
- assertEquals(1, map[1L])
- assertEquals(2, map[2L])
+ assertEquals(1, map1.size)
+ assertEquals(1, map1[1L])
+
+ val map2 = longIntMapOf(
+ 1L, 1,
+ 2L, 2,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1, map2[1L])
+ assertEquals(2, map2[2L])
+
+ val map3 = longIntMapOf(
+ 1L, 1,
+ 2L, 2,
+ 3L, 3,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1, map3[1L])
+ assertEquals(2, map3[2L])
+ assertEquals(3, map3[3L])
+
+ val map4 = longIntMapOf(
+ 1L, 1,
+ 2L, 2,
+ 3L, 3,
+ 4L, 4,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1, map4[1L])
+ assertEquals(2, map4[2L])
+ assertEquals(3, map4[3L])
+ assertEquals(4, map4[4L])
+
+ val map5 = longIntMapOf(
+ 1L, 1,
+ 2L, 2,
+ 3L, 3,
+ 4L, 4,
+ 5L, 5,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1, map5[1L])
+ assertEquals(2, map5[2L])
+ assertEquals(3, map5[3L])
+ assertEquals(4, map5[4L])
+ assertEquals(5, map5[5L])
+ }
+
+ @Test
+ fun mutableLongIntMapInitFunction() {
+ val map1 = mutableLongIntMapOf(
+ 1L, 1,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1, map1[1L])
+
+ val map2 = mutableLongIntMapOf(
+ 1L, 1,
+ 2L, 2,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1, map2[1L])
+ assertEquals(2, map2[2L])
+
+ val map3 = mutableLongIntMapOf(
+ 1L, 1,
+ 2L, 2,
+ 3L, 3,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1, map3[1L])
+ assertEquals(2, map3[2L])
+ assertEquals(3, map3[3L])
+
+ val map4 = mutableLongIntMapOf(
+ 1L, 1,
+ 2L, 2,
+ 3L, 3,
+ 4L, 4,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1, map4[1L])
+ assertEquals(2, map4[2L])
+ assertEquals(3, map4[3L])
+ assertEquals(4, map4[4L])
+
+ val map5 = mutableLongIntMapOf(
+ 1L, 1,
+ 2L, 2,
+ 3L, 3,
+ 4L, 4,
+ 5L, 5,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1, map5[1L])
+ assertEquals(2, map5[2L])
+ assertEquals(3, map5[3L])
+ assertEquals(4, map5[4L])
+ assertEquals(5, map5[5L])
}
@Test
@@ -146,38 +245,6 @@
}
@Test
- fun putAllArray() {
- val map = MutableLongIntMap()
- map[1L] = 1
- map[2L] = 2
-
- map.putAll(arrayOf(3L to 3, 7L to 7))
-
- assertEquals(4, map.size)
- assertEquals(3, map[3L])
- assertEquals(7, map[7L])
- }
-
- @Test
- fun plus() {
- val map = MutableLongIntMap()
- map += 1L to 1
-
- assertEquals(1, map.size)
- assertEquals(1, map[1L])
- }
-
- @Test
- fun plusArray() {
- val map = MutableLongIntMap()
- map += arrayOf(3L to 3, 7L to 7)
-
- assertEquals(2, map.size)
- assertEquals(3, map[3L])
- assertEquals(7, map[7L])
- }
-
- @Test
fun findNonExistingKey() {
val map = MutableLongIntMap()
map[1L] = 1
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/LongLongMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/LongLongMapTest.kt
index b45ae5a..65b9220 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/LongLongMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/LongLongMapTest.kt
@@ -78,14 +78,113 @@
}
@Test
- fun longLongMapPairsFunction() {
- val map = mutableLongLongMapOf(
- 1L to 1L,
- 2L to 2L
+ fun longLongMapInitFunction() {
+ val map1 = longLongMapOf(
+ 1L, 1L,
)
- assertEquals(2, map.size)
- assertEquals(1L, map[1L])
- assertEquals(2L, map[2L])
+ assertEquals(1, map1.size)
+ assertEquals(1L, map1[1L])
+
+ val map2 = longLongMapOf(
+ 1L, 1L,
+ 2L, 2L,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1L, map2[1L])
+ assertEquals(2L, map2[2L])
+
+ val map3 = longLongMapOf(
+ 1L, 1L,
+ 2L, 2L,
+ 3L, 3L,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1L, map3[1L])
+ assertEquals(2L, map3[2L])
+ assertEquals(3L, map3[3L])
+
+ val map4 = longLongMapOf(
+ 1L, 1L,
+ 2L, 2L,
+ 3L, 3L,
+ 4L, 4L,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1L, map4[1L])
+ assertEquals(2L, map4[2L])
+ assertEquals(3L, map4[3L])
+ assertEquals(4L, map4[4L])
+
+ val map5 = longLongMapOf(
+ 1L, 1L,
+ 2L, 2L,
+ 3L, 3L,
+ 4L, 4L,
+ 5L, 5L,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1L, map5[1L])
+ assertEquals(2L, map5[2L])
+ assertEquals(3L, map5[3L])
+ assertEquals(4L, map5[4L])
+ assertEquals(5L, map5[5L])
+ }
+
+ @Test
+ fun mutableLongLongMapInitFunction() {
+ val map1 = mutableLongLongMapOf(
+ 1L, 1L,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1L, map1[1L])
+
+ val map2 = mutableLongLongMapOf(
+ 1L, 1L,
+ 2L, 2L,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1L, map2[1L])
+ assertEquals(2L, map2[2L])
+
+ val map3 = mutableLongLongMapOf(
+ 1L, 1L,
+ 2L, 2L,
+ 3L, 3L,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1L, map3[1L])
+ assertEquals(2L, map3[2L])
+ assertEquals(3L, map3[3L])
+
+ val map4 = mutableLongLongMapOf(
+ 1L, 1L,
+ 2L, 2L,
+ 3L, 3L,
+ 4L, 4L,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1L, map4[1L])
+ assertEquals(2L, map4[2L])
+ assertEquals(3L, map4[3L])
+ assertEquals(4L, map4[4L])
+
+ val map5 = mutableLongLongMapOf(
+ 1L, 1L,
+ 2L, 2L,
+ 3L, 3L,
+ 4L, 4L,
+ 5L, 5L,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1L, map5[1L])
+ assertEquals(2L, map5[2L])
+ assertEquals(3L, map5[3L])
+ assertEquals(4L, map5[4L])
+ assertEquals(5L, map5[5L])
}
@Test
@@ -146,38 +245,6 @@
}
@Test
- fun putAllArray() {
- val map = MutableLongLongMap()
- map[1L] = 1L
- map[2L] = 2L
-
- map.putAll(arrayOf(3L to 3L, 7L to 7L))
-
- assertEquals(4, map.size)
- assertEquals(3L, map[3L])
- assertEquals(7L, map[7L])
- }
-
- @Test
- fun plus() {
- val map = MutableLongLongMap()
- map += 1L to 1L
-
- assertEquals(1, map.size)
- assertEquals(1L, map[1L])
- }
-
- @Test
- fun plusArray() {
- val map = MutableLongLongMap()
- map += arrayOf(3L to 3L, 7L to 7L)
-
- assertEquals(2, map.size)
- assertEquals(3L, map[3L])
- assertEquals(7L, map[7L])
- }
-
- @Test
fun findNonExistingKey() {
val map = MutableLongLongMap()
map[1L] = 1L
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/LongObjectMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/LongObjectMapTest.kt
index 1a5fd8bf..1c0ccae 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/LongObjectMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/LongObjectMapTest.kt
@@ -78,14 +78,113 @@
}
@Test
- fun longObjectMapPairsFunction() {
- val map = mutableLongObjectMapOf(
- 1L to "World",
- 2L to "Monde"
+ fun longObjectMapInitFunction() {
+ val map1 = longObjectMapOf(
+ 1L, "World",
)
- assertEquals(2, map.size)
- assertEquals("World", map[1L])
- assertEquals("Monde", map[2L])
+ assertEquals(1, map1.size)
+ assertEquals("World", map1[1L])
+
+ val map2 = longObjectMapOf(
+ 1L, "World",
+ 2L, "Monde",
+ )
+ assertEquals(2, map2.size)
+ assertEquals("World", map2[1L])
+ assertEquals("Monde", map2[2L])
+
+ val map3 = longObjectMapOf(
+ 1L, "World",
+ 2L, "Monde",
+ 3L, "Welt",
+ )
+ assertEquals(3, map3.size)
+ assertEquals("World", map3[1L])
+ assertEquals("Monde", map3[2L])
+ assertEquals("Welt", map3[3L])
+
+ val map4 = longObjectMapOf(
+ 1L, "World",
+ 2L, "Monde",
+ 3L, "Welt",
+ 4L, "Sekai",
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals("World", map4[1L])
+ assertEquals("Monde", map4[2L])
+ assertEquals("Welt", map4[3L])
+ assertEquals("Sekai", map4[4L])
+
+ val map5 = longObjectMapOf(
+ 1L, "World",
+ 2L, "Monde",
+ 3L, "Welt",
+ 4L, "Sekai",
+ 5L, "Mondo",
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals("World", map5[1L])
+ assertEquals("Monde", map5[2L])
+ assertEquals("Welt", map5[3L])
+ assertEquals("Sekai", map5[4L])
+ assertEquals("Mondo", map5[5L])
+ }
+
+ @Test
+ fun mutableLongObjectMapInitFunction() {
+ val map1 = mutableLongObjectMapOf(
+ 1L, "World",
+ )
+ assertEquals(1, map1.size)
+ assertEquals("World", map1[1L])
+
+ val map2 = mutableLongObjectMapOf(
+ 1L, "World",
+ 2L, "Monde",
+ )
+ assertEquals(2, map2.size)
+ assertEquals("World", map2[1L])
+ assertEquals("Monde", map2[2L])
+
+ val map3 = mutableLongObjectMapOf(
+ 1L, "World",
+ 2L, "Monde",
+ 3L, "Welt",
+ )
+ assertEquals(3, map3.size)
+ assertEquals("World", map3[1L])
+ assertEquals("Monde", map3[2L])
+ assertEquals("Welt", map3[3L])
+
+ val map4 = mutableLongObjectMapOf(
+ 1L, "World",
+ 2L, "Monde",
+ 3L, "Welt",
+ 4L, "Sekai",
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals("World", map4[1L])
+ assertEquals("Monde", map4[2L])
+ assertEquals("Welt", map4[3L])
+ assertEquals("Sekai", map4[4L])
+
+ val map5 = mutableLongObjectMapOf(
+ 1L, "World",
+ 2L, "Monde",
+ 3L, "Welt",
+ 4L, "Sekai",
+ 5L, "Mondo",
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals("World", map5[1L])
+ assertEquals("Monde", map5[2L])
+ assertEquals("Welt", map5[3L])
+ assertEquals("Sekai", map5[4L])
+ assertEquals("Mondo", map5[5L])
}
@Test
@@ -153,25 +252,12 @@
}
@Test
- fun putAllArray() {
- val map = MutableLongObjectMap<String?>()
- map[1L] = "World"
- map[2L] = null
-
- map.putAll(arrayOf(3L to "Welt", 7L to "Mundo"))
-
- assertEquals(4, map.size)
- assertEquals("Welt", map[3L])
- assertEquals("Mundo", map[7L])
- }
-
- @Test
fun putAllMap() {
val map = MutableLongObjectMap<String?>()
map[1L] = "World"
map[2L] = null
- map.putAll(mutableLongObjectMapOf(3L to "Welt", 7L to "Mundo"))
+ map.putAll(mutableLongObjectMapOf(3L, "Welt", 7L, "Mundo"))
assertEquals(4, map.size)
assertEquals("Welt", map[3L])
@@ -179,28 +265,9 @@
}
@Test
- fun plus() {
- val map = MutableLongObjectMap<String>()
- map += 1L to "World"
-
- assertEquals(1, map.size)
- assertEquals("World", map[1L])
- }
-
- @Test
fun plusMap() {
val map = MutableLongObjectMap<String>()
- map += longObjectMapOf(3L to "Welt", 7L to "Mundo")
-
- assertEquals(2, map.size)
- assertEquals("Welt", map[3L])
- assertEquals("Mundo", map[7L])
- }
-
- @Test
- fun plusArray() {
- val map = MutableLongObjectMap<String>()
- map += arrayOf(3L to "Welt", 7L to "Mundo")
+ map += longObjectMapOf(3L, "Welt", 7L, "Mundo")
assertEquals(2, map.size)
assertEquals("Welt", map[3L])
@@ -626,7 +693,7 @@
map[5L] = "Mondo"
map[6L] = "Sesang"
- assertTrue(map.all { key, value -> key < 7L && value.length > 0 })
+ assertTrue(map.all { key, value -> key < 7L && value.isNotEmpty() })
assertFalse(map.all { key, _ -> key < 6L })
}
}
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/ObjectFloatMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/ObjectFloatMapTest.kt
index 3ae3e6e..71752fb 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/ObjectFloatMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/ObjectFloatMapTest.kt
@@ -79,14 +79,113 @@
}
@Test
- fun objectFloatMapPairsFunction() {
- val map = mutableObjectFloatMapOf(
- "Hello" to 1f,
- "Bonjour" to 2f
+ fun objectFloatMapInitFunction() {
+ val map1 = objectFloatMapOf(
+ "Hello", 1f,
)
- assertEquals(2, map.size)
- assertEquals(1f, map["Hello"])
- assertEquals(2f, map["Bonjour"])
+ assertEquals(1, map1.size)
+ assertEquals(1f, map1["Hello"])
+
+ val map2 = objectFloatMapOf(
+ "Hello", 1f,
+ "Bonjour", 2f,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1f, map2["Hello"])
+ assertEquals(2f, map2["Bonjour"])
+
+ val map3 = objectFloatMapOf(
+ "Hello", 1f,
+ "Bonjour", 2f,
+ "Hallo", 3f,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1f, map3["Hello"])
+ assertEquals(2f, map3["Bonjour"])
+ assertEquals(3f, map3["Hallo"])
+
+ val map4 = objectFloatMapOf(
+ "Hello", 1f,
+ "Bonjour", 2f,
+ "Hallo", 3f,
+ "Konnichiwa", 4f,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1f, map4["Hello"])
+ assertEquals(2f, map4["Bonjour"])
+ assertEquals(3f, map4["Hallo"])
+ assertEquals(4f, map4["Konnichiwa"])
+
+ val map5 = objectFloatMapOf(
+ "Hello", 1f,
+ "Bonjour", 2f,
+ "Hallo", 3f,
+ "Konnichiwa", 4f,
+ "Ciao", 5f,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1f, map5["Hello"])
+ assertEquals(2f, map5["Bonjour"])
+ assertEquals(3f, map5["Hallo"])
+ assertEquals(4f, map5["Konnichiwa"])
+ assertEquals(5f, map5["Ciao"])
+ }
+
+ @Test
+ fun mutableObjectFloatMapInitFunction() {
+ val map1 = mutableObjectFloatMapOf(
+ "Hello", 1f,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1f, map1["Hello"])
+
+ val map2 = mutableObjectFloatMapOf(
+ "Hello", 1f,
+ "Bonjour", 2f,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1f, map2["Hello"])
+ assertEquals(2f, map2["Bonjour"])
+
+ val map3 = mutableObjectFloatMapOf(
+ "Hello", 1f,
+ "Bonjour", 2f,
+ "Hallo", 3f,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1f, map3["Hello"])
+ assertEquals(2f, map3["Bonjour"])
+ assertEquals(3f, map3["Hallo"])
+
+ val map4 = mutableObjectFloatMapOf(
+ "Hello", 1f,
+ "Bonjour", 2f,
+ "Hallo", 3f,
+ "Konnichiwa", 4f,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1f, map4["Hello"])
+ assertEquals(2f, map4["Bonjour"])
+ assertEquals(3f, map4["Hallo"])
+ assertEquals(4f, map4["Konnichiwa"])
+
+ val map5 = mutableObjectFloatMapOf(
+ "Hello", 1f,
+ "Bonjour", 2f,
+ "Hallo", 3f,
+ "Konnichiwa", 4f,
+ "Ciao", 5f,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1f, map5["Hello"])
+ assertEquals(2f, map5["Bonjour"])
+ assertEquals(3f, map5["Hallo"])
+ assertEquals(4f, map5["Konnichiwa"])
+ assertEquals(5f, map5["Ciao"])
}
@Test
@@ -147,39 +246,6 @@
}
@Test
- fun putAllArray() {
- val map = MutableObjectFloatMap<String?>()
- map["Hello"] = 1f
- map[null] = 2f
- map["Bonjour"] = 2f
-
- map.putAll(arrayOf("Hallo" to 3f, "Hola" to 7f))
-
- assertEquals(5, map.size)
- assertEquals(3f, map["Hallo"])
- assertEquals(7f, map["Hola"])
- }
-
- @Test
- fun plus() {
- val map = MutableObjectFloatMap<String>()
- map += "Hello" to 1f
-
- assertEquals(1, map.size)
- assertEquals(1f, map["Hello"])
- }
-
- @Test
- fun plusArray() {
- val map = MutableObjectFloatMap<String>()
- map += arrayOf("Hallo" to 3f, "Hola" to 7f)
-
- assertEquals(2, map.size)
- assertEquals(3f, map["Hallo"])
- assertEquals(7f, map["Hola"])
- }
-
- @Test
fun nullKey() {
val map = MutableObjectFloatMap<String?>()
map[null] = 1f
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/ObjectIntMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/ObjectIntMapTest.kt
index d3bf7c7..c64672a 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/ObjectIntMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/ObjectIntMapTest.kt
@@ -79,14 +79,113 @@
}
@Test
- fun objectIntMapPairsFunction() {
- val map = mutableObjectIntMapOf(
- "Hello" to 1,
- "Bonjour" to 2
+ fun objectIntMapInitFunction() {
+ val map1 = objectIntMapOf(
+ "Hello", 1,
)
- assertEquals(2, map.size)
- assertEquals(1, map["Hello"])
- assertEquals(2, map["Bonjour"])
+ assertEquals(1, map1.size)
+ assertEquals(1, map1["Hello"])
+
+ val map2 = objectIntMapOf(
+ "Hello", 1,
+ "Bonjour", 2,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1, map2["Hello"])
+ assertEquals(2, map2["Bonjour"])
+
+ val map3 = objectIntMapOf(
+ "Hello", 1,
+ "Bonjour", 2,
+ "Hallo", 3,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1, map3["Hello"])
+ assertEquals(2, map3["Bonjour"])
+ assertEquals(3, map3["Hallo"])
+
+ val map4 = objectIntMapOf(
+ "Hello", 1,
+ "Bonjour", 2,
+ "Hallo", 3,
+ "Konnichiwa", 4,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1, map4["Hello"])
+ assertEquals(2, map4["Bonjour"])
+ assertEquals(3, map4["Hallo"])
+ assertEquals(4, map4["Konnichiwa"])
+
+ val map5 = objectIntMapOf(
+ "Hello", 1,
+ "Bonjour", 2,
+ "Hallo", 3,
+ "Konnichiwa", 4,
+ "Ciao", 5,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1, map5["Hello"])
+ assertEquals(2, map5["Bonjour"])
+ assertEquals(3, map5["Hallo"])
+ assertEquals(4, map5["Konnichiwa"])
+ assertEquals(5, map5["Ciao"])
+ }
+
+ @Test
+ fun mutableObjectIntMapInitFunction() {
+ val map1 = mutableObjectIntMapOf(
+ "Hello", 1,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1, map1["Hello"])
+
+ val map2 = mutableObjectIntMapOf(
+ "Hello", 1,
+ "Bonjour", 2,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1, map2["Hello"])
+ assertEquals(2, map2["Bonjour"])
+
+ val map3 = mutableObjectIntMapOf(
+ "Hello", 1,
+ "Bonjour", 2,
+ "Hallo", 3,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1, map3["Hello"])
+ assertEquals(2, map3["Bonjour"])
+ assertEquals(3, map3["Hallo"])
+
+ val map4 = mutableObjectIntMapOf(
+ "Hello", 1,
+ "Bonjour", 2,
+ "Hallo", 3,
+ "Konnichiwa", 4,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1, map4["Hello"])
+ assertEquals(2, map4["Bonjour"])
+ assertEquals(3, map4["Hallo"])
+ assertEquals(4, map4["Konnichiwa"])
+
+ val map5 = mutableObjectIntMapOf(
+ "Hello", 1,
+ "Bonjour", 2,
+ "Hallo", 3,
+ "Konnichiwa", 4,
+ "Ciao", 5,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1, map5["Hello"])
+ assertEquals(2, map5["Bonjour"])
+ assertEquals(3, map5["Hallo"])
+ assertEquals(4, map5["Konnichiwa"])
+ assertEquals(5, map5["Ciao"])
}
@Test
@@ -147,39 +246,6 @@
}
@Test
- fun putAllArray() {
- val map = MutableObjectIntMap<String?>()
- map["Hello"] = 1
- map[null] = 2
- map["Bonjour"] = 2
-
- map.putAll(arrayOf("Hallo" to 3, "Hola" to 7))
-
- assertEquals(5, map.size)
- assertEquals(3, map["Hallo"])
- assertEquals(7, map["Hola"])
- }
-
- @Test
- fun plus() {
- val map = MutableObjectIntMap<String>()
- map += "Hello" to 1
-
- assertEquals(1, map.size)
- assertEquals(1, map["Hello"])
- }
-
- @Test
- fun plusArray() {
- val map = MutableObjectIntMap<String>()
- map += arrayOf("Hallo" to 3, "Hola" to 7)
-
- assertEquals(2, map.size)
- assertEquals(3, map["Hallo"])
- assertEquals(7, map["Hola"])
- }
-
- @Test
fun nullKey() {
val map = MutableObjectIntMap<String?>()
map[null] = 1
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/ObjectLongMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/ObjectLongMapTest.kt
index 3cf8c73..a748e10 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/ObjectLongMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/ObjectLongMapTest.kt
@@ -79,14 +79,113 @@
}
@Test
- fun objectLongMapPairsFunction() {
- val map = mutableObjectLongMapOf(
- "Hello" to 1L,
- "Bonjour" to 2L
+ fun objectLongMapInitFunction() {
+ val map1 = objectLongMapOf(
+ "Hello", 1L,
)
- assertEquals(2, map.size)
- assertEquals(1L, map["Hello"])
- assertEquals(2L, map["Bonjour"])
+ assertEquals(1, map1.size)
+ assertEquals(1L, map1["Hello"])
+
+ val map2 = objectLongMapOf(
+ "Hello", 1L,
+ "Bonjour", 2L,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1L, map2["Hello"])
+ assertEquals(2L, map2["Bonjour"])
+
+ val map3 = objectLongMapOf(
+ "Hello", 1L,
+ "Bonjour", 2L,
+ "Hallo", 3L,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1L, map3["Hello"])
+ assertEquals(2L, map3["Bonjour"])
+ assertEquals(3L, map3["Hallo"])
+
+ val map4 = objectLongMapOf(
+ "Hello", 1L,
+ "Bonjour", 2L,
+ "Hallo", 3L,
+ "Konnichiwa", 4L,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1L, map4["Hello"])
+ assertEquals(2L, map4["Bonjour"])
+ assertEquals(3L, map4["Hallo"])
+ assertEquals(4L, map4["Konnichiwa"])
+
+ val map5 = objectLongMapOf(
+ "Hello", 1L,
+ "Bonjour", 2L,
+ "Hallo", 3L,
+ "Konnichiwa", 4L,
+ "Ciao", 5L,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1L, map5["Hello"])
+ assertEquals(2L, map5["Bonjour"])
+ assertEquals(3L, map5["Hallo"])
+ assertEquals(4L, map5["Konnichiwa"])
+ assertEquals(5L, map5["Ciao"])
+ }
+
+ @Test
+ fun mutableObjectLongMapInitFunction() {
+ val map1 = mutableObjectLongMapOf(
+ "Hello", 1L,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1L, map1["Hello"])
+
+ val map2 = mutableObjectLongMapOf(
+ "Hello", 1L,
+ "Bonjour", 2L,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1L, map2["Hello"])
+ assertEquals(2L, map2["Bonjour"])
+
+ val map3 = mutableObjectLongMapOf(
+ "Hello", 1L,
+ "Bonjour", 2L,
+ "Hallo", 3L,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1L, map3["Hello"])
+ assertEquals(2L, map3["Bonjour"])
+ assertEquals(3L, map3["Hallo"])
+
+ val map4 = mutableObjectLongMapOf(
+ "Hello", 1L,
+ "Bonjour", 2L,
+ "Hallo", 3L,
+ "Konnichiwa", 4L,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1L, map4["Hello"])
+ assertEquals(2L, map4["Bonjour"])
+ assertEquals(3L, map4["Hallo"])
+ assertEquals(4L, map4["Konnichiwa"])
+
+ val map5 = mutableObjectLongMapOf(
+ "Hello", 1L,
+ "Bonjour", 2L,
+ "Hallo", 3L,
+ "Konnichiwa", 4L,
+ "Ciao", 5L,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1L, map5["Hello"])
+ assertEquals(2L, map5["Bonjour"])
+ assertEquals(3L, map5["Hallo"])
+ assertEquals(4L, map5["Konnichiwa"])
+ assertEquals(5L, map5["Ciao"])
}
@Test
@@ -147,39 +246,6 @@
}
@Test
- fun putAllArray() {
- val map = MutableObjectLongMap<String?>()
- map["Hello"] = 1L
- map[null] = 2L
- map["Bonjour"] = 2L
-
- map.putAll(arrayOf("Hallo" to 3L, "Hola" to 7L))
-
- assertEquals(5, map.size)
- assertEquals(3L, map["Hallo"])
- assertEquals(7L, map["Hola"])
- }
-
- @Test
- fun plus() {
- val map = MutableObjectLongMap<String>()
- map += "Hello" to 1L
-
- assertEquals(1, map.size)
- assertEquals(1L, map["Hello"])
- }
-
- @Test
- fun plusArray() {
- val map = MutableObjectLongMap<String>()
- map += arrayOf("Hallo" to 3L, "Hola" to 7L)
-
- assertEquals(2, map.size)
- assertEquals(3L, map["Hallo"])
- assertEquals(7L, map["Hola"])
- }
-
- @Test
fun nullKey() {
val map = MutableObjectLongMap<String?>()
map[null] = 1L
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/PairTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/PairTest.kt
index b132651..51cc5963 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/PairTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/PairTest.kt
@@ -24,18 +24,18 @@
@Test
fun intCreation() {
- val pair = PairIntInt(3, 5)
+ val pair = IntIntPair(3, 5)
assertEquals(3, pair.first)
assertEquals(5, pair.second)
}
@Test
fun intEquality() {
- val pair = PairIntInt(3, 5)
- val pairEqual = PairIntInt(3, 5)
- val pairUnequal1 = PairIntInt(4, 5)
- val pairUnequal2 = PairIntInt(3, 6)
- val pairUnequal3 = PairIntInt(4, 6)
+ val pair = IntIntPair(3, 5)
+ val pairEqual = IntIntPair(3, 5)
+ val pairUnequal1 = IntIntPair(4, 5)
+ val pairUnequal2 = IntIntPair(3, 6)
+ val pairUnequal3 = IntIntPair(4, 6)
assertEquals(pair, pairEqual)
assertNotEquals(pair, pairUnequal1)
@@ -45,7 +45,7 @@
@Test
fun intDestructing() {
- val pair = PairIntInt(3, 5)
+ val pair = IntIntPair(3, 5)
val (first, second) = pair
assertEquals(3, first)
assertEquals(5, second)
@@ -53,18 +53,18 @@
@Test
fun floatCreation() {
- val pair = PairFloatFloat(3f, 5f)
+ val pair = FloatFloatPair(3f, 5f)
assertEquals(3f, pair.first)
assertEquals(5f, pair.second)
}
@Test
fun floatEquality() {
- val pair = PairFloatFloat(3f, 5f)
- val pairEqual = PairFloatFloat(3f, 5f)
- val pairUnequal1 = PairFloatFloat(4f, 5f)
- val pairUnequal2 = PairFloatFloat(3f, 6f)
- val pairUnequal3 = PairFloatFloat(4f, 6f)
+ val pair = FloatFloatPair(3f, 5f)
+ val pairEqual = FloatFloatPair(3f, 5f)
+ val pairUnequal1 = FloatFloatPair(4f, 5f)
+ val pairUnequal2 = FloatFloatPair(3f, 6f)
+ val pairUnequal3 = FloatFloatPair(4f, 6f)
assertEquals(pair, pairEqual)
assertNotEquals(pair, pairUnequal1)
@@ -74,7 +74,7 @@
@Test
fun floatDestructing() {
- val pair = PairFloatFloat(3f, 5f)
+ val pair = FloatFloatPair(3f, 5f)
val (first, second) = pair
assertEquals(3f, first)
assertEquals(5f, second)
@@ -82,18 +82,18 @@
@Test
fun longCreation() {
- val pair = PairLongLong(3, 5)
+ val pair = LongLongPair(3, 5)
assertEquals(3, pair.first)
assertEquals(5, pair.second)
}
@Test
fun longEquality() {
- val pair = PairLongLong(3, 5)
- val pairEqual = PairLongLong(3, 5)
- val pairUnequal1 = PairLongLong(4, 5)
- val pairUnequal2 = PairLongLong(3, 6)
- val pairUnequal3 = PairLongLong(4, 6)
+ val pair = LongLongPair(3, 5)
+ val pairEqual = LongLongPair(3, 5)
+ val pairUnequal1 = LongLongPair(4, 5)
+ val pairUnequal2 = LongLongPair(3, 6)
+ val pairUnequal3 = LongLongPair(4, 6)
assertEquals(pair, pairEqual)
assertNotEquals(pair, pairUnequal1)
@@ -103,7 +103,7 @@
@Test
fun longDestructing() {
- val pair = PairLongLong(3, 5)
+ val pair = LongLongPair(3, 5)
val (first, second) = pair
assertEquals(3L, first)
assertEquals(5L, second)
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/ScatterMapTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/ScatterMapTest.kt
index a869735..a54c82d 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/ScatterMapTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/ScatterMapTest.kt
@@ -454,6 +454,34 @@
}
@Test
+ fun minusScatterSet() {
+ val map = MutableScatterMap<String, String>()
+ map["Hello"] = "World"
+ map["Bonjour"] = "Monde"
+ map["Hallo"] = "Welt"
+
+ map -= scatterSetOf("Hallo", "Bonjour")
+
+ assertEquals(1, map.size)
+ assertNull(map["Hallo"])
+ assertNull(map["Bonjour"])
+ }
+
+ @Test
+ fun minusObjectList() {
+ val map = MutableScatterMap<String, String>()
+ map["Hello"] = "World"
+ map["Bonjour"] = "Monde"
+ map["Hallo"] = "Welt"
+
+ map -= objectListOf("Hallo", "Bonjour")
+
+ assertEquals(1, map.size)
+ assertNull(map["Hallo"])
+ assertNull(map["Bonjour"])
+ }
+
+ @Test
fun conditionalRemove() {
val map = MutableScatterMap<String?, String?>()
assertFalse(map.remove("Hello", "World"))
diff --git a/collection/collection/src/commonTest/kotlin/androidx/collection/ScatterSetTest.kt b/collection/collection/src/commonTest/kotlin/androidx/collection/ScatterSetTest.kt
index 5a4ba52..b9e3892d 100644
--- a/collection/collection/src/commonTest/kotlin/androidx/collection/ScatterSetTest.kt
+++ b/collection/collection/src/commonTest/kotlin/androidx/collection/ScatterSetTest.kt
@@ -144,6 +144,16 @@
}
@Test
+ fun addAllObjectList() {
+ val set = mutableScatterSetOf("Hello")
+ assertFalse(set.addAll(objectListOf("Hello")))
+ assertEquals(1, set.size)
+ assertTrue(set.addAll(objectListOf("Hello", "World")))
+ assertEquals(2, set.size)
+ assertTrue("World" in set)
+ }
+
+ @Test
fun plusAssignArray() {
val set = mutableScatterSetOf("Hello")
set += arrayOf("Hello")
@@ -184,6 +194,16 @@
}
@Test
+ fun plusAssignObjectList() {
+ val set = mutableScatterSetOf("Hello")
+ set += objectListOf("Hello")
+ assertEquals(1, set.size)
+ set += objectListOf("Hello", "World")
+ assertEquals(2, set.size)
+ assertTrue("World" in set)
+ }
+
+ @Test
fun nullElement() {
val set = MutableScatterSet<String?>()
set += null
@@ -348,6 +368,16 @@
}
@Test
+ fun removeAllObjectList() {
+ val set = mutableScatterSetOf("Hello", "World")
+ assertFalse(set.removeAll(objectListOf("Hola", "Bonjour")))
+ assertEquals(2, set.size)
+ assertTrue(set.removeAll(objectListOf("Hola", "Hello", "Bonjour")))
+ assertEquals(1, set.size)
+ assertFalse("Hello" in set)
+ }
+
+ @Test
fun minusAssignArray() {
val set = mutableScatterSetOf("Hello", "World")
set -= arrayOf("Hola", "Bonjour")
@@ -388,6 +418,16 @@
}
@Test
+ fun minusAssignObjectList() {
+ val set = mutableScatterSetOf("Hello", "World")
+ set -= objectListOf("Hola", "Bonjour")
+ assertEquals(2, set.size)
+ set -= objectListOf("Hola", "Hello", "Bonjour")
+ assertEquals(1, set.size)
+ assertFalse("Hello" in set)
+ }
+
+ @Test
fun insertManyEntries() {
val set = MutableScatterSet<String>()
diff --git a/collection/collection/template/ObjectPValueMap.kt.template b/collection/collection/template/ObjectPValueMap.kt.template
index ba8284e..243e91b 100644
--- a/collection/collection/template/ObjectPValueMap.kt.template
+++ b/collection/collection/template/ObjectPValueMap.kt.template
@@ -54,38 +54,186 @@
EmptyObjectPValueMap as ObjectPValueMap<K>
/**
- * Returns a new [MutableObjectPValueMap].
+ * Returns a new [ObjectPValueMap] with only [key1] associated with [value1].
+ */
+public fun <K> objectPValueMapOf(
+ key1: K,
+ value1: PValue
+): ObjectPValueMap<K> =
+ MutableObjectPValueMap<K>().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [ObjectPValueMap] with only [key1] and [key2] associated with
+ * [value1] and [value2], respectively.
+ */
+public fun <K> objectPValueMapOf(
+ key1: K,
+ value1: PValue,
+ key2: K,
+ value2: PValue,
+): ObjectPValueMap<K> =
+ MutableObjectPValueMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [ObjectPValueMap] with only [key1], [key2], and [key3] associated with
+ * [value1], [value2], and [value3], respectively.
+ */
+public fun <K> objectPValueMapOf(
+ key1: K,
+ value1: PValue,
+ key2: K,
+ value2: PValue,
+ key3: K,
+ value3: PValue,
+): ObjectPValueMap<K> =
+ MutableObjectPValueMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [ObjectPValueMap] with only [key1], [key2], [key3], and [key4] associated with
+ * [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <K> objectPValueMapOf(
+ key1: K,
+ value1: PValue,
+ key2: K,
+ value2: PValue,
+ key3: K,
+ value3: PValue,
+ key4: K,
+ value4: PValue,
+): ObjectPValueMap<K> =
+ MutableObjectPValueMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [ObjectPValueMap] with only [key1], [key2], [key3], [key4], and [key5] associated
+ * with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <K> objectPValueMapOf(
+ key1: K,
+ value1: PValue,
+ key2: K,
+ value2: PValue,
+ key3: K,
+ value3: PValue,
+ key4: K,
+ value4: PValue,
+ key5: K,
+ value5: PValue,
+): ObjectPValueMap<K> =
+ MutableObjectPValueMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
+ }
+
+/**
+ * Returns a new empty [MutableObjectPValueMap].
*/
public fun <K> mutableObjectPValueMapOf(): MutableObjectPValueMap<K> = MutableObjectPValueMap()
/**
- * Returns a new [MutableObjectPValueMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [PValue] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [MutableObjectPValueMap] with only [key1] associated with [value1].
*/
-public fun <K> objectPValueMapOf(vararg pairs: Pair<K, PValue>): ObjectPValueMap<K> =
- MutableObjectPValueMap<K>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <K> mutableObjectPValueMapOf(
+ key1: K,
+ value1: PValue,
+): MutableObjectPValueMap<K> =
+ MutableObjectPValueMap<K>().also { map ->
+ map[key1] = value1
}
/**
- * Returns a new [MutableObjectPValueMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [PValue] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [MutableObjectPValueMap] with only [key1] and [key2] associated with
+ * [value1] and [value2], respectively.
*/
-public fun <K> mutableObjectPValueMapOf(vararg pairs: Pair<K, PValue>): MutableObjectPValueMap<K> =
- MutableObjectPValueMap<K>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <K> mutableObjectPValueMapOf(
+ key1: K,
+ value1: PValue,
+ key2: K,
+ value2: PValue,
+): MutableObjectPValueMap<K> =
+ MutableObjectPValueMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutableObjectPValueMap] with only [key1], [key2], and [key3] associated with
+ * [value1], [value2], and [value3], respectively.
+ */
+public fun <K> mutableObjectPValueMapOf(
+ key1: K,
+ value1: PValue,
+ key2: K,
+ value2: PValue,
+ key3: K,
+ value3: PValue,
+): MutableObjectPValueMap<K> =
+ MutableObjectPValueMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutableObjectPValueMap] with only [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <K> mutableObjectPValueMapOf(
+ key1: K,
+ value1: PValue,
+ key2: K,
+ value2: PValue,
+ key3: K,
+ value3: PValue,
+ key4: K,
+ value4: PValue,
+): MutableObjectPValueMap<K> =
+ MutableObjectPValueMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutableObjectPValueMap] with only [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <K> mutableObjectPValueMapOf(
+ key1: K,
+ value1: PValue,
+ key2: K,
+ value2: PValue,
+ key3: K,
+ value3: PValue,
+ key4: K,
+ value4: PValue,
+ key5: K,
+ value5: PValue,
+): MutableObjectPValueMap<K> =
+ MutableObjectPValueMap<K>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -560,20 +708,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [PValue] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<out Pair<K, PValue>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: ObjectPValueMap<K>) {
@@ -583,29 +717,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that the [Pair] is allocated and the [PValue] value is boxed.
- * Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<K, PValue>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [PValue] value is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<out Pair<K, PValue>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: ObjectPValueMap<K>): Unit = putAll(from)
diff --git a/collection/collection/template/ObjectPValueMapTest.kt.template b/collection/collection/template/ObjectPValueMapTest.kt.template
index d2c6f43..0972a4a 100644
--- a/collection/collection/template/ObjectPValueMapTest.kt.template
+++ b/collection/collection/template/ObjectPValueMapTest.kt.template
@@ -79,14 +79,113 @@
}
@Test
- fun objectPValueMapPairsFunction() {
- val map = mutableObjectPValueMapOf(
- "Hello" to 1ValueSuffix,
- "Bonjour" to 2ValueSuffix
+ fun objectPValueMapInitFunction() {
+ val map1 = objectPValueMapOf(
+ "Hello", 1ValueSuffix,
)
- assertEquals(2, map.size)
- assertEquals(1ValueSuffix, map["Hello"])
- assertEquals(2ValueSuffix, map["Bonjour"])
+ assertEquals(1, map1.size)
+ assertEquals(1ValueSuffix, map1["Hello"])
+
+ val map2 = objectPValueMapOf(
+ "Hello", 1ValueSuffix,
+ "Bonjour", 2ValueSuffix,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1ValueSuffix, map2["Hello"])
+ assertEquals(2ValueSuffix, map2["Bonjour"])
+
+ val map3 = objectPValueMapOf(
+ "Hello", 1ValueSuffix,
+ "Bonjour", 2ValueSuffix,
+ "Hallo", 3ValueSuffix,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1ValueSuffix, map3["Hello"])
+ assertEquals(2ValueSuffix, map3["Bonjour"])
+ assertEquals(3ValueSuffix, map3["Hallo"])
+
+ val map4 = objectPValueMapOf(
+ "Hello", 1ValueSuffix,
+ "Bonjour", 2ValueSuffix,
+ "Hallo", 3ValueSuffix,
+ "Konnichiwa", 4ValueSuffix,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1ValueSuffix, map4["Hello"])
+ assertEquals(2ValueSuffix, map4["Bonjour"])
+ assertEquals(3ValueSuffix, map4["Hallo"])
+ assertEquals(4ValueSuffix, map4["Konnichiwa"])
+
+ val map5 = objectPValueMapOf(
+ "Hello", 1ValueSuffix,
+ "Bonjour", 2ValueSuffix,
+ "Hallo", 3ValueSuffix,
+ "Konnichiwa", 4ValueSuffix,
+ "Ciao", 5ValueSuffix,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1ValueSuffix, map5["Hello"])
+ assertEquals(2ValueSuffix, map5["Bonjour"])
+ assertEquals(3ValueSuffix, map5["Hallo"])
+ assertEquals(4ValueSuffix, map5["Konnichiwa"])
+ assertEquals(5ValueSuffix, map5["Ciao"])
+ }
+
+ @Test
+ fun mutableObjectPValueMapInitFunction() {
+ val map1 = mutableObjectPValueMapOf(
+ "Hello", 1ValueSuffix,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1ValueSuffix, map1["Hello"])
+
+ val map2 = mutableObjectPValueMapOf(
+ "Hello", 1ValueSuffix,
+ "Bonjour", 2ValueSuffix,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1ValueSuffix, map2["Hello"])
+ assertEquals(2ValueSuffix, map2["Bonjour"])
+
+ val map3 = mutableObjectPValueMapOf(
+ "Hello", 1ValueSuffix,
+ "Bonjour", 2ValueSuffix,
+ "Hallo", 3ValueSuffix,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1ValueSuffix, map3["Hello"])
+ assertEquals(2ValueSuffix, map3["Bonjour"])
+ assertEquals(3ValueSuffix, map3["Hallo"])
+
+ val map4 = mutableObjectPValueMapOf(
+ "Hello", 1ValueSuffix,
+ "Bonjour", 2ValueSuffix,
+ "Hallo", 3ValueSuffix,
+ "Konnichiwa", 4ValueSuffix,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1ValueSuffix, map4["Hello"])
+ assertEquals(2ValueSuffix, map4["Bonjour"])
+ assertEquals(3ValueSuffix, map4["Hallo"])
+ assertEquals(4ValueSuffix, map4["Konnichiwa"])
+
+ val map5 = mutableObjectPValueMapOf(
+ "Hello", 1ValueSuffix,
+ "Bonjour", 2ValueSuffix,
+ "Hallo", 3ValueSuffix,
+ "Konnichiwa", 4ValueSuffix,
+ "Ciao", 5ValueSuffix,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1ValueSuffix, map5["Hello"])
+ assertEquals(2ValueSuffix, map5["Bonjour"])
+ assertEquals(3ValueSuffix, map5["Hallo"])
+ assertEquals(4ValueSuffix, map5["Konnichiwa"])
+ assertEquals(5ValueSuffix, map5["Ciao"])
}
@Test
@@ -147,39 +246,6 @@
}
@Test
- fun putAllArray() {
- val map = MutableObjectPValueMap<String?>()
- map["Hello"] = 1ValueSuffix
- map[null] = 2ValueSuffix
- map["Bonjour"] = 2ValueSuffix
-
- map.putAll(arrayOf("Hallo" to 3ValueSuffix, "Hola" to 7ValueSuffix))
-
- assertEquals(5, map.size)
- assertEquals(3ValueSuffix, map["Hallo"])
- assertEquals(7ValueSuffix, map["Hola"])
- }
-
- @Test
- fun plus() {
- val map = MutableObjectPValueMap<String>()
- map += "Hello" to 1ValueSuffix
-
- assertEquals(1, map.size)
- assertEquals(1ValueSuffix, map["Hello"])
- }
-
- @Test
- fun plusArray() {
- val map = MutableObjectPValueMap<String>()
- map += arrayOf("Hallo" to 3ValueSuffix, "Hola" to 7ValueSuffix)
-
- assertEquals(2, map.size)
- assertEquals(3ValueSuffix, map["Hallo"])
- assertEquals(7ValueSuffix, map["Hola"])
- }
-
- @Test
fun nullKey() {
val map = MutableObjectPValueMap<String?>()
map[null] = 1ValueSuffix
diff --git a/collection/collection/template/PKeyObjectMap.kt.template b/collection/collection/template/PKeyObjectMap.kt.template
index 2bb53a2b..ad2de7eb 100644
--- a/collection/collection/template/PKeyObjectMap.kt.template
+++ b/collection/collection/template/PKeyObjectMap.kt.template
@@ -52,18 +52,87 @@
public fun <V> pKeyObjectMapOf(): PKeyObjectMap<V> = EmptyPKeyObjectMap as PKeyObjectMap<V>
/**
- * Returns a new [PKeyObjectMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [PKey] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [PKeyObjectMap] with [key1] associated with [value1].
*/
-public fun <V> pKeyObjectMapOf(vararg pairs: Pair<PKey, V>): PKeyObjectMap<V> =
- MutablePKeyObjectMap<V>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <V> pKeyObjectMapOf(
+ key1: PKey,
+ value1: V
+): PKeyObjectMap<V> = MutablePKeyObjectMap<V>().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [PKeyObjectMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun <V> pKeyObjectMapOf(
+ key1: PKey,
+ value1: V,
+ key2: PKey,
+ value2: V,
+): PKeyObjectMap<V> = MutablePKeyObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [PKeyObjectMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun <V> pKeyObjectMapOf(
+ key1: PKey,
+ value1: V,
+ key2: PKey,
+ value2: V,
+ key3: PKey,
+ value3: V,
+): PKeyObjectMap<V> = MutablePKeyObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [PKeyObjectMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <V> pKeyObjectMapOf(
+ key1: PKey,
+ value1: V,
+ key2: PKey,
+ value2: V,
+ key3: PKey,
+ value3: V,
+ key4: PKey,
+ value4: V,
+): PKeyObjectMap<V> = MutablePKeyObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [PKeyObjectMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <V> pKeyObjectMapOf(
+ key1: PKey,
+ value1: V,
+ key2: PKey,
+ value2: V,
+ key3: PKey,
+ value3: V,
+ key4: PKey,
+ value4: V,
+ key5: PKey,
+ value5: V,
+): PKeyObjectMap<V> = MutablePKeyObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -72,18 +141,87 @@
public fun <V> mutablePKeyObjectMapOf(): MutablePKeyObjectMap<V> = MutablePKeyObjectMap()
/**
- * Returns a new [MutablePKeyObjectMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [PKey] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
+ * Returns a new [MutablePKeyObjectMap] with [key1] associated with [value1].
*/
-public fun <V> mutablePKeyObjectMapOf(vararg pairs: Pair<PKey, V>): MutablePKeyObjectMap<V> =
- MutablePKeyObjectMap<V>(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun <V> mutablePKeyObjectMapOf(
+ key1: PKey,
+ value1: V
+): MutablePKeyObjectMap<V> = MutablePKeyObjectMap<V>().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutablePKeyObjectMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun <V> mutablePKeyObjectMapOf(
+ key1: PKey,
+ value1: V,
+ key2: PKey,
+ value2: V,
+): MutablePKeyObjectMap<V> = MutablePKeyObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutablePKeyObjectMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun <V> mutablePKeyObjectMapOf(
+ key1: PKey,
+ value1: V,
+ key2: PKey,
+ value2: V,
+ key3: PKey,
+ value3: V,
+): MutablePKeyObjectMap<V> = MutablePKeyObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutablePKeyObjectMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun <V> mutablePKeyObjectMapOf(
+ key1: PKey,
+ value1: V,
+ key2: PKey,
+ value2: V,
+ key3: PKey,
+ value3: V,
+ key4: PKey,
+ value4: V,
+): MutablePKeyObjectMap<V> = MutablePKeyObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutablePKeyObjectMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun <V> mutablePKeyObjectMapOf(
+ key1: PKey,
+ value1: V,
+ key2: PKey,
+ value2: V,
+ key3: PKey,
+ value3: V,
+ key4: PKey,
+ value4: V,
+ key5: PKey,
+ value5: V,
+): MutablePKeyObjectMap<V> = MutablePKeyObjectMap<V>().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +692,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [PKey] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<out Pair<PKey, V>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: PKeyObjectMap<V>) {
@@ -577,29 +701,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that the [Pair] is allocated and the [PKey] key is boxed.
- * Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<PKey, V>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * the [PKey] key is boxed. Use [set] for each entry instead when it is
- * important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<out Pair<PKey, V>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: PKeyObjectMap<V>): Unit = putAll(from)
diff --git a/collection/collection/template/PKeyObjectMapTest.kt.template b/collection/collection/template/PKeyObjectMapTest.kt.template
index d04a330..dea3242 100644
--- a/collection/collection/template/PKeyObjectMapTest.kt.template
+++ b/collection/collection/template/PKeyObjectMapTest.kt.template
@@ -78,14 +78,113 @@
}
@Test
- fun pKeyObjectMapPairsFunction() {
- val map = mutablePKeyObjectMapOf(
- 1KeySuffix to "World",
- 2KeySuffix to "Monde"
+ fun pKeyObjectMapInitFunction() {
+ val map1 = pKeyObjectMapOf(
+ 1KeySuffix, "World",
)
- assertEquals(2, map.size)
- assertEquals("World", map[1KeySuffix])
- assertEquals("Monde", map[2KeySuffix])
+ assertEquals(1, map1.size)
+ assertEquals("World", map1[1KeySuffix])
+
+ val map2 = pKeyObjectMapOf(
+ 1KeySuffix, "World",
+ 2KeySuffix, "Monde",
+ )
+ assertEquals(2, map2.size)
+ assertEquals("World", map2[1KeySuffix])
+ assertEquals("Monde", map2[2KeySuffix])
+
+ val map3 = pKeyObjectMapOf(
+ 1KeySuffix, "World",
+ 2KeySuffix, "Monde",
+ 3KeySuffix, "Welt",
+ )
+ assertEquals(3, map3.size)
+ assertEquals("World", map3[1KeySuffix])
+ assertEquals("Monde", map3[2KeySuffix])
+ assertEquals("Welt", map3[3KeySuffix])
+
+ val map4 = pKeyObjectMapOf(
+ 1KeySuffix, "World",
+ 2KeySuffix, "Monde",
+ 3KeySuffix, "Welt",
+ 4KeySuffix, "Sekai",
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals("World", map4[1KeySuffix])
+ assertEquals("Monde", map4[2KeySuffix])
+ assertEquals("Welt", map4[3KeySuffix])
+ assertEquals("Sekai", map4[4KeySuffix])
+
+ val map5 = pKeyObjectMapOf(
+ 1KeySuffix, "World",
+ 2KeySuffix, "Monde",
+ 3KeySuffix, "Welt",
+ 4KeySuffix, "Sekai",
+ 5KeySuffix, "Mondo",
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals("World", map5[1KeySuffix])
+ assertEquals("Monde", map5[2KeySuffix])
+ assertEquals("Welt", map5[3KeySuffix])
+ assertEquals("Sekai", map5[4KeySuffix])
+ assertEquals("Mondo", map5[5KeySuffix])
+ }
+
+ @Test
+ fun mutablePKeyObjectMapInitFunction() {
+ val map1 = mutablePKeyObjectMapOf(
+ 1KeySuffix, "World",
+ )
+ assertEquals(1, map1.size)
+ assertEquals("World", map1[1KeySuffix])
+
+ val map2 = mutablePKeyObjectMapOf(
+ 1KeySuffix, "World",
+ 2KeySuffix, "Monde",
+ )
+ assertEquals(2, map2.size)
+ assertEquals("World", map2[1KeySuffix])
+ assertEquals("Monde", map2[2KeySuffix])
+
+ val map3 = mutablePKeyObjectMapOf(
+ 1KeySuffix, "World",
+ 2KeySuffix, "Monde",
+ 3KeySuffix, "Welt",
+ )
+ assertEquals(3, map3.size)
+ assertEquals("World", map3[1KeySuffix])
+ assertEquals("Monde", map3[2KeySuffix])
+ assertEquals("Welt", map3[3KeySuffix])
+
+ val map4 = mutablePKeyObjectMapOf(
+ 1KeySuffix, "World",
+ 2KeySuffix, "Monde",
+ 3KeySuffix, "Welt",
+ 4KeySuffix, "Sekai",
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals("World", map4[1KeySuffix])
+ assertEquals("Monde", map4[2KeySuffix])
+ assertEquals("Welt", map4[3KeySuffix])
+ assertEquals("Sekai", map4[4KeySuffix])
+
+ val map5 = mutablePKeyObjectMapOf(
+ 1KeySuffix, "World",
+ 2KeySuffix, "Monde",
+ 3KeySuffix, "Welt",
+ 4KeySuffix, "Sekai",
+ 5KeySuffix, "Mondo",
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals("World", map5[1KeySuffix])
+ assertEquals("Monde", map5[2KeySuffix])
+ assertEquals("Welt", map5[3KeySuffix])
+ assertEquals("Sekai", map5[4KeySuffix])
+ assertEquals("Mondo", map5[5KeySuffix])
}
@Test
@@ -153,25 +252,12 @@
}
@Test
- fun putAllArray() {
- val map = MutablePKeyObjectMap<String?>()
- map[1KeySuffix] = "World"
- map[2KeySuffix] = null
-
- map.putAll(arrayOf(3KeySuffix to "Welt", 7KeySuffix to "Mundo"))
-
- assertEquals(4, map.size)
- assertEquals("Welt", map[3KeySuffix])
- assertEquals("Mundo", map[7KeySuffix])
- }
-
- @Test
fun putAllMap() {
val map = MutablePKeyObjectMap<String?>()
map[1KeySuffix] = "World"
map[2KeySuffix] = null
- map.putAll(mutablePKeyObjectMapOf(3KeySuffix to "Welt", 7KeySuffix to "Mundo"))
+ map.putAll(mutablePKeyObjectMapOf(3KeySuffix, "Welt", 7KeySuffix, "Mundo"))
assertEquals(4, map.size)
assertEquals("Welt", map[3KeySuffix])
@@ -179,28 +265,9 @@
}
@Test
- fun plus() {
- val map = MutablePKeyObjectMap<String>()
- map += 1KeySuffix to "World"
-
- assertEquals(1, map.size)
- assertEquals("World", map[1KeySuffix])
- }
-
- @Test
fun plusMap() {
val map = MutablePKeyObjectMap<String>()
- map += pKeyObjectMapOf(3KeySuffix to "Welt", 7KeySuffix to "Mundo")
-
- assertEquals(2, map.size)
- assertEquals("Welt", map[3KeySuffix])
- assertEquals("Mundo", map[7KeySuffix])
- }
-
- @Test
- fun plusArray() {
- val map = MutablePKeyObjectMap<String>()
- map += arrayOf(3KeySuffix to "Welt", 7KeySuffix to "Mundo")
+ map += pKeyObjectMapOf(3KeySuffix, "Welt", 7KeySuffix, "Mundo")
assertEquals(2, map.size)
assertEquals("Welt", map[3KeySuffix])
@@ -626,7 +693,7 @@
map[5KeySuffix] = "Mondo"
map[6KeySuffix] = "Sesang"
- assertTrue(map.all { key, value -> key < 7KeySuffix && value.length > 0 })
+ assertTrue(map.all { key, value -> key < 7KeySuffix && value.isNotEmpty() })
assertFalse(map.all { key, _ -> key < 6KeySuffix })
}
}
diff --git a/collection/collection/template/PKeyPValueMap.kt.template b/collection/collection/template/PKeyPValueMap.kt.template
index 0d0a6fe..c81830b 100644
--- a/collection/collection/template/PKeyPValueMap.kt.template
+++ b/collection/collection/template/PKeyPValueMap.kt.template
@@ -41,7 +41,6 @@
/**
* Returns an empty, read-only [PKeyPValueMap].
*/
-@Suppress("UNCHECKED_CAST")
public fun emptyPKeyPValueMap(): PKeyPValueMap = EmptyPKeyPValueMap
/**
@@ -50,18 +49,87 @@
public fun pKeyPValueMapOf(): PKeyPValueMap = EmptyPKeyPValueMap
/**
- * Returns a new [PKeyPValueMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [PKey] key and [PValue] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [PKeyPValueMap] with [key1] associated with [value1].
*/
-public fun pKeyPValueMapOf(vararg pairs: Pair<PKey, PValue>): PKeyPValueMap =
- MutablePKeyPValueMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun pKeyPValueMapOf(
+ key1: PKey,
+ value1: PValue
+): PKeyPValueMap = MutablePKeyPValueMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [PKeyPValueMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun pKeyPValueMapOf(
+ key1: PKey,
+ value1: PValue,
+ key2: PKey,
+ value2: PValue,
+): PKeyPValueMap = MutablePKeyPValueMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [PKeyPValueMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun pKeyPValueMapOf(
+ key1: PKey,
+ value1: PValue,
+ key2: PKey,
+ value2: PValue,
+ key3: PKey,
+ value3: PValue,
+): PKeyPValueMap = MutablePKeyPValueMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [PKeyPValueMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun pKeyPValueMapOf(
+ key1: PKey,
+ value1: PValue,
+ key2: PKey,
+ value2: PValue,
+ key3: PKey,
+ value3: PValue,
+ key4: PKey,
+ value4: PValue,
+): PKeyPValueMap = MutablePKeyPValueMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [PKeyPValueMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun pKeyPValueMapOf(
+ key1: PKey,
+ value1: PValue,
+ key2: PKey,
+ value2: PValue,
+ key3: PKey,
+ value3: PValue,
+ key4: PKey,
+ value4: PValue,
+ key5: PKey,
+ value5: PValue,
+): PKeyPValueMap = MutablePKeyPValueMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -70,18 +138,87 @@
public fun mutablePKeyPValueMapOf(): MutablePKeyPValueMap = MutablePKeyPValueMap()
/**
- * Returns a new [MutablePKeyPValueMap] with the specified contents, given as
- * a list of pairs where the first component is the key and the second
- * is the value. If multiple pairs have the same key, the resulting map
- * will contain the value from the last of those pairs.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [PKey] key and [PValue] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
+ * Returns a new [MutablePKeyPValueMap] with [key1] associated with [value1].
*/
-public fun mutablePKeyPValueMapOf(vararg pairs: Pair<PKey, PValue>): MutablePKeyPValueMap =
- MutablePKeyPValueMap(pairs.size).also { map ->
- pairs.forEach { (key, value) -> map[key] = value }
+public fun mutablePKeyPValueMapOf(
+ key1: PKey,
+ value1: PValue
+): MutablePKeyPValueMap = MutablePKeyPValueMap().also { map ->
+ map[key1] = value1
+ }
+
+/**
+ * Returns a new [MutablePKeyPValueMap] with [key1], and [key2]
+ * associated with [value1], and [value2], respectively.
+ */
+public fun mutablePKeyPValueMapOf(
+ key1: PKey,
+ value1: PValue,
+ key2: PKey,
+ value2: PValue,
+): MutablePKeyPValueMap = MutablePKeyPValueMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ }
+
+/**
+ * Returns a new [MutablePKeyPValueMap] with [key1], [key2], and [key3]
+ * associated with [value1], [value2], and [value3], respectively.
+ */
+public fun mutablePKeyPValueMapOf(
+ key1: PKey,
+ value1: PValue,
+ key2: PKey,
+ value2: PValue,
+ key3: PKey,
+ value3: PValue,
+): MutablePKeyPValueMap = MutablePKeyPValueMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ }
+
+/**
+ * Returns a new [MutablePKeyPValueMap] with [key1], [key2], [key3], and [key4]
+ * associated with [value1], [value2], [value3], and [value4], respectively.
+ */
+public fun mutablePKeyPValueMapOf(
+ key1: PKey,
+ value1: PValue,
+ key2: PKey,
+ value2: PValue,
+ key3: PKey,
+ value3: PValue,
+ key4: PKey,
+ value4: PValue,
+): MutablePKeyPValueMap = MutablePKeyPValueMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ }
+
+/**
+ * Returns a new [MutablePKeyPValueMap] with [key1], [key2], [key3], [key4], and [key5]
+ * associated with [value1], [value2], [value3], [value4], and [value5], respectively.
+ */
+public fun mutablePKeyPValueMapOf(
+ key1: PKey,
+ value1: PValue,
+ key2: PKey,
+ value2: PValue,
+ key3: PKey,
+ value3: PValue,
+ key4: PKey,
+ value4: PValue,
+ key5: PKey,
+ value5: PValue,
+): MutablePKeyPValueMap = MutablePKeyPValueMap().also { map ->
+ map[key1] = value1
+ map[key2] = value2
+ map[key3] = value3
+ map[key4] = value4
+ map[key5] = value5
}
/**
@@ -554,20 +691,6 @@
}
/**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [PKey] key and [PValue] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public fun putAll(@Suppress("ArrayReturn") pairs: Array<Pair<PKey, PValue>>) {
- for ((key, value) in pairs) {
- this[key] = value
- }
- }
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public fun putAll(from: PKeyPValueMap) {
@@ -577,29 +700,6 @@
}
/**
- * Puts the key/value mapping from the [pair] in this map, using the first
- * element as the key, and the second element as the value.
- *
- * Note that [pair] allocated and both the [PKey] key and [PValue] value are
- * boxed. Use [set] instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(pair: Pair<PKey, PValue>) {
- this[pair.first] = pair.second
- }
-
- /**
- * Puts all the [pairs] into this map, using the first component of the pair
- * as the key, and the second component as the value.
- *
- * Note that [pairs] is an allocated array, and each [Pair] is allocated and
- * both the [PKey] key and [PValue] value are boxed. Use [set] for each
- * entry instead when it is important to reduce allocations.
- */
- public inline operator fun plusAssign(
- @Suppress("ArrayReturn") pairs: Array<Pair<PKey, PValue>>
- ): Unit = putAll(pairs)
-
- /**
* Puts all the key/value mappings in the [from] map into this map.
*/
public inline operator fun plusAssign(from: PKeyPValueMap): Unit = putAll(from)
diff --git a/collection/collection/template/PKeyPValueMapTest.kt.template b/collection/collection/template/PKeyPValueMapTest.kt.template
index c8f3cd5..3fd934f 100644
--- a/collection/collection/template/PKeyPValueMapTest.kt.template
+++ b/collection/collection/template/PKeyPValueMapTest.kt.template
@@ -78,14 +78,113 @@
}
@Test
- fun pKeyPValueMapPairsFunction() {
- val map = mutablePKeyPValueMapOf(
- 1KeySuffix to 1ValueSuffix,
- 2KeySuffix to 2ValueSuffix
+ fun pKeyPValueMapInitFunction() {
+ val map1 = pKeyPValueMapOf(
+ 1KeySuffix, 1ValueSuffix,
)
- assertEquals(2, map.size)
- assertEquals(1ValueSuffix, map[1KeySuffix])
- assertEquals(2ValueSuffix, map[2KeySuffix])
+ assertEquals(1, map1.size)
+ assertEquals(1ValueSuffix, map1[1KeySuffix])
+
+ val map2 = pKeyPValueMapOf(
+ 1KeySuffix, 1ValueSuffix,
+ 2KeySuffix, 2ValueSuffix,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1ValueSuffix, map2[1KeySuffix])
+ assertEquals(2ValueSuffix, map2[2KeySuffix])
+
+ val map3 = pKeyPValueMapOf(
+ 1KeySuffix, 1ValueSuffix,
+ 2KeySuffix, 2ValueSuffix,
+ 3KeySuffix, 3ValueSuffix,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1ValueSuffix, map3[1KeySuffix])
+ assertEquals(2ValueSuffix, map3[2KeySuffix])
+ assertEquals(3ValueSuffix, map3[3KeySuffix])
+
+ val map4 = pKeyPValueMapOf(
+ 1KeySuffix, 1ValueSuffix,
+ 2KeySuffix, 2ValueSuffix,
+ 3KeySuffix, 3ValueSuffix,
+ 4KeySuffix, 4ValueSuffix,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1ValueSuffix, map4[1KeySuffix])
+ assertEquals(2ValueSuffix, map4[2KeySuffix])
+ assertEquals(3ValueSuffix, map4[3KeySuffix])
+ assertEquals(4ValueSuffix, map4[4KeySuffix])
+
+ val map5 = pKeyPValueMapOf(
+ 1KeySuffix, 1ValueSuffix,
+ 2KeySuffix, 2ValueSuffix,
+ 3KeySuffix, 3ValueSuffix,
+ 4KeySuffix, 4ValueSuffix,
+ 5KeySuffix, 5ValueSuffix,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1ValueSuffix, map5[1KeySuffix])
+ assertEquals(2ValueSuffix, map5[2KeySuffix])
+ assertEquals(3ValueSuffix, map5[3KeySuffix])
+ assertEquals(4ValueSuffix, map5[4KeySuffix])
+ assertEquals(5ValueSuffix, map5[5KeySuffix])
+ }
+
+ @Test
+ fun mutablePKeyPValueMapInitFunction() {
+ val map1 = mutablePKeyPValueMapOf(
+ 1KeySuffix, 1ValueSuffix,
+ )
+ assertEquals(1, map1.size)
+ assertEquals(1ValueSuffix, map1[1KeySuffix])
+
+ val map2 = mutablePKeyPValueMapOf(
+ 1KeySuffix, 1ValueSuffix,
+ 2KeySuffix, 2ValueSuffix,
+ )
+ assertEquals(2, map2.size)
+ assertEquals(1ValueSuffix, map2[1KeySuffix])
+ assertEquals(2ValueSuffix, map2[2KeySuffix])
+
+ val map3 = mutablePKeyPValueMapOf(
+ 1KeySuffix, 1ValueSuffix,
+ 2KeySuffix, 2ValueSuffix,
+ 3KeySuffix, 3ValueSuffix,
+ )
+ assertEquals(3, map3.size)
+ assertEquals(1ValueSuffix, map3[1KeySuffix])
+ assertEquals(2ValueSuffix, map3[2KeySuffix])
+ assertEquals(3ValueSuffix, map3[3KeySuffix])
+
+ val map4 = mutablePKeyPValueMapOf(
+ 1KeySuffix, 1ValueSuffix,
+ 2KeySuffix, 2ValueSuffix,
+ 3KeySuffix, 3ValueSuffix,
+ 4KeySuffix, 4ValueSuffix,
+ )
+
+ assertEquals(4, map4.size)
+ assertEquals(1ValueSuffix, map4[1KeySuffix])
+ assertEquals(2ValueSuffix, map4[2KeySuffix])
+ assertEquals(3ValueSuffix, map4[3KeySuffix])
+ assertEquals(4ValueSuffix, map4[4KeySuffix])
+
+ val map5 = mutablePKeyPValueMapOf(
+ 1KeySuffix, 1ValueSuffix,
+ 2KeySuffix, 2ValueSuffix,
+ 3KeySuffix, 3ValueSuffix,
+ 4KeySuffix, 4ValueSuffix,
+ 5KeySuffix, 5ValueSuffix,
+ )
+
+ assertEquals(5, map5.size)
+ assertEquals(1ValueSuffix, map5[1KeySuffix])
+ assertEquals(2ValueSuffix, map5[2KeySuffix])
+ assertEquals(3ValueSuffix, map5[3KeySuffix])
+ assertEquals(4ValueSuffix, map5[4KeySuffix])
+ assertEquals(5ValueSuffix, map5[5KeySuffix])
}
@Test
@@ -146,38 +245,6 @@
}
@Test
- fun putAllArray() {
- val map = MutablePKeyPValueMap()
- map[1KeySuffix] = 1ValueSuffix
- map[2KeySuffix] = 2ValueSuffix
-
- map.putAll(arrayOf(3KeySuffix to 3ValueSuffix, 7KeySuffix to 7ValueSuffix))
-
- assertEquals(4, map.size)
- assertEquals(3ValueSuffix, map[3KeySuffix])
- assertEquals(7ValueSuffix, map[7KeySuffix])
- }
-
- @Test
- fun plus() {
- val map = MutablePKeyPValueMap()
- map += 1KeySuffix to 1ValueSuffix
-
- assertEquals(1, map.size)
- assertEquals(1ValueSuffix, map[1KeySuffix])
- }
-
- @Test
- fun plusArray() {
- val map = MutablePKeyPValueMap()
- map += arrayOf(3KeySuffix to 3ValueSuffix, 7KeySuffix to 7ValueSuffix)
-
- assertEquals(2, map.size)
- assertEquals(3ValueSuffix, map[3KeySuffix])
- assertEquals(7ValueSuffix, map[7KeySuffix])
- }
-
- @Test
fun findNonExistingKey() {
val map = MutablePKeyPValueMap()
map[1KeySuffix] = 1ValueSuffix
diff --git a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeTextSelectionLazy.kt b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeTextSelectionLazy.kt
deleted file mode 100644
index 3e596cc..0000000
--- a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeTextSelectionLazy.kt
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx.compose.foundation.demos.text
-
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.lazy.LazyColumn
-import androidx.compose.foundation.text.BasicText
-import androidx.compose.foundation.text.selection.SelectionContainer
-import androidx.compose.material.Text
-import androidx.compose.runtime.Composable
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.text.TextStyle
-import androidx.compose.ui.text.style.TextAlign
-import androidx.compose.ui.tooling.preview.Preview
-import androidx.compose.ui.unit.dp
-
-@Preview
-@Composable
-fun TextLazySelectionDemo() {
- Column {
- Text(
- text = "We expect that selection works, regardless of how many times each text" +
- " goes in or out of composition via scrolling the lazy column.",
- modifier = Modifier.padding(16.dp),
- )
- SelectionContainer {
- LazyColumn {
- items(100) {
- BasicText(
- text = it.toString(),
- style = TextStyle(fontSize = fontSize8, textAlign = TextAlign.Center),
- modifier = Modifier.fillMaxWidth()
- )
- }
- }
- }
- }
-}
diff --git a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeTextSelectionScrollable.kt b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeTextSelectionScrollable.kt
new file mode 100644
index 0000000..d46aded
--- /dev/null
+++ b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/ComposeTextSelectionScrollable.kt
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.compose.foundation.demos.text
+
+import android.annotation.SuppressLint
+import androidx.compose.foundation.layout.Arrangement.spacedBy
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.selection.selectable
+import androidx.compose.foundation.selection.selectableGroup
+import androidx.compose.foundation.text.selection.SelectionContainer
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material.MaterialTheme
+import androidx.compose.material.RadioButton
+import androidx.compose.material.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.tooling.preview.Preview
+import androidx.compose.ui.unit.dp
+
+@SuppressLint("PrimitiveInLambda")
+@Preview
+@Composable
+fun TextScrollableColumnSelectionDemo() {
+ val spacing = 16.dp
+ Column(
+ modifier = Modifier.padding(spacing),
+ verticalArrangement = spacedBy(spacing)
+ ) {
+ Text(
+ text = "We expect that selection works, " +
+ "regardless of how many times each text goes in or out of view. " +
+ "The selection handles and text toolbar also should follow the selection " +
+ "when it is scrolled.",
+ style = MaterialTheme.typography.body1.merge(),
+ )
+ val (selectedOption, onOptionSelected) = remember {
+ mutableStateOf(Options.LongScrollableText)
+ }
+ Column(Modifier.selectableGroup()) {
+ Options.values().forEach { option ->
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .selectable(
+ selected = option == selectedOption,
+ onClick = { onOptionSelected(option) }
+ ),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ RadioButton(
+ selected = option == selectedOption,
+ onClick = { onOptionSelected(option) }
+ )
+ Text(
+ text = option.displayText,
+ style = MaterialTheme.typography.body1.merge(),
+ )
+ }
+ }
+ }
+ selectedOption.Content()
+ }
+}
+
+@Suppress("unused") // enum values used in .values()
+private enum class Options(val displayText: String, val content: @Composable () -> Unit) {
+ LongScrollableText("Long Scrollable Single Text", {
+ MyText(
+ modifier = Modifier.verticalScroll(rememberScrollState()),
+ text = (0..100).joinToString(separator = "\n") { it.toString() },
+ )
+ }),
+ LongTextScrollableColumn("Long Single Text in Scrollable Column", {
+ Column(Modifier.verticalScroll(rememberScrollState())) {
+ MyText((0..100).joinToString(separator = "\n") { it.toString() })
+ }
+ }),
+ MultiTextScrollableColumn("Multiple Texts in Scrollable Column", {
+ Column(Modifier.verticalScroll(rememberScrollState())) {
+ repeat(100) { MyText(it.toString()) }
+ }
+ }),
+ MultiTextLazyColumn("Multiple Texts in LazyColumn", {
+ LazyColumn {
+ items(100) { MyText(it.toString()) }
+ }
+ });
+
+ @Composable
+ fun Content() {
+ SelectionContainer(content = content)
+ }
+}
+
+@Composable
+private fun MyText(text: String, modifier: Modifier = Modifier) {
+ Text(
+ text = text,
+ style = TextStyle(fontSize = fontSize8, textAlign = TextAlign.Center),
+ modifier = modifier.fillMaxWidth()
+ )
+}
diff --git a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TextDemos.kt b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TextDemos.kt
index 90304cc..ef5b5ac 100644
--- a/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TextDemos.kt
+++ b/compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/TextDemos.kt
@@ -152,7 +152,9 @@
ComposableDemo("Text selection") { TextSelectionDemo() },
ComposableDemo("Text selection sample") { TextSelectionSample() },
ComposableDemo("Overflowed Selection") { TextOverflowedSelectionDemo() },
- ComposableDemo("LazyColumn Text Selection") { TextLazySelectionDemo() },
+ ComposableDemo("Scrollable Column Text Selection") {
+ TextScrollableColumnSelectionDemo()
+ },
)
),
DemoCategory(
diff --git a/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/modifiers/SelectionControllerTest.kt b/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/modifiers/SelectionControllerTest.kt
index 905a598..86e71928b 100644
--- a/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/modifiers/SelectionControllerTest.kt
+++ b/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/modifiers/SelectionControllerTest.kt
@@ -18,38 +18,38 @@
import android.os.Build
import androidx.annotation.RequiresApi
-import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.size
-import androidx.compose.foundation.text.ceilToIntPx
-import androidx.compose.foundation.text.selection.Selectable
-import androidx.compose.foundation.text.selection.Selection
-import androidx.compose.foundation.text.selection.Selection.AnchorInfo
-import androidx.compose.foundation.text.selection.SelectionAdjustment
-import androidx.compose.foundation.text.selection.SelectionLayoutBuilder
-import androidx.compose.foundation.text.selection.SelectionRegistrar
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.text.BasicText
+import androidx.compose.foundation.text.selection.LocalTextSelectionColors
+import androidx.compose.foundation.text.selection.SelectionContainer
+import androidx.compose.foundation.text.selection.TextSelectionColors
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
-import androidx.compose.ui.geometry.Offset
-import androidx.compose.ui.geometry.Rect
-import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.graphics.toArgb
-import androidx.compose.ui.layout.LayoutCoordinates
+import androidx.compose.ui.platform.LocalDensity
+import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.captureToImage
+import androidx.compose.ui.test.getBoundsInRoot
import androidx.compose.ui.test.junit4.createComposeRule
-import androidx.compose.ui.test.onRoot
-import androidx.compose.ui.text.AnnotatedString
-import androidx.compose.ui.text.TextRange
-import androidx.compose.ui.text.style.ResolvedTextDirection
+import androidx.compose.ui.test.longClick
+import androidx.compose.ui.test.onNodeWithTag
+import androidx.compose.ui.test.performTouchInput
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.roundToIntRect
+import androidx.compose.ui.unit.sp
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SdkSuppress
import androidx.test.filters.SmallTest
-import org.junit.Assert
+import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -61,223 +61,80 @@
@get:Rule
val rule = createComposeRule()
+ private val boxTag = "boxTag"
+ private val tag = "tag"
+
+ private val highlightColor = Color.Blue
+ private val foregroundColor = Color.Black
+ private val backgroundColor = Color.White
+
+ private val highlightArgb get() = highlightColor.toArgb()
+ private val foregroundArgb get() = foregroundColor.toArgb()
+ private val backgroundArgb get() = backgroundColor.toArgb()
+
+ private val density = Density(1f)
+ private val textSelectionColors = TextSelectionColors(highlightColor, highlightColor)
+
@Test
@SdkSuppress(minSdkVersion = 26)
- fun drawWithClip_doesClip() {
- val canvasSize = 10.dp
- val pathSize = 10_000f
- val path = Path().also {
- it.addRect(Rect(0f, 0f, pathSize, pathSize))
- }
-
- val fixedSelectionFake = FixedSelectionFake(0, 1000, 200)
- val subject = SelectionController(
- selectableId = fixedSelectionFake.nextSelectableId(),
- selectionRegistrar = fixedSelectionFake,
- backgroundSelectionColor = Color.White,
- params = FakeParams(
- path, true
- )
- )
- var size: Size? = null
-
- rule.setContent {
- Box(
- Modifier
- .fillMaxSize()
- .drawBehind { drawRect(Color.Black) }) {
- Canvas(Modifier.size(canvasSize)) {
- size = this.size
- subject.draw(this)
- }
- }
- }
-
- rule.waitForIdle()
- assertClipped(size!!, true)
+ fun drawWithClip_doesClip() = runDrawWithClipTest(TextOverflow.Clip) { argbSet ->
+ assertThat(argbSet).containsExactly(backgroundArgb)
}
@Test
@SdkSuppress(minSdkVersion = 26)
- fun drawWithOut_doesNotClip() {
- val canvasSize = 10.dp
- val pathSize = 10_000f
- val path = Path().also {
- it.addRect(Rect(0f, 0f, pathSize, pathSize))
- }
-
- val fixedSelectionFake = FixedSelectionFake(0, 1000, 200)
- val subject = SelectionController(
- selectableId = fixedSelectionFake.nextSelectableId(),
- selectionRegistrar = fixedSelectionFake,
- backgroundSelectionColor = Color.White,
- params = FakeParams(
- path, false
- )
- )
- var size: Size? = null
-
- rule.setContent {
- Box(
- Modifier
- .fillMaxSize()
- .drawBehind { drawRect(Color.Black) }) {
- Canvas(Modifier.size(canvasSize)) {
- size = this.size
- drawRect(Color.Black)
- subject.draw(this)
- }
- }
- }
-
- rule.waitForIdle()
- assertClipped(size!!, false)
+ fun drawWithVisible_doesNotClip() = runDrawWithClipTest(TextOverflow.Visible) { argbSet ->
+ // there could be more colors due to anti-aliasing, so check that we have at least the
+ // expected colors, and none of the unexpected colors.
+ assertThat(argbSet).containsAtLeast(highlightArgb, foregroundArgb)
+ assertThat(argbSet).doesNotContain(backgroundArgb)
}
@RequiresApi(Build.VERSION_CODES.O)
- private fun assertClipped(size: Size, isClipped: Boolean) {
- val expectedColor = if (isClipped) { Color.Black } else { Color.White }
- rule.onRoot().captureToImage().asAndroidBitmap().apply {
- Assert.assertEquals(
- expectedColor.toArgb(),
- getPixel(
- size.width.ceilToIntPx() + 5,
- size.height.ceilToIntPx() + 5
- )
- )
+ private fun runDrawWithClipTest(overflow: TextOverflow, assertBlock: (Set<Int>) -> Unit) {
+ rule.setContent {
+ CompositionLocalProvider(
+ LocalTextSelectionColors provides textSelectionColors,
+ LocalDensity provides density,
+ ) {
+ Box(
+ modifier = Modifier
+ .fillMaxSize()
+ .drawBehind { drawRect(backgroundColor) }
+ .testTag(boxTag),
+ contentAlignment = Alignment.Center,
+ ) {
+ SelectionContainer {
+ BasicText(
+ modifier = Modifier
+ .width(10.dp)
+ .testTag(tag),
+ text = "OOOOOOO",
+ overflow = overflow,
+ softWrap = false,
+ style = TextStyle(color = foregroundColor, fontSize = 48.sp),
+ )
+ }
+ }
+ }
+ }
+ rule.waitForIdle()
+ rule.onNodeWithTag(tag).performTouchInput { longClick() }
+ rule.waitForIdle()
+
+ with(density) {
+ val bitmap = rule.onNodeWithTag(boxTag).captureToImage().asAndroidBitmap()
+ val bitmapPositionInRoot =
+ rule.onNodeWithTag(boxTag).getBoundsInRoot().toRect().roundToIntRect().topLeft
+ val centerRightOffset =
+ rule.onNodeWithTag(tag).getBoundsInRoot().toRect().roundToIntRect().centerRight
+
+ val centerRightOffsetInRoot = centerRightOffset - bitmapPositionInRoot
+ val (x, y) = centerRightOffsetInRoot
+
+ // grab a row of pixels in the area that may be clipped.
+ val seenColors = (1..50).map { bitmap.getPixel(x + it, y) }.toSet()
+ assertBlock(seenColors)
}
}
}
-
-/**
- * Fake that always has selection
- */
-private class FixedSelectionFake(
- val start: Int,
- val end: Int,
- val lastVisible: Int
-) : SelectionRegistrar {
-
- var selectableId = 0L
- var allSelectables = mutableListOf<Long>()
-
- override val subselections: Map<Long, Selection>
- get() = allSelectables.associateWith { selectionId ->
- Selection(
- AnchorInfo(ResolvedTextDirection.Ltr, start, selectionId),
- AnchorInfo(ResolvedTextDirection.Ltr, end, selectionId)
- )
- }
-
- override fun subscribe(selectable: Selectable): Selectable {
- return FakeSelectableWithLastVisibleOffset(selectable.selectableId, lastVisible)
- }
-
- override fun unsubscribe(selectable: Selectable) {
- // nothing
- }
-
- override fun nextSelectableId(): Long {
- return selectableId++.also {
- allSelectables.add(it)
- }
- }
-
- override fun notifyPositionChange(selectableId: Long) {
- FAKE("Not yet implemented")
- }
-
- override fun notifySelectionUpdateStart(
- layoutCoordinates: LayoutCoordinates,
- startPosition: Offset,
- adjustment: SelectionAdjustment,
- isInTouchMode: Boolean
- ) {
- FAKE("Selection not editable")
- }
-
- override fun notifySelectionUpdateSelectAll(selectableId: Long, isInTouchMode: Boolean) {
- FAKE()
- }
-
- override fun notifySelectionUpdate(
- layoutCoordinates: LayoutCoordinates,
- newPosition: Offset,
- previousPosition: Offset,
- isStartHandle: Boolean,
- adjustment: SelectionAdjustment,
- isInTouchMode: Boolean
- ): Boolean {
- FAKE("Selection not editable")
- }
-
- override fun notifySelectionUpdateEnd() {
- FAKE("Selection not editable")
- }
-
- override fun notifySelectableChange(selectableId: Long) {
- FAKE("Selection not editable")
- }
-}
-
-private class FakeSelectableWithLastVisibleOffset(
- override val selectableId: Long,
- private val lastVisible: Int
-) : Selectable {
- override fun appendSelectableInfoToBuilder(builder: SelectionLayoutBuilder) {
- FAKE()
- }
-
- override fun getSelectAllSelection(): Selection? {
- FAKE()
- }
-
- override fun getHandlePosition(selection: Selection, isStartHandle: Boolean): Offset {
- FAKE()
- }
-
- override fun getLayoutCoordinates(): LayoutCoordinates? {
- FAKE()
- }
-
- override fun getText(): AnnotatedString {
- FAKE()
- }
-
- override fun getBoundingBox(offset: Int): Rect {
- FAKE()
- }
-
- override fun getLineLeft(offset: Int): Float {
- FAKE()
- }
-
- override fun getLineRight(offset: Int): Float {
- FAKE()
- }
-
- override fun getCenterYForOffset(offset: Int): Float {
- FAKE()
- }
-
- override fun getRangeOfLineContaining(offset: Int): TextRange {
- FAKE()
- }
-
- override fun getLastVisibleOffset(): Int {
- return lastVisible
- }
-}
-
-private class FakeParams(
- val path: Path,
- override val shouldClip: Boolean
-) : StaticTextSelectionParams(null, null) {
-
- override fun getPathForRange(start: Int, end: Int): Path? {
- return path
- }
-}
-
-private fun FAKE(reason: String = "Unsupported fake method on fake"): Nothing =
- throw NotImplementedError("No support in fake: $reason")
diff --git a/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/selection/gestures/LazyColumnMultiTextRegressionTest.kt b/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/selection/gestures/LazyColumnMultiTextRegressionTest.kt
index d78a009..4aa35e8 100644
--- a/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/selection/gestures/LazyColumnMultiTextRegressionTest.kt
+++ b/compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/selection/gestures/LazyColumnMultiTextRegressionTest.kt
@@ -16,27 +16,36 @@
package androidx.compose.foundation.text.selection.gestures
+import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
-import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.text.BasicText
+import androidx.compose.foundation.text.Handle
import androidx.compose.foundation.text.selection.Selection
import androidx.compose.foundation.text.selection.SelectionContainer
+import androidx.compose.foundation.text.selection.SelectionHandleInfoKey
import androidx.compose.foundation.text.selection.fetchTextLayoutResult
import androidx.compose.foundation.text.selection.gestures.util.longPress
+import androidx.compose.foundation.text.selection.isSelectionHandle
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
import androidx.compose.runtime.snapshots.Snapshot
import androidx.compose.testutils.TestViewConfiguration
+import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.platform.ClipboardManager
import androidx.compose.ui.platform.LocalClipboardManager
+import androidx.compose.ui.platform.LocalTextToolbar
import androidx.compose.ui.platform.LocalViewConfiguration
+import androidx.compose.ui.platform.TextToolbar
+import androidx.compose.ui.platform.TextToolbarStatus
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.TouchInjectionScope
@@ -64,6 +73,7 @@
@get:Rule
val rule = createComposeRule()
private val stateRestorationTester = StateRestorationTester(rule)
+ private val textCount = 20
// regression - text going out of composition and then returning
// resulted in selection not working
@@ -98,6 +108,84 @@
assertClipboardTextEquals("01234")
}
+ @Test
+ fun whenScrollingTextOutOfViewUpwards_handlesDisappear() = runTest {
+ var prevStart: Offset? = null
+ var prevEnd: Offset? = null
+
+ fun updateHandlePositions() {
+ prevStart = startHandlePosition
+ prevEnd = endHandlePosition
+ }
+
+ assertHandleNotShown(Handle.SelectionStart)
+ assertHandleNotShown(Handle.SelectionEnd)
+
+ createSelection(startLine = 1, endLine = 3)
+ assertHandleShown(Handle.SelectionStart)
+ assertHandleShown(Handle.SelectionEnd)
+ updateHandlePositions()
+
+ scrollLines(fromLine = 3, toLine = 2)
+ assertHandleShown(Handle.SelectionStart)
+ assertHandleShown(Handle.SelectionEnd)
+ assertPositionMovedUp(prevStart, startHandlePosition)
+ assertPositionMovedUp(prevEnd, endHandlePosition)
+ updateHandlePositions()
+
+ scrollLines(fromLine = 4, toLine = 2)
+ assertHandleNotShown(Handle.SelectionStart)
+ assertHandleShown(Handle.SelectionEnd)
+ assertPositionMovedUp(prevEnd, endHandlePosition)
+
+ scrollLines(fromLine = 6, toLine = 4)
+ assertHandleNotShown(Handle.SelectionStart)
+ assertHandleNotShown(Handle.SelectionEnd)
+ updateHandlePositions()
+
+ scrollLines(fromLine = 6, toLine = 8)
+ assertHandleNotShown(Handle.SelectionStart)
+ assertHandleShown(Handle.SelectionEnd)
+ updateHandlePositions()
+
+ scrollLines(fromLine = 4, toLine = 6)
+ assertHandleShown(Handle.SelectionStart)
+ assertHandleShown(Handle.SelectionEnd)
+ assertHandleMovedDown(prevEnd, endHandlePosition)
+ updateHandlePositions()
+
+ scrollLines(fromLine = 2, toLine = 5)
+ assertHandleShown(Handle.SelectionStart)
+ assertHandleShown(Handle.SelectionEnd)
+ assertHandleMovedDown(prevStart, startHandlePosition)
+ assertHandleMovedDown(prevEnd, endHandlePosition)
+ updateHandlePositions()
+ }
+
+ @Test
+ fun whenScrollingTextOutOfViewUpwards_textToolbarCoercedToTop() = runTest {
+ assertThat(textToolbarShown).isFalse()
+
+ createSelection(startLine = 1, endLine = 3)
+ assertThat(textToolbarShown).isTrue()
+ assertTextToolbarTopAt(boundingBoxForLineInRoot(1).top)
+
+ scrollLines(fromLine = 3, toLine = 1)
+ assertThat(textToolbarShown).isTrue()
+ assertTextToolbarTopAt(pointerAreaRect.top)
+
+ scrollLines(fromLine = 5, toLine = 3)
+ assertThat(textToolbarShown).isFalse()
+
+ scrollLines(fromLine = 5, toLine = 7)
+ assertThat(textToolbarShown).isTrue()
+ assertTextToolbarTopAt(pointerAreaRect.top)
+
+ scrollLines(fromLine = 3, toLine = 5)
+ assertThat(textToolbarShown).isTrue()
+ assertTextToolbarTopAt(boundingBoxForLineInRoot(1).top)
+ }
+
// TODO(b/298067619)
// When we support saving selection, this test should instead check that
// the previous and current selection is the same.
@@ -114,21 +202,27 @@
private val pointerAreaTag: String,
private val selectionState: MutableState<Selection?>,
private val clipboardManager: ClipboardManager,
+ private val textToolbar: TextToolbarWrapper,
) {
val initialText = "Initial text"
- val selection get() = Snapshot.withoutReadObservation { selectionState.value }
+ val selection: Selection? get() = Snapshot.withoutReadObservation { selectionState.value }
+ val textToolbarRect: Rect? get() = textToolbar.mostRecentRect
+ val textToolbarShown: Boolean get() = textToolbar.shown
+
+ val startHandlePosition get() = handlePosition(Handle.SelectionStart)
+ val endHandlePosition get() = handlePosition(Handle.SelectionEnd)
fun createSelection(startLine: Int, endLine: Int) {
performTouchInput {
- longPress(positionForLine(startLine))
- moveTo(positionForLine(endLine))
+ longPress(positionForLineInPointerArea(startLine))
+ moveTo(positionForLineInPointerArea(endLine))
up()
}
}
fun createSelection(line: Int) {
performTouchInput {
- longClick(positionForLine(line))
+ longClick(positionForLineInPointerArea(line))
}
}
@@ -137,25 +231,38 @@
rule.waitForIdle()
}
- private fun positionForLine(lineNumber: Int): Offset {
+ fun boundingBoxForLineInPointerArea(lineNumber: Int): Rect {
val containerPosition = rule.onNodeWithTag(pointerAreaTag).fetchSemanticsNode()
.positionInRoot
- .also { println(it) }
-
- val textTag = lineNumber.toString()
- val textPosition = rule.onNodeWithTag(textTag).fetchSemanticsNode()
- .positionInRoot
- .also { println(it) }
-
- val textLayoutResult = rule.onNodeWithTag(textTag)
- .fetchTextLayoutResult()
-
- return textLayoutResult.getBoundingBox(0)
- .translate(textPosition - containerPosition)
- .center
- .also { println(it) }
+ return boundingBoxForLineInRoot(lineNumber).translate(-containerPosition)
}
+ fun boundingBoxForLineInRoot(lineNumber: Int): Rect {
+ val textTag = lineNumber.toString()
+ val textPosition = rule.onNodeWithTag(textTag).fetchSemanticsNode().positionInRoot
+ val textLayoutResult = rule.onNodeWithTag(textTag).fetchTextLayoutResult()
+ val lineStart = textLayoutResult.getLineStart(0)
+ val lineEnd = textLayoutResult.getLineEnd(0)
+
+ val rect = if (lineStart == lineEnd - 1) {
+ textLayoutResult.getBoundingBox(lineStart)
+ } else {
+ val startRect = textLayoutResult.getBoundingBox(lineStart)
+ val endRect = textLayoutResult.getBoundingBox(lineEnd - 1)
+ Rect(
+ left = minOf(startRect.left, endRect.left),
+ top = minOf(startRect.top, endRect.top),
+ right = maxOf(startRect.right, endRect.right),
+ bottom = maxOf(startRect.bottom, endRect.bottom),
+ )
+ }
+
+ return rect.translate(textPosition)
+ }
+
+ fun positionForLineInPointerArea(lineNumber: Int): Offset =
+ boundingBoxForLineInPointerArea(lineNumber).center
+
@OptIn(ExperimentalTestApi::class)
fun performCopy() {
rule.onNodeWithTag(pointerAreaTag).performKeyInput {
@@ -195,6 +302,69 @@
swipe(topCenter + Offset(0f, 1f), bottomCenter - Offset(0f, 1f))
}
}
+
+ fun scrollLines(fromLine: Int, toLine: Int) {
+ performTouchInput {
+ swipe(positionForLineInPointerArea(fromLine), positionForLineInPointerArea(toLine))
+ }
+ }
+
+ fun assertPositionMovedUp(previous: Offset?, current: Offset?) {
+ assertHandleMoved(previous, current, up = true)
+ }
+
+ fun assertHandleMovedDown(previous: Offset?, current: Offset?) {
+ assertHandleMoved(previous, current, up = false)
+ }
+
+ private fun assertHandleMoved(previous: Offset?, current: Offset?, up: Boolean) {
+ assertWithMessage("previous handle position should not be null")
+ .that(previous)
+ .isNotNull()
+
+ assertWithMessage("current handle position should not be null")
+ .that(current)
+ .isNotNull()
+
+ val (x, y) = current!!
+ val (prevX, prevY) = previous!!
+
+ assertWithMessage("x should not change")
+ .that(x)
+ .isWithin(0.1f)
+ .of(prevX)
+
+ assertWithMessage("y should have moved ${if (up) "up" else "down"}")
+ .that(y)
+ .run {
+ if (up) isLessThan(prevY) else isGreaterThan(prevY)
+ }
+ }
+
+ private fun handlePosition(handle: Handle): Offset? =
+ rule.onAllNodes(isSelectionHandle(handle))
+ .fetchSemanticsNodes()
+ .singleOrNull()
+ ?.config
+ ?.get(SelectionHandleInfoKey)
+ ?.position
+
+ fun assertHandleShown(handle: Handle) {
+ rule.onNode(isSelectionHandle(handle)).assertExists()
+ }
+
+ fun assertHandleNotShown(handle: Handle) {
+ rule.onNode(isSelectionHandle(handle)).assertDoesNotExist()
+ }
+
+ fun assertTextToolbarTopAt(y: Float) {
+ assertThat(textToolbarRect?.top)
+ .isWithin(0.1f)
+ .of(y)
+ }
+
+ val pointerAreaRect: Rect
+ get() = rule.onNodeWithTag(pointerAreaTag).fetchSemanticsNode().boundsInRoot
}
private fun runTest(block: TestScope.() -> Unit) {
@@ -204,38 +374,83 @@
minimumTouchTargetSize = DpSize.Zero
)
lateinit var clipboardManager: ClipboardManager
+ lateinit var textToolbar: TextToolbarWrapper
stateRestorationTester.setContent {
clipboardManager = LocalClipboardManager.current
- CompositionLocalProvider(LocalViewConfiguration provides testViewConfiguration) {
- SelectionContainer(
- selection = selection.value,
- onSelectionChange = { selection.value = it },
- modifier = Modifier
- .fillMaxSize()
- .wrapContentHeight()
+ val originalTextToolbar = LocalTextToolbar.current
+ textToolbar = remember(originalTextToolbar) {
+ TextToolbarWrapper(originalTextToolbar)
+ }
+ CompositionLocalProvider(
+ LocalTextToolbar provides textToolbar,
+ LocalViewConfiguration provides testViewConfiguration,
+ ) {
+ Box(
+ modifier = Modifier.fillMaxSize(),
+ contentAlignment = Alignment.Center,
) {
- LazyColumn(
- modifier = Modifier
- .height(100.dp)
- .wrapContentHeight()
- .testTag(tag)
+ SelectionContainer(
+ modifier = Modifier.height(100.dp),
+ selection = selection.value,
+ onSelectionChange = { selection.value = it },
) {
- items(count = 20) {
- BasicText(
- text = it.toString(),
- style = TextStyle(fontSize = 15.sp, textAlign = TextAlign.Center),
- modifier = Modifier
- .fillMaxWidth()
- .testTag(it.toString())
- )
+ LazyColumn(
+ modifier = Modifier.testTag(tag)
+ ) {
+ items(count = textCount) {
+ BasicText(
+ text = it.toString(),
+ style = TextStyle(
+ fontSize = 15.sp,
+ textAlign = TextAlign.Center
+ ),
+ modifier = Modifier
+ .fillMaxWidth()
+ .testTag(it.toString())
+ )
+ }
}
}
}
}
}
- val scope = TestScope(tag, selection, clipboardManager)
+ val scope = TestScope(tag, selection, clipboardManager, textToolbar)
scope.resetClipboard()
scope.block()
}
}
+
+private class TextToolbarWrapper(private val delegate: TextToolbar) : TextToolbar {
+ private var _shown: Boolean = false
+ val shown: Boolean get() = _shown
+
+ private var _mostRecentRect: Rect? = null
+ val mostRecentRect: Rect? get() = _mostRecentRect
+
+ override fun showMenu(
+ rect: Rect,
+ onCopyRequested: (() -> Unit)?,
+ onPasteRequested: (() -> Unit)?,
+ onCutRequested: (() -> Unit)?,
+ onSelectAllRequested: (() -> Unit)?
+ ) {
+ _shown = true
+ _mostRecentRect = rect
+ delegate.showMenu(
+ rect,
+ onCopyRequested,
+ onPasteRequested,
+ onCutRequested,
+ onSelectAllRequested
+ )
+ }
+
+ override fun hide() {
+ _shown = false
+ delegate.hide()
+ }
+
+ override val status: TextToolbarStatus
+ get() = delegate.status
+}
diff --git a/compose/foundation/foundation/src/androidUnitTest/kotlin/androidx/compose/foundation/text/selection/SelectionFakes.kt b/compose/foundation/foundation/src/androidUnitTest/kotlin/androidx/compose/foundation/text/selection/SelectionFakes.kt
index 624fb70..df963b9 100644
--- a/compose/foundation/foundation/src/androidUnitTest/kotlin/androidx/compose/foundation/text/selection/SelectionFakes.kt
+++ b/compose/foundation/foundation/src/androidUnitTest/kotlin/androidx/compose/foundation/text/selection/SelectionFakes.kt
@@ -274,6 +274,7 @@
var endXHandleDirection = Direction.ON
var endYHandleDirection = Direction.ON
var rawPreviousHandleOffset = -1 // -1 = no previous offset
+ var layoutCoordinatesToReturn: LayoutCoordinates? = null
private val selectableKey = 1L
private val fakeSelectAllSelection: Selection = Selection(
@@ -313,7 +314,7 @@
}
override fun getLayoutCoordinates(): LayoutCoordinates? {
- return null
+ return layoutCoordinatesToReturn
}
override fun getHandlePosition(selection: Selection, isStartHandle: Boolean): Offset {
diff --git a/compose/foundation/foundation/src/androidUnitTest/kotlin/androidx/compose/foundation/text/selection/SelectionManagerTest.kt b/compose/foundation/foundation/src/androidUnitTest/kotlin/androidx/compose/foundation/text/selection/SelectionManagerTest.kt
index b72ff38..295f7af 100644
--- a/compose/foundation/foundation/src/androidUnitTest/kotlin/androidx/compose/foundation/text/selection/SelectionManagerTest.kt
+++ b/compose/foundation/foundation/src/androidUnitTest/kotlin/androidx/compose/foundation/text/selection/SelectionManagerTest.kt
@@ -17,10 +17,8 @@
package androidx.compose.foundation.text.selection
import androidx.compose.ui.geometry.Offset
-import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.hapticfeedback.HapticFeedback
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
-import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.platform.ClipboardManager
import androidx.compose.ui.platform.TextToolbar
import androidx.compose.ui.text.AnnotatedString
@@ -31,8 +29,6 @@
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.mockito.kotlin.any
-import org.mockito.kotlin.doReturn
-import org.mockito.kotlin.eq
import org.mockito.kotlin.isNull
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
@@ -49,9 +45,7 @@
private val selectionManager = SelectionManager(selectionRegistrar)
private var onSelectionChangeCalledTimes = 0
- private val containerLayoutCoordinates = mock<LayoutCoordinates> {
- on { isAttached } doReturn true
- }
+ private val containerLayoutCoordinates = MockCoordinates()
private val startSelectableId = 2L
private val startSelectable = mock<Selectable> {
@@ -249,7 +243,7 @@
val startOffset = text.indexOf('e')
val endOffset = text.indexOf('m')
selectable.textToReturn = annotatedString
- selectionManager.selection = Selection(
+ val selection = Selection(
start = Selection.AnchorInfo(
direction = ResolvedTextDirection.Ltr,
offset = startOffset,
@@ -262,6 +256,8 @@
),
handlesCrossed = false
)
+ selectionManager.selection = selection
+ selectionRegistrar.subselections = mapOf(selectableId to selection)
assertThat(selectionManager.isNonEmptySelection()).isTrue()
}
@@ -272,7 +268,7 @@
val annotatedString = AnnotatedString(text)
val startOffset = text.indexOf('e')
selectable.textToReturn = annotatedString
- selectionManager.selection = Selection(
+ val selection = Selection(
start = Selection.AnchorInfo(
direction = ResolvedTextDirection.Ltr,
offset = startOffset,
@@ -285,6 +281,8 @@
),
handlesCrossed = false
)
+ selectionManager.selection = selection
+ selectionRegistrar.subselections = mapOf(selectableId to selection)
assertThat(selectionManager.isNonEmptySelection()).isFalse()
}
@@ -318,6 +316,48 @@
handlesCrossed = true
)
+ selectionRegistrar.subselections = mapOf(
+ endSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = annotatedString.length,
+ selectableId = endSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = endOffset,
+ selectableId = endSelectableId
+ ),
+ handlesCrossed = true
+ ),
+ middleSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = annotatedString.length,
+ selectableId = middleSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = middleSelectableId
+ ),
+ handlesCrossed = true
+ ),
+ startSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = startOffset,
+ selectableId = startSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = startSelectableId
+ ),
+ handlesCrossed = true
+ ),
+ )
+
assertThat(selectionManager.isNonEmptySelection()).isTrue()
}
@@ -350,6 +390,48 @@
handlesCrossed = false
)
+ selectionRegistrar.subselections = mapOf(
+ startSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = annotatedString.length,
+ selectableId = startSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = annotatedString.length,
+ selectableId = startSelectableId
+ ),
+ handlesCrossed = false
+ ),
+ middleSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = middleSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = middleSelectableId
+ ),
+ handlesCrossed = false
+ ),
+ endSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = endSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = endSelectableId
+ ),
+ handlesCrossed = false
+ ),
+ )
+
assertThat(selectionManager.isNonEmptySelection()).isFalse()
}
@@ -382,12 +464,55 @@
handlesCrossed = true
)
+ selectionRegistrar.subselections = mapOf(
+ startSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = annotatedString.length,
+ selectableId = startSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = annotatedString.length,
+ selectableId = startSelectableId
+ ),
+ handlesCrossed = true
+ ),
+ middleSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = middleSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = middleSelectableId
+ ),
+ handlesCrossed = true
+ ),
+ endSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = endSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = endSelectableId
+ ),
+ handlesCrossed = true
+ ),
+ )
+
assertThat(selectionManager.isNonEmptySelection()).isFalse()
}
@Test
fun getSelectedText_selection_null_return_null() {
selectionManager.selection = null
+ selectionRegistrar.subselections = emptyMap()
assertThat(selectionManager.getSelectedText()).isNull()
assertThat(selectable.getTextCalledTimes).isEqualTo(0)
@@ -400,7 +525,7 @@
val startOffset = text.indexOf('e')
val endOffset = text.indexOf('m')
selectable.textToReturn = annotatedString
- selectionManager.selection = Selection(
+ val selection = Selection(
start = Selection.AnchorInfo(
direction = ResolvedTextDirection.Ltr,
offset = startOffset,
@@ -413,6 +538,8 @@
),
handlesCrossed = false
)
+ selectionManager.selection = selection
+ selectionRegistrar.subselections = mapOf(selectableId to selection)
assertThat(selectionManager.getSelectedText())
.isEqualTo(annotatedString.subSequence(startOffset, endOffset))
@@ -426,7 +553,7 @@
val startOffset = text.indexOf('m')
val endOffset = text.indexOf('x')
selectable.textToReturn = annotatedString
- selectionManager.selection = Selection(
+ val selection = Selection(
start = Selection.AnchorInfo(
direction = ResolvedTextDirection.Ltr,
offset = startOffset,
@@ -439,6 +566,8 @@
),
handlesCrossed = true
)
+ selectionManager.selection = selection
+ selectionRegistrar.subselections = mapOf(selectableId to selection)
assertThat(selectionManager.getSelectedText())
.isEqualTo(annotatedString.subSequence(endOffset, startOffset))
@@ -474,6 +603,48 @@
handlesCrossed = false
)
+ selectionRegistrar.subselections = mapOf(
+ startSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = startOffset,
+ selectableId = startSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = annotatedString.length,
+ selectableId = startSelectableId
+ ),
+ handlesCrossed = false
+ ),
+ middleSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = middleSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = annotatedString.length,
+ selectableId = middleSelectableId
+ ),
+ handlesCrossed = false
+ ),
+ endSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = endSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = endOffset,
+ selectableId = endSelectableId
+ ),
+ handlesCrossed = false
+ ),
+ )
+
val result = annotatedString.subSequence(startOffset, annotatedString.length) +
annotatedString + annotatedString.subSequence(0, endOffset)
assertThat(selectionManager.getSelectedText()).isEqualTo(result)
@@ -513,6 +684,48 @@
handlesCrossed = true
)
+ selectionRegistrar.subselections = mapOf(
+ endSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = annotatedString.length,
+ selectableId = endSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = endOffset,
+ selectableId = endSelectableId
+ ),
+ handlesCrossed = true
+ ),
+ middleSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = annotatedString.length,
+ selectableId = middleSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = middleSelectableId
+ ),
+ handlesCrossed = true
+ ),
+ startSelectableId to Selection(
+ start = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = startOffset,
+ selectableId = startSelectableId
+ ),
+ end = Selection.AnchorInfo(
+ direction = ResolvedTextDirection.Ltr,
+ offset = 0,
+ selectableId = startSelectableId
+ ),
+ handlesCrossed = true
+ ),
+ )
+
val result = annotatedString.subSequence(endOffset, annotatedString.length) +
annotatedString + annotatedString.subSequence(0, startOffset)
assertThat(selectionManager.getSelectedText()).isEqualTo(result)
@@ -526,6 +739,7 @@
@Test
fun copy_selection_null_not_trigger_clipboardManager() {
selectionManager.selection = null
+ selectionRegistrar.subselections = emptyMap()
selectionManager.copy()
@@ -539,7 +753,7 @@
val startOffset = text.indexOf('m')
val endOffset = text.indexOf('x')
selectable.textToReturn = annotatedString
- selectionManager.selection = Selection(
+ val selection = Selection(
start = Selection.AnchorInfo(
direction = ResolvedTextDirection.Ltr,
offset = startOffset,
@@ -552,6 +766,8 @@
),
handlesCrossed = true
)
+ selectionManager.selection = selection
+ selectionRegistrar.subselections = mapOf(selectableId to selection)
selectionManager.copy()
@@ -570,7 +786,8 @@
val startOffset = text.indexOf('m')
val endOffset = text.indexOf('x')
selectable.textToReturn = annotatedString
- selectionManager.selection = Selection(
+ selectable.layoutCoordinatesToReturn = containerLayoutCoordinates
+ val selection = Selection(
start = Selection.AnchorInfo(
direction = ResolvedTextDirection.Ltr,
offset = startOffset,
@@ -583,12 +800,14 @@
),
handlesCrossed = true
)
+ selectionManager.selection = selection
+ selectionRegistrar.subselections = mapOf(selectableId to selection)
selectionManager.hasFocus = true
selectionManager.showToolbar = true
verify(textToolbar, times(1)).showMenu(
- eq(Rect.Zero),
+ any(),
any(),
isNull(),
isNull(),
@@ -603,7 +822,7 @@
val startOffset = text.indexOf('m')
val endOffset = text.indexOf('x')
selectable.textToReturn = annotatedString
- selectionManager.selection = Selection(
+ val selection = Selection(
start = Selection.AnchorInfo(
direction = ResolvedTextDirection.Ltr,
offset = startOffset,
@@ -616,12 +835,14 @@
),
handlesCrossed = true
)
+ selectionManager.selection = selection
+ selectionRegistrar.subselections = mapOf(selectableId to selection)
selectionManager.hasFocus = false
selectionManager.showToolbar = true
verify(textToolbar, never()).showMenu(
- eq(Rect.Zero),
+ any(),
any(),
isNull(),
isNull(),
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/BasicTooltip.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/BasicTooltip.kt
index dd0593b..99b38b0 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/BasicTooltip.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/BasicTooltip.kt
@@ -20,8 +20,7 @@
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.saveable.Saver
-import androidx.compose.runtime.saveable.rememberSaveable
+import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.window.PopupPositionProvider
@@ -79,10 +78,9 @@
isPersistent: Boolean = true,
mutatorMutex: MutatorMutex = BasicTooltipDefaults.GlobalMutatorMutex
): BasicTooltipState =
- rememberSaveable(
+ remember(
isPersistent,
- mutatorMutex,
- saver = BasicTooltipStateImpl.Saver
+ mutatorMutex
) {
BasicTooltipStateImpl(
initialIsVisible = initialIsVisible,
@@ -180,29 +178,6 @@
override fun onDispose() {
job?.cancel()
}
-
- companion object {
- /**
- * The default [Saver] implementation for [BasicTooltipStateImpl].
- */
- val Saver = Saver<BasicTooltipStateImpl, Any>(
- save = {
- listOf(
- it.isVisible,
- it.isPersistent,
- it.mutatorMutex
- )
- },
- restore = {
- val (isVisible, isPersistent, mutatorMutex) = it as List<*>
- BasicTooltipStateImpl(
- initialIsVisible = isVisible as Boolean,
- isPersistent = isPersistent as Boolean,
- mutatorMutex = mutatorMutex as MutatorMutex,
- )
- }
- )
- }
}
/**
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Draggable.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Draggable.kt
index 4b6c4856..08efb0a 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Draggable.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/gestures/Draggable.kt
@@ -303,15 +303,18 @@
private val _canDrag: (PointerInputChange) -> Boolean = { canDrag(it) }
private val _startDragImmediately: () -> Boolean = { startDragImmediately() }
private val velocityTracker = VelocityTracker()
+ private var isListeningForEvents = false
- /**
- * To preserve the original behavior we had (before the Modifier.Node migration) we need to
- * scope the DragStopped and DragCancel methods to the node's coroutine scope instead of using
- * the one provided by the pointer input modifier, this is to ensure that even when the pointer
- * input scope is reset we will continue any coroutine scope scope that we started from these
- * methods while the pointer input scope was active.
- */
- override fun onAttach() {
+ private fun startListeningForEvents() {
+ isListeningForEvents = true
+
+ /**
+ * To preserve the original behavior we had (before the Modifier.Node migration) we need to
+ * scope the DragStopped and DragCancel methods to the node's coroutine scope instead of using
+ * the one provided by the pointer input modifier, this is to ensure that even when the pointer
+ * input scope is reset we will continue any coroutine scope scope that we started from these
+ * methods while the pointer input scope was active.
+ */
coroutineScope.launch {
while (isActive) {
var event = channel.receive()
@@ -349,6 +352,13 @@
velocityTracker,
orientation
)?.let {
+ /**
+ * The gesture crossed the touch slop, events are now relevant
+ * and should be propagated
+ */
+ if (!isListeningForEvents) {
+ startListeningForEvents()
+ }
var isDragSuccessful = false
try {
isDragSuccessful = awaitDrag(
@@ -391,6 +401,7 @@
private var dragInteraction: DragInteraction.Start? = null
override fun onDetach() {
+ isListeningForEvents = false
disposeInteractionSource()
}
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/modifiers/SelectionController.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/modifiers/SelectionController.kt
index ff34ae3..248d6d7 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/modifiers/SelectionController.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/modifiers/SelectionController.kt
@@ -49,7 +49,9 @@
}
open val shouldClip: Boolean
- get() = textLayoutResult?.layoutInput?.overflow == TextOverflow.Visible
+ get() = textLayoutResult?.let {
+ it.layoutInput.overflow != TextOverflow.Visible && it.hasVisualOverflow
+ } ?: false
// if this copy shows up in traces, this class may become mutable
fun copy(
@@ -115,6 +117,7 @@
fun updateGlobalPosition(coordinates: LayoutCoordinates) {
params = params.copy(layoutCoordinates = coordinates)
+ selectionRegistrar.notifyPositionChange(selectableId)
}
fun draw(drawScope: DrawScope) {
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/SelectionManager.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/SelectionManager.kt
index a02f411..5bf0b16 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/SelectionManager.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/SelectionManager.kt
@@ -23,6 +23,7 @@
import androidx.compose.foundation.text.Handle
import androidx.compose.foundation.text.TextDragObserver
import androidx.compose.foundation.text.selection.Selection.AnchorInfo
+import androidx.compose.foundation.text2.input.internal.coerceIn
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
import androidx.compose.runtime.getValue
@@ -50,14 +51,14 @@
import androidx.compose.ui.platform.TextToolbar
import androidx.compose.ui.platform.TextToolbarStatus
import androidx.compose.ui.text.AnnotatedString
+import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.util.fastAny
+import androidx.compose.ui.util.fastFilter
import androidx.compose.ui.util.fastFold
import androidx.compose.ui.util.fastForEach
import androidx.compose.ui.util.fastForEachIndexed
import kotlin.math.absoluteValue
-import kotlin.math.max
-import kotlin.math.min
/**
* A bridge class between user interaction to the text composables for text selection.
@@ -87,7 +88,7 @@
set(value) {
if (_isInTouchMode.value != value) {
_isInTouchMode.value = value
- if (value && showToolbar) showSelectionToolbar() else hideSelectionToolbar()
+ updateSelectionToolbar()
}
}
@@ -162,7 +163,7 @@
if (previousPosition != positionInWindow) {
previousPosition = positionInWindow
updateHandleOffsets()
- updateSelectionToolbarPosition()
+ updateSelectionToolbar()
}
}
}
@@ -221,12 +222,9 @@
init {
selectionRegistrar.onPositionChangeCallback = { selectableId ->
- if (
- selectableId == selection?.start?.selectableId ||
- selectableId == selection?.end?.selectableId
- ) {
+ if (selectableId in selectionRegistrar.subselections) {
updateHandleOffsets()
- updateSelectionToolbarPosition()
+ updateSelectionToolbar()
}
}
@@ -297,22 +295,26 @@
selectionRegistrar.onSelectableChangeCallback = { selectableKey ->
if (selectableKey in selectionRegistrar.subselections) {
- // clear the selection range of each Selectable.
+ // Clear the selection range of each Selectable.
onRelease()
selection = null
}
}
- selectionRegistrar.afterSelectableUnsubscribe = { selectableKey ->
- if (
- selectableKey == selection?.start?.selectableId ||
- selectableKey == selection?.end?.selectableId
- ) {
+ selectionRegistrar.afterSelectableUnsubscribe = { selectableId ->
+ if (selectableId == selection?.start?.selectableId) {
// The selectable that contains a selection handle just unsubscribed.
- // Hide selection handles for now
+ // Hide the associated selection handle
startHandlePosition = null
+ }
+ if (selectableId == selection?.end?.selectableId) {
endHandlePosition = null
}
+
+ if (selectableId in selectionRegistrar.subselections) {
+ // Unsubscribing the selectable may make the selection empty, which would hide it.
+ updateSelectionToolbar()
+ }
}
}
@@ -331,46 +333,38 @@
val endSelectable = selection?.end?.let(::getAnchorSelectable)
val startLayoutCoordinates = startSelectable?.getLayoutCoordinates()
val endLayoutCoordinates = endSelectable?.getLayoutCoordinates()
+
if (
selection == null ||
containerCoordinates == null ||
!containerCoordinates.isAttached ||
- startLayoutCoordinates == null ||
- endLayoutCoordinates == null
+ (startLayoutCoordinates == null && endLayoutCoordinates == null)
) {
this.startHandlePosition = null
this.endHandlePosition = null
return
}
- val startHandlePosition = containerCoordinates.localPositionOf(
- startLayoutCoordinates,
- startSelectable.getHandlePosition(
- selection = selection,
- isStartHandle = true
- )
- )
- val endHandlePosition = containerCoordinates.localPositionOf(
- endLayoutCoordinates,
- endSelectable.getHandlePosition(
- selection = selection,
- isStartHandle = false
- )
- )
-
val visibleBounds = containerCoordinates.visibleBounds()
-
- // set the new handle position only if the handle is in visible bounds or
- // the handle is still dragging. If handle goes out of visible bounds during drag, handle
- // popup is also removed from composition, halting the drag gesture. This affects multiple
- // text selection when selected text is configured with maxLines=1 and overflow=clip.
- this.startHandlePosition = startHandlePosition.takeIf {
- visibleBounds.containsInclusive(startHandlePosition) ||
- draggingHandle == Handle.SelectionStart
+ this.startHandlePosition = startLayoutCoordinates?.let { handleCoordinates ->
+ // Set the new handle position only if the handle is in visible bounds or
+ // the handle is still dragging. If handle goes out of visible bounds during drag,
+ // handle popup is also removed from composition, halting the drag gesture. This
+ // affects multiple text selection when selected text is configured with maxLines=1
+ // and overflow=clip.
+ val handlePosition = startSelectable.getHandlePosition(selection, isStartHandle = true)
+ val position = containerCoordinates.localPositionOf(handleCoordinates, handlePosition)
+ position.takeIf {
+ draggingHandle == Handle.SelectionStart || visibleBounds.containsInclusive(it)
+ }
}
- this.endHandlePosition = endHandlePosition.takeIf {
- visibleBounds.containsInclusive(endHandlePosition) ||
- draggingHandle == Handle.SelectionEnd
+
+ this.endHandlePosition = endLayoutCoordinates?.let { handleCoordinates ->
+ val handlePosition = endSelectable.getHandlePosition(selection, isStartHandle = false)
+ val position = containerCoordinates.localPositionOf(handleCoordinates, handlePosition)
+ position.takeIf {
+ draggingHandle == Handle.SelectionEnd || visibleBounds.containsInclusive(it)
+ }
}
}
@@ -428,61 +422,49 @@
return false
}
- var betweenSelectables = false
- selectionRegistrar.sort(requireContainerCoordinates()).fastForEach {
- if (
- it.selectableId != selection.start.selectableId &&
- it.selectableId != selection.end.selectableId &&
- !betweenSelectables
- ) {
- // haven't found our selection yet, continue
- return@fastForEach
- }
-
- betweenSelectables = true
- if (!isCurrentSelectionEmpty(selection = selection, selectable = it)) {
- return true
- }
-
- // short-circuit if this is the last selectable
- if (it.selectableId == selection.end.selectableId && !selection.handlesCrossed ||
- it.selectableId == selection.start.selectableId && selection.handlesCrossed
- ) return false
+ if (selection.start.selectableId == selection.end.selectableId) {
+ // Selection is in the same selectable, but not the same anchors,
+ // so there must be some selected text.
+ return true
}
- return false
+
+ // All subselections associated with a selectable must be an empty selection.
+ return selectionRegistrar.sort(requireContainerCoordinates()).fastAny { selectable ->
+ selectionRegistrar.subselections[selectable.selectableId]
+ ?.run { start.offset != end.offset }
+ ?: false
+ }
}
internal fun getSelectedText(): AnnotatedString? {
- val selectables = selectionRegistrar.sort(requireContainerCoordinates())
- var selectedText: AnnotatedString? = null
+ if (selection == null || selectionRegistrar.subselections.isEmpty()) {
+ return null
+ }
- selection?.let {
- for (i in selectables.indices) {
- val selectable = selectables[i]
- // Continue if the current selectable is before the selection starts.
- if (selectable.selectableId != it.start.selectableId &&
- selectable.selectableId != it.end.selectableId &&
- selectedText == null
- ) continue
+ return buildAnnotatedString {
+ selectionRegistrar.sort(requireContainerCoordinates()).fastForEach { selectable ->
+ selectionRegistrar.subselections[selectable.selectableId]?.let { subSelection ->
+ val currentText = selectable.getText()
+ val currentSelectedText = if (subSelection.handlesCrossed) {
+ currentText.subSequence(
+ subSelection.end.offset,
+ subSelection.start.offset
+ )
+ } else {
+ currentText.subSequence(
+ subSelection.start.offset,
+ subSelection.end.offset
+ )
+ }
- val currentSelectedText = getCurrentSelectedText(
- selectable = selectable,
- selection = it
- )
- selectedText = selectedText?.plus(currentSelectedText) ?: currentSelectedText
-
- // Break if the current selectable is the last selected selectable.
- if (selectable.selectableId == it.end.selectableId && !it.handlesCrossed ||
- selectable.selectableId == it.start.selectableId && it.handlesCrossed
- ) break
+ append(currentSelectedText)
+ }
}
}
- return selectedText
}
internal fun copy() {
- val selectedText = getSelectedText()
- selectedText?.takeIf { it.isNotEmpty() }?.let { clipboardManager?.setText(it) }
+ getSelectedText()?.takeIf { it.isNotEmpty() }?.let { clipboardManager?.setText(it) }
}
/**
@@ -494,103 +476,114 @@
internal var showToolbar = false
internal set(value) {
field = value
- if (value && isInTouchMode) showSelectionToolbar() else hideSelectionToolbar()
+ updateSelectionToolbar()
}
+ private fun toolbarCopy() {
+ copy()
+ onRelease()
+ }
+
+ private fun updateSelectionToolbar() {
+ if (!hasFocus) {
+ return
+ }
+
+ val textToolbar = textToolbar ?: return
+ if (showToolbar && isInTouchMode && isNonEmptySelection()) {
+ val rect = getContentRect() ?: return
+ textToolbar.showMenu(rect = rect, onCopyRequested = ::toolbarCopy)
+ } else if (textToolbar.status == TextToolbarStatus.Shown) {
+ textToolbar.hide()
+ }
+ }
+
/**
- * This function get the selected region as a Rectangle region, and pass it to [TextToolbar]
- * to make the FloatingToolbar show up in the proper place. In addition, this function passes
- * the copy method as a callback when "copy" is clicked.
+ * Calculate selected region as [Rect].
+ * The result is the smallest [Rect] that encapsulates the entire selection,
+ * coerced into visible bounds.
*/
- private fun showSelectionToolbar() {
- if (hasFocus && isNonEmptySelection()) {
- textToolbar?.showMenu(
- getContentRect(),
- onCopyRequested = {
- copy()
- onRelease()
+ private fun getContentRect(): Rect? {
+ selection ?: return null
+ val containerCoordinates = containerLayoutCoordinates ?: return null
+ if (!containerCoordinates.isAttached) return null
+ val visibleBounds = containerCoordinates.visibleBounds()
+
+ var anyExists = false
+ var rootLeft = Float.POSITIVE_INFINITY
+ var rootTop = Float.POSITIVE_INFINITY
+ var rootRight = Float.NEGATIVE_INFINITY
+ var rootBottom = Float.NEGATIVE_INFINITY
+
+ val sortedSelectables = selectionRegistrar.sort(requireContainerCoordinates())
+ .fastFilter {
+ it.selectableId in selectionRegistrar.subselections
+ }
+
+ if (sortedSelectables.isEmpty()) {
+ return null
+ }
+
+ val selectedSelectables = if (sortedSelectables.size == 1) {
+ sortedSelectables
+ } else {
+ listOf(sortedSelectables.first(), sortedSelectables.last())
+ }
+
+ selectedSelectables.fastForEach { selectable ->
+ val subSelection = selectionRegistrar.subselections[selectable.selectableId]
+ ?: return@fastForEach
+
+ val coordinates = selectable.getLayoutCoordinates()
+ ?: return@fastForEach
+
+ with(subSelection) {
+ if (start.offset == end.offset) {
+ return@fastForEach
}
- )
+
+ val minOffset = minOf(start.offset, end.offset)
+ val maxOffset = maxOf(start.offset, end.offset)
+
+ var left = Float.POSITIVE_INFINITY
+ var top = Float.POSITIVE_INFINITY
+ var right = Float.NEGATIVE_INFINITY
+ var bottom = Float.NEGATIVE_INFINITY
+ for (i in intArrayOf(minOffset, maxOffset)) {
+ val rect = selectable.getBoundingBox(i)
+ left = minOf(left, rect.left)
+ top = minOf(top, rect.top)
+ right = maxOf(right, rect.right)
+ bottom = maxOf(bottom, rect.bottom)
+ }
+
+ val localTopLeft = Offset(left, top)
+ val localBottomRight = Offset(right, bottom)
+
+ val containerTopLeft =
+ containerCoordinates.localPositionOf(coordinates, localTopLeft)
+ val containerBottomRight =
+ containerCoordinates.localPositionOf(coordinates, localBottomRight)
+
+ val rootVisibleTopLeft =
+ containerCoordinates.localToRoot(containerTopLeft.coerceIn(visibleBounds))
+ val rootVisibleBottomRight =
+ containerCoordinates.localToRoot(containerBottomRight.coerceIn(visibleBounds))
+
+ rootLeft = minOf(rootLeft, rootVisibleTopLeft.x)
+ rootTop = minOf(rootTop, rootVisibleTopLeft.y)
+ rootRight = maxOf(rootRight, rootVisibleBottomRight.x)
+ rootBottom = maxOf(rootBottom, rootVisibleBottomRight.y)
+ anyExists = true
+ }
}
- }
- private fun hideSelectionToolbar() {
- if (hasFocus && textToolbar?.status == TextToolbarStatus.Shown) {
- textToolbar?.hide()
+ if (!anyExists) {
+ return null
}
- }
- private fun updateSelectionToolbarPosition() {
- if (hasFocus && textToolbar?.status == TextToolbarStatus.Shown) {
- showSelectionToolbar()
- }
- }
-
- /**
- * Calculate selected region as [Rect]. The top is the top of the first selected
- * line, and the bottom is the bottom of the last selected line. The left is the leftmost
- * handle's horizontal coordinates, and the right is the rightmost handle's coordinates.
- */
- private fun getContentRect(): Rect {
- val selection = selection ?: return Rect.Zero
- val startSelectable = getAnchorSelectable(selection.start)
- val endSelectable = getAnchorSelectable(selection.end)
- val startLayoutCoordinates = startSelectable?.getLayoutCoordinates() ?: return Rect.Zero
- val endLayoutCoordinates = endSelectable?.getLayoutCoordinates() ?: return Rect.Zero
-
- val localLayoutCoordinates = containerLayoutCoordinates
- if (localLayoutCoordinates != null && localLayoutCoordinates.isAttached) {
- var startOffset = localLayoutCoordinates.localPositionOf(
- startLayoutCoordinates,
- startSelectable.getHandlePosition(
- selection = selection,
- isStartHandle = true
- )
- )
- var endOffset = localLayoutCoordinates.localPositionOf(
- endLayoutCoordinates,
- endSelectable.getHandlePosition(
- selection = selection,
- isStartHandle = false
- )
- )
-
- startOffset = localLayoutCoordinates.localToRoot(startOffset)
- endOffset = localLayoutCoordinates.localToRoot(endOffset)
-
- val left = min(startOffset.x, endOffset.x)
- val right = max(startOffset.x, endOffset.x)
-
- var startTop = localLayoutCoordinates.localPositionOf(
- startLayoutCoordinates,
- Offset(
- 0f,
- startSelectable.getBoundingBox(selection.start.offset).top
- )
- )
-
- var endTop = localLayoutCoordinates.localPositionOf(
- endLayoutCoordinates,
- Offset(
- 0.0f,
- endSelectable.getBoundingBox(selection.end.offset).top
- )
- )
-
- startTop = localLayoutCoordinates.localToRoot(startTop)
- endTop = localLayoutCoordinates.localToRoot(endTop)
-
- val top = min(startTop.y, endTop.y)
- val bottom = max(startOffset.y, endOffset.y) + (HandleHeight.value * 4.0).toFloat()
-
- return Rect(
- left,
- top,
- right,
- bottom
- )
- }
- return Rect.Zero
+ rootBottom += HandleHeight.value * 4
+ return Rect(rootLeft, rootTop, rootRight, rootBottom)
}
// This is for PressGestureDetector to cancel the selection.
@@ -985,70 +978,6 @@
)
}
-private fun isCurrentSelectionEmpty(
- selectable: Selectable,
- selection: Selection
-): Boolean {
- val selectableId = selectable.selectableId
- val startSelectableId = selection.start.selectableId
- val endSelectableId = selection.end.selectableId
-
- if (selectableId == startSelectableId && selectableId == endSelectableId) {
- return selection.start.offset == selection.end.offset
- }
-
- val text = selectable.getText()
- val handlesCrossed = selection.handlesCrossed
- return when (selectableId) {
- startSelectableId -> selection.start.offset == if (handlesCrossed) 0 else text.length
- endSelectableId -> selection.end.offset == if (handlesCrossed) text.length else 0
- else -> text.isEmpty()
- }
-}
-
-internal fun getCurrentSelectedText(
- selectable: Selectable,
- selection: Selection
-): AnnotatedString {
- val currentText = selectable.getText()
-
- return if (
- selectable.selectableId != selection.start.selectableId &&
- selectable.selectableId != selection.end.selectableId
- ) {
- // Select the full text content if the current selectable is between the
- // start and the end selectables.
- currentText
- } else if (
- selectable.selectableId == selection.start.selectableId &&
- selectable.selectableId == selection.end.selectableId
- ) {
- // Select partial text content if the current selectable is the start and
- // the end selectable.
- if (selection.handlesCrossed) {
- currentText.subSequence(selection.end.offset, selection.start.offset)
- } else {
- currentText.subSequence(selection.start.offset, selection.end.offset)
- }
- } else if (selectable.selectableId == selection.start.selectableId) {
- // Select partial text content if the current selectable is the start
- // selectable.
- if (selection.handlesCrossed) {
- currentText.subSequence(0, selection.start.offset)
- } else {
- currentText.subSequence(selection.start.offset, currentText.length)
- }
- } else {
- // Selectable partial text content if the current selectable is the end
- // selectable.
- if (selection.handlesCrossed) {
- currentText.subSequence(selection.end.offset, currentText.length)
- } else {
- currentText.subSequence(0, selection.end.offset)
- }
- }
-}
-
/** Returns the boundary of the visible area in this [LayoutCoordinates]. */
internal fun LayoutCoordinates.visibleBounds(): Rect {
// globalBounds is the global boundaries of this LayoutCoordinates after it's clipped by
diff --git a/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Tooltip.kt b/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Tooltip.kt
index 21e04e7..22cfbbf 100644
--- a/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Tooltip.kt
+++ b/compose/material3/material3/src/commonMain/kotlin/androidx/compose/material3/Tooltip.kt
@@ -43,8 +43,6 @@
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
-import androidx.compose.runtime.saveable.Saver
-import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.graphics.Color
@@ -422,11 +420,10 @@
initialIsVisible: Boolean = false,
isPersistent: Boolean = false,
mutatorMutex: MutatorMutex = BasicTooltipDefaults.GlobalMutatorMutex
-): TooltipState {
- return rememberSaveable(
+): TooltipState =
+ remember(
isPersistent,
- mutatorMutex,
- saver = TooltipStateImpl.Saver
+ mutatorMutex
) {
TooltipStateImpl(
initialIsVisible = initialIsVisible,
@@ -434,7 +431,6 @@
mutatorMutex = mutatorMutex
)
}
-}
/**
* Constructor extension function for [TooltipState]
@@ -528,29 +524,6 @@
override fun onDispose() {
job?.cancel()
}
-
- companion object {
- /**
- * The default [Saver] implementation for [TooltipStateImpl].
- */
- val Saver = Saver<TooltipStateImpl, Any>(
- save = {
- listOf(
- it.isVisible,
- it.isPersistent,
- it.mutatorMutex
- )
- },
- restore = {
- val (isVisible, isPersistent, mutatorMutex) = it as List<*>
- TooltipStateImpl(
- initialIsVisible = isVisible as Boolean,
- isPersistent = isPersistent as Boolean,
- mutatorMutex = mutatorMutex as MutatorMutex,
- )
- }
- )
- }
}
/**
diff --git a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutNodeLayoutDelegate.kt b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutNodeLayoutDelegate.kt
index 2e4eb7a..7e16660 100644
--- a/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutNodeLayoutDelegate.kt
+++ b/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutNodeLayoutDelegate.kt
@@ -244,6 +244,13 @@
internal var lookaheadPassDelegate: LookaheadPassDelegate? = null
private set
+ // Used by performMeasureBlock so that we don't have to allocate a lambda on every call
+ private var performMeasureConstraints = Constraints()
+
+ private val performMeasureBlock: () -> Unit = {
+ outerCoordinator.measure(performMeasureConstraints)
+ }
+
fun onCoordinatesUsed() {
val state = layoutNode.layoutState
if (state == LayoutState.LayingOut || state == LayoutState.LookaheadLayingOut) {
@@ -349,6 +356,20 @@
var layingOutChildren = false
private set
+ private val layoutChildrenBlock: () -> Unit = {
+ clearPlaceOrder()
+ forEachChildAlignmentLinesOwner {
+ it.alignmentLines.usedDuringParentLayout = false
+ }
+ innerCoordinator.measureResult.placeChildren()
+
+ checkChildrenPlaceOrderForUpdates()
+ forEachChildAlignmentLinesOwner {
+ it.alignmentLines.previousUsedDuringParentLayout =
+ it.alignmentLines.usedDuringParentLayout
+ }
+ }
+
override fun layoutChildren() {
layingOutChildren = true
alignmentLines.recalculateQueryOwner()
@@ -370,20 +391,9 @@
val owner = requireOwner()
owner.snapshotObserver.observeLayoutSnapshotReads(
this,
- affectsLookahead = false
- ) {
- clearPlaceOrder()
- forEachChildAlignmentLinesOwner {
- it.alignmentLines.usedDuringParentLayout = false
- }
- innerCoordinator.measureResult.placeChildren()
-
- checkChildrenPlaceOrderForUpdates()
- forEachChildAlignmentLinesOwner {
- it.alignmentLines.previousUsedDuringParentLayout =
- it.alignmentLines.usedDuringParentLayout
- }
- }
+ affectsLookahead = false,
+ block = layoutChildrenBlock
+ )
}
layoutState = oldLayoutState
@@ -464,6 +474,29 @@
private var onNodePlacedCalled = false
+ // Used by placeOuterBlock to avoid allocating the lambda on every call
+ private var placeOuterCoordinatorLayerBlock: (GraphicsLayerScope.() -> Unit)? = null
+ private var placeOuterCoordinatorPosition = IntOffset.Zero
+ private var placeOuterCoordinatorZIndex = 0f
+
+ private val placeOuterCoordinatorBlock: () -> Unit = {
+ with(PlacementScope) {
+ val layerBlock = placeOuterCoordinatorLayerBlock
+ if (layerBlock == null) {
+ outerCoordinator.place(
+ placeOuterCoordinatorPosition,
+ placeOuterCoordinatorZIndex
+ )
+ } else {
+ outerCoordinator.placeWithLayer(
+ placeOuterCoordinatorPosition,
+ placeOuterCoordinatorZIndex,
+ layerBlock
+ )
+ }
+ }
+ }
+
/**
* Invoked when the parent placed the node. It will trigger the layout.
*/
@@ -701,17 +734,13 @@
} else {
alignmentLines.usedByModifierLayout = false
coordinatesAccessedDuringModifierPlacement = false
+ placeOuterCoordinatorLayerBlock = layerBlock
+ placeOuterCoordinatorPosition = position
+ placeOuterCoordinatorZIndex = zIndex
owner.snapshotObserver.observeLayoutModifierSnapshotReads(
- layoutNode, affectsLookahead = false
- ) {
- with(PlacementScope) {
- if (layerBlock == null) {
- outerCoordinator.place(position, zIndex)
- } else {
- outerCoordinator.placeWithLayer(position, zIndex, layerBlock)
- }
- }
- }
+ layoutNode, affectsLookahead = false, block = placeOuterCoordinatorBlock
+ )
+ placeOuterCoordinatorLayerBlock = null
}
layoutState = LayoutState.Idle
@@ -1548,12 +1577,12 @@
}
layoutState = LayoutState.Measuring
measurePending = false
+ performMeasureConstraints = constraints
layoutNode.requireOwner().snapshotObserver.observeMeasureSnapshotReads(
layoutNode,
- affectsLookahead = false
- ) {
- outerCoordinator.measure(constraints)
- }
+ affectsLookahead = false,
+ performMeasureBlock
+ )
// The resulting layout state might be Ready. This can happen when the layout node's
// own modifier is querying an alignment line during measurement, therefore we
// need to also layout the layout node.
diff --git a/constraintlayout/constraintlayout-compose/src/androidMain/kotlin/androidx/constraintlayout/compose/ConstraintLayout.kt b/constraintlayout/constraintlayout-compose/src/androidMain/kotlin/androidx/constraintlayout/compose/ConstraintLayout.kt
index 337d63a..04f1c6d 100644
--- a/constraintlayout/constraintlayout-compose/src/androidMain/kotlin/androidx/constraintlayout/compose/ConstraintLayout.kt
+++ b/constraintlayout/constraintlayout-compose/src/androidMain/kotlin/androidx/constraintlayout/compose/ConstraintLayout.kt
@@ -20,7 +20,7 @@
import android.os.Handler
import android.os.Looper
import android.util.Log
-import androidx.collection.PairIntInt
+import androidx.collection.IntIntPair
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.tween
@@ -2019,7 +2019,7 @@
private fun measureWidget(
constraintWidget: ConstraintWidget,
constraints: Constraints
- ): PairIntInt {
+ ): IntIntPair {
val measurable = constraintWidget.companionWidget
val widgetId = constraintWidget.stringId
return when {
@@ -2042,15 +2042,15 @@
heightMode,
constraints.maxHeight
)
- PairIntInt(constraintWidget.measuredWidth, constraintWidget.measuredHeight)
+ IntIntPair(constraintWidget.measuredWidth, constraintWidget.measuredHeight)
}
measurable is Measurable -> {
val result = measurable.measure(constraints).also { placeables[measurable] = it }
- PairIntInt(result.width, result.height)
+ IntIntPair(result.width, result.height)
}
else -> {
Log.w("CCL", "Nothing to measure for widget: $widgetId")
- PairIntInt(0, 0)
+ IntIntPair(0, 0)
}
}
}
diff --git a/core/core-telecom/src/androidTest/java/androidx/core/telecom/test/E2ECallExtensionExtrasTests.kt b/core/core-telecom/src/androidTest/java/androidx/core/telecom/test/E2ECallExtensionExtrasTests.kt
index 458a920..7fa9e16 100644
--- a/core/core-telecom/src/androidTest/java/androidx/core/telecom/test/E2ECallExtensionExtrasTests.kt
+++ b/core/core-telecom/src/androidTest/java/androidx/core/telecom/test/E2ECallExtensionExtrasTests.kt
@@ -159,18 +159,21 @@
runBlocking {
assertWithinTimeout_addCall(callAttributesCompat) {
launch {
- val call = TestUtils.waitOnInCallServiceToReachXCalls(1)
- Assert.assertNotNull("The returned Call object is <NULL>", call!!)
+ try {
+ val call = TestUtils.waitOnInCallServiceToReachXCalls(1)
+ Assert.assertNotNull("The returned Call object is <NULL>", call!!)
- // Enforce waiting logic to ensure that the call details extras are populated.
- if (waitForCallDetailExtras) {
- TestUtils.waitOnCallExtras(call)
+ // Enforce waiting logic to ensure that the call details extras are populated.
+ if (waitForCallDetailExtras) {
+ TestUtils.waitOnCallExtras(call)
+ }
+
+ // Assert the call extra or call property from the details
+ assertCallExtraOrProperty(call)
+ } finally {
+ // Always send disconnect signal if possible.
+ assertTrue(disconnect(DisconnectCause(DisconnectCause.LOCAL)))
}
-
- // Assert the call extra or call property from the details
- assertCallExtraOrProperty(call)
- // Always send disconnect signal if possible.
- assertTrue(disconnect(DisconnectCause(DisconnectCause.LOCAL)))
}
}
}
diff --git a/core/core-telecom/src/androidTest/java/androidx/core/telecom/test/utils/TestUtils.kt b/core/core-telecom/src/androidTest/java/androidx/core/telecom/test/utils/TestUtils.kt
index c44414ca..e879ead 100644
--- a/core/core-telecom/src/androidTest/java/androidx/core/telecom/test/utils/TestUtils.kt
+++ b/core/core-telecom/src/androidTest/java/androidx/core/telecom/test/utils/TestUtils.kt
@@ -318,7 +318,8 @@
suspend fun waitOnCallExtras(call: Call) {
try {
withTimeout(TestUtils.WAIT_ON_CALL_STATE_TIMEOUT) {
- while (isActive /* aka within timeout window */ && call.details?.extras == null) {
+ while (isActive /* aka within timeout window */ && (
+ call.details?.extras == null || call.details.extras.isEmpty)) {
yield() // another mechanism to stop the while loop if the coroutine is dead
delay(1) // sleep x millisecond(s) instead of spamming check
}
diff --git a/libraryversions.toml b/libraryversions.toml
index 1f1cb09..05bfaeef 100644
--- a/libraryversions.toml
+++ b/libraryversions.toml
@@ -1,5 +1,5 @@
[versions]
-ACTIVITY = "1.8.0-beta01"
+ACTIVITY = "1.8.0-rc01"
ANNOTATION = "1.8.0-alpha01"
ANNOTATION_EXPERIMENTAL = "1.4.0-alpha01"
APPACTIONS_BUILTINTYPES = "1.0.0-alpha01"
@@ -9,7 +9,7 @@
ARCH_CORE = "2.3.0-alpha01"
ASYNCLAYOUTINFLATER = "1.1.0-alpha02"
AUTOFILL = "1.3.0-alpha02"
-BENCHMARK = "1.2.0-beta05"
+BENCHMARK = "1.3.0-alpha01"
BIOMETRIC = "1.2.0-alpha06"
BLUETOOTH = "1.0.0-alpha01"
BROWSER = "1.7.0-alpha01"
@@ -19,7 +19,7 @@
CARDVIEW = "1.1.0-alpha01"
CAR_APP = "1.4.0-beta02"
COLLECTION = "1.4.0-alpha01"
-COMPOSE = "1.6.0-alpha05"
+COMPOSE = "1.6.0-alpha06"
COMPOSE_COMPILER = "1.5.3"
COMPOSE_MATERIAL3 = "1.2.0-alpha08"
COMPOSE_MATERIAL3_ADAPTIVE = "1.0.0-alpha01"
@@ -58,7 +58,7 @@
EMOJI2 = "1.5.0-alpha01"
ENTERPRISE = "1.1.0-rc01"
EXIFINTERFACE = "1.4.0-alpha01"
-FRAGMENT = "1.7.0-alpha04"
+FRAGMENT = "1.7.0-alpha05"
FUTURES = "1.2.0-alpha02"
GLANCE = "1.1.0-alpha01"
GLANCE_PREVIEW = "1.0.0-alpha06"
@@ -69,7 +69,7 @@
GRAPHICS_PATH = "1.0.0-alpha02"
GRAPHICS_SHAPES = "1.0.0-alpha03"
GRIDLAYOUT = "1.1.0-beta02"
-HEALTH_CONNECT = "1.1.0-alpha04"
+HEALTH_CONNECT = "1.1.0-alpha05"
HEALTH_SERVICES_CLIENT = "1.1.0-alpha02"
HEIFWRITER = "1.1.0-alpha03"
HILT = "1.1.0-alpha02"
diff --git a/paging/paging-testing/build.gradle b/paging/paging-testing/build.gradle
index 4b85a2d..3499ff2 100644
--- a/paging/paging-testing/build.gradle
+++ b/paging/paging-testing/build.gradle
@@ -15,14 +15,20 @@
*/
import androidx.build.LibraryType
+import androidx.build.KmpPlatformsKt
import androidx.build.PlatformIdentifier
+import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import androidx.build.Publish
+import org.jetbrains.kotlin.konan.target.Family
plugins {
id("AndroidXPlugin")
id("com.android.library")
}
+def macEnabled = KmpPlatformsKt.enableMac(project)
+def linuxEnabled = KmpPlatformsKt.enableLinux(project)
+
androidXMultiplatform {
jvm()
mac()
@@ -33,20 +39,57 @@
defaultPlatform(PlatformIdentifier.ANDROID)
sourceSets {
- androidMain {
+ commonMain {
dependencies {
api(libs.kotlinStdlib)
implementation(project(":paging:paging-common"))
}
}
- androidUnitTest {
+
+ androidMain {
+ dependsOn(jvmMain)
+ }
+
+ commonTest {
dependencies {
- implementation(libs.junit)
- implementation(libs.kotlinCoroutinesTest)
- implementation((libs.kotlinCoroutinesAndroid))
- implementation(project(":internal-testutils-paging"))
implementation(libs.kotlinTest)
- implementation(libs.truth)
+ implementation(libs.kotlinCoroutinesTest)
+ implementation(project(":internal-testutils-paging"))
+ implementation(project(":kruth:kruth"))
+ }
+ }
+
+ if (macEnabled || linuxEnabled) {
+ nativeMain {
+ dependsOn(commonMain)
+ dependencies {
+ implementation(libs.atomicFu)
+ }
+ }
+ }
+ if (macEnabled) {
+ darwinMain {
+ dependsOn(nativeMain)
+ }
+ }
+ if (linuxEnabled) {
+ linuxMain {
+ dependsOn(nativeMain)
+ }
+ }
+
+ targets.all { target ->
+ if (target.platformType == KotlinPlatformType.native) {
+ target.compilations["main"].defaultSourceSet {
+ def konanTargetFamily = target.konanTarget.family
+ if (konanTargetFamily == Family.OSX || konanTargetFamily == Family.IOS) {
+ dependsOn(darwinMain)
+ } else if (konanTargetFamily == Family.LINUX) {
+ dependsOn(linuxMain)
+ } else {
+ throw new GradleException("unknown native target ${target}")
+ }
+ }
}
}
}
diff --git a/paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/LoadErrorHandler.kt b/paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/LoadErrorHandler.kt
similarity index 100%
rename from paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/LoadErrorHandler.kt
rename to paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/LoadErrorHandler.kt
diff --git a/paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/PagerFlowSnapshot.kt b/paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/PagerFlowSnapshot.kt
similarity index 99%
rename from paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/PagerFlowSnapshot.kt
rename to paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/PagerFlowSnapshot.kt
index 825b27b..c6dc443 100644
--- a/paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/PagerFlowSnapshot.kt
+++ b/paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/PagerFlowSnapshot.kt
@@ -33,6 +33,7 @@
import androidx.paging.testing.LoaderCallback.CallbackType.ON_INSERTED
import androidx.paging.testing.LoaderCallback.CallbackType.ON_REMOVED
import kotlin.coroutines.CoroutineContext
+import kotlin.jvm.JvmSuppressWildcards
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
diff --git a/paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/SnapshotLoader.kt b/paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/SnapshotLoader.kt
similarity index 98%
rename from paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/SnapshotLoader.kt
rename to paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/SnapshotLoader.kt
index 1ebbdbf..b8258d3 100644
--- a/paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/SnapshotLoader.kt
+++ b/paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/SnapshotLoader.kt
@@ -25,8 +25,9 @@
import androidx.paging.PagingDataDiffer
import androidx.paging.PagingSource
import androidx.paging.testing.LoaderCallback.CallbackType.ON_INSERTED
-import java.util.concurrent.atomic.AtomicInteger
-import java.util.concurrent.atomic.AtomicReference
+import androidx.paging.testing.internal.AtomicInt
+import androidx.paging.testing.internal.AtomicRef
+import kotlin.jvm.JvmSuppressWildcards
import kotlin.math.abs
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.filterNotNull
@@ -451,12 +452,12 @@
* Temporarily stores the latest [DifferCallback] to track prepends to the beginning of list.
* Value is reset to null once read.
*/
- val callbackState: AtomicReference<LoaderCallback?> = AtomicReference(null),
+ val callbackState: AtomicRef<LoaderCallback?> = AtomicRef(null),
/**
* Tracks the last accessed(peeked) index on the differ for this generation
*/
- var lastAccessedIndex: AtomicInteger = AtomicInteger()
+ var lastAccessedIndex: AtomicInt = AtomicInt(0)
)
internal data class LoaderCallback(
diff --git a/paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/StaticListPagingSource.kt b/paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/StaticListPagingSource.kt
similarity index 100%
rename from paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/StaticListPagingSource.kt
rename to paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/StaticListPagingSource.kt
diff --git a/paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/StaticListPagingSourceFactory.kt b/paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/StaticListPagingSourceFactory.kt
similarity index 98%
rename from paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/StaticListPagingSourceFactory.kt
rename to paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/StaticListPagingSourceFactory.kt
index 000e2a1..fc5ea4d 100644
--- a/paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/StaticListPagingSourceFactory.kt
+++ b/paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/StaticListPagingSourceFactory.kt
@@ -22,6 +22,7 @@
import androidx.paging.Pager
import androidx.paging.PagingSource
import androidx.paging.PagingSourceFactory
+import kotlin.jvm.JvmSuppressWildcards
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
diff --git a/paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/TestPager.kt b/paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/TestPager.kt
similarity index 99%
rename from paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/TestPager.kt
rename to paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/TestPager.kt
index 35b14ad..6cca56c 100644
--- a/paging/paging-testing/src/androidMain/kotlin/androidx/paging/testing/TestPager.kt
+++ b/paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/TestPager.kt
@@ -28,7 +28,8 @@
import androidx.paging.PagingSource.LoadResult
import androidx.paging.PagingSource.LoadResult.Page.Companion.COUNT_UNDEFINED
import androidx.paging.PagingState
-import java.util.concurrent.atomic.AtomicBoolean
+import androidx.paging.testing.internal.AtomicBoolean
+import kotlin.jvm.JvmSuppressWildcards
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
diff --git a/paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/internal/Atomics.kt b/paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/internal/Atomics.kt
new file mode 100644
index 0000000..8aed900
--- /dev/null
+++ b/paging/paging-testing/src/commonMain/kotlin/androidx/paging/testing/internal/Atomics.kt
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.paging.testing.internal
+
+internal expect class AtomicInt(initialValue: Int) {
+ fun get(): Int
+ fun set(value: Int)
+}
+
+internal expect class AtomicBoolean(initialValue: Boolean) {
+ fun get(): Boolean
+ fun set(value: Boolean)
+ fun compareAndSet(expect: Boolean, update: Boolean): Boolean
+}
+
+internal expect class AtomicRef<T>(initialValue: T) {
+ fun get(): T
+ fun set(value: T)
+ fun getAndSet(value: T): T
+}
diff --git a/paging/paging-testing/src/androidUnitTest/kotlin/androidx/paging/testing/PagerFlowSnapshotTest.kt b/paging/paging-testing/src/commonTest/kotlin/androidx/paging/testing/PagerFlowSnapshotTest.kt
similarity index 65%
rename from paging/paging-testing/src/androidUnitTest/kotlin/androidx/paging/testing/PagerFlowSnapshotTest.kt
rename to paging/paging-testing/src/commonTest/kotlin/androidx/paging/testing/PagerFlowSnapshotTest.kt
index d4bd050..6fd3153 100644
--- a/paging/paging-testing/src/androidUnitTest/kotlin/androidx/paging/testing/PagerFlowSnapshotTest.kt
+++ b/paging/paging-testing/src/commonTest/kotlin/androidx/paging/testing/PagerFlowSnapshotTest.kt
@@ -16,6 +16,8 @@
package androidx.paging.testing
+import androidx.kruth.assertThat
+import androidx.kruth.assertWithMessage
import androidx.paging.LoadState
import androidx.paging.LoadStates
import androidx.paging.Pager
@@ -27,8 +29,7 @@
import androidx.paging.PagingState
import androidx.paging.cachedIn
import androidx.paging.insertSeparators
-import com.google.common.truth.Truth.assertThat
-import com.google.common.truth.Truth.assertWithMessage
+import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
@@ -40,39 +41,32 @@
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.junit.runners.Parameterized
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class)
-@RunWith(Parameterized::class)
-class PagerFlowSnapshotTest(
- private val loadDelay: Long
-) {
- companion object {
- @Parameterized.Parameters
- @JvmStatic
- fun withLoadDelay(): Array<Long> {
- return arrayOf(0, 10000)
- }
- }
-
+class PagerFlowSnapshotTest {
private val testScope = TestScope(UnconfinedTestDispatcher())
- private fun createFactory(dataFlow: Flow<List<Int>>) = WrappedPagingSourceFactory(
- dataFlow.asPagingSourceFactory(testScope.backgroundScope),
- loadDelay
- )
+ private fun createFactory(dataFlow: Flow<List<Int>>, loadDelay: Long) =
+ WrappedPagingSourceFactory(
+ dataFlow.asPagingSourceFactory(testScope.backgroundScope),
+ loadDelay
+ )
- private fun createSingleGenFactory(data: List<Int>) = WrappedPagingSourceFactory(
- data.asPagingSourceFactory(),
- loadDelay
- )
+ private fun createSingleGenFactory(data: List<Int>, loadDelay: Long) =
+ WrappedPagingSourceFactory(
+ data.asPagingSourceFactory(),
+ loadDelay
+ )
@Test
- fun initialRefresh() {
+ fun initialRefresh_loadDelay0() = initialRefresh(0)
+
+ @Test
+ fun initialRefresh_loadDelay10000() = initialRefresh(10000)
+
+ private fun initialRefresh(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot()
// first page + prefetched page
@@ -83,9 +77,14 @@
}
@Test
- fun initialRefreshSingleGen() {
+ fun initialRefreshSingleGen_loadDelay0() = initialRefreshSingleGen(0)
+
+ @Test
+ fun initialRefreshSingleGen_loadDelay10000() = initialRefreshSingleGen(10000)
+
+ private fun initialRefreshSingleGen(loadDelay: Long) {
val data = List(30) { it }
- val pager = createPager(data)
+ val pager = createPager(data, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot()
// first page + prefetched page
@@ -96,9 +95,15 @@
}
@Test
- fun initialRefresh_emptyOperations() {
+ fun initialRefresh_emptyOperations_loadDelay0() = initialRefresh_emptyOperations(0)
+
+ @Test
+ fun initialRefresh_emptyOperations_loadDelay10000() =
+ initialRefresh_emptyOperations(10000)
+
+ private fun initialRefresh_emptyOperations(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {}
// first page + prefetched page
@@ -109,9 +114,14 @@
}
@Test
- fun initialRefresh_withSeparators() {
+ fun initialRefresh_withSeparators_loadDelay0() = initialRefresh_withSeparators(0)
+
+ @Test
+ fun initialRefresh_withSeparators_loadDelay10000() = initialRefresh_withSeparators(10000)
+
+ private fun initialRefresh_withSeparators(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow).map { pagingData ->
+ val pager = createPager(dataFlow, loadDelay).map { pagingData ->
pagingData.insertSeparators { before: Int?, after: Int? ->
if (before != null && after != null) "sep" else null
}
@@ -126,9 +136,14 @@
}
@Test
- fun initialRefresh_withoutPrefetch() {
+ fun initialRefresh_withoutPrefetch_loadDelay0() = initialRefresh_withoutPrefetch(0)
+
+ @Test
+ fun initialRefresh_withoutPrefetch_loadDelay10000() = initialRefresh_withoutPrefetch(10000)
+
+ private fun initialRefresh_withoutPrefetch(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPagerNoPrefetch(dataFlow)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot()
@@ -139,9 +154,14 @@
}
@Test
- fun initialRefresh_withInitialKey() {
+ fun initialRefresh_withInitialKey_loadDelay0() = initialRefresh_withInitialKey(0)
+
+ @Test
+ fun initialRefresh_withInitialKey_loadDelay10000() = initialRefresh_withInitialKey(10000)
+
+ private fun initialRefresh_withInitialKey(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow, 10)
+ val pager = createPager(dataFlow, loadDelay, 10)
testScope.runTest {
val snapshot = pager.asSnapshot()
@@ -152,9 +172,16 @@
}
@Test
- fun initialRefresh_withInitialKey_withoutPrefetch() {
+ fun initialRefresh_withInitialKey_withoutPrefetch_loadDelay0() =
+ initialRefresh_withInitialKey_withoutPrefetch(0)
+
+ @Test
+ fun initialRefresh_withInitialKey_withoutPrefetch_loadDelay10000() =
+ initialRefresh_withInitialKey_withoutPrefetch(10000)
+
+ private fun initialRefresh_withInitialKey_withoutPrefetch(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPagerNoPrefetch(dataFlow, 10)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay, 10)
testScope.runTest {
val snapshot = pager.asSnapshot()
@@ -195,9 +222,14 @@
}
@Test
- fun emptyInitialRefresh() {
+ fun emptyInitialRefresh_loadDelay0() = emptyInitialRefresh(0)
+
+ @Test
+ fun emptyInitialRefresh_loadDelay10000() = emptyInitialRefresh(10000)
+
+ private fun emptyInitialRefresh(loadDelay: Long) {
val dataFlow = emptyFlow<List<Int>>()
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot()
@@ -208,9 +240,14 @@
}
@Test
- fun emptyInitialRefreshSingleGen() {
+ fun emptyInitialRefreshSingleGen_loadDelay0() = emptyInitialRefreshSingleGen(0)
+
+ @Test
+ fun emptyInitialRefreshSingleGen_loadDelay10000() = emptyInitialRefreshSingleGen(10000)
+
+ private fun emptyInitialRefreshSingleGen(loadDelay: Long) {
val data = emptyList<Int>()
- val pager = createPager(data)
+ val pager = createPager(data, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot()
@@ -221,9 +258,15 @@
}
@Test
- fun emptyInitialRefresh_emptyOperations() {
+ fun emptyInitialRefresh_emptyOperations_loadDelay0() = emptyInitialRefresh_emptyOperations(0)
+
+ @Test
+ fun emptyInitialRefresh_emptyOperations_loadDelay10000() =
+ emptyInitialRefresh_emptyOperations(10000)
+
+ private fun emptyInitialRefresh_emptyOperations(loadDelay: Long) {
val dataFlow = emptyFlow<List<Int>>()
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot()
@@ -234,9 +277,14 @@
}
@Test
- fun manualRefresh() {
+ fun manualRefresh_loadDelay0() = manualRefresh(0)
+
+ @Test
+ fun manualRefresh_loadDelay10000() = manualRefresh(10000)
+
+ private fun manualRefresh(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPagerNoPrefetch(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
refresh()
@@ -248,9 +296,14 @@
}
@Test
- fun manualRefreshSingleGen() {
+ fun manualRefreshSingleGen_loadDelay0() = manualRefreshSingleGen(0)
+
+ @Test
+ fun manualRefreshSingleGen_loadDelay10000() = manualRefreshSingleGen(10000)
+
+ private fun manualRefreshSingleGen(loadDelay: Long) {
val data = List(30) { it }
- val pager = createPager(data)
+ val pager = createPager(data, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
refresh()
@@ -313,9 +366,14 @@
}
@Test
- fun manualEmptyRefresh() {
+ fun manualEmptyRefresh_loadDelay0() = manualEmptyRefresh(0)
+
+ @Test
+ fun manualEmptyRefresh_loadDelay10000() = manualEmptyRefresh(10000)
+
+ private fun manualEmptyRefresh(loadDelay: Long) {
val dataFlow = emptyFlow<List<Int>>()
- val pager = createPagerNoPrefetch(dataFlow)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
refresh()
@@ -327,9 +385,14 @@
}
@Test
- fun appendWhile() {
+ fun appendWhile_loadDelay0() = appendWhile(0)
+
+ @Test
+ fun appendWhile_loadDelay10000() = appendWhile(10000)
+
+ private fun appendWhile(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
appendScrollWhile { item: Int ->
@@ -347,9 +410,14 @@
}
@Test
- fun appendWhile_withDrops() {
+ fun appendWhile_withDrops_loadDelay0() = appendWhile_withDrops(0)
+
+ @Test
+ fun appendWhile_withDrops_loadDelay10000() = appendWhile_withDrops(10000)
+
+ private fun appendWhile_withDrops(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPagerWithDrops(dataFlow)
+ val pager = createPagerWithDrops(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
appendScrollWhile { item ->
@@ -364,9 +432,14 @@
}
@Test
- fun appendWhile_withSeparators() {
+ fun appendWhile_withSeparators_loadDelay0() = appendWhile_withSeparators(0)
+
+ @Test
+ fun appendWhile_withSeparators_loadDelay10000() = appendWhile_withSeparators(10000)
+
+ private fun appendWhile_withSeparators(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow).map { pagingData ->
+ val pager = createPager(dataFlow, loadDelay).map { pagingData ->
pagingData.insertSeparators { before: Int?, _ ->
if (before == 9 || before == 12) "sep" else null
}
@@ -391,9 +464,14 @@
}
@Test
- fun appendWhile_withoutPrefetch() {
+ fun appendWhile_withoutPrefetch_loadDelay0() = appendWhile_withoutPrefetch(0)
+
+ @Test
+ fun appendWhile_withoutPrefetch_loadDelay10000() = appendWhile_withoutPrefetch(10000)
+
+ private fun appendWhile_withoutPrefetch(loadDelay: Long) {
val dataFlow = flowOf(List(50) { it })
- val pager = createPagerNoPrefetch(dataFlow)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
appendScrollWhile { item: Int ->
@@ -409,9 +487,14 @@
}
@Test
- fun appendWhile_withoutPlaceholders() {
+ fun appendWhile_withoutPlaceholders_loadDelay0() = appendWhile_withoutPlaceholders(0)
+
+ @Test
+ fun appendWhile_withoutPlaceholders_loadDelay10000() = appendWhile_withoutPlaceholders(10000)
+
+ private fun appendWhile_withoutPlaceholders(loadDelay: Long) {
val dataFlow = flowOf(List(50) { it })
- val pager = createPagerNoPlaceholders(dataFlow)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
appendScrollWhile { item: Int ->
@@ -429,9 +512,14 @@
}
@Test
- fun prependWhile() {
+ fun prependWhile_loadDelay0() = prependWhile(0)
+
+ @Test
+ fun prependWhile_loadDelay10000() = prependWhile(10000)
+
+ private fun prependWhile(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow, 20)
+ val pager = createPager(dataFlow, loadDelay, 20)
testScope.runTest {
val snapshot = pager.asSnapshot {
prependScrollWhile { item: Int ->
@@ -449,9 +537,14 @@
}
@Test
- fun prependWhile_withDrops() {
+ fun prependWhile_withDrops_loadDelay0() = prependWhile_withDrops(0)
+
+ @Test
+ fun prependWhile_withDrops_loadDelay10000() = prependWhile_withDrops(10000)
+
+ private fun prependWhile_withDrops(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPagerWithDrops(dataFlow, 20)
+ val pager = createPagerWithDrops(dataFlow, loadDelay, 20)
testScope.runTest {
val snapshot = pager.asSnapshot {
prependScrollWhile { item: Int ->
@@ -466,9 +559,14 @@
}
@Test
- fun prependWhile_withSeparators() {
+ fun prependWhile_withSeparators_loadDelay0() = prependWhile_withSeparators(0)
+
+ @Test
+ fun prependWhile_withSeparators_loadDelay10000() = prependWhile_withSeparators(10000)
+
+ private fun prependWhile_withSeparators(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow, 20).map { pagingData ->
+ val pager = createPager(dataFlow, loadDelay, 20).map { pagingData ->
pagingData.insertSeparators { before: Int?, _ ->
if (before == 14 || before == 18) "sep" else null
}
@@ -493,9 +591,14 @@
}
@Test
- fun prependWhile_withoutPrefetch() {
+ fun prependWhile_withoutPrefetch_loadDelay0() = prependWhile_withoutPrefetch(0)
+
+ @Test
+ fun prependWhile_withoutPrefetch_loadDelay10000() = prependWhile_withoutPrefetch(10000)
+
+ private fun prependWhile_withoutPrefetch(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPagerNoPrefetch(dataFlow, 20)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay, 20)
testScope.runTest {
val snapshot = pager.asSnapshot {
prependScrollWhile { item: Int ->
@@ -511,9 +614,14 @@
}
@Test
- fun prependWhile_withoutPlaceholders() {
+ fun prependWhile_withoutPlaceholders_loadDelay0() = prependWhile_withoutPlaceholders(0)
+
+ @Test
+ fun prependWhile_withoutPlaceholders_loadDelay10000() = prependWhile_withoutPlaceholders(10000)
+
+ private fun prependWhile_withoutPlaceholders(loadDelay: Long) {
val dataFlow = flowOf(List(50) { it })
- val pager = createPagerNoPlaceholders(dataFlow, 30)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay, 30)
testScope.runTest {
val snapshot = pager.asSnapshot {
prependScrollWhile { item: Int ->
@@ -533,9 +641,14 @@
}
@Test
- fun appendWhile_withInitialKey() {
+ fun appendWhile_withInitialKey_loadDelay0() = appendWhile_withInitialKey(0)
+
+ @Test
+ fun appendWhile_withInitialKey_loadDelay10000() = appendWhile_withInitialKey(10000)
+
+ private fun appendWhile_withInitialKey(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow, 10)
+ val pager = createPager(dataFlow, loadDelay, 10)
testScope.runTest {
val snapshot = pager.asSnapshot {
appendScrollWhile { item: Int ->
@@ -553,9 +666,16 @@
}
@Test
- fun appendWhile_withInitialKey_withoutPlaceholders() {
+ fun appendWhile_withInitialKey_withoutPlaceholders_loadDelay0() =
+ appendWhile_withInitialKey_withoutPlaceholders(0)
+
+ @Test
+ fun appendWhile_withInitialKey_withoutPlaceholders_loadDelay10000() =
+ appendWhile_withInitialKey_withoutPlaceholders(10000)
+
+ private fun appendWhile_withInitialKey_withoutPlaceholders(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPagerNoPlaceholders(dataFlow, 10)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay, 10)
testScope.runTest {
val snapshot = pager.asSnapshot {
appendScrollWhile { item: Int ->
@@ -573,9 +693,16 @@
}
@Test
- fun appendWhile_withInitialKey_withoutPrefetch() {
+ fun appendWhile_withInitialKey_withoutPrefetch_loadDelay0() =
+ appendWhile_withInitialKey_withoutPrefetch(0)
+
+ @Test
+ fun appendWhile_withInitialKey_withoutPrefetch_loadDelay10000() =
+ appendWhile_withInitialKey_withoutPrefetch(10000)
+
+ private fun appendWhile_withInitialKey_withoutPrefetch(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPagerNoPrefetch(dataFlow, 10)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay, 10)
testScope.runTest {
val snapshot = pager.asSnapshot {
appendScrollWhile { item: Int ->
@@ -591,9 +718,14 @@
}
@Test
- fun prependWhile_withoutInitialKey() {
+ fun prependWhile_withoutInitialKey_loadDelay0() = prependWhile_withoutInitialKey(0)
+
+ @Test
+ fun prependWhile_withoutInitialKey_loadDelay10000() = prependWhile_withoutInitialKey(10000)
+
+ private fun prependWhile_withoutInitialKey(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
prependScrollWhile { item: Int ->
@@ -609,9 +741,14 @@
}
@Test
- fun consecutiveAppendWhile() {
+ fun consecutiveAppendWhile_loadDelay0() = consecutiveAppendWhile(0)
+
+ @Test
+ fun consecutiveAppendWhile_loadDelay10000() = consecutiveAppendWhile(10000)
+
+ private fun consecutiveAppendWhile(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPager(dataFlow, loadDelay).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot1 = pager.asSnapshot {
appendScrollWhile { item: Int ->
@@ -638,9 +775,15 @@
}
@Test
- fun consecutivePrependWhile() {
+ fun consecutivePrependWhile_loadDelay0() = consecutivePrependWhile(0)
+
+ @Test
+ fun consecutivePrependWhile_loadDelay10000() = consecutivePrependWhile(10000)
+
+ private fun consecutivePrependWhile(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPagerNoPrefetch(dataFlow, 20).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay, 20)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot1 = pager.asSnapshot {
prependScrollWhile { item: Int ->
@@ -662,9 +805,16 @@
}
@Test
- fun appendWhile_outOfBounds_returnsCurrentlyLoadedItems() {
+ fun appendWhile_outOfBounds_returnsCurrentlyLoadedItems_loadDelay0() =
+ appendWhile_outOfBounds_returnsCurrentlyLoadedItems(0)
+
+ @Test
+ fun appendWhile_outOfBounds_returnsCurrentlyLoadedItems_loadDelay10000() =
+ appendWhile_outOfBounds_returnsCurrentlyLoadedItems(10000)
+
+ private fun appendWhile_outOfBounds_returnsCurrentlyLoadedItems(loadDelay: Long) {
val dataFlow = flowOf(List(10) { it })
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
appendScrollWhile { item: Int ->
@@ -681,9 +831,16 @@
}
@Test
- fun prependWhile_outOfBounds_returnsCurrentlyLoadedItems() {
+ fun prependWhile_outOfBounds_returnsCurrentlyLoadedItems_loadDelay0() =
+ prependWhile_outOfBounds_returnsCurrentlyLoadedItems(0)
+
+ @Test
+ fun prependWhile_outOfBounds_returnsCurrentlyLoadedItems_loadDelay10000() =
+ prependWhile_outOfBounds_returnsCurrentlyLoadedItems(10000)
+
+ private fun prependWhile_outOfBounds_returnsCurrentlyLoadedItems(loadDelay: Long) {
val dataFlow = flowOf(List(20) { it })
- val pager = createPager(dataFlow, 10)
+ val pager = createPager(dataFlow, loadDelay, 10)
testScope.runTest {
val snapshot = pager.asSnapshot {
prependScrollWhile { item: Int ->
@@ -702,9 +859,14 @@
}
@Test
- fun refreshAndAppendWhile() {
+ fun refreshAndAppendWhile_loadDelay0() = refreshAndAppendWhile(0)
+
+ @Test
+ fun refreshAndAppendWhile_loadDelay10000() = refreshAndAppendWhile(10000)
+
+ private fun refreshAndAppendWhile(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPager(dataFlow, loadDelay).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
refresh() // triggers second gen
@@ -719,9 +881,14 @@
}
@Test
- fun refreshAndPrependWhile() {
+ fun refreshAndPrependWhile_loadDelay0() = refreshAndPrependWhile(0)
+
+ @Test
+ fun refreshAndPrependWhile_loadDelay10000() = refreshAndPrependWhile(10000)
+
+ private fun refreshAndPrependWhile(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow, 20).cachedIn(testScope.backgroundScope)
+ val pager = createPager(dataFlow, loadDelay, 20).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// this prependScrollWhile does not cause paging to load more items
@@ -746,9 +913,14 @@
}
@Test
- fun appendWhileAndRefresh() {
+ fun appendWhileAndRefresh_loadDelay0() = appendWhileAndRefresh(0)
+
+ @Test
+ fun appendWhileAndRefresh_loadDelay10000() = appendWhileAndRefresh(10000)
+
+ private fun appendWhileAndRefresh(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPager(dataFlow, loadDelay).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
appendScrollWhile { item: Int ->
@@ -766,9 +938,14 @@
}
@Test
- fun prependWhileAndRefresh() {
+ fun prependWhileAndRefresh_loadDelay0() = prependWhileAndRefresh(0)
+
+ @Test
+ fun prependWhileAndRefresh_loadDelay10000() = prependWhileAndRefresh(10000)
+
+ private fun prependWhileAndRefresh(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val pager = createPager(dataFlow, 15).cachedIn(testScope.backgroundScope)
+ val pager = createPager(dataFlow, loadDelay, 15).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
prependScrollWhile { item: Int ->
@@ -786,19 +963,23 @@
}
@Test
- fun consecutiveGenerations_fromFlow() {
- val loadDelay = 500 + loadDelay
+ fun consecutiveGenerations_fromFlow_loadDelay0() = consecutiveGenerations_fromFlow(0)
+
+ @Test
+ fun consecutiveGenerations_fromFlow_loadDelay10000() = consecutiveGenerations_fromFlow(10000)
+
+ private fun consecutiveGenerations_fromFlow(loadDelay: Long) {
// wait for 500 + loadDelay between each emission
val dataFlow = flow {
emit(emptyList())
- delay(loadDelay)
+ delay(500 + loadDelay)
emit(List(30) { it })
- delay(loadDelay)
+ delay(500 + loadDelay)
emit(List(30) { it + 30 })
}
- val pager = createPagerNoPrefetch(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot1 = pager.asSnapshot()
assertThat(snapshot1).containsExactlyElementsIn(
@@ -822,15 +1003,21 @@
}
@Test
- fun consecutiveGenerations_PagingDataFrom_withoutLoadStates() {
- val loadDelay = 500 + loadDelay
+ fun consecutiveGenerations_PagingDataFrom_withoutLoadStates_loadDelay0() =
+ consecutiveGenerations_PagingDataFrom_withoutLoadStates(0)
+
+ @Test
+ fun consecutiveGenerations_PagingDataFrom_withoutLoadStates_loadDelay10000() =
+ consecutiveGenerations_PagingDataFrom_withoutLoadStates(10000)
+
+ private fun consecutiveGenerations_PagingDataFrom_withoutLoadStates(loadDelay: Long) {
// wait for 500 + loadDelay between each emission
val pager = flow {
emit(PagingData.empty())
- delay(loadDelay)
+ delay(500 + loadDelay)
emit(PagingData.from(List(10) { it }))
- delay(loadDelay)
+ delay(500 + loadDelay)
emit(PagingData.from(List(10) { it + 30 }))
}
@@ -844,8 +1031,14 @@
}
@Test
- fun consecutiveGenerations_PagingDataFrom_withLoadStates() {
- val loadDelay = 500 + loadDelay
+ fun consecutiveGenerations_PagingDataFrom_withLoadStates_loadDelay0() =
+ consecutiveGenerations_PagingDataFrom_withLoadStates(0)
+
+ @Test
+ fun consecutiveGenerations_PagingDataFrom_withLoadStates_loadDelay10000() =
+ consecutiveGenerations_PagingDataFrom_withLoadStates(10000)
+
+ private fun consecutiveGenerations_PagingDataFrom_withLoadStates(loadDelay: Long) {
// wait for 500 + loadDelay between each emission
val pager = flow {
emit(PagingData.empty(LoadStates(
@@ -853,14 +1046,14 @@
prepend = LoadState.NotLoading(true),
append = LoadState.NotLoading(true)
)))
- delay(loadDelay)
+ delay(500 + loadDelay)
emit(PagingData.from(List(10) { it }, LoadStates(
refresh = LoadState.NotLoading(true),
prepend = LoadState.NotLoading(true),
append = LoadState.NotLoading(true)
)))
- delay(loadDelay)
+ delay(500 + loadDelay)
emit(PagingData.from(List(10) { it + 30 }, LoadStates(
refresh = LoadState.NotLoading(true),
@@ -874,14 +1067,14 @@
emptyList<Int>()
)
- delay(loadDelay)
+ delay(500 + loadDelay)
val snapshot2 = pager.asSnapshot()
assertThat(snapshot2).containsExactlyElementsIn(
listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
)
- delay(loadDelay)
+ delay(500 + loadDelay)
val snapshot3 = pager.asSnapshot()
assertThat(snapshot3).containsExactlyElementsIn(
@@ -891,9 +1084,16 @@
}
@Test
- fun consecutiveGenerations_fromSharedFlow_emitAfterRefresh() {
+ fun consecutiveGenerations_fromSharedFlow_emitAfterRefresh_loadDelay0() =
+ consecutiveGenerations_fromSharedFlow_emitAfterRefresh(0)
+
+ @Test
+ fun consecutiveGenerations_fromSharedFlow_emitAfterRefresh_loadDelay10000() =
+ consecutiveGenerations_fromSharedFlow_emitAfterRefresh(10000)
+
+ private fun consecutiveGenerations_fromSharedFlow_emitAfterRefresh(loadDelay: Long) {
val dataFlow = MutableSharedFlow<List<Int>>()
- val pager = createPagerNoPrefetch(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot1 = pager.asSnapshot()
assertThat(snapshot1).containsExactlyElementsIn(
@@ -917,9 +1117,16 @@
}
@Test
- fun consecutiveGenerations_fromSharedFlow_emitBeforeRefresh() {
+ fun consecutiveGenerations_fromSharedFlow_emitBeforeRefresh_loadDelay0() =
+ consecutiveGenerations_fromSharedFlow_emitBeforeRefresh(0)
+
+ @Test
+ fun consecutiveGenerations_fromSharedFlow_emitBeforeRefresh_loadDelay10000() =
+ consecutiveGenerations_fromSharedFlow_emitBeforeRefresh(10000)
+
+ private fun consecutiveGenerations_fromSharedFlow_emitBeforeRefresh(loadDelay: Long) {
val dataFlow = MutableSharedFlow<List<Int>>()
- val pager = createPagerNoPrefetch(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay).cachedIn(testScope.backgroundScope)
testScope.runTest {
dataFlow.emit(emptyList())
val snapshot1 = pager.asSnapshot()
@@ -942,17 +1149,23 @@
}
@Test
- fun consecutiveGenerations_nonNullRefreshKey() {
- val loadDelay = 500 + loadDelay
+ fun consecutiveGenerations_nonNullRefreshKey_loadDelay0() =
+ consecutiveGenerations_nonNullRefreshKey(0)
+
+ @Test
+ fun consecutiveGenerations_nonNullRefreshKey_loadDelay10000() =
+ consecutiveGenerations_nonNullRefreshKey(10000)
+
+ private fun consecutiveGenerations_nonNullRefreshKey(loadDelay: Long) {
val dataFlow = flow {
// first gen
emit(List(20) { it })
// wait for refresh + append
- delay(loadDelay * 2)
+ delay((500 + loadDelay) * 2)
// second gen
emit(List(20) { it })
}
- val pager = createPagerNoPrefetch(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot1 = pager.asSnapshot {
// we scroll to register a non-null anchorPos
@@ -974,17 +1187,24 @@
}
@Test
- fun consecutiveGenerations_withInitialKey_nullRefreshKey() {
- val loadDelay = 500 + loadDelay
+ fun consecutiveGenerations_withInitialKey_nullRefreshKey_loadDelay0() =
+ consecutiveGenerations_withInitialKey_nullRefreshKey(0)
+
+ @Test
+ fun consecutiveGenerations_withInitialKey_nullRefreshKey_loadDelay10000() =
+ consecutiveGenerations_withInitialKey_nullRefreshKey(10000)
+
+ private fun consecutiveGenerations_withInitialKey_nullRefreshKey(loadDelay: Long) {
// wait for 500 + loadDelay between each emission
val dataFlow = flow {
// first gen
emit(List(20) { it })
- delay(loadDelay)
+ delay(500 + loadDelay)
// second gen
emit(List(20) { it })
}
- val pager = createPagerNoPrefetch(dataFlow, 10).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay, 10)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot1 = pager.asSnapshot()
assertThat(snapshot1).containsExactlyElementsIn(
@@ -1000,17 +1220,24 @@
}
@Test
- fun consecutiveGenerations_withInitialKey_nonNullRefreshKey() {
- val loadDelay = 500 + loadDelay
+ fun consecutiveGenerations_withInitialKey_nonNullRefreshKey_loadDelay0() =
+ consecutiveGenerations_withInitialKey_nonNullRefreshKey(0)
+
+ @Test
+ fun consecutiveGenerations_withInitialKey_nonNullRefreshKey_loadDelay10000() =
+ consecutiveGenerations_withInitialKey_nonNullRefreshKey(10000)
+
+ private fun consecutiveGenerations_withInitialKey_nonNullRefreshKey(loadDelay: Long) {
val dataFlow = flow {
// first gen
emit(List(20) { it })
// wait for refresh + append
- delay(loadDelay * 2)
+ delay((500 + loadDelay) * 2)
// second gen
emit(List(20) { it })
}
- val pager = createPagerNoPrefetch(dataFlow, 10).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay, 10)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot1 = pager.asSnapshot {
// we scroll to register a non-null anchorPos
@@ -1032,9 +1259,14 @@
}
@Test
- fun prependScroll() {
+ fun prependScroll_loadDelay0() = prependScroll(0)
+
+ @Test
+ fun prependScroll_loadDelay10000() = prependScroll(10000)
+
+ private fun prependScroll(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow, 50)
+ val pager = createPager(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(42)
@@ -1052,9 +1284,14 @@
}
@Test
- fun prependScroll_withDrops() {
+ fun prependScroll_withDrops_loadDelay0() = prependScroll_withDrops(0)
+
+ @Test
+ fun prependScroll_withDrops_loadDelay10000() = prependScroll_withDrops(10000)
+
+ private fun prependScroll_withDrops(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerWithDrops(dataFlow, 50)
+ val pager = createPagerWithDrops(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(42)
@@ -1067,9 +1304,14 @@
}
@Test
- fun prependScroll_withSeparators() {
+ fun prependScroll_withSeparators_loadDelay0() = prependScroll_withSeparators(0)
+
+ @Test
+ fun prependScroll_withSeparators_loadDelay10000() = prependScroll_withSeparators(10000)
+
+ private fun prependScroll_withSeparators(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow, 50).map { pagingData ->
+ val pager = createPager(dataFlow, loadDelay, 50).map { pagingData ->
pagingData.insertSeparators { before: Int?, _ ->
if (before == 42 || before == 49) "sep" else null
}
@@ -1092,9 +1334,14 @@
}
@Test
- fun consecutivePrependScroll() {
+ fun consecutivePrependScroll_loadDelay0() = consecutivePrependScroll(0)
+
+ @Test
+ fun consecutivePrependScroll_loadDelay10000() = consecutivePrependScroll(10000)
+
+ private fun consecutivePrependScroll(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow, 50)
+ val pager = createPager(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(42)
@@ -1114,9 +1361,16 @@
}
@Test
- fun consecutivePrependScroll_multiSnapshots() {
+ fun consecutivePrependScroll_multiSnapshots_loadDelay0() =
+ consecutivePrependScroll_multiSnapshots(0)
+
+ @Test
+ fun consecutivePrependScroll_multiSnapshots_loadDelay10000() =
+ consecutivePrependScroll_multiSnapshots(10000)
+
+ private fun consecutivePrependScroll_multiSnapshots(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow, 50)
+ val pager = createPager(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(42)
@@ -1145,9 +1399,14 @@
}
@Test
- fun prependScroll_indexOutOfBounds() {
+ fun prependScroll_indexOutOfBounds_loadDelay0() = prependScroll_indexOutOfBounds(0)
+
+ @Test
+ fun prependScroll_indexOutOfBounds_loadDelay10000() = prependScroll_indexOutOfBounds(10000)
+
+ private fun prependScroll_indexOutOfBounds(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow, 5).cachedIn(testScope.backgroundScope)
+ val pager = createPager(dataFlow, loadDelay, 5).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(-5)
@@ -1163,9 +1422,14 @@
}
@Test
- fun prependScroll_accessPageBoundary() {
+ fun prependScroll_accessPageBoundary_loadDelay0() = prependScroll_accessPageBoundary(0)
+
+ @Test
+ fun prependScroll_accessPageBoundary_loadDelay10000() = prependScroll_accessPageBoundary(10000)
+
+ private fun prependScroll_accessPageBoundary(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow, 50).cachedIn(testScope.backgroundScope)
+ val pager = createPager(dataFlow, loadDelay, 50).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(47)
@@ -1181,9 +1445,14 @@
}
@Test
- fun prependScroll_withoutPrefetch() {
+ fun prependScroll_withoutPrefetch_loadDelay0() = prependScroll_withoutPrefetch(0)
+
+ @Test
+ fun prependScroll_withoutPrefetch_loadDelay10000() = prependScroll_withoutPrefetch(10000)
+
+ private fun prependScroll_withoutPrefetch(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPrefetch(dataFlow, 50)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(42)
@@ -1197,9 +1466,16 @@
}
@Test
- fun prependScroll_withoutPlaceholders() {
+ fun prependScroll_withoutPlaceholders_loadDelay0() = prependScroll_withoutPlaceholders(0)
+
+ @Test
+ fun prependScroll_withoutPlaceholders_loadDelay10000() =
+ prependScroll_withoutPlaceholders(10000)
+
+ private fun prependScroll_withoutPlaceholders(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow, 50).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay, 50)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// Without placeholders, first loaded page always starts at index[0]
@@ -1215,9 +1491,17 @@
}
@Test
- fun prependScroll_withoutPlaceholders_indexOutOfBounds() {
+ fun prependScroll_withoutPlaceholders_indexOutOfBounds_loadDelay0() =
+ prependScroll_withoutPlaceholders_indexOutOfBounds(0)
+
+ @Test
+ fun prependScroll_withoutPlaceholders_indexOutOfBounds_loadDelay10000() =
+ prependScroll_withoutPlaceholders_indexOutOfBounds(10000)
+
+ private fun prependScroll_withoutPlaceholders_indexOutOfBounds(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow, 50).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay, 50)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(-5)
@@ -1236,9 +1520,17 @@
}
@Test
- fun prependScroll_withoutPlaceholders_indexOutOfBoundsIsCapped() {
+ fun prependScroll_withoutPlaceholders_indexOutOfBoundsIsCapped_loadDelay0() =
+ prependScroll_withoutPlaceholders_indexOutOfBoundsIsCapped(0)
+
+ @Test
+ fun prependScroll_withoutPlaceholders_indexOutOfBoundsIsCapped_loadDelay10000() =
+ prependScroll_withoutPlaceholders_indexOutOfBoundsIsCapped(10000)
+
+ private fun prependScroll_withoutPlaceholders_indexOutOfBoundsIsCapped(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow, 5).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay, 5)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(-5)
@@ -1254,9 +1546,17 @@
}
@Test
- fun consecutivePrependScroll_withoutPlaceholders() {
+ fun consecutivePrependScroll_withoutPlaceholders_loadDelay0() =
+ consecutivePrependScroll_withoutPlaceholders(0)
+
+ @Test
+ fun consecutivePrependScroll_withoutPlaceholders_loadDelay10000() =
+ consecutivePrependScroll_withoutPlaceholders(10000)
+
+ private fun consecutivePrependScroll_withoutPlaceholders(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow, 50).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay, 50)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// Without placeholders, first loaded page always starts at index[0]
@@ -1280,9 +1580,17 @@
}
@Test
- fun consecutivePrependScroll_withoutPlaceholders_multiSnapshot() {
+ fun consecutivePrependScroll_withoutPlaceholders_multiSnapshot_loadDelay0() =
+ consecutivePrependScroll_withoutPlaceholders_multiSnapshot(0)
+
+ @Test
+ fun consecutivePrependScroll_withoutPlaceholders_multiSnapshot_loadDelay10000() =
+ consecutivePrependScroll_withoutPlaceholders_multiSnapshot(10000)
+
+ private fun consecutivePrependScroll_withoutPlaceholders_multiSnapshot(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow, 50).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay, 50)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// Without placeholders, first loaded page always starts at index[0]
@@ -1312,7 +1620,14 @@
}
@Test
- fun prependScroll_withoutPlaceholders_noPrefetchTriggered() {
+ fun prependScroll_withoutPlaceholders_noPrefetchTriggered_loadDelay0() =
+ prependScroll_withoutPlaceholders_noPrefetchTriggered(0)
+
+ @Test
+ fun prependScroll_withoutPlaceholders_noPrefetchTriggered_loadDelay10000() =
+ prependScroll_withoutPlaceholders_noPrefetchTriggered(10000)
+
+ private fun prependScroll_withoutPlaceholders_noPrefetchTriggered(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
val pager = Pager(
config = PagingConfig(
@@ -1323,7 +1638,7 @@
prefetchDistance = 1
),
initialKey = 50,
- pagingSourceFactory = createFactory(dataFlow),
+ pagingSourceFactory = createFactory(dataFlow, loadDelay),
).flow.cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
@@ -1340,9 +1655,14 @@
}
@Test
- fun appendScroll() {
+ fun appendScroll_loadDelay0() = appendScroll(0)
+
+ @Test
+ fun appendScroll_loadDelay10000() = appendScroll(10000)
+
+ private fun appendScroll(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(12)
@@ -1358,9 +1678,14 @@
}
@Test
- fun appendScroll_withDrops() {
+ fun appendScroll_withDrops_loadDelay0() = appendScroll_withDrops(0)
+
+ @Test
+ fun appendScroll_withDrops_loadDelay10000() = appendScroll_withDrops(10000)
+
+ private fun appendScroll_withDrops(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerWithDrops(dataFlow)
+ val pager = createPagerWithDrops(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(12)
@@ -1373,9 +1698,14 @@
}
@Test
- fun appendScroll_withSeparators() {
+ fun appendScroll_withSeparators_loadDelay0() = appendScroll_withSeparators(0)
+
+ @Test
+ fun appendScroll_withSeparators_loadDelay10000() = appendScroll_withSeparators(10000)
+
+ private fun appendScroll_withSeparators(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow).map { pagingData ->
+ val pager = createPager(dataFlow, loadDelay).map { pagingData ->
pagingData.insertSeparators { before: Int?, _ ->
if (before == 0 || before == 14) "sep" else null
}
@@ -1394,10 +1724,15 @@
}
}
+ @Test
+ fun consecutiveAppendScroll_loadDelay0() = consecutiveAppendScroll(0)
+
@Test
- fun consecutiveAppendScroll() {
+ fun consecutiveAppendScroll_loadDelay10000() = consecutiveAppendScroll(10000)
+
+ private fun consecutiveAppendScroll(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(12)
@@ -1414,10 +1749,17 @@
}
}
+ @Test
+ fun consecutiveAppendScroll_multiSnapshots_loadDelay0() =
+ consecutiveAppendScroll_multiSnapshots(0)
+
@Test
- fun consecutiveAppendScroll_multiSnapshots() {
+ fun consecutiveAppendScroll_multiSnapshots_loadDelay10000() =
+ consecutiveAppendScroll_multiSnapshots(10000)
+
+ private fun consecutiveAppendScroll_multiSnapshots(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(12)
@@ -1444,9 +1786,14 @@
}
@Test
- fun appendScroll_indexOutOfBounds() {
+ fun appendScroll_indexOutOfBounds_loadDelay0() = appendScroll_indexOutOfBounds(0)
+
+ @Test
+ fun appendScroll_indexOutOfBounds_loadDelay10000() = appendScroll_indexOutOfBounds(10000)
+
+ private fun appendScroll_indexOutOfBounds(loadDelay: Long) {
val dataFlow = flowOf(List(15) { it })
- val pager = createPager(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPager(dataFlow, loadDelay).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// index out of bounds
@@ -1462,9 +1809,14 @@
}
@Test
- fun appendScroll_accessPageBoundary() {
+ fun appendScroll_accessPageBoundary_loadDelay0() = appendScroll_accessPageBoundary(0)
+
+ @Test
+ fun appendScroll_accessPageBoundary_loadDelay10000() = appendScroll_accessPageBoundary(10000)
+
+ private fun appendScroll_accessPageBoundary(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPager(dataFlow, loadDelay).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// after initial Load and prefetch, max loaded index is 7
@@ -1481,9 +1833,14 @@
}
@Test
- fun appendScroll_withoutPrefetch() {
+ fun appendScroll_withoutPrefetch_loadDelay0() = appendScroll_withoutPrefetch(0)
+
+ @Test
+ fun appendScroll_withoutPrefetch_loadDelay10000() = appendScroll_withoutPrefetch(10000)
+
+ private fun appendScroll_withoutPrefetch(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPrefetch(dataFlow)
+ val pager = createPagerNoPrefetch(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(10)
@@ -1497,9 +1854,15 @@
}
@Test
- fun appendScroll_withoutPlaceholders() {
+ fun appendScroll_withoutPlaceholders_loadDelay0() = appendScroll_withoutPlaceholders(0)
+
+ @Test
+ fun appendScroll_withoutPlaceholders_loadDelay10000() = appendScroll_withoutPlaceholders(10000)
+
+ private fun appendScroll_withoutPlaceholders(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// scroll to max loaded index
@@ -1515,9 +1878,17 @@
}
@Test
- fun appendScroll_withoutPlaceholders_indexOutOfBounds() {
+ fun appendScroll_withoutPlaceholders_indexOutOfBounds_loadDelay0() =
+ appendScroll_withoutPlaceholders_indexOutOfBounds(0)
+
+ @Test
+ fun appendScroll_withoutPlaceholders_indexOutOfBounds_loadDelay10000() =
+ appendScroll_withoutPlaceholders_indexOutOfBounds(10000)
+
+ private fun appendScroll_withoutPlaceholders_indexOutOfBounds(loadDelay: Long) {
val dataFlow = flowOf(List(20) { it })
- val pager = createPagerNoPlaceholders(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// 12 is larger than differ.size = 8 after initial refresh
@@ -1535,9 +1906,17 @@
}
@Test
- fun appendToScroll_withoutPlaceholders_indexOutOfBoundsIsCapped() {
+ fun appendToScroll_withoutPlaceholders_indexOutOfBoundsIsCapped_loadDelay0() =
+ appendToScroll_withoutPlaceholders_indexOutOfBoundsIsCapped(0)
+
+ @Test
+ fun appendToScroll_withoutPlaceholders_indexOutOfBoundsIsCapped_loadDelay10000() =
+ appendToScroll_withoutPlaceholders_indexOutOfBoundsIsCapped(10000)
+
+ private fun appendToScroll_withoutPlaceholders_indexOutOfBoundsIsCapped(loadDelay: Long) {
val dataFlow = flowOf(List(20) { it })
- val pager = createPagerNoPlaceholders(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(50)
@@ -1553,9 +1932,17 @@
}
@Test
- fun consecutiveAppendScroll_withoutPlaceholders() {
+ fun consecutiveAppendScroll_withoutPlaceholders_loadDelay0() =
+ consecutiveAppendScroll_withoutPlaceholders(0)
+
+ @Test
+ fun consecutiveAppendScroll_withoutPlaceholders_loadDelay10000() =
+ consecutiveAppendScroll_withoutPlaceholders(10000)
+
+ private fun consecutiveAppendScroll_withoutPlaceholders(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(12)
@@ -1574,9 +1961,17 @@
}
@Test
- fun consecutiveAppendScroll_withoutPlaceholders_multiSnapshot() {
+ fun consecutiveAppendScroll_withoutPlaceholders_multiSnapshot_loadDelay0() =
+ consecutiveAppendScroll_withoutPlaceholders_multiSnapshot(0)
+
+ @Test
+ fun consecutiveAppendScroll_withoutPlaceholders_multiSnapshot_loadDelay10000() =
+ consecutiveAppendScroll_withoutPlaceholders_multiSnapshot(10000)
+
+ private fun consecutiveAppendScroll_withoutPlaceholders_multiSnapshot(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(12)
@@ -1605,9 +2000,15 @@
}
@Test
- fun scrollTo_indexAccountsForSeparators() {
+ fun scrollTo_indexAccountsForSeparators_loadDelay0() = scrollTo_indexAccountsForSeparators(0)
+
+ @Test
+ fun scrollTo_indexAccountsForSeparators_loadDelay10000() =
+ scrollTo_indexAccountsForSeparators(10000)
+
+ private fun scrollTo_indexAccountsForSeparators(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
val pagerWithSeparator = pager.map { pagingData ->
pagingData.insertSeparators { before: Int?, _ ->
if (before == 6) "sep" else null
@@ -1639,9 +2040,14 @@
}
@Test
- fun prependFling() {
+ fun prependFling_loadDelay0() = prependFling(0)
+
+ @Test
+ fun prependFling_loadDelay10000() = prependFling(10000)
+
+ private fun prependFling(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow, 50)
+ val pager = createPager(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(42)
@@ -1659,9 +2065,14 @@
}
@Test
- fun prependFling_withDrops() {
+ fun prependFling_withDrops_loadDelay0() = prependFling_withDrops(0)
+
+ @Test
+ fun prependFling_withDrops_loadDelay10000() = prependFling_withDrops(10000)
+
+ private fun prependFling_withDrops(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerWithDrops(dataFlow, 50)
+ val pager = createPagerWithDrops(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(42)
@@ -1674,9 +2085,14 @@
}
@Test
- fun prependFling_withSeparators() {
+ fun prependFling_withSeparators_loadDelay0() = prependFling_withSeparators(0)
+
+ @Test
+ fun prependFling_withSeparators_loadDelay10000() = prependFling_withSeparators(10000)
+
+ private fun prependFling_withSeparators(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow, 50).map { pagingData ->
+ val pager = createPager(dataFlow, loadDelay, 50).map { pagingData ->
pagingData.insertSeparators { before: Int?, _ ->
if (before == 42 || before == 49) "sep" else null
}
@@ -1699,9 +2115,14 @@
}
@Test
- fun consecutivePrependFling() {
+ fun consecutivePrependFling_loadDelay0() = consecutivePrependFling(0)
+
+ @Test
+ fun consecutivePrependFling_loadDelay10000() = consecutivePrependFling(10000)
+
+ private fun consecutivePrependFling(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow, 50)
+ val pager = createPager(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(42)
@@ -1721,9 +2142,16 @@
}
@Test
- fun consecutivePrependFling_multiSnapshots() {
+ fun consecutivePrependFling_multiSnapshots_loadDelay0() =
+ consecutivePrependFling_multiSnapshots(0)
+
+ @Test
+ fun consecutivePrependFling_multiSnapshots_loadDelay10000() =
+ consecutivePrependFling_multiSnapshots(10000)
+
+ private fun consecutivePrependFling_multiSnapshots(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow, 50)
+ val pager = createPager(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(42)
@@ -1750,10 +2178,16 @@
)
}
}
+
@Test
- fun prependFling_jump() {
+ fun prependFling_jump_loadDelay0() = prependFling_jump(0)
+
+ @Test
+ fun prependFling_jump_loadDelay10000() = prependFling_jump(10000)
+
+ private fun prependFling_jump(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerWithJump(dataFlow, 50)
+ val pager = createPagerWithJump(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(30)
@@ -1768,9 +2202,14 @@
}
@Test
- fun prependFling_scrollThenJump() {
+ fun prependFling_scrollThenJump_loadDelay0() = prependFling_scrollThenJump(0)
+
+ @Test
+ fun prependFling_scrollThenJump_loadDelay10000() = prependFling_scrollThenJump(10000)
+
+ private fun prependFling_scrollThenJump(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerWithJump(dataFlow, 50)
+ val pager = createPagerWithJump(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(43)
@@ -1786,9 +2225,14 @@
}
@Test
- fun prependFling_jumpThenFling() {
+ fun prependFling_jumpThenFling_loadDelay0() = prependFling_jumpThenFling(0)
+
+ @Test
+ fun prependFling_jumpThenFling_loadDelay10000() = prependFling_jumpThenFling(10000)
+
+ private fun prependFling_jumpThenFling(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerWithJump(dataFlow, 50)
+ val pager = createPagerWithJump(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(30)
@@ -1806,9 +2250,14 @@
}
@Test
- fun prependFling_indexOutOfBounds() {
+ fun prependFling_indexOutOfBounds_loadDelay0() = prependFling_indexOutOfBounds(0)
+
+ @Test
+ fun prependFling_indexOutOfBounds_loadDelay10000() = prependFling_indexOutOfBounds(10000)
+
+ private fun prependFling_indexOutOfBounds(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow, 10)
+ val pager = createPager(dataFlow, loadDelay, 10)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(-3)
@@ -1823,9 +2272,14 @@
}
@Test
- fun prependFling_accessPageBoundary() {
+ fun prependFling_accessPageBoundary_loadDelay0() = prependFling_accessPageBoundary(0)
+
+ @Test
+ fun prependFling_accessPageBoundary_loadDelay10000() = prependFling_accessPageBoundary(10000)
+
+ private fun prependFling_accessPageBoundary(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow, 50)
+ val pager = createPager(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
// page boundary
@@ -1843,9 +2297,15 @@
}
@Test
- fun prependFling_withoutPlaceholders() {
+ fun prependFling_withoutPlaceholders_loadDelay0() = prependFling_withoutPlaceholders(0)
+
+ @Test
+ fun prependFling_withoutPlaceholders_loadDelay10000() = prependFling_withoutPlaceholders(10000)
+
+ private fun prependFling_withoutPlaceholders(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow, 50).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay, 50)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// Without placeholders, first loaded page always starts at index[0]
@@ -1861,9 +2321,16 @@
}
@Test
- fun prependFling_withoutPlaceholders_indexOutOfBounds() {
+ fun prependFling_withoutPlaceholders_indexOutOfBounds_loadDelay0() =
+ prependFling_withoutPlaceholders_indexOutOfBounds(0)
+
+ @Test
+ fun prependFling_withoutPlaceholders_indexOutOfBounds_loadDelay10000() =
+ prependFling_withoutPlaceholders_indexOutOfBounds(10000)
+
+ private fun prependFling_withoutPlaceholders_indexOutOfBounds(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow, 50)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay, 50)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(-8)
@@ -1883,9 +2350,17 @@
}
@Test
- fun prependFling_withoutPlaceholders_indexOutOfBoundsIsCapped() {
+ fun prependFling_withoutPlaceholders_indexOutOfBoundsIsCapped_loadDelay0() =
+ prependFling_withoutPlaceholders_indexOutOfBoundsIsCapped(0)
+
+ @Test
+ fun prependFling_withoutPlaceholders_indexOutOfBoundsIsCapped_loadDelay10000() =
+ prependFling_withoutPlaceholders_indexOutOfBoundsIsCapped(10000)
+
+ private fun prependFling_withoutPlaceholders_indexOutOfBoundsIsCapped(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow, 5).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay, 5)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(-20)
@@ -1901,9 +2376,17 @@
}
@Test
- fun consecutivePrependFling_withoutPlaceholders() {
+ fun consecutivePrependFling_withoutPlaceholders_loadDelay0() =
+ consecutivePrependFling_withoutPlaceholders(0)
+
+ @Test
+ fun consecutivePrependFling_withoutPlaceholders_loadDelay10000() =
+ consecutivePrependFling_withoutPlaceholders(10000)
+
+ private fun consecutivePrependFling_withoutPlaceholders(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow, 50).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay, 50)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// Without placeholders, first loaded page always starts at index[0]
@@ -1927,9 +2410,17 @@
}
@Test
- fun consecutivePrependFling_withoutPlaceholders_multiSnapshot() {
+ fun consecutivePrependFling_withoutPlaceholders_multiSnapshot_loadDelay0() =
+ consecutivePrependFling_withoutPlaceholders_multiSnapshot(0)
+
+ @Test
+ fun consecutivePrependFling_withoutPlaceholders_multiSnapshot_loadDelay10000() =
+ consecutivePrependFling_withoutPlaceholders_multiSnapshot(10000)
+
+ private fun consecutivePrependFling_withoutPlaceholders_multiSnapshot(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow, 50).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay, 50)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// Without placeholders, first loaded page always starts at index[0]
@@ -1959,7 +2450,14 @@
}
@Test
- fun prependFling_withoutPlaceholders_indexPrecision() {
+ fun prependFling_withoutPlaceholders_indexPrecision_loadDelay0() =
+ prependFling_withoutPlaceholders_indexPrecision(0)
+
+ @Test
+ fun prependFling_withoutPlaceholders_indexPrecision_loadDelay10000() =
+ prependFling_withoutPlaceholders_indexPrecision(10000)
+
+ private fun prependFling_withoutPlaceholders_indexPrecision(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
// load sizes and prefetch set to 1 to test precision of flingTo indexing
val pager = Pager(
@@ -1970,7 +2468,7 @@
prefetchDistance = 1
),
initialKey = 50,
- pagingSourceFactory = createFactory(dataFlow),
+ pagingSourceFactory = createFactory(dataFlow, loadDelay),
)
testScope.runTest {
val snapshot = pager.flow.asSnapshot {
@@ -1988,9 +2486,14 @@
}
@Test
- fun appendFling() {
+ fun appendFling_loadDelay0() = appendFling(0)
+
+ @Test
+ fun appendFling_loadDelay10000() = appendFling(10000)
+
+ private fun appendFling(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(12)
@@ -2006,9 +2509,14 @@
}
@Test
- fun appendFling_withDrops() {
+ fun appendFling_withDrops_loadDelay0() = appendFling_withDrops(0)
+
+ @Test
+ fun appendFling_withDrops_loadDelay10000() = appendFling_withDrops(10000)
+
+ private fun appendFling_withDrops(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerWithDrops(dataFlow)
+ val pager = createPagerWithDrops(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(12)
@@ -2021,9 +2529,14 @@
}
@Test
- fun appendFling_withSeparators() {
+ fun appendFling_withSeparators_loadDelay0() = appendFling_withSeparators(0)
+
+ @Test
+ fun appendFling_withSeparators_loadDelay10000() = appendFling_withSeparators(10000)
+
+ private fun appendFling_withSeparators(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow).map { pagingData ->
+ val pager = createPager(dataFlow, loadDelay).map { pagingData ->
pagingData.insertSeparators { before: Int?, _ ->
if (before == 0 || before == 14) "sep" else null
}
@@ -2043,9 +2556,14 @@
}
@Test
- fun consecutiveAppendFling() {
+ fun consecutiveAppendFling_loadDelay0() = consecutiveAppendFling(0)
+
+ @Test
+ fun consecutiveAppendFling_loadDelay10000() = consecutiveAppendFling(10000)
+
+ private fun consecutiveAppendFling(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(12)
@@ -2063,9 +2581,16 @@
}
@Test
- fun consecutiveAppendFling_multiSnapshots() {
+ fun consecutiveAppendFling_multiSnapshots_loadDelay0() =
+ consecutiveAppendFling_multiSnapshots(0)
+
+ @Test
+ fun consecutiveAppendFling_multiSnapshots_loadDelay10000() =
+ consecutiveAppendFling_multiSnapshots(10000)
+
+ private fun consecutiveAppendFling_multiSnapshots(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow)
+ val pager = createPager(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(12)
@@ -2092,9 +2617,14 @@
}
@Test
- fun appendFling_jump() {
+ fun appendFling_jump_loadDelay0() = appendFling_jump(0)
+
+ @Test
+ fun appendFling_jump_loadDelay10000() = appendFling_jump(10000)
+
+ private fun appendFling_jump(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerWithJump(dataFlow)
+ val pager = createPagerWithJump(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(30)
@@ -2109,9 +2639,14 @@
}
@Test
- fun appendFling_scrollThenJump() {
+ fun appendFling_scrollThenJump_loadDelay0() = appendFling_scrollThenJump(0)
+
+ @Test
+ fun appendFling_scrollThenJump_loadDelay10000() = appendFling_scrollThenJump(10000)
+
+ private fun appendFling_scrollThenJump(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerWithJump(dataFlow)
+ val pager = createPagerWithJump(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
scrollTo(30)
@@ -2127,9 +2662,14 @@
}
@Test
- fun appendFling_jumpThenFling() {
+ fun appendFling_jumpThenFling_loadDelay0() = appendFling_jumpThenFling(0)
+
+ @Test
+ fun appendFling_jumpThenFling_loadDelay10000() = appendFling_jumpThenFling(10000)
+
+ private fun appendFling_jumpThenFling(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerWithJump(dataFlow)
+ val pager = createPagerWithJump(dataFlow, loadDelay)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(30)
@@ -2147,9 +2687,14 @@
}
@Test
- fun appendFling_indexOutOfBounds() {
+ fun appendFling_indexOutOfBounds_loadDelay0() = appendFling_indexOutOfBounds(0)
+
+ @Test
+ fun appendFling_indexOutOfBounds_loadDelay10000() = appendFling_indexOutOfBounds(10000)
+
+ private fun appendFling_indexOutOfBounds(loadDelay: Long) {
val dataFlow = flowOf(List(15) { it })
- val pager = createPager(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPager(dataFlow, loadDelay).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// index out of bounds
@@ -2165,9 +2710,14 @@
}
@Test
- fun appendFling_accessPageBoundary() {
+ fun appendFling_accessPageBoundary_loadDelay0() = appendFling_accessPageBoundary(0)
+
+ @Test
+ fun appendFling_accessPageBoundary_loadDelay10000() = appendFling_accessPageBoundary(10000)
+
+ private fun appendFling_accessPageBoundary(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPager(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPager(dataFlow, loadDelay).cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// after initial Load and prefetch, max loaded index is 7
@@ -2184,9 +2734,15 @@
}
@Test
- fun appendFling_withoutPlaceholders() {
+ fun appendFling_withoutPlaceholders_loadDelay0() = appendFling_withoutPlaceholders(0)
+
+ @Test
+ fun appendFling_withoutPlaceholders_loadDelay10000() = appendFling_withoutPlaceholders(10000)
+
+ private fun appendFling_withoutPlaceholders(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// scroll to max loaded index
@@ -2202,9 +2758,17 @@
}
@Test
- fun appendFling_withoutPlaceholders_indexOutOfBounds() {
+ fun appendFling_withoutPlaceholders_indexOutOfBounds_loadDelay0() =
+ appendFling_withoutPlaceholders_indexOutOfBounds(0)
+
+ @Test
+ fun appendFling_withoutPlaceholders_indexOutOfBounds_loadDelay10000() =
+ appendFling_withoutPlaceholders_indexOutOfBounds(10000)
+
+ private fun appendFling_withoutPlaceholders_indexOutOfBounds(loadDelay: Long) {
val dataFlow = flowOf(List(20) { it })
- val pager = createPagerNoPlaceholders(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
// 12 is larger than differ.size = 8 after initial refresh
@@ -2222,9 +2786,17 @@
}
@Test
- fun appendFling_withoutPlaceholders_indexOutOfBoundsIsCapped() {
+ fun appendFling_withoutPlaceholders_indexOutOfBoundsIsCapped_loadDelay0() =
+ appendFling_withoutPlaceholders_indexOutOfBoundsIsCapped(0)
+
+ @Test
+ fun appendFling_withoutPlaceholders_indexOutOfBoundsIsCapped_loadDelay10000() =
+ appendFling_withoutPlaceholders_indexOutOfBoundsIsCapped(10000)
+
+ private fun appendFling_withoutPlaceholders_indexOutOfBoundsIsCapped(loadDelay: Long) {
val dataFlow = flowOf(List(20) { it })
- val pager = createPagerNoPlaceholders(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(50)
@@ -2240,9 +2812,17 @@
}
@Test
- fun consecutiveAppendFling_withoutPlaceholders() {
+ fun consecutiveAppendFling_withoutPlaceholders_loadDelay0() =
+ consecutiveAppendFling_withoutPlaceholders(0)
+
+ @Test
+ fun consecutiveAppendFling_withoutPlaceholders_loadDelay10000() =
+ consecutiveAppendFling_withoutPlaceholders(10000)
+
+ private fun consecutiveAppendFling_withoutPlaceholders(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(12)
@@ -2261,9 +2841,17 @@
}
@Test
- fun consecutiveAppendFling_withoutPlaceholders_multiSnapshot() {
+ fun consecutiveAppendFling_withoutPlaceholders_multiSnapshot_loadDelay0() =
+ consecutiveAppendFling_withoutPlaceholders_multiSnapshot(0)
+
+ @Test
+ fun consecutiveAppendFling_withoutPlaceholders_multiSnapshot_loadDelay10000() =
+ consecutiveAppendFling_withoutPlaceholders_multiSnapshot(10000)
+
+ private fun consecutiveAppendFling_withoutPlaceholders_multiSnapshot(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
- val pager = createPagerNoPlaceholders(dataFlow).cachedIn(testScope.backgroundScope)
+ val pager = createPagerNoPlaceholders(dataFlow, loadDelay)
+ .cachedIn(testScope.backgroundScope)
testScope.runTest {
val snapshot = pager.asSnapshot {
flingTo(12)
@@ -2292,7 +2880,14 @@
}
@Test
- fun appendFling_withoutPlaceholders_indexPrecision() {
+ fun appendFling_withoutPlaceholders_indexPrecision_loadDelay0() =
+ appendFling_withoutPlaceholders_indexPrecision(0)
+
+ @Test
+ fun appendFling_withoutPlaceholders_indexPrecision_loadDelay10000() =
+ appendFling_withoutPlaceholders_indexPrecision(10000)
+
+ private fun appendFling_withoutPlaceholders_indexPrecision(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
// load sizes and prefetch set to 1 to test precision of flingTo indexing
val pager = Pager(
@@ -2302,7 +2897,7 @@
enablePlaceholders = false,
prefetchDistance = 1
),
- pagingSourceFactory = createFactory(dataFlow),
+ pagingSourceFactory = createFactory(dataFlow, loadDelay),
)
testScope.runTest {
val snapshot = pager.flow.asSnapshot {
@@ -2320,7 +2915,13 @@
}
@Test
- fun flingTo_indexAccountsForSeparators() {
+ fun flingTo_indexAccountsForSeparators_loadDelay0() = flingTo_indexAccountsForSeparators(0)
+
+ @Test
+ fun flingTo_indexAccountsForSeparators_loadDelay10000() =
+ flingTo_indexAccountsForSeparators(10000)
+
+ private fun flingTo_indexAccountsForSeparators(loadDelay: Long) {
val dataFlow = flowOf(List(100) { it })
val pager = createPager(
dataFlow,
@@ -2329,6 +2930,7 @@
initialLoadSize = 1,
prefetchDistance = 1
),
+ loadDelay,
50
)
val pagerWithSeparator = pager.map { pagingData ->
@@ -2360,9 +2962,14 @@
}
@Test
- fun errorHandler_throw() {
+ fun errorHandler_throw_loadDelay0() = errorHandler_throw(0)
+
+ @Test
+ fun errorHandler_throw_loadDelay10000() = errorHandler_throw(10000)
+
+ private fun errorHandler_throw(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val factory = createFactory(dataFlow)
+ val factory = createFactory(dataFlow, loadDelay)
val pagingSources = mutableListOf<TestPagingSource>()
val pager = Pager(
config = PagingConfig(pageSize = 3, initialLoadSize = 5),
@@ -2383,9 +2990,14 @@
}
@Test
- fun errorHandler_retry() {
+ fun errorHandler_retry_loadDelay0() = errorHandler_retry(0)
+
+ @Test
+ fun errorHandler_retry_loadDelay10000() = errorHandler_retry(10000)
+
+ private fun errorHandler_retry(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val factory = createFactory(dataFlow)
+ val factory = createFactory(dataFlow, loadDelay)
val pagingSources = mutableListOf<TestPagingSource>()
val pager = Pager(
config = PagingConfig(pageSize = 3, initialLoadSize = 5),
@@ -2422,9 +3034,14 @@
}
@Test
- fun errorHandler_retryFails() {
+ fun errorHandler_retryFails_loadDelay0() = errorHandler_retryFails(0)
+
+ @Test
+ fun errorHandler_retryFails_loadDelay10000() = errorHandler_retryFails(10000)
+
+ private fun errorHandler_retryFails(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val factory = createFactory(dataFlow)
+ val factory = createFactory(dataFlow, loadDelay)
val pagingSources = mutableListOf<TestPagingSource>()
val pager = Pager(
config = PagingConfig(pageSize = 3, initialLoadSize = 5),
@@ -2463,9 +3080,14 @@
}
@Test
- fun errorHandler_returnSnapshot() {
+ fun errorHandler_returnSnapshot_loadDelay0() = errorHandler_returnSnapshot(0)
+
+ @Test
+ fun errorHandler_returnSnapshot_loadDelay10000() = errorHandler_returnSnapshot(10000)
+
+ private fun errorHandler_returnSnapshot(loadDelay: Long) {
val dataFlow = flowOf(List(30) { it })
- val factory = createFactory(dataFlow)
+ val factory = createFactory(dataFlow, loadDelay)
val pagingSources = mutableListOf<TestPagingSource>()
val pager = Pager(
config = PagingConfig(pageSize = 3, initialLoadSize = 5),
@@ -2486,21 +3108,26 @@
}
}
- private fun createPager(dataFlow: Flow<List<Int>>, initialKey: Int = 0) =
+ private fun createPager(dataFlow: Flow<List<Int>>, loadDelay: Long, initialKey: Int = 0) =
createPager(
dataFlow,
PagingConfig(pageSize = 3, initialLoadSize = 5),
+ loadDelay,
initialKey
)
- private fun createPager(data: List<Int>, initialKey: Int = 0) =
+ private fun createPager(data: List<Int>, loadDelay: Long, initialKey: Int = 0) =
Pager(
PagingConfig(pageSize = 3, initialLoadSize = 5),
initialKey,
- createSingleGenFactory(data),
+ createSingleGenFactory(data, loadDelay),
).flow
- private fun createPagerNoPlaceholders(dataFlow: Flow<List<Int>>, initialKey: Int = 0) =
+ private fun createPagerNoPlaceholders(
+ dataFlow: Flow<List<Int>>,
+ loadDelay: Long,
+ initialKey: Int = 0
+ ) =
createPager(
dataFlow,
PagingConfig(
@@ -2509,37 +3136,54 @@
enablePlaceholders = false,
prefetchDistance = 3
),
+ loadDelay,
initialKey)
- private fun createPagerNoPrefetch(dataFlow: Flow<List<Int>>, initialKey: Int = 0) =
+ private fun createPagerNoPrefetch(
+ dataFlow: Flow<List<Int>>,
+ loadDelay: Long,
+ initialKey: Int = 0
+ ) =
createPager(
dataFlow,
PagingConfig(pageSize = 3, initialLoadSize = 5, prefetchDistance = 0),
+ loadDelay,
initialKey
)
- private fun createPagerWithJump(dataFlow: Flow<List<Int>>, initialKey: Int = 0) =
+ private fun createPagerWithJump(
+ dataFlow: Flow<List<Int>>,
+ loadDelay: Long,
+ initialKey: Int = 0
+ ) =
createPager(
dataFlow,
PagingConfig(pageSize = 3, initialLoadSize = 5, jumpThreshold = 5),
+ loadDelay,
initialKey
)
- private fun createPagerWithDrops(dataFlow: Flow<List<Int>>, initialKey: Int = 0) =
+ private fun createPagerWithDrops(
+ dataFlow: Flow<List<Int>>,
+ loadDelay: Long,
+ initialKey: Int = 0
+ ) =
createPager(
dataFlow,
PagingConfig(pageSize = 3, initialLoadSize = 5, maxSize = 9),
+ loadDelay,
initialKey
)
private fun createPager(
dataFlow: Flow<List<Int>>,
config: PagingConfig,
+ loadDelay: Long,
initialKey: Int = 0,
) = Pager(
config = config,
initialKey = initialKey,
- pagingSourceFactory = createFactory(dataFlow),
+ pagingSourceFactory = createFactory(dataFlow, loadDelay),
).flow
}
diff --git a/paging/paging-testing/src/androidUnitTest/kotlin/androidx/paging/testing/StaticListPagingSourceFactoryTest.kt b/paging/paging-testing/src/commonTest/kotlin/androidx/paging/testing/StaticListPagingSourceFactoryTest.kt
similarity index 97%
rename from paging/paging-testing/src/androidUnitTest/kotlin/androidx/paging/testing/StaticListPagingSourceFactoryTest.kt
rename to paging/paging-testing/src/commonTest/kotlin/androidx/paging/testing/StaticListPagingSourceFactoryTest.kt
index b4cc8d1..0419b4f 100644
--- a/paging/paging-testing/src/androidUnitTest/kotlin/androidx/paging/testing/StaticListPagingSourceFactoryTest.kt
+++ b/paging/paging-testing/src/commonTest/kotlin/androidx/paging/testing/StaticListPagingSourceFactoryTest.kt
@@ -16,10 +16,11 @@
package androidx.paging.testing
+import androidx.kruth.assertThat
import androidx.paging.PagingConfig
import androidx.paging.PagingSource.LoadResult.Page
import androidx.paging.PagingSourceFactory
-import com.google.common.truth.Truth.assertThat
+import kotlin.test.Test
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
@@ -31,12 +32,8 @@
import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runTest
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.junit.runners.JUnit4
@OptIn(ExperimentalCoroutinesApi::class)
-@RunWith(JUnit4::class)
class StaticListPagingSourceFactoryTest {
private val testScope = TestScope(UnconfinedTestDispatcher())
diff --git a/paging/paging-testing/src/androidUnitTest/kotlin/androidx/paging/testing/StaticListPagingSourceTest.kt b/paging/paging-testing/src/commonTest/kotlin/androidx/paging/testing/StaticListPagingSourceTest.kt
similarity index 97%
rename from paging/paging-testing/src/androidUnitTest/kotlin/androidx/paging/testing/StaticListPagingSourceTest.kt
rename to paging/paging-testing/src/commonTest/kotlin/androidx/paging/testing/StaticListPagingSourceTest.kt
index dd4197f..ae8ce3b 100644
--- a/paging/paging-testing/src/androidUnitTest/kotlin/androidx/paging/testing/StaticListPagingSourceTest.kt
+++ b/paging/paging-testing/src/commonTest/kotlin/androidx/paging/testing/StaticListPagingSourceTest.kt
@@ -16,16 +16,13 @@
package androidx.paging.testing
+import androidx.kruth.assertThat
import androidx.paging.PagingConfig
import androidx.paging.PagingSource
import androidx.paging.PagingSource.LoadResult
-import com.google.common.truth.Truth.assertThat
+import kotlin.test.Test
import kotlinx.coroutines.test.runTest
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.junit.runners.JUnit4
-@RunWith(JUnit4::class)
class StaticListPagingSourceTest {
private val DATA = List(100) { it }
diff --git a/paging/paging-testing/src/androidUnitTest/kotlin/androidx/paging/testing/TestPagerTest.kt b/paging/paging-testing/src/commonTest/kotlin/androidx/paging/testing/TestPagerTest.kt
similarity index 98%
rename from paging/paging-testing/src/androidUnitTest/kotlin/androidx/paging/testing/TestPagerTest.kt
rename to paging/paging-testing/src/commonTest/kotlin/androidx/paging/testing/TestPagerTest.kt
index 477450e..b534856 100644
--- a/paging/paging-testing/src/androidUnitTest/kotlin/androidx/paging/testing/TestPagerTest.kt
+++ b/paging/paging-testing/src/commonTest/kotlin/androidx/paging/testing/TestPagerTest.kt
@@ -16,24 +16,21 @@
package androidx.paging.testing
+import androidx.kruth.assertThat
import androidx.paging.PagingConfig
import androidx.paging.PagingSource.LoadResult
import androidx.paging.PagingState
import androidx.paging.TestPagingSource
-import com.google.common.truth.Truth.assertThat
+import kotlin.test.Test
import kotlin.test.assertFailsWith
+import kotlin.test.assertTrue
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runTest
-import org.junit.Assert.assertTrue
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.junit.runners.JUnit4
@OptIn(ExperimentalCoroutinesApi::class)
-@RunWith(JUnit4::class)
class TestPagerTest {
@Test
@@ -101,7 +98,7 @@
// simulate a PagingSource that returns LoadResult.Invalid when it's invalidated
source.nextLoadResult = LoadResult.Invalid()
- assertThat(pager.refresh()).isInstanceOf(LoadResult.Invalid::class.java)
+ assertThat(pager.refresh()).isInstanceOf<LoadResult.Invalid<Int, Int>>()
}
}
@@ -361,7 +358,7 @@
source.nextLoadResult = LoadResult.Invalid()
append()
}
- assertThat(result).isInstanceOf(LoadResult.Invalid::class.java)
+ assertThat(result).isInstanceOf<LoadResult.Invalid<Int, Int>>()
}
@Test
@@ -377,7 +374,7 @@
source.nextLoadResult = LoadResult.Invalid()
prepend()
}
- assertThat(result).isInstanceOf(LoadResult.Invalid::class.java)
+ assertThat(result).isInstanceOf<LoadResult.Invalid<Int, Int>>()
}
@Test
@@ -642,7 +639,7 @@
append()
getPagingState(-1)
}
- }.localizedMessage
+ }.message
assertThat(msg).isEqualTo(
"anchorPosition -1 is out of bounds between [0..${ITEM_COUNT - 1}]. Please " +
"provide a valid anchorPosition."
@@ -650,7 +647,7 @@
val msg2 = assertFailsWith<IllegalStateException> {
pager.getPagingState(ITEM_COUNT)
- }.localizedMessage
+ }.message
assertThat(msg2).isEqualTo(
"anchorPosition $ITEM_COUNT is out of bounds between [0..${ITEM_COUNT - 1}]. " +
"Please provide a valid anchorPosition."
@@ -675,7 +672,7 @@
append()
getPagingState(-1)
}
- }.localizedMessage
+ }.message
assertThat(msg).isEqualTo(
"anchorPosition -1 is out of bounds between [0..7]. Please " +
"provide a valid anchorPosition."
@@ -684,7 +681,7 @@
// total loaded items = 8, anchorPos with index 8 should be out of bounds
val msg2 = assertFailsWith<IllegalStateException> {
pager.getPagingState(8)
- }.localizedMessage
+ }.message
assertThat(msg2).isEqualTo(
"anchorPosition 8 is out of bounds between [0..7]. Please " +
"provide a valid anchorPosition."
diff --git a/paging/paging-testing/src/jvmMain/kotlin/androidx/paging/testing/internal/Atomics.jvm.kt b/paging/paging-testing/src/jvmMain/kotlin/androidx/paging/testing/internal/Atomics.jvm.kt
new file mode 100644
index 0000000..b9532be
--- /dev/null
+++ b/paging/paging-testing/src/jvmMain/kotlin/androidx/paging/testing/internal/Atomics.jvm.kt
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+@file:Suppress("ACTUAL_WITHOUT_EXPECT") // https://youtrack.jetbrains.com/issue/KT-37316
+package androidx.paging.testing.internal
+
+internal actual typealias AtomicInt = java.util.concurrent.atomic.AtomicInteger
+
+internal actual typealias AtomicBoolean = java.util.concurrent.atomic.AtomicBoolean
+
+internal actual typealias AtomicRef<T> = java.util.concurrent.atomic.AtomicReference<T>
diff --git a/paging/paging-testing/src/nativeMain/kotlin/androidx/paging/testing/internal/Atomics.native.kt b/paging/paging-testing/src/nativeMain/kotlin/androidx/paging/testing/internal/Atomics.native.kt
new file mode 100644
index 0000000..bc053e9
--- /dev/null
+++ b/paging/paging-testing/src/nativeMain/kotlin/androidx/paging/testing/internal/Atomics.native.kt
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+@file:OptIn(ExperimentalForeignApi::class)
+
+package androidx.paging.testing.internal
+
+import kotlinx.atomicfu.AtomicBoolean as AtomicFuAtomicBoolean
+import kotlinx.atomicfu.AtomicInt as AtomicFuAtomicInt
+import kotlinx.atomicfu.AtomicRef as AtomicFuAtomicRef
+import kotlinx.atomicfu.atomic
+import kotlinx.cinterop.ExperimentalForeignApi
+
+internal actual class AtomicInt actual constructor(initialValue: Int) {
+ private var delegate: AtomicFuAtomicInt = atomic(initialValue)
+ private var property by delegate
+
+ actual fun get(): Int = property
+
+ actual fun set(value: Int) {
+ property = value
+ }
+}
+
+internal actual class AtomicBoolean actual constructor(initialValue: Boolean) {
+ private var delegate: AtomicFuAtomicBoolean = atomic(initialValue)
+ private var property by delegate
+
+ actual fun get(): Boolean = property
+
+ actual fun set(value: Boolean) {
+ property = value
+ }
+
+ actual fun compareAndSet(expect: Boolean, update: Boolean): Boolean {
+ return delegate.compareAndSet(expect, update)
+ }
+}
+
+internal actual class AtomicRef<T> actual constructor(initialValue: T) {
+ private var delegate: AtomicFuAtomicRef<T> = atomic(initialValue)
+ private var property by delegate
+
+ actual fun get(): T = property
+
+ actual fun set(value: T) {
+ property = value
+ }
+
+ actual fun getAndSet(value: T): T {
+ return delegate.getAndSet(value)
+ }
+}
diff --git a/privacysandbox/ui/ui-client/api/current.txt b/privacysandbox/ui/ui-client/api/current.txt
index bc9a40d..47ff65b 100644
--- a/privacysandbox/ui/ui-client/api/current.txt
+++ b/privacysandbox/ui/ui-client/api/current.txt
@@ -48,9 +48,9 @@
ctor public SandboxedSdkView(android.content.Context context);
ctor public SandboxedSdkView(android.content.Context context, optional android.util.AttributeSet? attrs);
method public void addStateChangedListener(androidx.privacysandbox.ui.client.view.SandboxedSdkUiSessionStateChangedListener stateChangedListener);
+ method public void orderProviderUiAboveClientUi(boolean providerUiOnTop);
method public void removeStateChangedListener(androidx.privacysandbox.ui.client.view.SandboxedSdkUiSessionStateChangedListener stateChangedListener);
method public void setAdapter(androidx.privacysandbox.ui.core.SandboxedUiAdapter sandboxedUiAdapter);
- method public void setZOrderOnTopAndEnableUserInteraction(boolean setOnTop);
}
}
diff --git a/privacysandbox/ui/ui-client/api/restricted_current.txt b/privacysandbox/ui/ui-client/api/restricted_current.txt
index bc9a40d..47ff65b 100644
--- a/privacysandbox/ui/ui-client/api/restricted_current.txt
+++ b/privacysandbox/ui/ui-client/api/restricted_current.txt
@@ -48,9 +48,9 @@
ctor public SandboxedSdkView(android.content.Context context);
ctor public SandboxedSdkView(android.content.Context context, optional android.util.AttributeSet? attrs);
method public void addStateChangedListener(androidx.privacysandbox.ui.client.view.SandboxedSdkUiSessionStateChangedListener stateChangedListener);
+ method public void orderProviderUiAboveClientUi(boolean providerUiOnTop);
method public void removeStateChangedListener(androidx.privacysandbox.ui.client.view.SandboxedSdkUiSessionStateChangedListener stateChangedListener);
method public void setAdapter(androidx.privacysandbox.ui.core.SandboxedUiAdapter sandboxedUiAdapter);
- method public void setZOrderOnTopAndEnableUserInteraction(boolean setOnTop);
}
}
diff --git a/privacysandbox/ui/ui-client/build.gradle b/privacysandbox/ui/ui-client/build.gradle
index 41e0a3c..fad9e90 100644
--- a/privacysandbox/ui/ui-client/build.gradle
+++ b/privacysandbox/ui/ui-client/build.gradle
@@ -31,7 +31,7 @@
implementation("androidx.core:core:1.12.0-alpha05")
implementation("androidx.lifecycle:lifecycle-common:2.2.0")
- implementation project(path: ':privacysandbox:sdkruntime:sdkruntime-client')
+ implementation("androidx.privacysandbox.sdkruntime:sdkruntime-client:1.0.0-alpha08")
implementation project(path: ':privacysandbox:ui:ui-core')
androidTestImplementation(project(":internal-testutils-runtime"))
diff --git a/privacysandbox/ui/ui-client/src/androidTest/java/androidx/privacysandbox/ui/client/test/SandboxedSdkViewTest.kt b/privacysandbox/ui/ui-client/src/androidTest/java/androidx/privacysandbox/ui/client/test/SandboxedSdkViewTest.kt
index 7498242..8028c83 100644
--- a/privacysandbox/ui/ui-client/src/androidTest/java/androidx/privacysandbox/ui/client/test/SandboxedSdkViewTest.kt
+++ b/privacysandbox/ui/ui-client/src/androidTest/java/androidx/privacysandbox/ui/client/test/SandboxedSdkViewTest.kt
@@ -288,13 +288,13 @@
assertThat(adapter.isZOrderOnTop).isTrue()
// When state changes to false, the provider should be notified.
- view.setZOrderOnTopAndEnableUserInteraction(false)
+ view.orderProviderUiAboveClientUi(false)
assertThat(session.zOrderChangedLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue()
assertThat(adapter.isZOrderOnTop).isFalse()
// When state changes back to true, the provider should be notified.
session.zOrderChangedLatch = CountDownLatch(1)
- view.setZOrderOnTopAndEnableUserInteraction(true)
+ view.orderProviderUiAboveClientUi(true)
assertThat(session.zOrderChangedLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue()
assertThat(adapter.isZOrderOnTop).isTrue()
}
@@ -311,14 +311,14 @@
// When Z-order state is unchanged, the provider should not be notified.
session.zOrderChangedLatch = CountDownLatch(1)
- view.setZOrderOnTopAndEnableUserInteraction(true)
+ view.orderProviderUiAboveClientUi(true)
assertThat(session.zOrderChangedLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)).isFalse()
assertThat(adapter.isZOrderOnTop).isTrue()
}
@Test
fun setZOrderNotOnTopBeforeOpeningSession() {
- view.setZOrderOnTopAndEnableUserInteraction(false)
+ view.orderProviderUiAboveClientUi(false)
addViewToLayout()
assertThat(openSessionLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue()
val session = testSandboxedUiAdapter.testSession!!
@@ -333,7 +333,7 @@
testSandboxedUiAdapter.delayOpenSessionCallback = true
addViewToLayout()
assertThat(openSessionLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue()
- view.setZOrderOnTopAndEnableUserInteraction(false)
+ view.orderProviderUiAboveClientUi(false)
val session = testSandboxedUiAdapter.testSession!!
assertThat(session.zOrderChangedLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)).isFalse()
activity.runOnUiThread {
diff --git a/privacysandbox/ui/ui-client/src/main/java/androidx/privacysandbox/ui/client/view/SandboxedSdkView.kt b/privacysandbox/ui/ui-client/src/main/java/androidx/privacysandbox/ui/client/view/SandboxedSdkView.kt
index 34e205b..49c553f 100644
--- a/privacysandbox/ui/ui-client/src/main/java/androidx/privacysandbox/ui/client/view/SandboxedSdkView.kt
+++ b/privacysandbox/ui/ui-client/src/main/java/androidx/privacysandbox/ui/client/view/SandboxedSdkView.kt
@@ -162,14 +162,15 @@
/**
* Sets the Z-ordering of the [SandboxedSdkView]'s surface, relative to its window.
*
- * When [setOnTop] is true, every [android.view.MotionEvent] on the [SandboxedSdkView] will be
- * sent to the UI provider. When [setOnTop] is false, every [android.view.MotionEvent] will be
- * sent to the client. By default, motion events are sent to the UI provider.
+ * When [providerUiOnTop] is true, every [android.view.MotionEvent] on the [SandboxedSdkView]
+ * will be sent to the UI provider. When [providerUiOnTop] is false, every
+ * [android.view.MotionEvent] will be sent to the client. By default, motion events are sent to
+ * the UI provider.
*/
- fun setZOrderOnTopAndEnableUserInteraction(setOnTop: Boolean) {
- if (setOnTop == isZOrderOnTop) return
- client?.notifyZOrderChanged(setOnTop)
- isZOrderOnTop = setOnTop
+ fun orderProviderUiAboveClientUi(providerUiOnTop: Boolean) {
+ if (providerUiOnTop == isZOrderOnTop) return
+ client?.notifyZOrderChanged(providerUiOnTop)
+ isZOrderOnTop = providerUiOnTop
checkClientOpenSession()
}
diff --git a/privacysandbox/ui/ui-tests/src/androidTest/java/androidx/privacysandbox/ui/tests/endtoend/IntegrationTests.kt b/privacysandbox/ui/ui-tests/src/androidTest/java/androidx/privacysandbox/ui/tests/endtoend/IntegrationTests.kt
index 3333303..295e120 100644
--- a/privacysandbox/ui/ui-tests/src/androidTest/java/androidx/privacysandbox/ui/tests/endtoend/IntegrationTests.kt
+++ b/privacysandbox/ui/ui-tests/src/androidTest/java/androidx/privacysandbox/ui/tests/endtoend/IntegrationTests.kt
@@ -218,7 +218,7 @@
val adapterFromCoreLibInfo = SandboxedUiAdapterFactory.createFromCoreLibInfo(coreLibInfo)
view.setAdapter(adapterFromCoreLibInfo)
assertThat(openSessionLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue()
- view.setZOrderOnTopAndEnableUserInteraction(!adapter.initialZOrderOnTop)
+ view.orderProviderUiAboveClientUi(!adapter.initialZOrderOnTop)
assertThat(adapter.zOrderLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue()
}
@@ -237,7 +237,7 @@
val adapterFromCoreLibInfo = SandboxedUiAdapterFactory.createFromCoreLibInfo(coreLibInfo)
view.setAdapter(adapterFromCoreLibInfo)
assertThat(openSessionLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)).isTrue()
- view.setZOrderOnTopAndEnableUserInteraction(adapter.initialZOrderOnTop)
+ view.orderProviderUiAboveClientUi(adapter.initialZOrderOnTop)
assertThat(adapter.zOrderLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)).isFalse()
}
diff --git a/room/room-common/build.gradle b/room/room-common/build.gradle
index 4f3fd52..49e5177 100644
--- a/room/room-common/build.gradle
+++ b/room/room-common/build.gradle
@@ -14,27 +14,52 @@
* limitations under the License.
*/
+
+import androidx.build.LibraryType
+import androidx.build.PlatformIdentifier
import androidx.build.Publish
-import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("AndroidXPlugin")
- id("kotlin")
}
-dependencies {
- api("androidx.annotation:annotation:1.3.0")
- api(libs.kotlinStdlibJdk8)
- testImplementation(libs.junit)
- testImplementation(libs.mockitoCore4)
- testImplementation(libs.guava)
- testImplementation(project(":kruth:kruth"))
+androidXMultiplatform {
+ jvm() {
+ withJava()
+ }
+ mac()
+ linux()
+ ios()
+
+ defaultPlatform(PlatformIdentifier.JVM)
+
+ sourceSets {
+ all {
+ languageSettings.optIn("kotlin.RequiresOptIn")
+ }
+
+ commonMain {
+ dependencies {
+ api(libs.kotlinStdlib)
+ api("androidx.annotation:annotation:1.3.0")
+ }
+ }
+ commonTest {
+ dependencies {
+ implementation(project(":kruth:kruth"))
+ implementation(libs.junit)
+ implementation(libs.guava)
+ }
+ }
+ }
}
androidx {
name = "Room-Common"
+ type = LibraryType.PUBLISHED_LIBRARY
publish = Publish.SNAPSHOT_AND_RELEASE
inceptionYear = "2017"
description = "Android Room-Common"
+ legacyDisableKotlinStrictApiMode = true
metalavaK2UastEnabled = true
}
diff --git a/room/room-common/src/main/java/androidx/room/AmbiguousColumnResolver.kt b/room/room-common/src/commonMain/kotlin/androidx/room/AmbiguousColumnResolver.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/AmbiguousColumnResolver.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/AmbiguousColumnResolver.kt
diff --git a/room/room-common/src/main/java/androidx/room/AutoMigration.kt b/room/room-common/src/commonMain/kotlin/androidx/room/AutoMigration.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/AutoMigration.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/AutoMigration.kt
diff --git a/room/room-common/src/main/java/androidx/room/BuiltInTypeConverters.kt b/room/room-common/src/commonMain/kotlin/androidx/room/BuiltInTypeConverters.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/BuiltInTypeConverters.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/BuiltInTypeConverters.kt
diff --git a/room/room-common/src/main/java/androidx/room/ColumnInfo.kt b/room/room-common/src/commonMain/kotlin/androidx/room/ColumnInfo.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/ColumnInfo.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/ColumnInfo.kt
diff --git a/room/room-common/src/main/java/androidx/room/Dao.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Dao.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Dao.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Dao.kt
diff --git a/room/room-common/src/main/java/androidx/room/Database.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Database.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Database.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Database.kt
diff --git a/room/room-common/src/main/java/androidx/room/DatabaseView.kt b/room/room-common/src/commonMain/kotlin/androidx/room/DatabaseView.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/DatabaseView.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/DatabaseView.kt
diff --git a/room/room-common/src/main/java/androidx/room/Delete.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Delete.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Delete.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Delete.kt
diff --git a/room/room-common/src/main/java/androidx/room/DeleteColumn.kt b/room/room-common/src/commonMain/kotlin/androidx/room/DeleteColumn.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/DeleteColumn.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/DeleteColumn.kt
diff --git a/room/room-common/src/main/java/androidx/room/DeleteTable.kt b/room/room-common/src/commonMain/kotlin/androidx/room/DeleteTable.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/DeleteTable.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/DeleteTable.kt
diff --git a/room/room-common/src/main/java/androidx/room/Embedded.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Embedded.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Embedded.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Embedded.kt
diff --git a/room/room-common/src/main/java/androidx/room/Entity.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Entity.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Entity.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Entity.kt
diff --git a/room/room-common/src/main/java/androidx/room/ForeignKey.kt b/room/room-common/src/commonMain/kotlin/androidx/room/ForeignKey.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/ForeignKey.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/ForeignKey.kt
diff --git a/room/room-common/src/main/java/androidx/room/Fts3.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Fts3.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Fts3.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Fts3.kt
diff --git a/room/room-common/src/main/java/androidx/room/Fts4.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Fts4.kt
similarity index 97%
rename from room/room-common/src/main/java/androidx/room/Fts4.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Fts4.kt
index f9ed6e1..fcd8895 100644
--- a/room/room-common/src/main/java/androidx/room/Fts4.kt
+++ b/room/room-common/src/commonMain/kotlin/androidx/room/Fts4.kt
@@ -17,8 +17,6 @@
package androidx.room
import androidx.annotation.RequiresApi
-import androidx.room.FtsOptions.MatchInfo
-import androidx.room.FtsOptions.Order
import androidx.room.FtsOptions.TOKENIZER_SIMPLE
import kotlin.reflect.KClass
@@ -144,7 +142,7 @@
*
* @return The match info version, either [MatchInfo.FTS4] or [MatchInfo.FTS3].
*/
- val matchInfo: MatchInfo = MatchInfo.FTS4,
+ val matchInfo: FtsOptions.MatchInfo = FtsOptions.MatchInfo.FTS4,
/**
* The list of column names on the FTS table that won't be indexed.
@@ -176,5 +174,5 @@
*
* @return The preferred order, either [Order.ASC] or [Order.DESC].
*/
- val order: Order = Order.ASC
+ val order: FtsOptions.Order = FtsOptions.Order.ASC
)
diff --git a/room/room-common/src/main/java/androidx/room/FtsOptions.kt b/room/room-common/src/commonMain/kotlin/androidx/room/FtsOptions.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/FtsOptions.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/FtsOptions.kt
diff --git a/room/room-common/src/main/java/androidx/room/Ignore.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Ignore.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Ignore.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Ignore.kt
diff --git a/room/room-common/src/main/java/androidx/room/Index.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Index.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Index.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Index.kt
diff --git a/room/room-common/src/main/java/androidx/room/Insert.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Insert.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Insert.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Insert.kt
diff --git a/room/room-common/src/main/java/androidx/room/Junction.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Junction.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Junction.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Junction.kt
diff --git a/room/room-common/src/main/java/androidx/room/MapColumn.kt b/room/room-common/src/commonMain/kotlin/androidx/room/MapColumn.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/MapColumn.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/MapColumn.kt
diff --git a/room/room-common/src/main/java/androidx/room/MapInfo.kt b/room/room-common/src/commonMain/kotlin/androidx/room/MapInfo.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/MapInfo.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/MapInfo.kt
diff --git a/room/room-common/src/main/java/androidx/room/OnConflictStrategy.kt b/room/room-common/src/commonMain/kotlin/androidx/room/OnConflictStrategy.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/OnConflictStrategy.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/OnConflictStrategy.kt
diff --git a/room/room-common/src/main/java/androidx/room/PrimaryKey.kt b/room/room-common/src/commonMain/kotlin/androidx/room/PrimaryKey.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/PrimaryKey.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/PrimaryKey.kt
diff --git a/room/room-common/src/main/java/androidx/room/ProvidedAutoMigrationSpec.kt b/room/room-common/src/commonMain/kotlin/androidx/room/ProvidedAutoMigrationSpec.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/ProvidedAutoMigrationSpec.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/ProvidedAutoMigrationSpec.kt
diff --git a/room/room-common/src/main/java/androidx/room/ProvidedTypeConverter.kt b/room/room-common/src/commonMain/kotlin/androidx/room/ProvidedTypeConverter.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/ProvidedTypeConverter.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/ProvidedTypeConverter.kt
diff --git a/room/room-common/src/main/java/androidx/room/Query.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Query.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Query.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Query.kt
diff --git a/room/room-common/src/main/java/androidx/room/RawQuery.kt b/room/room-common/src/commonMain/kotlin/androidx/room/RawQuery.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/RawQuery.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/RawQuery.kt
diff --git a/room/room-common/src/main/java/androidx/room/Relation.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Relation.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Relation.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Relation.kt
diff --git a/room/room-common/src/main/java/androidx/room/RenameColumn.kt b/room/room-common/src/commonMain/kotlin/androidx/room/RenameColumn.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/RenameColumn.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/RenameColumn.kt
diff --git a/room/room-common/src/main/java/androidx/room/RenameTable.kt b/room/room-common/src/commonMain/kotlin/androidx/room/RenameTable.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/RenameTable.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/RenameTable.kt
diff --git a/room/room-common/src/main/java/androidx/room/RewriteQueriesToDropUnusedColumns.kt b/room/room-common/src/commonMain/kotlin/androidx/room/RewriteQueriesToDropUnusedColumns.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/RewriteQueriesToDropUnusedColumns.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/RewriteQueriesToDropUnusedColumns.kt
diff --git a/room/room-common/src/main/java/androidx/room/RoomMasterTable.kt b/room/room-common/src/commonMain/kotlin/androidx/room/RoomMasterTable.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/RoomMasterTable.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/RoomMasterTable.kt
diff --git a/room/room-common/src/main/java/androidx/room/RoomWarnings.kt b/room/room-common/src/commonMain/kotlin/androidx/room/RoomWarnings.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/RoomWarnings.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/RoomWarnings.kt
diff --git a/room/room-common/src/main/java/androidx/room/SkipQueryVerification.kt b/room/room-common/src/commonMain/kotlin/androidx/room/SkipQueryVerification.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/SkipQueryVerification.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/SkipQueryVerification.kt
diff --git a/room/room-common/src/main/java/androidx/room/Transaction.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Transaction.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Transaction.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Transaction.kt
diff --git a/room/room-common/src/main/java/androidx/room/TypeConverter.kt b/room/room-common/src/commonMain/kotlin/androidx/room/TypeConverter.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/TypeConverter.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/TypeConverter.kt
diff --git a/room/room-common/src/main/java/androidx/room/TypeConverters.kt b/room/room-common/src/commonMain/kotlin/androidx/room/TypeConverters.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/TypeConverters.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/TypeConverters.kt
diff --git a/room/room-common/src/main/java/androidx/room/Update.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Update.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Update.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Update.kt
diff --git a/room/room-common/src/main/java/androidx/room/Upsert.kt b/room/room-common/src/commonMain/kotlin/androidx/room/Upsert.kt
similarity index 100%
rename from room/room-common/src/main/java/androidx/room/Upsert.kt
rename to room/room-common/src/commonMain/kotlin/androidx/room/Upsert.kt
diff --git a/room/room-common/src/test/java/androidx/room/AmbiguousColumnResolverTest.kt b/room/room-common/src/commonTest/kotlin/androidx/room/AmbiguousColumnResolverTest.kt
similarity index 100%
rename from room/room-common/src/test/java/androidx/room/AmbiguousColumnResolverTest.kt
rename to room/room-common/src/commonTest/kotlin/androidx/room/AmbiguousColumnResolverTest.kt
diff --git a/room/room-common/src/test/java/androidx/room/AnnotationRetentionPolicyTest.kt b/room/room-common/src/commonTest/kotlin/androidx/room/AnnotationRetentionPolicyTest.kt
similarity index 100%
rename from room/room-common/src/test/java/androidx/room/AnnotationRetentionPolicyTest.kt
rename to room/room-common/src/commonTest/kotlin/androidx/room/AnnotationRetentionPolicyTest.kt
diff --git a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KSTypeJavaPoetExt.kt b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KSTypeJavaPoetExt.kt
index 442930d..44457bd 100644
--- a/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KSTypeJavaPoetExt.kt
+++ b/room/room-compiler-processing/src/main/java/androidx/room/compiler/processing/ksp/KSTypeJavaPoetExt.kt
@@ -179,7 +179,10 @@
): JTypeName {
return if (declaration is KSTypeAlias) {
replaceTypeAliases(resolver).asJTypeName(resolver, typeResolutionContext)
- } else if (this.arguments.isNotEmpty() && !resolver.isJavaRawType(this)) {
+ } else if (this.arguments.isNotEmpty() && !resolver.isJavaRawType(this) &&
+ // Excluding generic value classes otherwise we may generate something
+ // like `Object<String>`.
+ !declaration.isValueClass()) {
val args: Array<JTypeName> = this.arguments
.map { typeArg -> typeArg.asJTypeName(resolver, typeResolutionContext) }
.map { it.tryBox() }
diff --git a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeTest.kt b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeTest.kt
index 1a68ad3..af27478 100644
--- a/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeTest.kt
+++ b/room/room-compiler-processing/src/test/java/androidx/room/compiler/processing/XTypeTest.kt
@@ -39,6 +39,8 @@
import androidx.room.compiler.processing.util.runKspTest
import androidx.room.compiler.processing.util.runProcessorTest
import com.google.devtools.ksp.getClassDeclarationByName
+import com.google.testing.junit.testparameterinjector.TestParameter
+import com.google.testing.junit.testparameterinjector.TestParameterInjector
import com.squareup.javapoet.ClassName
import com.squareup.javapoet.ParameterizedTypeName
import com.squareup.javapoet.TypeVariableName
@@ -56,9 +58,8 @@
import com.squareup.kotlinpoet.javapoet.KTypeVariableName
import org.junit.Test
import org.junit.runner.RunWith
-import org.junit.runners.JUnit4
-@RunWith(JUnit4::class)
+@RunWith(TestParameterInjector::class)
class XTypeTest {
@Test
fun typeArguments() {
@@ -1842,22 +1843,57 @@
}
@Test
- fun valueTypes() {
+ fun valueTypes(@TestParameter isPrecompiled: Boolean,) {
val kotlinSrc = Source.kotlin(
"KotlinClass.kt",
"""
@JvmInline value class PackageName(val value: String)
+ @JvmInline value class MyResult<T>(val value: T)
class KotlinClass {
+ // @JvmName disables name mangling for functions that use inline classes and
+ // make them visible to Java:
+ // https://kotlinlang.org/docs/inline-classes.html#calling-from-java-code
+ @JvmName("getResult")
+ fun getResult(): MyResult<String> = TODO()
+ @JvmName("setResult")
+ fun setResult(result: MyResult<String>) { }
fun getPackageNames(): Set<PackageName> = emptySet()
fun setPackageNames(pkgNames: Set<PackageName>) { }
}
""".trimIndent()
)
runProcessorTest(
- sources = listOf(kotlinSrc)
+ sources = if (isPrecompiled) { emptyList() } else { listOf(kotlinSrc) },
+ classpath = if (isPrecompiled) { compileFiles(listOf(kotlinSrc)) } else { emptyList() }
) { invocation ->
val kotlinElm = invocation.processingEnv.requireTypeElement("KotlinClass")
+
+ kotlinElm.getDeclaredMethodByJvmName("getResult").apply {
+ assertThat(returnType.asTypeName().java.toString())
+ .isEqualTo("java.lang.Object")
+ if (invocation.isKsp) {
+ assertThat(returnType.asTypeName().kotlin.toString())
+ .isEqualTo("MyResult<kotlin.String>")
+ } else {
+ // Can't generate Kotlin code with KAPT
+ assertThat(returnType.asTypeName().kotlin.toString())
+ .isEqualTo("androidx.room.compiler.codegen.Unavailable")
+ }
+ }
+ kotlinElm.getDeclaredMethodByJvmName("setResult").apply {
+ assertThat(parameters.single().type.asTypeName().java.toString())
+ .isEqualTo("java.lang.Object")
+ if (invocation.isKsp) {
+ assertThat(parameters.single().type.asTypeName().kotlin.toString())
+ .isEqualTo("MyResult<kotlin.String>")
+ } else {
+ // Can't generate Kotlin code with KAPT
+ assertThat(parameters.single().type.asTypeName().kotlin.toString())
+ .isEqualTo("androidx.room.compiler.codegen.Unavailable")
+ }
+ }
+
kotlinElm.getMethodByJvmName("getPackageNames").apply {
assertThat(returnType.typeName.toString())
.isEqualTo("java.util.Set<PackageName>")
diff --git a/settings.gradle b/settings.gradle
index 7459ae1..821a4df 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -948,7 +948,7 @@
includeProject(":room:integration-tests:room-testapp-kotlin", "room/integration-tests/kotlintestapp", [BuildType.MAIN])
includeProject(":room:integration-tests:room-testapp-noappcompat", "room/integration-tests/noappcompattestapp", [BuildType.MAIN])
includeProject(":room:room-benchmark", "room/benchmark", [BuildType.MAIN])
-includeProject(":room:room-common", [BuildType.MAIN, BuildType.COMPOSE])
+includeProject(":room:room-common", [BuildType.MAIN, BuildType.COMPOSE, BuildType.KMP])
includeProject(":room:room-compiler", [BuildType.MAIN, BuildType.COMPOSE])
includeProject(":room:room-compiler-processing", [BuildType.MAIN, BuildType.COMPOSE, BuildType.FLAN])
includeProject(":room:room-compiler-processing-testing", [BuildType.MAIN, BuildType.COMPOSE, BuildType.FLAN])
diff --git a/transition/transition/src/main/java/androidx/transition/FragmentTransitionSupport.java b/transition/transition/src/main/java/androidx/transition/FragmentTransitionSupport.java
index 6a0d6c9..52dacee 100644
--- a/transition/transition/src/main/java/androidx/transition/FragmentTransitionSupport.java
+++ b/transition/transition/src/main/java/androidx/transition/FragmentTransitionSupport.java
@@ -229,6 +229,11 @@
}
@Override
+ public boolean isSeekingSupported() {
+ return true;
+ }
+
+ @Override
public boolean isSeekingSupported(@NonNull Object transition) {
boolean supported = ((Transition) transition).isSeekingSupported();
if (!supported) {
diff --git a/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/FeaturedCarousel.kt b/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/FeaturedCarousel.kt
index ac7fe19..85c9d28 100644
--- a/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/FeaturedCarousel.kt
+++ b/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/FeaturedCarousel.kt
@@ -28,6 +28,7 @@
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
+import androidx.compose.foundation.focusGroup
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -45,6 +46,7 @@
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
+import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
@@ -54,6 +56,7 @@
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
+import androidx.compose.ui.focus.focusRestorer
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onPlaced
@@ -69,37 +72,48 @@
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.rememberCarouselState
+@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun FeaturedCarouselContent() {
LazyColumn(verticalArrangement = Arrangement.spacedBy(20.dp)) {
items(3) { SampleLazyRow() }
item {
Row(horizontalArrangement = Arrangement.spacedBy(20.dp)) {
- Column(verticalArrangement = Arrangement.spacedBy(20.dp)) {
+ Column(
+ modifier = Modifier.focusRestorer().focusGroup(),
+ verticalArrangement = Arrangement.spacedBy(20.dp)
+ ) {
repeat(3) {
- Box(
- modifier = Modifier
- .background(Color.Magenta.copy(alpha = 0.3f))
- .width(50.dp)
- .height(50.dp)
- .drawBorderOnFocus()
- .focusable()
- )
+ key(it) {
+ Box(
+ modifier = Modifier
+ .background(Color.Magenta.copy(alpha = 0.3f))
+ .width(50.dp)
+ .height(50.dp)
+ .drawBorderOnFocus()
+ .focusable()
+ )
+ }
}
}
FeaturedCarousel(Modifier.weight(1f))
- Column(verticalArrangement = Arrangement.spacedBy(20.dp)) {
+ Column(
+ modifier = Modifier.focusRestorer().focusGroup(),
+ verticalArrangement = Arrangement.spacedBy(20.dp)
+ ) {
repeat(3) {
- Box(
- modifier = Modifier
- .background(Color.Magenta.copy(alpha = 0.3f))
- .width(50.dp)
- .height(50.dp)
- .drawBorderOnFocus()
- .focusable()
- )
+ key(it) {
+ Box(
+ modifier = Modifier
+ .background(Color.Magenta.copy(alpha = 0.3f))
+ .width(50.dp)
+ .height(50.dp)
+ .drawBorderOnFocus()
+ .focusable()
+ )
+ }
}
}
}
diff --git a/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/NavigationDrawer.kt b/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/NavigationDrawer.kt
index c9d1f31..8d9971c 100644
--- a/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/NavigationDrawer.kt
+++ b/tv/integration-tests/playground/src/main/java/androidx/tv/integration/playground/NavigationDrawer.kt
@@ -38,6 +38,7 @@
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.LayoutDirection
@@ -75,7 +76,13 @@
Row(Modifier.fillMaxSize()) {
Box(modifier = Modifier.height(400.dp)) {
androidx.tv.material3.ModalNavigationDrawer(
- drawerContent = { Sidebar(direction = direction) }
+ drawerContent = { Sidebar(direction = direction) },
+ scrimBrush = Brush.verticalGradient(
+ listOf(
+ Color.DarkGray,
+ Color.LightGray
+ )
+ )
) {
CommonBackground()
}
diff --git a/tv/tv-material/src/androidTest/java/androidx/tv/material3/CarouselTest.kt b/tv/tv-material/src/androidTest/java/androidx/tv/material3/CarouselTest.kt
index 5b302d8..c6569aa 100644
--- a/tv/tv-material/src/androidTest/java/androidx/tv/material3/CarouselTest.kt
+++ b/tv/tv-material/src/androidTest/java/androidx/tv/material3/CarouselTest.kt
@@ -24,6 +24,7 @@
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.foundation.background
import androidx.compose.foundation.border
+import androidx.compose.foundation.focusGroup
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -44,14 +45,17 @@
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
+import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.NativeKeyEvent
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.semantics.SemanticsActions
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsFocused
import androidx.compose.ui.test.assertIsNotFocused
@@ -63,6 +67,7 @@
import androidx.compose.ui.test.onParent
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performKeyPress
+import androidx.compose.ui.test.performSemanticsAction
import androidx.compose.ui.test.requestFocus
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
@@ -828,6 +833,80 @@
// slide should have changed.
rule.onNodeWithText("Left Button 2").assertIsFocused()
}
+
+ @Test
+ fun carousel_manualScrollingLtr_loopsAroundWhenNoAdjacentFocusableItemsArePresent() {
+ rule.setContent {
+ // No AutoScrolling
+ SampleCarousel(timeToDisplayItemMillis = Long.MAX_VALUE, itemCount = 3) {
+ Row {
+ SampleButton("Button-$it")
+ }
+ }
+ }
+
+ rule.onNodeWithText("Button-0")
+ .performSemanticsAction(SemanticsActions.RequestFocus)
+
+ // Carousel should loop around the edges if there are no adjacent focusable items in the
+ // direction of dpad key press (left)
+ performKeyPress(KeyEvent.KEYCODE_DPAD_LEFT)
+ rule.onNodeWithText("Button-2").assertIsFocused()
+
+ // Carousel should loop around the edges if there are no adjacent focusable items in the
+ // direction of dpad key press (right)
+ performKeyPress(KeyEvent.KEYCODE_DPAD_RIGHT)
+ rule.onNodeWithText("Button-0").assertIsFocused()
+ }
+
+ @OptIn(ExperimentalComposeUiApi::class)
+ @Test
+ fun carousel_manualScrollingLtr_focusMovesToAdjacentItemsOutsideCarousel() {
+ rule.setContent {
+ val focusRequester = remember { FocusRequester() }
+ Row {
+ Column(
+ Modifier
+ .focusProperties {
+ enter = {
+ focusRequester.requestFocus()
+ FocusRequester.Cancel
+ }
+ }
+ .focusGroup()
+ ) {
+ repeat(3) {
+ Box(
+ modifier = Modifier
+ .size(10.dp)
+ .testTag("Item-$it")
+ .then(
+ if (it == 0) Modifier.focusRequester(focusRequester)
+ else Modifier
+ )
+ .focusable()
+ )
+ }
+ }
+ // No AutoScrolling
+ Box(Modifier.weight(1f)) {
+ SampleCarousel(timeToDisplayItemMillis = Long.MAX_VALUE, itemCount = 2) {
+ Row {
+ SampleButton("Button-$it")
+ }
+ }
+ }
+ }
+ }
+
+ rule.onNodeWithText("Button-0")
+ .performSemanticsAction(SemanticsActions.RequestFocus)
+
+ // Focus should exit Carousel if there are any adjacent focusable items in the direction
+ // of dpad key press (left)
+ performKeyPress(KeyEvent.KEYCODE_DPAD_LEFT)
+ rule.onNodeWithTag("Item-0").assertIsFocused()
+ }
}
@OptIn(ExperimentalTvMaterial3Api::class)
@@ -861,7 +940,6 @@
)
}
-@OptIn(ExperimentalTvMaterial3Api::class, ExperimentalAnimationApi::class)
@Composable
private fun AnimatedContentScope.SampleCarouselItem(
index: Int,
diff --git a/tv/tv-material/src/androidTest/java/androidx/tv/material3/ModalNavigationDrawerTest.kt b/tv/tv-material/src/androidTest/java/androidx/tv/material3/ModalNavigationDrawerTest.kt
index a522dc83..3db7b7c 100644
--- a/tv/tv-material/src/androidTest/java/androidx/tv/material3/ModalNavigationDrawerTest.kt
+++ b/tv/tv-material/src/androidTest/java/androidx/tv/material3/ModalNavigationDrawerTest.kt
@@ -16,6 +16,7 @@
package androidx.tv.material3
+import android.os.Build
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.focusable
@@ -31,6 +32,8 @@
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
+import androidx.compose.testutils.assertContainsColor
+import androidx.compose.testutils.assertDoesNotContainColor
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
@@ -38,6 +41,7 @@
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.testTag
@@ -50,6 +54,7 @@
import androidx.compose.ui.test.assertIsFocused
import androidx.compose.ui.test.assertIsNotFocused
import androidx.compose.ui.test.assertWidthIsEqualTo
+import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.getUnclippedBoundsInRoot
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onAllNodesWithText
@@ -62,6 +67,7 @@
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.toSize
+import androidx.test.filters.SdkSuppress
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Rule
import org.junit.Test
@@ -356,6 +362,26 @@
rule.onNodeWithTag("box-container").assertIsFocused()
}
+ @SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
+ @Test
+ fun modalNavigationDrawer_onOpen_scrimIsDrawnAboveContent() {
+ val backgroundContentColor = Color.Blue
+ val scrimColor = Color.Red
+ rule.setContent {
+ ModalNavigationDrawer(
+ drawerState = remember { DrawerState(DrawerValue.Open) },
+ drawerContent = {
+ BasicText(text = if (it == DrawerValue.Open) "Opened" else "Closed")
+ },
+ scrimBrush = SolidColor(scrimColor)
+ ) { Box(Modifier.fillMaxSize().background(backgroundContentColor)) }
+ }
+
+ // the image should show only scrim color and no background content color
+ rule.onRoot().captureToImage().assertContainsColor(scrimColor)
+ rule.onRoot().captureToImage().assertDoesNotContainColor(backgroundContentColor)
+ }
+
private fun SemanticsNodeInteractionCollection.assertAnyAreDisplayed() {
val result = (0 until fetchSemanticsNodes().size).map { get(it) }.any {
try {
diff --git a/tv/tv-material/src/main/java/androidx/tv/material3/Carousel.kt b/tv/tv-material/src/main/java/androidx/tv/material3/Carousel.kt
index 23ffe4e..1f059dc 100644
--- a/tv/tv-material/src/main/java/androidx/tv/material3/Carousel.kt
+++ b/tv/tv-material/src/main/java/androidx/tv/material3/Carousel.kt
@@ -291,7 +291,8 @@
KeyEventPropagation.StopPropagation
}
- !focusManager.moveFocus(direction) -> {
+ !focusManager.moveFocus(direction) &&
+ currentCarouselBoxFocusState()?.hasFocus == true -> {
// if focus search was unsuccessful, interpret as input for slide change
updateItemBasedOnLayout(direction, isLtr)
KeyEventPropagation.StopPropagation
diff --git a/tv/tv-material/src/main/java/androidx/tv/material3/NavigationDrawer.kt b/tv/tv-material/src/main/java/androidx/tv/material3/NavigationDrawer.kt
index 320fe9e..5e7abdb 100644
--- a/tv/tv-material/src/main/java/androidx/tv/material3/NavigationDrawer.kt
+++ b/tv/tv-material/src/main/java/androidx/tv/material3/NavigationDrawer.kt
@@ -114,15 +114,15 @@
content = drawerContent
)
+ Box(Modifier.padding(start = closedDrawerWidth.value ?: ClosedDrawerWidth.dp)) {
+ content()
+ }
if (drawerState.currentValue == DrawerValue.Open) {
// Scrim
Canvas(Modifier.fillMaxSize()) {
drawRect(scrimBrush)
}
}
- Box(Modifier.padding(start = closedDrawerWidth.value ?: ClosedDrawerWidth.dp)) {
- content()
- }
}
}
diff --git a/wear/tiles/tiles-tooling-preview/api/current.txt b/wear/tiles/tiles-tooling-preview/api/current.txt
index e2c0e4e..f1331ab 100644
--- a/wear/tiles/tiles-tooling-preview/api/current.txt
+++ b/wear/tiles/tiles-tooling-preview/api/current.txt
@@ -19,11 +19,12 @@
}
public final class TilePreviewData {
- ctor public TilePreviewData(optional kotlin.jvm.functions.Function2<? super androidx.wear.tiles.RequestBuilders.ResourcesRequest,? super android.content.Context,androidx.wear.protolayout.ResourceBuilders.Resources> onTileResourceRequest, kotlin.jvm.functions.Function2<? super androidx.wear.tiles.RequestBuilders.TileRequest,? super android.content.Context,androidx.wear.tiles.TileBuilders.Tile> onTileRequest);
- method public kotlin.jvm.functions.Function2<androidx.wear.tiles.RequestBuilders.TileRequest,android.content.Context,androidx.wear.tiles.TileBuilders.Tile> getOnTileRequest();
- method public kotlin.jvm.functions.Function2<androidx.wear.tiles.RequestBuilders.ResourcesRequest,android.content.Context,androidx.wear.protolayout.ResourceBuilders.Resources> getOnTileResourceRequest();
- property public final kotlin.jvm.functions.Function2<androidx.wear.tiles.RequestBuilders.TileRequest,android.content.Context,androidx.wear.tiles.TileBuilders.Tile> onTileRequest;
- property public final kotlin.jvm.functions.Function2<androidx.wear.tiles.RequestBuilders.ResourcesRequest,android.content.Context,androidx.wear.protolayout.ResourceBuilders.Resources> onTileResourceRequest;
+ ctor public TilePreviewData(optional kotlin.jvm.functions.Function1<? super androidx.wear.tiles.RequestBuilders.ResourcesRequest,androidx.wear.protolayout.ResourceBuilders.Resources> onTileResourceRequest, kotlin.jvm.functions.Function1<? super androidx.wear.tiles.RequestBuilders.TileRequest,androidx.wear.tiles.TileBuilders.Tile> onTileRequest);
+ ctor public TilePreviewData(kotlin.jvm.functions.Function1<? super androidx.wear.tiles.RequestBuilders.TileRequest,androidx.wear.tiles.TileBuilders.Tile> onTileRequest);
+ method public kotlin.jvm.functions.Function1<androidx.wear.tiles.RequestBuilders.TileRequest,androidx.wear.tiles.TileBuilders.Tile> getOnTileRequest();
+ method public kotlin.jvm.functions.Function1<androidx.wear.tiles.RequestBuilders.ResourcesRequest,androidx.wear.protolayout.ResourceBuilders.Resources> getOnTileResourceRequest();
+ property public final kotlin.jvm.functions.Function1<androidx.wear.tiles.RequestBuilders.TileRequest,androidx.wear.tiles.TileBuilders.Tile> onTileRequest;
+ property public final kotlin.jvm.functions.Function1<androidx.wear.tiles.RequestBuilders.ResourcesRequest,androidx.wear.protolayout.ResourceBuilders.Resources> onTileResourceRequest;
}
public final class TilePreviewHelper {
diff --git a/wear/tiles/tiles-tooling-preview/api/restricted_current.txt b/wear/tiles/tiles-tooling-preview/api/restricted_current.txt
index e2c0e4e..f1331ab 100644
--- a/wear/tiles/tiles-tooling-preview/api/restricted_current.txt
+++ b/wear/tiles/tiles-tooling-preview/api/restricted_current.txt
@@ -19,11 +19,12 @@
}
public final class TilePreviewData {
- ctor public TilePreviewData(optional kotlin.jvm.functions.Function2<? super androidx.wear.tiles.RequestBuilders.ResourcesRequest,? super android.content.Context,androidx.wear.protolayout.ResourceBuilders.Resources> onTileResourceRequest, kotlin.jvm.functions.Function2<? super androidx.wear.tiles.RequestBuilders.TileRequest,? super android.content.Context,androidx.wear.tiles.TileBuilders.Tile> onTileRequest);
- method public kotlin.jvm.functions.Function2<androidx.wear.tiles.RequestBuilders.TileRequest,android.content.Context,androidx.wear.tiles.TileBuilders.Tile> getOnTileRequest();
- method public kotlin.jvm.functions.Function2<androidx.wear.tiles.RequestBuilders.ResourcesRequest,android.content.Context,androidx.wear.protolayout.ResourceBuilders.Resources> getOnTileResourceRequest();
- property public final kotlin.jvm.functions.Function2<androidx.wear.tiles.RequestBuilders.TileRequest,android.content.Context,androidx.wear.tiles.TileBuilders.Tile> onTileRequest;
- property public final kotlin.jvm.functions.Function2<androidx.wear.tiles.RequestBuilders.ResourcesRequest,android.content.Context,androidx.wear.protolayout.ResourceBuilders.Resources> onTileResourceRequest;
+ ctor public TilePreviewData(optional kotlin.jvm.functions.Function1<? super androidx.wear.tiles.RequestBuilders.ResourcesRequest,androidx.wear.protolayout.ResourceBuilders.Resources> onTileResourceRequest, kotlin.jvm.functions.Function1<? super androidx.wear.tiles.RequestBuilders.TileRequest,androidx.wear.tiles.TileBuilders.Tile> onTileRequest);
+ ctor public TilePreviewData(kotlin.jvm.functions.Function1<? super androidx.wear.tiles.RequestBuilders.TileRequest,androidx.wear.tiles.TileBuilders.Tile> onTileRequest);
+ method public kotlin.jvm.functions.Function1<androidx.wear.tiles.RequestBuilders.TileRequest,androidx.wear.tiles.TileBuilders.Tile> getOnTileRequest();
+ method public kotlin.jvm.functions.Function1<androidx.wear.tiles.RequestBuilders.ResourcesRequest,androidx.wear.protolayout.ResourceBuilders.Resources> getOnTileResourceRequest();
+ property public final kotlin.jvm.functions.Function1<androidx.wear.tiles.RequestBuilders.TileRequest,androidx.wear.tiles.TileBuilders.Tile> onTileRequest;
+ property public final kotlin.jvm.functions.Function1<androidx.wear.tiles.RequestBuilders.ResourcesRequest,androidx.wear.protolayout.ResourceBuilders.Resources> onTileResourceRequest;
}
public final class TilePreviewHelper {
diff --git a/wear/tiles/tiles-tooling-preview/src/main/java/androidx/wear/tiles/tooling/preview/TilePreview.kt b/wear/tiles/tiles-tooling-preview/src/main/java/androidx/wear/tiles/tooling/preview/TilePreview.kt
index 73aee32..84e1282 100644
--- a/wear/tiles/tiles-tooling-preview/src/main/java/androidx/wear/tiles/tooling/preview/TilePreview.kt
+++ b/wear/tiles/tiles-tooling-preview/src/main/java/androidx/wear/tiles/tooling/preview/TilePreview.kt
@@ -16,13 +16,42 @@
package androidx.wear.tiles.tooling.preview
+import android.content.Context
import androidx.annotation.FloatRange
import androidx.wear.tooling.preview.devices.WearDevice
import androidx.wear.tooling.preview.devices.WearDevices
/**
- * The annotation that marks Tile preview components (functions that return [TilePreviewData]) that
- * should have a visual preview in the Android Studio preview panel.
+ * The annotation that marks Tile preview components that should have a visual preview in the
+ * Android Studio preview panel. Tile preview components are methods that take an optional [Context]
+ * parameter and return a [TilePreviewData]. Methods annotated with [TilePreview] must be top level
+ * declarations or in a top level class with a default constructor.
+ *
+ * For example:
+ * ```kotlin
+ * @TilePreview
+ * fun myTilePreview(): TilePreviewData {
+ * return TilePreviewData { request -> myTile(request) }
+ * }
+ * ```
+ * or:
+ * ```kotlin
+ * @TilePreview
+ * fun myTilePreview(context: Context): TilePreviewData {
+ * return TilePreviewData { request -> myTile(request, context) }
+ * }
+ * ```
+ *
+ * Because of the way previews are rendered within Android Studio, they are lightweight and don't
+ * require the whole Android framework to render them. However, this comes with the following
+ * limitations:
+ * * No network access
+ * * No file access
+ * * Some [Context] APIs may not be fully available, such as launching activities or retrieving
+ * services
+ *
+ * For more information, see
+ * https://developer.android.com/jetpack/compose/tooling/previews#preview-limitations
*
* The annotation contains a number of parameters that allow to define the way the Tile will be
* rendered within the preview. The passed parameters are only read by Studio when rendering the
diff --git a/wear/tiles/tiles-tooling-preview/src/main/java/androidx/wear/tiles/tooling/preview/TilePreviewData.kt b/wear/tiles/tiles-tooling-preview/src/main/java/androidx/wear/tiles/tooling/preview/TilePreviewData.kt
index 10f2910..cd36965 100644
--- a/wear/tiles/tiles-tooling-preview/src/main/java/androidx/wear/tiles/tooling/preview/TilePreviewData.kt
+++ b/wear/tiles/tiles-tooling-preview/src/main/java/androidx/wear/tiles/tooling/preview/TilePreviewData.kt
@@ -16,7 +16,6 @@
package androidx.wear.tiles.tooling.preview
-import android.content.Context
import androidx.wear.protolayout.ResourceBuilders.Resources
import androidx.wear.tiles.RequestBuilders.ResourcesRequest
import androidx.wear.tiles.RequestBuilders.TileRequest
@@ -39,10 +38,10 @@
*
* @see [TilePreviewHelper.singleTimelineEntryTileBuilder]
*/
-class TilePreviewData(
- val onTileResourceRequest: (ResourcesRequest, Context) -> Resources =
- { _, _ -> defaultResources },
- val onTileRequest: (TileRequest, Context) -> TileBuilders.Tile,
+class TilePreviewData
+@JvmOverloads constructor(
+ val onTileResourceRequest: (ResourcesRequest) -> Resources = { defaultResources },
+ val onTileRequest: (TileRequest) -> TileBuilders.Tile,
) {
override fun toString(): String {
return "TilePreviewData(onTileResourceRequest=$onTileResourceRequest," +
diff --git a/wear/tiles/tiles-tooling/src/androidTest/java/androidx/wear/tiles/tooling/TestTilePreviews.java b/wear/tiles/tiles-tooling/src/androidTest/java/androidx/wear/tiles/tooling/TestTilePreviews.java
new file mode 100644
index 0000000..7ffe0ac
--- /dev/null
+++ b/wear/tiles/tiles-tooling/src/androidTest/java/androidx/wear/tiles/tooling/TestTilePreviews.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.wear.tiles.tooling;
+
+import static androidx.wear.protolayout.ColorBuilders.argb;
+import static androidx.wear.tiles.tooling.preview.TilePreviewHelper.singleTimelineEntryTileBuilder;
+
+import android.content.Context;
+
+import androidx.wear.protolayout.LayoutElementBuilders.FontStyle;
+import androidx.wear.protolayout.LayoutElementBuilders.Layout;
+import androidx.wear.protolayout.LayoutElementBuilders.LayoutElement;
+import androidx.wear.protolayout.LayoutElementBuilders.Text;
+import androidx.wear.protolayout.ResourceBuilders.Resources;
+import androidx.wear.protolayout.TimelineBuilders.Timeline;
+import androidx.wear.protolayout.TimelineBuilders.TimelineEntry;
+import androidx.wear.tiles.TileBuilders.Tile;
+import androidx.wear.tiles.tooling.preview.TilePreview;
+import androidx.wear.tiles.tooling.preview.TilePreviewData;
+
+public class TestTilePreviews {
+ private static final String RESOURCES_VERSION = "1";
+ private static final Resources RESOURCES = new Resources.Builder().setVersion(
+ RESOURCES_VERSION).build();
+
+ private static LayoutElement layoutElement() {
+ return new Text.Builder()
+ .setText("Hello world!")
+ .setFontStyle(new FontStyle.Builder()
+ .setColor(argb(0xFF000000))
+ .build())
+ .build();
+ }
+
+ private static Layout layout() {
+ return new Layout.Builder()
+ .setRoot(layoutElement())
+ .build();
+ }
+
+ private static Tile tile() {
+ return new Tile.Builder()
+ .setResourcesVersion(RESOURCES_VERSION)
+ .setTileTimeline(new Timeline.Builder()
+ .addTimelineEntry(new TimelineEntry.Builder()
+ .setLayout(layout())
+ .build())
+ .build())
+ .build();
+ }
+
+ /** Declaration of a static tile preview method */
+ @TilePreview
+ public static TilePreviewData tilePreview() {
+ return new TilePreviewData((request) -> RESOURCES, (request) -> tile());
+ }
+
+ @TilePreview
+ static TilePreviewData tileLayoutPreview() {
+ return new TilePreviewData((request) -> singleTimelineEntryTileBuilder(layout()).build());
+ }
+
+ @TilePreview
+ static TilePreviewData tileLayoutElementPreview() {
+ return new TilePreviewData((request) ->
+ singleTimelineEntryTileBuilder(layoutElement()).build());
+ }
+
+ @TilePreview
+ private static TilePreviewData tilePreviewWithPrivateVisibility() {
+ return new TilePreviewData((request) -> tile());
+ }
+
+ static int duplicateFunctionName(int x) {
+ return x;
+ }
+
+ @TilePreview
+ static TilePreviewData duplicateFunctionName() {
+ return new TilePreviewData((request) -> tile());
+ }
+
+ @TilePreview
+ static TilePreviewData tilePreviewWithContextParameter(Context context) {
+ return new TilePreviewData((request) -> tile());
+ }
+
+ @TilePreview
+ static void tilePreviewWithWrongReturnType() {
+ }
+
+ @TilePreview
+ static TilePreviewData tilePreviewWithNonContextParameter(int i) {
+ return new TilePreviewData((request) -> tile());
+ }
+
+ @TilePreview
+ TilePreviewData nonStaticMethod() {
+ return new TilePreviewData((request) -> tile());
+ }
+}
diff --git a/wear/tiles/tiles-tooling/src/androidTest/java/androidx/wear/tiles/tooling/TestTilePreviews.kt b/wear/tiles/tiles-tooling/src/androidTest/java/androidx/wear/tiles/tooling/TestTilePreviews.kt
index 56bdd72..7ed3346 100644
--- a/wear/tiles/tiles-tooling/src/androidTest/java/androidx/wear/tiles/tooling/TestTilePreviews.kt
+++ b/wear/tiles/tiles-tooling/src/androidTest/java/androidx/wear/tiles/tooling/TestTilePreviews.kt
@@ -16,6 +16,7 @@
package androidx.wear.tiles.tooling
+import android.content.Context
import androidx.wear.protolayout.ColorBuilders.argb
import androidx.wear.protolayout.LayoutElementBuilders
import androidx.wear.protolayout.ResourceBuilders
@@ -51,25 +52,41 @@
).build()
@TilePreview
-fun TilePreview() = TilePreviewData(
- onTileResourceRequest = { _, _ -> resources },
- onTileRequest = { _, _ -> tile() },
+fun tilePreview() = TilePreviewData(
+ onTileResourceRequest = { resources },
+ onTileRequest = { tile() },
)
@TilePreview
-fun TileLayoutPreview() = TilePreviewData { _, _ ->
+fun tileLayoutPreview() = TilePreviewData {
singleTimelineEntryTileBuilder(layout()).build()
}
@TilePreview
-fun TileLayoutElementPreview() = TilePreviewData { _, _ ->
+fun tileLayoutElementPreview() = TilePreviewData {
singleTimelineEntryTileBuilder(layoutElement()).build()
}
@TilePreview
-private fun TilePreviewWithPrivateVisibility() = TilePreviewData { _, _ -> tile() }
+private fun tilePreviewWithPrivateVisibility() = TilePreviewData { tile() }
fun duplicateFunctionName(x: Int) = x
@TilePreview
-fun duplicateFunctionName() = TilePreviewData { _, _ -> tile() }
+fun duplicateFunctionName() = TilePreviewData { tile() }
+
+@TilePreview
+fun tilePreviewWithContextParameter(@Suppress("UNUSED_PARAMETER") context: Context) =
+ TilePreviewData { tile() }
+
+@TilePreview
+fun tilePreviewWithWrongReturnType() = Unit
+
+@TilePreview
+fun tilePreviewWithNonContextParameter(@Suppress("UNUSED_PARAMETER") i: Int) =
+ TilePreviewData { tile() }
+
+class SomeClass {
+ @TilePreview
+ fun nonStaticMethod() = TilePreviewData { tile() }
+}
diff --git a/wear/tiles/tiles-tooling/src/androidTest/java/androidx/wear/tiles/tooling/TileServiceViewAdapterTest.kt b/wear/tiles/tiles-tooling/src/androidTest/java/androidx/wear/tiles/tooling/TileServiceViewAdapterTest.kt
index 32605b1..eeb74fc 100644
--- a/wear/tiles/tiles-tooling/src/androidTest/java/androidx/wear/tiles/tooling/TileServiceViewAdapterTest.kt
+++ b/wear/tiles/tiles-tooling/src/androidTest/java/androidx/wear/tiles/tooling/TileServiceViewAdapterTest.kt
@@ -27,10 +27,16 @@
import org.junit.Before
import org.junit.Rule
import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.Parameterized
-private const val TEST_TILE_PREVIEWS_FILE = "androidx.wear.tiles.tooling.TestTilePreviewsKt"
+private const val TEST_TILE_PREVIEWS_KOTLIN_FILE = "androidx.wear.tiles.tooling.TestTilePreviewsKt"
+private const val TEST_TILE_PREVIEWS_JAVA_FILE = "androidx.wear.tiles.tooling.TestTilePreviews"
-class TileServiceViewAdapterTest {
+@RunWith(Parameterized::class)
+class TileServiceViewAdapterTest(
+ private val testFile: String,
+) {
@Suppress("DEPRECATION")
@get:Rule
val activityTestRule = androidx.test.rule.ActivityTestRule(TestActivity::class.java)
@@ -54,70 +60,99 @@
@Test
fun testTilePreview() {
- initAndInflate("$TEST_TILE_PREVIEWS_FILE.TilePreview")
+ initAndInflate("$testFile.tilePreview")
- activityTestRule.runOnUiThread {
- val textView =
- (tileServiceViewAdapter.getChildAt(0) as ViewGroup)
- .getChildAt(0) as TextView
- assertNotNull(textView)
- assertEquals("Hello world!", textView.text.toString())
- }
+ assertThatTileHasInflatedSuccessfully()
}
@Test
fun testTileLayoutPreview() {
- initAndInflate("$TEST_TILE_PREVIEWS_FILE.TileLayoutPreview")
+ initAndInflate("$testFile.tileLayoutPreview")
- activityTestRule.runOnUiThread {
- val textView =
- (tileServiceViewAdapter.getChildAt(0) as ViewGroup)
- .getChildAt(0) as TextView
- assertNotNull(textView)
- assertEquals("Hello world!", textView.text.toString())
- }
+ assertThatTileHasInflatedSuccessfully()
}
@Test
fun testTileLayoutElementPreview() {
- initAndInflate("$TEST_TILE_PREVIEWS_FILE.TileLayoutElementPreview")
+ initAndInflate("$testFile.tileLayoutElementPreview")
- activityTestRule.runOnUiThread {
- val textView =
- ((tileServiceViewAdapter.getChildAt(0) as ViewGroup)
- .getChildAt(0) as FrameLayout).getChildAt(0) as TextView
- assertNotNull(textView)
- assertEquals("Hello world!", textView.text.toString())
- }
+ assertThatTileHasInflatedSuccessfully()
}
@Test
fun testTilePreviewDeclaredWithPrivateMethod() {
- initAndInflate("$TEST_TILE_PREVIEWS_FILE.TilePreviewWithPrivateVisibility")
+ initAndInflate("$testFile.tilePreviewWithPrivateVisibility")
- activityTestRule.runOnUiThread {
- val textView =
- (tileServiceViewAdapter.getChildAt(0) as ViewGroup)
- .getChildAt(0) as TextView
- assertNotNull(textView)
- assertEquals("Hello world!", textView.text.toString())
- }
+ assertThatTileHasInflatedSuccessfully()
}
@Test
fun testTilePreviewThatHasSharedFunctionName() {
- initAndInflate("$TEST_TILE_PREVIEWS_FILE.duplicateFunctionName")
+ initAndInflate("$testFile.duplicateFunctionName")
+ assertThatTileHasInflatedSuccessfully()
+ }
+
+ @Test
+ fun testTilePreviewWithContextParameter() {
+ initAndInflate("$testFile.tilePreviewWithContextParameter")
+
+ assertThatTileHasInflatedSuccessfully()
+ }
+
+ @Test
+ fun testTileWithWrongReturnTypeIsNotInflated() {
+ initAndInflate("$testFile.tilePreviewWithWrongReturnType")
+
+ assertThatTileHasNotInflated()
+ }
+
+ @Test
+ fun testTilePreviewWithNonContextParameterIsNotInflated() {
+ initAndInflate("$testFile.tilePreviewWithNonContextParameter")
+
+ assertThatTileHasNotInflated()
+ }
+
+ @Test
+ fun testNonStaticPreviewMethodWithDefaultConstructor() {
+ if (testFile == TEST_TILE_PREVIEWS_KOTLIN_FILE) {
+ initAndInflate("androidx.wear.tiles.tooling.SomeClass.nonStaticMethod")
+ } else {
+ initAndInflate("$testFile.nonStaticMethod")
+ }
+
+ assertThatTileHasInflatedSuccessfully()
+ }
+
+ private fun assertThatTileHasInflatedSuccessfully() {
activityTestRule.runOnUiThread {
- val textView =
- (tileServiceViewAdapter.getChildAt(0) as ViewGroup)
- .getChildAt(0) as TextView
+ val textView = when (
+ val child = (tileServiceViewAdapter.getChildAt(0) as ViewGroup).getChildAt(0)
+ ) {
+ is TextView -> child
+ // layout elements are wrapped with a FrameLayout
+ else -> (child as? FrameLayout)?.getChildAt(0) as? TextView
+ }
assertNotNull(textView)
- assertEquals("Hello world!", textView.text.toString())
+ assertEquals("Hello world!", textView?.text.toString())
+ }
+ }
+
+ private fun assertThatTileHasNotInflated() {
+ activityTestRule.runOnUiThread {
+ assertEquals(0, tileServiceViewAdapter.childCount)
}
}
companion object {
+ @Parameterized.Parameters
+ @JvmStatic
+ fun parameters() = listOf(
+ TEST_TILE_PREVIEWS_KOTLIN_FILE,
+ TEST_TILE_PREVIEWS_JAVA_FILE,
+ )
+
class TestActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
diff --git a/wear/tiles/tiles-tooling/src/main/java/androidx/wear/tiles/tooling/TileServiceViewAdapter.kt b/wear/tiles/tiles-tooling/src/main/java/androidx/wear/tiles/tooling/TileServiceViewAdapter.kt
index e8a1a9c..d9e6909 100644
--- a/wear/tiles/tiles-tooling/src/main/java/androidx/wear/tiles/tooling/TileServiceViewAdapter.kt
+++ b/wear/tiles/tiles-tooling/src/main/java/androidx/wear/tiles/tooling/TileServiceViewAdapter.kt
@@ -32,6 +32,7 @@
import androidx.wear.tiles.timeline.TilesTimelineCache
import androidx.wear.tiles.tooling.preview.TilePreviewData
import java.lang.reflect.Method
+import java.lang.reflect.Modifier
import kotlin.math.roundToInt
private const val TOOLS_NS_URI = "http://schemas.android.com/tools"
@@ -77,7 +78,7 @@
}
internal fun init(tilePreviewMethodFqn: String) {
- val tilePreview = getTilePreview(tilePreviewMethodFqn)
+ val tilePreview = getTilePreview(tilePreviewMethodFqn) ?: return
lateinit var tileRenderer: TileRenderer
tileRenderer = TileRenderer(context, executor) { newState ->
tileRenderer.previewTile(tilePreview, newState)
@@ -98,7 +99,7 @@
.setDeviceConfiguration(deviceParams)
.build()
- val tile = tilePreview.onTileRequest(tileRequest, context).also { tile ->
+ val tile = tilePreview.onTileRequest(tileRequest).also { tile ->
tile.state?.let { setState(it.keyToValueMapping) }
}
val layout = tile.tileTimeline?.getCurrentLayout() ?: return
@@ -107,7 +108,7 @@
.setDeviceConfiguration(deviceParams)
.setVersion(tile.resourcesVersion)
.build()
- val resources = tilePreview.onTileResourceRequest(resourcesRequest, context)
+ val resources = tilePreview.onTileResourceRequest(resourcesRequest)
val inflateFuture = inflateAsync(layout, resources, this@TileServiceViewAdapter)
inflateFuture.addListener({
@@ -116,20 +117,36 @@
}
}, executor)
}
-}
-@SuppressLint("BanUncheckedReflection")
-internal fun getTilePreview(tilePreviewMethodFqn: String): TilePreviewData {
- val className = tilePreviewMethodFqn.substringBeforeLast('.')
- val methodName = tilePreviewMethodFqn.substringAfterLast('.')
+ @SuppressLint("BanUncheckedReflection")
+ internal fun getTilePreview(tilePreviewMethodFqn: String): TilePreviewData? {
+ val className = tilePreviewMethodFqn.substringBeforeLast('.')
+ val methodName = tilePreviewMethodFqn.substringAfterLast('.')
- val method = Class.forName(className).declaredMethods.first {
- it.name == methodName && it.parameterCount == 0
- }.apply {
- isAccessible = true
+ val methods = Class.forName(className).declaredMethods.filter { it.name == methodName }
+ methods.firstOrNull {
+ it.parameterCount == 1 && it.parameters.first().type == Context::class.java
+ }?.let { methodWithContextParameter ->
+ return invokeTilePreviewMethod(methodWithContextParameter, context)
+ }
+
+ return methods.firstOrNull {
+ it.name == methodName && it.parameterCount == 0
+ }?.let { methodWithoutContextParameter ->
+ return invokeTilePreviewMethod(methodWithoutContextParameter)
+ }
}
- return method.invoke(null) as TilePreviewData
+ @SuppressLint("BanUncheckedReflection")
+ private fun invokeTilePreviewMethod(method: Method, vararg args: Any?): TilePreviewData? {
+ method.isAccessible = true
+ return if (Modifier.isStatic(method.modifiers)) {
+ method.invoke(null, *args) as? TilePreviewData
+ } else {
+ val instance = method.declaringClass.getConstructor().newInstance()
+ method.invoke(instance, *args) as? TilePreviewData
+ }
+ }
}
internal fun TimelineBuilders.Timeline?.getCurrentLayout(): LayoutElementBuilders.Layout? {
diff --git a/wear/watchface/watchface-style/src/main/java/androidx/wear/watchface/style/CurrentUserStyleRepository.kt b/wear/watchface/watchface-style/src/main/java/androidx/wear/watchface/style/CurrentUserStyleRepository.kt
index 33b865a..4a563e0 100644
--- a/wear/watchface/watchface-style/src/main/java/androidx/wear/watchface/style/CurrentUserStyleRepository.kt
+++ b/wear/watchface/watchface-style/src/main/java/androidx/wear/watchface/style/CurrentUserStyleRepository.kt
@@ -722,6 +722,15 @@
mutableUserStyle.value = newUserStyle
}
+ /** Sets the user style, and returns a restoration function. */
+ @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
+ public fun updateUserStyleForScreenshot(newUserStyle: UserStyle): AutoCloseable {
+ val originalStyle = userStyle.value
+ updateUserStyle(newUserStyle)
+ // Avoid overwriting a change made by someone else.
+ return AutoCloseable { mutableUserStyle.compareAndSet(newUserStyle, originalStyle) }
+ }
+
@Suppress("Deprecation") // userStyleSettings
internal fun validateUserStyle(userStyle: UserStyle) {
for ((key, value) in userStyle) {
diff --git a/wear/watchface/watchface/src/main/java/androidx/wear/watchface/ComplicationSlot.kt b/wear/watchface/watchface/src/main/java/androidx/wear/watchface/ComplicationSlot.kt
index e8f57d7..f186e83 100644
--- a/wear/watchface/watchface/src/main/java/androidx/wear/watchface/ComplicationSlot.kt
+++ b/wear/watchface/watchface/src/main/java/androidx/wear/watchface/ComplicationSlot.kt
@@ -1038,19 +1038,35 @@
* Sets the current [ComplicationData] and if it's a timeline, the correct override for
* [instant] is chosen. Any images are loaded synchronously. The complication history is not
* updated.
+ *
+ * Returns a restoration function.
*/
internal fun setComplicationDataForScreenshot(
complicationData: ComplicationData,
instant: Instant
- ) {
- lastComplicationUpdate = instant
- timelineComplicationData = complicationData
- timelineEntries = complicationData.asWireComplicationData().timelineEntries?.toList()
- selectComplicationDataForInstant(
- instant,
- loadDrawablesAsynchronous = false,
- forceUpdate = true
- )
+ ): AutoCloseable {
+ val originalComplicationData = timelineComplicationData
+ val originalInstant = lastComplicationUpdate
+ val restore = AutoCloseable {
+ // Avoid overwriting a change made by someone else, can still race.
+ if (timelineComplicationData !== complicationData) return@AutoCloseable
+ setComplicationDataForScreenshot(originalComplicationData, originalInstant)
+ }
+ try {
+ lastComplicationUpdate = instant
+ timelineComplicationData = complicationData
+ timelineEntries = complicationData.asWireComplicationData().timelineEntries?.toList()
+ selectComplicationDataForInstant(
+ instant,
+ loadDrawablesAsynchronous = false,
+ forceUpdate = true
+ )
+ } catch (e: Throwable) {
+ // Cleanup on failure.
+ restore.close()
+ throw e
+ }
+ return restore
}
/**
diff --git a/wear/watchface/watchface/src/main/java/androidx/wear/watchface/ComplicationSlotsManager.kt b/wear/watchface/watchface/src/main/java/androidx/wear/watchface/ComplicationSlotsManager.kt
index 22d34a0..a406dfb 100644
--- a/wear/watchface/watchface/src/main/java/androidx/wear/watchface/ComplicationSlotsManager.kt
+++ b/wear/watchface/watchface/src/main/java/androidx/wear/watchface/ComplicationSlotsManager.kt
@@ -331,24 +331,36 @@
}
/**
- * For use by screen shot code which will reset the data afterwards, hence dirty bit not set.
+ * Sets complication data, returning a restoration function.
+ *
+ * As this is used for screen shots, dirty bit (used for content description) is not set.
*/
@UiThread
- internal fun setComplicationDataUpdateForScreenshot(
- complicationSlotId: Int,
- data: ComplicationData,
- instant: Instant
- ) {
- val complication = complicationSlots[complicationSlotId]
- if (complication == null) {
- Log.e(
- TAG,
- "setComplicationDataUpdateSync failed due to invalid complicationSlotId=" +
- "$complicationSlotId with data=$data"
- )
- return
+ internal fun setComplicationDataForScreenshot(
+ slotIdToData: Map<Int, ComplicationData>,
+ instant: Instant,
+ ): AutoCloseable {
+ val restores = mutableListOf<AutoCloseable>()
+ val restore = AutoCloseable { restores.forEach(AutoCloseable::close) }
+ try {
+ for ((id, data) in slotIdToData) {
+ val slot = complicationSlots[id]
+ if (slot == null) {
+ Log.e(
+ TAG,
+ "setComplicationDataForScreenshot failed due to invalid " +
+ "complicationSlotId=$id with data=$data"
+ )
+ continue
+ }
+ restores.add(slot.setComplicationDataForScreenshot(data, instant))
+ }
+ } catch (e: Throwable) {
+ // Cleanup changes on failure.
+ restore.close()
+ throw e
}
- complication.setComplicationDataForScreenshot(data, instant)
+ return restore
}
/**
diff --git a/wear/watchface/watchface/src/main/java/androidx/wear/watchface/WatchFace.kt b/wear/watchface/watchface/src/main/java/androidx/wear/watchface/WatchFace.kt
index 74af498..270373f 100644
--- a/wear/watchface/watchface/src/main/java/androidx/wear/watchface/WatchFace.kt
+++ b/wear/watchface/watchface/src/main/java/androidx/wear/watchface/WatchFace.kt
@@ -665,27 +665,30 @@
internal var nextDrawTimeMillis: Long = 0
internal val componentName = watchFaceHostApi.getComponentName()
+ private val displayManager: DisplayManager
+ private val displayListener: DisplayManager.DisplayListener
init {
val context = watchFaceHostApi.getContext()
- val displayManager = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
- displayManager.registerDisplayListener(
- object : DisplayManager.DisplayListener {
- override fun onDisplayAdded(displayId: Int) {}
+ displayManager = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
+ displayListener = object : DisplayManager.DisplayListener {
+ override fun onDisplayAdded(displayId: Int) {}
- override fun onDisplayChanged(displayId: Int) {
- val display = displayManager.getDisplay(Display.DEFAULT_DISPLAY)!!
- if (display.state == Display.STATE_OFF && watchState.isVisible.value == false) {
- // We want to avoid a glimpse of a stale time when transitioning from
- // hidden to visible, so we render two black frames to clear the buffers
- // when the display has been turned off and the watch is not visible.
- renderer.renderBlackFrame()
- renderer.renderBlackFrame()
- }
+ override fun onDisplayChanged(displayId: Int) {
+ val display = displayManager.getDisplay(Display.DEFAULT_DISPLAY)!!
+ if (display.state == Display.STATE_OFF && watchState.isVisible.value == false) {
+ // We want to avoid a glimpse of a stale time when transitioning from
+ // hidden to visible, so we render two black frames to clear the buffers
+ // when the display has been turned off and the watch is not visible.
+ renderer.renderBlackFrame()
+ renderer.renderBlackFrame()
}
+ }
- override fun onDisplayRemoved(displayId: Int) {}
- },
+ override fun onDisplayRemoved(displayId: Int) {}
+ }
+ displayManager.registerDisplayListener(
+ displayListener,
watchFaceHostApi.getUiThreadHandler()
)
}
@@ -905,37 +908,14 @@
slotIdToComplicationData: Map<Int, ComplicationData>?
): Bitmap =
TraceEvent("WFEditorDelegate.takeScreenshot").use {
- val oldComplicationData =
- complicationSlotsManager.complicationSlots.values.associateBy(
- { it.id },
- { it.renderer.getData() }
- )
-
- slotIdToComplicationData?.let {
- for ((id, complicationData) in it) {
- complicationSlotsManager.setComplicationDataUpdateForScreenshot(
- id,
- complicationData,
- instant
+ slotIdToComplicationData
+ ?.let { complicationSlotsManager.setComplicationDataForScreenshot(it, instant) }
+ .use {
+ renderer.takeScreenshot(
+ ZonedDateTime.ofInstant(instant, ZoneId.of("UTC")),
+ renderParameters
)
}
- }
- val screenShot =
- renderer.takeScreenshot(
- ZonedDateTime.ofInstant(instant, ZoneId.of("UTC")),
- renderParameters
- )
- slotIdToComplicationData?.let {
- val now = getNow()
- for ((id, complicationData) in oldComplicationData) {
- complicationSlotsManager.setComplicationDataUpdateForScreenshot(
- id,
- complicationData,
- now
- )
- }
- }
- return screenShot
}
override fun setComplicationSlotConfigExtrasChangeCallback(
@@ -963,6 +943,7 @@
WatchFace.unregisterEditorDelegate(componentName)
}
unregisterReceivers()
+ displayManager.unregisterDisplayListener(displayListener)
}
@UiThread
@@ -1178,57 +1159,26 @@
@RequiresApi(27)
internal fun renderWatchFaceToBitmap(params: WatchFaceRenderParams): Bundle =
TraceEvent("WatchFaceImpl.renderWatchFaceToBitmap").use {
- val oldStyle = currentUserStyleRepository.userStyle.value
val instant = Instant.ofEpochMilli(params.calendarTimeMillis)
-
- params.userStyle?.let {
- currentUserStyleRepository.updateUserStyle(
- UserStyle(UserStyleData(it), currentUserStyleRepository.schema)
- )
- }
-
- val oldComplicationData =
- complicationSlotsManager.complicationSlots.values.associateBy(
- { it.id },
- { it.renderer.getData() }
- )
-
- params.idAndComplicationDatumWireFormats?.let {
- for (idAndData in it) {
- complicationSlotsManager.setComplicationDataUpdateForScreenshot(
- idAndData.id,
- idAndData.complicationData.toApiComplicationData(),
+ val bitmap =
+ setForScreenshot(
+ params.userStyle?.let {
+ UserStyle(UserStyleData(it), currentUserStyleRepository.schema)
+ },
+ params.idAndComplicationDatumWireFormats?.let { idAndData ->
+ idAndData.associate {
+ it.id to it.complicationData.toApiComplicationData()
+ }
+ },
instant
)
- }
- }
-
- val bitmap =
- renderer.takeScreenshot(
- ZonedDateTime.ofInstant(instant, ZoneId.of("UTC")),
- RenderParameters(params.renderParametersWireFormat)
- )
-
- // No point in restoring the old style and complication if this is headless.
- if (!watchState.isHeadless) {
- // Restore previous style & complicationSlots if required.
- if (params.userStyle != null) {
- currentUserStyleRepository.updateUserStyle(oldStyle)
- }
-
- if (params.idAndComplicationDatumWireFormats != null) {
- val now = getNow()
- for ((id, complicationData) in oldComplicationData) {
- complicationSlotsManager.setComplicationDataUpdateForScreenshot(
- id,
- complicationData,
- now
+ .use {
+ renderer.takeScreenshot(
+ ZonedDateTime.ofInstant(instant, ZoneId.of("UTC")),
+ RenderParameters(params.renderParametersWireFormat)
)
}
- }
- }
-
- return SharedMemoryImage.ashmemWriteImageBundle(bitmap)
+ SharedMemoryImage.ashmemWriteImageBundle(bitmap)
}
@UiThread
@@ -1255,102 +1205,94 @@
@RequiresApi(27)
internal fun renderComplicationToBitmap(params: ComplicationRenderParams): Bundle? =
TraceEvent("WatchFaceImpl.renderComplicationToBitmap").use {
- val zonedDateTime =
- ZonedDateTime.ofInstant(
- Instant.ofEpochMilli(params.calendarTimeMillis),
- ZoneId.of("UTC")
+ val slot = complicationSlotsManager[params.complicationSlotId] ?: return@use null
+ setForScreenshot(
+ params.userStyle?.let {
+ UserStyle(UserStyleData(it), currentUserStyleRepository.schema)
+ },
+ params.complicationData?.let {
+ mapOf(params.complicationSlotId to it.toApiComplicationData())
+ },
+ Instant.ofEpochMilli(params.calendarTimeMillis)
)
- return complicationSlotsManager[params.complicationSlotId]?.let {
- val oldStyle = currentUserStyleRepository.userStyle.value
- val instant = Instant.ofEpochMilli(params.calendarTimeMillis)
-
- val newStyle = params.userStyle
- if (newStyle != null) {
- currentUserStyleRepository.updateUserStyle(
- UserStyle(UserStyleData(newStyle), currentUserStyleRepository.schema)
- )
- }
-
- // Compute the bounds of the complication based on the display rather than
- // the headless renderer (which may be smaller).
- val bounds =
- it.computeBounds(
- Rect(
- 0,
- 0,
- Resources.getSystem().displayMetrics.widthPixels,
- Resources.getSystem().displayMetrics.heightPixels
+ .use {
+ val zonedDateTime =
+ ZonedDateTime.ofInstant(
+ Instant.ofEpochMilli(params.calendarTimeMillis),
+ ZoneId.of("UTC")
)
- )
-
- var prevData: ComplicationData? = null
- val screenshotComplicationData = params.complicationData
- if (screenshotComplicationData != null) {
- prevData = it.renderer.getData()
- complicationSlotsManager.setComplicationDataUpdateForScreenshot(
- params.complicationSlotId,
- screenshotComplicationData.toApiComplicationData(),
- instant
- )
- }
-
- val complicationBitmap: Bitmap
- val picture = Picture()
- if (Build.VERSION.SDK_INT >= 28) {
- it.renderer.render(
- picture.beginRecording(bounds.width(), bounds.height()),
- Rect(0, 0, bounds.width(), bounds.height()),
- zonedDateTime,
- RenderParameters(params.renderParametersWireFormat),
- params.complicationSlotId
- )
- picture.endRecording()
- complicationBitmap =
- Api28CreateBitmapHelper.createBitmap(
- picture,
- bounds.width(),
- bounds.height(),
- Bitmap.Config.ARGB_8888
+ // Compute the bounds of the complication based on the display rather than
+ // the headless renderer (which may be smaller).
+ val bounds =
+ slot.computeBounds(
+ Rect(
+ 0,
+ 0,
+ Resources.getSystem().displayMetrics.widthPixels,
+ Resources.getSystem().displayMetrics.heightPixels
+ )
)
- } else {
- complicationBitmap =
- Bitmap.createBitmap(
- bounds.width(),
- bounds.height(),
- Bitmap.Config.ARGB_8888
- )
- it.renderer.render(
- Canvas(complicationBitmap),
- Rect(0, 0, bounds.width(), bounds.height()),
- zonedDateTime,
- RenderParameters(params.renderParametersWireFormat),
- params.complicationSlotId
- )
- }
- // No point in restoring the old style and complication if this is headless.
- if (!watchState.isHeadless) {
- // Restore previous ComplicationData & style if required.
- if (prevData != null) {
- val now = getNow()
- complicationSlotsManager.setComplicationDataUpdateForScreenshot(
- params.complicationSlotId,
- prevData,
- now
+ val complicationBitmap: Bitmap
+ val picture = Picture()
+ if (Build.VERSION.SDK_INT >= 28) {
+ slot.renderer.render(
+ picture.beginRecording(bounds.width(), bounds.height()),
+ Rect(0, 0, bounds.width(), bounds.height()),
+ zonedDateTime,
+ RenderParameters(params.renderParametersWireFormat),
+ params.complicationSlotId
+ )
+ picture.endRecording()
+ complicationBitmap =
+ Api28CreateBitmapHelper.createBitmap(
+ picture,
+ bounds.width(),
+ bounds.height(),
+ Bitmap.Config.ARGB_8888
+ )
+ } else {
+ complicationBitmap =
+ Bitmap.createBitmap(
+ bounds.width(),
+ bounds.height(),
+ Bitmap.Config.ARGB_8888
+ )
+ slot.renderer.render(
+ Canvas(complicationBitmap),
+ Rect(0, 0, bounds.width(), bounds.height()),
+ zonedDateTime,
+ RenderParameters(params.renderParametersWireFormat),
+ params.complicationSlotId
)
}
-
- if (newStyle != null) {
- currentUserStyleRepository.updateUserStyle(oldStyle)
- }
+ val bundle = SharedMemoryImage.ashmemWriteImageBundle(complicationBitmap)
+ complicationBitmap.recycle()
+ bundle
}
-
- val bundle = SharedMemoryImage.ashmemWriteImageBundle(complicationBitmap)
- complicationBitmap.recycle()
- bundle
- }
}
+ /** Sets the user style and complication data, and returns a restoration function. */
+ internal fun setForScreenshot(
+ userStyle: UserStyle?,
+ complicationIdToData: Map<Int, ComplicationData>?,
+ instant: Instant,
+ ): AutoCloseable {
+ val restoreUserStyle =
+ userStyle?.let { currentUserStyleRepository.updateUserStyleForScreenshot(it) }
+ try {
+ val restoreComplications =
+ complicationIdToData?.let {
+ complicationSlotsManager.setComplicationDataForScreenshot(it, instant)
+ }
+ return AutoCloseable { restoreUserStyle?.use { restoreComplications?.close() } }
+ } catch (e: Throwable) {
+ // Cleanup on failure.
+ restoreUserStyle?.close()
+ throw e
+ }
+ }
+
@UiThread
internal fun dump(writer: IndentingPrintWriter) {
writer.println("WatchFaceImpl ($componentName): ")
@@ -1417,52 +1359,27 @@
return RemoteWatchFaceView(view, host, watchFaceHostApi.getUiThreadCoroutineScope()) {
surfaceHolder,
params ->
- val oldStyle = watchFaceImpl.currentUserStyleRepository.userStyle.value
val instant = Instant.ofEpochMilli(params.calendarTimeMillis)
-
- params.userStyle?.let {
- watchFaceImpl.currentUserStyleRepository.updateUserStyle(
- UserStyle(UserStyleData(it), watchFaceImpl.currentUserStyleRepository.schema)
+ watchFaceImpl
+ .setForScreenshot(
+ params.userStyle?.let {
+ UserStyle(
+ UserStyleData(it),
+ watchFaceImpl.currentUserStyleRepository.schema
+ )
+ },
+ params.idAndComplicationDatumWireFormats?.associate {
+ it.id to it.complicationData.toApiComplicationData()
+ },
+ instant
)
- }
-
- val oldComplicationData =
- watchFaceImpl.complicationSlotsManager.complicationSlots.values.associateBy(
- { it.id },
- { it.renderer.getData() }
- )
-
- params.idAndComplicationDatumWireFormats?.let {
- for (idAndData in it) {
- watchFaceImpl.complicationSlotsManager.setComplicationDataUpdateForScreenshot(
- idAndData.id,
- idAndData.complicationData.toApiComplicationData(),
- instant
+ .use {
+ watchFaceImpl.renderer.renderScreenshotToSurface(
+ ZonedDateTime.ofInstant(instant, ZoneId.of("UTC")),
+ RenderParameters(params.renderParametersWireFormat),
+ surfaceHolder
)
}
- }
-
- watchFaceImpl.renderer.renderScreenshotToSurface(
- ZonedDateTime.ofInstant(instant, ZoneId.of("UTC")),
- RenderParameters(params.renderParametersWireFormat),
- surfaceHolder
- )
-
- // Restore previous style & complicationSlots if required.
- if (params.userStyle != null) {
- watchFaceImpl.currentUserStyleRepository.updateUserStyle(oldStyle)
- }
-
- if (params.idAndComplicationDatumWireFormats != null) {
- val now = watchFaceImpl.getNow()
- for ((id, complicationData) in oldComplicationData) {
- watchFaceImpl.complicationSlotsManager.setComplicationDataUpdateForScreenshot(
- id,
- complicationData,
- now
- )
- }
- }
}
}
}
diff --git a/wear/watchface/watchface/src/test/java/androidx/wear/watchface/WatchFaceServiceTest.kt b/wear/watchface/watchface/src/test/java/androidx/wear/watchface/WatchFaceServiceTest.kt
index f131d12..e2caf60 100644
--- a/wear/watchface/watchface/src/test/java/androidx/wear/watchface/WatchFaceServiceTest.kt
+++ b/wear/watchface/watchface/src/test/java/androidx/wear/watchface/WatchFaceServiceTest.kt
@@ -57,6 +57,7 @@
import androidx.wear.watchface.complications.ComplicationSlotBounds
import androidx.wear.watchface.complications.DefaultComplicationDataSourcePolicy
import androidx.wear.watchface.complications.SystemDataSources
+import androidx.wear.watchface.complications.data.ComplicationData
import androidx.wear.watchface.complications.data.ComplicationDisplayPolicies
import androidx.wear.watchface.complications.data.ComplicationExperimental
import androidx.wear.watchface.complications.data.ComplicationPersistencePolicies
@@ -2860,12 +2861,9 @@
@Test
@Config(sdk = [Build.VERSION_CODES.O_MR1])
public fun updateComplicationData_appendsToHistory() {
- initWallpaperInteractiveWatchFaceInstance(
- complicationSlots = listOf(leftComplication)
- )
+ initWallpaperInteractiveWatchFaceInstance(complicationSlots = listOf(leftComplication))
// Validate that the history is initially empty.
- assertThat(leftComplication.complicationHistory!!.iterator().asSequence().toList())
- .isEmpty()
+ assertThat(leftComplication.complicationHistory!!).isEmpty()
val longTextComplication =
WireComplicationData.Builder(WireComplicationData.TYPE_LONG_TEXT)
.setLongText(WireComplicationText.plainText("TYPE_LONG_TEXT"))
@@ -2875,28 +2873,78 @@
listOf(IdAndComplicationDataWireFormat(LEFT_COMPLICATION_ID, longTextComplication))
)
- assertThat(leftComplication.complicationHistory.toList().map { it.complicationData })
+ assertThat(leftComplication.complicationHistory.map { it.complicationData })
.containsExactly(longTextComplication.toApiComplicationData())
}
@Test
@Config(sdk = [Build.VERSION_CODES.O_MR1])
- public fun setComplicationDataUpdateForScreenshot_doesNotAppendToHistory() {
- initWallpaperInteractiveWatchFaceInstance(
- complicationSlots = listOf(leftComplication)
- )
-
- complicationSlotsManager.setComplicationDataUpdateForScreenshot(
- LEFT_COMPLICATION_ID,
+ public fun setComplicationDataUpdateForScreenshot_restoresAndDoesNotChangeHistoryOrDirtyFlag() {
+ // Arrange
+ val firstTimelineData: ComplicationData =
WireComplicationData.Builder(WireComplicationData.TYPE_LONG_TEXT)
- .setLongText(WireComplicationText.plainText("TYPE_LONG_TEXT"))
+ .setLongText(WireComplicationText.plainText("first timeline data"))
.build()
- .toApiComplicationData(),
- Instant.now()
+ .also {
+ it.timelineStartEpochSecond = 1000L
+ it.timelineEndEpochSecond = 2000L
+ }
+ .toApiComplicationData()
+ val secondTimelineData: ComplicationData =
+ WireComplicationData.Builder(WireComplicationData.TYPE_LONG_TEXT)
+ .setLongText(WireComplicationText.plainText("second timeline data"))
+ .build()
+ .also {
+ it.timelineStartEpochSecond = 2000L
+ it.timelineEndEpochSecond = 3000L
+ }
+ .toApiComplicationData()
+ val wrapperTimelineData: ComplicationData =
+ WireComplicationData.Builder(WireComplicationData.TYPE_NO_DATA)
+ .build()
+ .also {
+ it.timelineStartEpochSecond = 0L
+ it.timelineEndEpochSecond = 1000L
+ it.setTimelineEntryCollection(
+ listOf(
+ firstTimelineData.asWireComplicationData(),
+ secondTimelineData.asWireComplicationData(),
+ )
+ )
+ }
+ .toApiComplicationData()
+ val screenshotData: ComplicationData =
+ WireComplicationData.Builder(WireComplicationData.TYPE_LONG_TEXT)
+ .setLongText(WireComplicationText.plainText("screenshot"))
+ .build()
+ .toApiComplicationData()
+ initWallpaperInteractiveWatchFaceInstance(complicationSlots = listOf(leftComplication))
+ complicationSlotsManager.onComplicationDataUpdate(
+ leftComplication.id,
+ wrapperTimelineData,
+ Instant.ofEpochSecond(1000)
)
+ leftComplication.dataDirty = false
- assertThat(leftComplication.complicationHistory!!.iterator().asSequence().toList())
- .isEmpty()
+ // Act
+ val actualScreenshotData =
+ complicationSlotsManager
+ .setComplicationDataForScreenshot(
+ mapOf(LEFT_COMPLICATION_ID to screenshotData),
+ Instant.ofEpochSecond(4000) // Also restored.
+ )
+ .use { leftComplication.complicationData.value }
+
+ // Assert
+ assertThat(actualScreenshotData).isEqualTo(screenshotData)
+ assertThat(leftComplication.complicationData.value).isEqualTo(firstTimelineData)
+ // History and dirty flag unchanged for screenshots
+ assertThat(leftComplication.complicationHistory!!.map { it.complicationData })
+ .containsExactly(wrapperTimelineData)
+ assertThat(leftComplication.dataDirty).isFalse()
+ // Timeline preserved
+ complicationSlotsManager.selectComplicationDataForInstant(Instant.ofEpochSecond(2000L))
+ assertThat(leftComplication.complicationData.value).isEqualTo(secondTimelineData)
}
@Test