-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add list extension * Fix test function description * Update java version * Revert jdk change.
- Loading branch information
1 parent
95779e7
commit e67d4bf
Showing
5 changed files
with
25 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
kt-extensions/src/main/java/com/mindera/skeletoid/kt/extensions/utils/Collection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
package com.mindera.skeletoid.kt.extensions.utils | ||
|
||
fun <T: Any> Collection<T>.nullIfEmpty(): Collection<T>? { | ||
return if (isEmpty()) null else this | ||
} | ||
fun <T> Collection<T>.nullIfEmpty() = if (isEmpty()) null else this |
3 changes: 3 additions & 0 deletions
3
kt-extensions/src/main/java/com/mindera/skeletoid/kt/extensions/utils/ListExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.mindera.skeletoid.kt.extensions.utils | ||
|
||
fun <T> List<T>.nullIfEmpty() = if (isEmpty()) null else this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
kt-extensions/src/test/java/com/mindera/skeletoid/kt/extensions/utils/ListExtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.mindera.skeletoid.kt.extensions.utils | ||
|
||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class ListExtTest { | ||
|
||
@Test | ||
fun `test nullIfEmpty with non empty list`() { | ||
val list = listOf("One", "Two", "Three") | ||
Assert.assertNotNull(list.nullIfEmpty()) | ||
} | ||
|
||
@Test | ||
fun `test nullIfEmpty with empty list`() { | ||
val list = listOf<String>() | ||
Assert.assertNull(list.nullIfEmpty()) | ||
} | ||
} |