refactored filterNulls() to filterNotNull() which is a clearer name - thanks Stepan!

This commit is contained in:
James Strachan
2012-03-08 14:36:23 +00:00
parent 8d48e3c8a8
commit db72208a91
6 changed files with 21 additions and 16 deletions
@@ -55,7 +55,7 @@ class KDocConfig() {
*/
fun resolveLink(packageName: String): String {
// TODO should be able to do something like
// for (e in packageUrls.filterNulls()) {
// for (e in packageUrls.filterNotNull()) {
val entrySet = packagePrefixToUrls.entrySet()
if (entrySet != null) {
for (e in entrySet) {
-10
View File
@@ -39,16 +39,6 @@
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<modules>
<module>stdlib</module>
<module>kunit</module>
+15
View File
@@ -14,6 +14,12 @@
<artifactId>stdlib</artifactId>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@@ -27,6 +33,15 @@
<plugin>
<groupId>com.goldin.plugins</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<executions>
<execution>
<id>compile-kotlin-sources</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
+2 -2
View File
@@ -54,10 +54,10 @@ inline fun <T, C: Collection<in T>> java.lang.Iterable<T>.filterTo(result: C, pr
}
/** Returns a List containing all the non null elements in this collection */
inline fun <T> java.lang.Iterable<T?>?.filterNulls() : Collection<T> = filterNullsTo(java.util.ArrayList<T>())
inline fun <T> java.lang.Iterable<T?>?.filterNotNull() : Collection<T> = filterNotNullTo(java.util.ArrayList<T>())
/** Filters all the null elements in this collection winto the given result collection */
inline fun <T, C: Collection<in T>> java.lang.Iterable<T?>?.filterNullsTo(result: C) : C {
inline fun <T, C: Collection<in T>> java.lang.Iterable<T?>?.filterNotNullTo(result: C) : C {
if (this != null) {
for (elem in this) {
if (elem != null)
@@ -57,10 +57,10 @@ inline fun <T, C: Collection<in T>> Array<T>.filterTo(result: C, predicate: (T)-
}
/** Returns a List containing all the non null elements in this collection */
inline fun <T> Array<T?>?.filterNulls() : Collection<T> = filterNullsTo(java.util.ArrayList<T>())
inline fun <T> Array<T?>?.filterNotNull() : Collection<T> = filterNotNullTo(java.util.ArrayList<T>())
/** Filters all the null elements in this collection winto the given result collection */
inline fun <T, C: Collection<in T>> Array<T?>?.filterNullsTo(result: C) : C {
inline fun <T, C: Collection<in T>> Array<T?>?.filterNotNullTo(result: C) : C {
if (this != null) {
for (elem in this) {
if (elem != null)
+1 -1
View File
@@ -10,7 +10,7 @@ class StringUtilTest() : TestCase() {
fun testToRegex() {
val re = """foo""".toRegex()
val list = re.split("hellofoobar").filterNulls()
val list = re.split("hellofoobar").filterNotNull()
assertEquals(arrayList("hello", "bar"), list)
}
}