Improve isNullOrEmpty() extensions

- Annotate with SinceKotlin("1.3") and InlineOnly
- Add contract linking the receiver and the returned value
- Unify wording in docs
- Add sample for Map.isNullOrEmpty

#KT-23279
This commit is contained in:
Ilya Gorbunov
2018-07-15 06:53:46 +03:00
parent d0788148e2
commit cd0906a357
5 changed files with 43 additions and 7 deletions
@@ -17,6 +17,7 @@
package samples.collections
import samples.*
import kotlin.test.*
@RunWith(Enclosed::class)
@@ -38,10 +39,10 @@ class Arrays {
val nullArray: Array<Any>? = null
assertTrue(nullArray.isNullOrEmpty())
val emptyArray = emptyArray<Any>()
val emptyArray: Array<Any>? = emptyArray<Any>()
assertTrue(emptyArray.isNullOrEmpty())
val array = arrayOf('a', 'b', 'c')
val array: Array<Char>? = arrayOf('a', 'b', 'c')
assertFalse(array.isNullOrEmpty())
}
}
@@ -106,6 +106,18 @@ class Maps {
}
}
@Sample
fun mapIsNullOrEmpty() {
val nullMap: Map<String, Any>? = null
assertTrue(nullMap.isNullOrEmpty())
val emptyMap: Map<String, Any>? = emptyMap<String, Any>()
assertTrue(emptyMap.isNullOrEmpty())
val map: Map<Char, Int>? = mapOf('a' to 1, 'b' to 2, 'c' to 3)
assertFalse(map.isNullOrEmpty())
}
}
class Filtering {