From 95909e314061c94b6852fc8828d5f58b083c9f4e Mon Sep 17 00:00:00 2001 From: "Travis.Cobbs" <77415528+tcobbs-bentley@users.noreply.github.com> Date: Mon, 11 Mar 2024 14:38:33 -0700 Subject: [PATCH] Updates so detektDebug passes --- .../com/github/itwin/mobilesdk/Extensions.kt | 4 ++-- .../com/github/itwin/mobilesdk/ITMActionable.kt | 2 +- .../java/com/github/itwin/mobilesdk/ITMAlert.kt | 9 +++------ .../itwin/mobilesdk/jsonvalue/JSONValue.kt | 16 ++++++++-------- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/Extensions.kt b/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/Extensions.kt index a2d3b38..8c59061 100644 --- a/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/Extensions.kt +++ b/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/Extensions.kt @@ -86,7 +86,7 @@ fun Map.getOptionalDouble(key: K) = * `null`. */ inline fun Map<*,*>.checkEntriesAre(): Map? = - this.takeIf { + this.takeIf { _ -> all { it.key is K && it.value is V } }?.let { @Suppress("UNCHECKED_CAST") @@ -107,7 +107,7 @@ inline fun Map<*,*>.ensureEntriesAre(): Map List<*>.checkItemsAre(): List? = - this.takeIf { + this.takeIf { _ -> all { it is T } }?.let { @Suppress("UNCHECKED_CAST") diff --git a/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/ITMActionable.kt b/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/ITMActionable.kt index e2b4acc..2935a81 100644 --- a/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/ITMActionable.kt +++ b/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/ITMActionable.kt @@ -58,7 +58,7 @@ abstract class ITMActionable(nativeUI: ITMNativeUI): ITMNativeUIComponent(native style?.takeIf { it.isNotEmpty() }?.let { - Style.valueOf(style.replaceFirstChar { it.uppercase() }) + Style.valueOf(it.replaceFirstChar { char -> char.uppercase() }) } ?: Default } } diff --git a/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/ITMAlert.kt b/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/ITMAlert.kt index 3162e71..cc36225 100644 --- a/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/ITMAlert.kt +++ b/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/ITMAlert.kt @@ -21,17 +21,14 @@ class ITMAlert(nativeUI: ITMNativeUI): ITMActionable(nativeUI) { handler = coMessenger.registerQueryHandler("Bentley_ITM_presentAlert", ::handleQuery) } - private fun toAlertActionsOrItems(actions: List): Pair, MutableList?> { + private fun toAlertActionsOrItems(actions: List): Pair, List?> { var index = 0 var neutralAction: Action? = null var negativeAction: Action? = null var positiveAction: Action? = null - var items: MutableList? = null + var items: List? = null if (actions.size > 3) { - items = mutableListOf() - actions.forEach { - items += it.styledTitle - } + items = actions.map { it.styledTitle } } else { // Note: The mapping of actions to buttons is documented in mobile-sdk-core. if (actions.size == 3) { diff --git a/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/jsonvalue/JSONValue.kt b/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/jsonvalue/JSONValue.kt index 887d0a7..617582a 100644 --- a/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/jsonvalue/JSONValue.kt +++ b/mobile-sdk/src/main/java/com/github/itwin/mobilesdk/jsonvalue/JSONValue.kt @@ -150,8 +150,8 @@ class JSONValue private constructor(value: Any?) { */ val anyValue: Any? get() = when (value) { - is JSONObject -> objectValue!!.toMap() - is JSONArray -> arrayValue!!.toList() + is JSONObject -> objectValue?.toMap() + is JSONArray -> arrayValue?.toList() else -> value } @@ -220,26 +220,26 @@ class JSONValue private constructor(value: Any?) { * receiver is not an object, or the key does not exist, throws an exception. This allows the * subscript operator to be directly used on [JSONValue]. */ - operator fun get(key: String): Any = objectValue!!.get(key) + operator fun get(key: String): Any = (objectValue as JSONObject).get(key) /** * If the receiver is an object, maps `name` to `value`, clobbering any name/value mapping with - * the same name. + * the same name. If the receiver is not an object, throws an exception. */ - fun put(key: String, value: Any?): JSONObject = objectValue!!.put(key, value) + fun put(key: String, value: Any?): JSONObject = (objectValue as JSONObject).put(key, value) /** * If the receiver is an array, returns the value at the specified index in the array. If the * receiver is not an array, throws an exception. This allows the subscript operator to be used * directly on [JSONValue]. */ - operator fun get(index: Int): Any = arrayValue!!.get(index) + operator fun get(index: Int): Any = (arrayValue as JSONArray).get(index) /** * If the receiver is an array, sets the value at `index` to `value`, null-padding the array to - * the required length if necessary.. + * the required length if necessary. If the receiver is not an array, throws an exception. */ - fun put(index: Int, value: Any?): JSONArray = arrayValue!!.put(index, value) + fun put(index: Int, value: Any?): JSONArray = (arrayValue as JSONArray).put(index, value) /** * If the receiver is an object, returns the optional value of the specified key in the object