Convert MethodCallsLogger to Kotlin
Part of the kotlin conversion process for the Lifecycle library.
RelNote: "`MethodCallsLogger` is now in Kotlin"
Test: ./gradlew checkApi
Bug: 240298691
Change-Id: Ibb2b3c3c6bd4e2437851bf3ff0058ebf3d810867
diff --git a/lifecycle/lifecycle-common/api/restricted_current.txt b/lifecycle/lifecycle-common/api/restricted_current.txt
index 86f017b..e8ec1e4 100644
--- a/lifecycle/lifecycle-common/api/restricted_current.txt
+++ b/lifecycle/lifecycle-common/api/restricted_current.txt
@@ -65,7 +65,7 @@
@RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public class MethodCallsLogger {
ctor public MethodCallsLogger();
- method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public boolean approveCall(String, int);
+ method @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public boolean approveCall(String name, int type);
}
@Deprecated @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @java.lang.annotation.Target(java.lang.annotation.ElementType.METHOD) public @interface OnLifecycleEvent {
diff --git a/lifecycle/lifecycle-common/src/main/java/androidx/lifecycle/MethodCallsLogger.kt b/lifecycle/lifecycle-common/src/main/java/androidx/lifecycle/MethodCallsLogger.kt
index d72a3ac..c14c15e 100644
--- a/lifecycle/lifecycle-common/src/main/java/androidx/lifecycle/MethodCallsLogger.kt
+++ b/lifecycle/lifecycle-common/src/main/java/androidx/lifecycle/MethodCallsLogger.kt
@@ -13,31 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package androidx.lifecycle
-package androidx.lifecycle;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.RestrictTo;
-
-import java.util.HashMap;
-import java.util.Map;
+import androidx.annotation.RestrictTo
/**
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
-public class MethodCallsLogger {
- private Map<String, Integer> mCalledMethods = new HashMap<>();
+public open class MethodCallsLogger() {
+ private val calledMethods: MutableMap<String, Int> = HashMap()
/**
* @hide
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
- public boolean approveCall(@NonNull String name, int type) {
- Integer nullableMask = mCalledMethods.get(name);
- int mask = nullableMask != null ? nullableMask : 0;
- boolean wasCalled = (mask & type) != 0;
- mCalledMethods.put(name, mask | type);
- return !wasCalled;
+ public open fun approveCall(name: String, type: Int): Boolean {
+ val nullableMask = calledMethods[name]
+ val mask = nullableMask ?: 0
+ val wasCalled = mask and type != 0
+ calledMethods[name] = mask or type
+ return !wasCalled
}
-}
+}
\ No newline at end of file