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:
parent
ae343e6d58
commit
056944f325
|
@ -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;
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -19,7 +19,7 @@ internal class MapUtilsTest {
|
|||
)
|
||||
assertEquals(4, map.size)
|
||||
|
||||
val filteredMap = map.filterNullValues()
|
||||
val filteredMap = map.filterNotNullValues()
|
||||
assertEquals(3, filteredMap.size)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue