refactor(util-kotlin): Deprecate `Map.filterNullValues` function and add `Map.filterNotNullValues` instead.

The naming `filterNullValues` is not consistent with Kotlin's naming convention, where `filterNotNull` will remove the `null` values from a list.
This commit is contained in:
Mateusz Armatys 2024-03-25 17:25:27 +01:00
parent ae343e6d58
commit 056944f325
3 changed files with 10 additions and 2 deletions

View File

@ -122,6 +122,7 @@ public abstract interface class me/proton/core/util/kotlin/Logger {
}
public final class me/proton/core/util/kotlin/MapUtilsKt {
public static final fun filterNotNullValues (Ljava/util/Map;)Ljava/util/Map;
public static final fun filterNullValues (Ljava/util/Map;)Ljava/util/Map;
public static final fun filterValues (Ljava/util/Map;Ljava/lang/Class;)Ljava/util/Map;
public static final fun filterValues (Ljava/util/Map;Lkotlin/reflect/KClass;)Ljava/util/Map;

View File

@ -9,9 +9,16 @@ import kotlin.reflect.KClass
* Author: Davide Farella
*/
/** @return [Map] without `null` values */
@Deprecated(
"The name of this function is not consistent with Kotlin's conventional naming.",
replaceWith = ReplaceWith("filterNotNullValues()", "me.proton.core.util.kotlin.filterNotNullValues")
)
fun <T : Any, V : Any> Map<T, V?>.filterNullValues() = filterNotNullValues()
/** @return [Map] without `null` values */
@Suppress("UNCHECKED_CAST") // All values as not null
fun <T : Any, V : Any> Map<T, V?>.filterNullValues() = filterValues { it != null } as Map<T, V>
fun <T : Any, V : Any> Map<T, V?>.filterNotNullValues() = filterValues { it != null } as Map<T, V>
/** @return [Map] of [K] and [V] by filtering by values which are instance of [javaClass] */
@Suppress("UNCHECKED_CAST")

View File

@ -19,7 +19,7 @@ internal class MapUtilsTest {
)
assertEquals(4, map.size)
val filteredMap = map.filterNullValues()
val filteredMap = map.filterNotNullValues()
assertEquals(3, filteredMap.size)
}