Skip to content

Commit c581e77

Browse files
committed
Moved helper methods for "Iterables" to dedicated class
*This commit is related to issue #529 [1]* [1] #529
1 parent 2c17283 commit c581e77

2 files changed

Lines changed: 39 additions & 27 deletions

File tree

‎data/src/test/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabaseTest.kt‎

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ import org.cryptomator.data.db.sqlmapping.MappingSupportSQLiteDatabase.MappingSu
2020
import org.cryptomator.data.testing.ValueExtractor
2121
import org.cryptomator.data.testing.anyPseudoEquals
2222
import org.cryptomator.data.testing.anyPseudoEqualsUnlessNull
23+
import org.cryptomator.data.testing.argCount
2324
import org.cryptomator.data.testing.asCached
25+
import org.cryptomator.data.testing.cartesianProductFour
26+
import org.cryptomator.data.testing.cartesianProductThree
27+
import org.cryptomator.data.testing.cartesianProductTwo
28+
import org.cryptomator.data.testing.nullCount
29+
import org.cryptomator.data.testing.toArgumentsStream
30+
import org.cryptomator.data.testing.toBindingsMap
2431
import org.junit.jupiter.api.Assertions.assertEquals
2532
import org.junit.jupiter.api.Assertions.assertInstanceOf
2633
import org.junit.jupiter.api.Assertions.assertNotSame
@@ -1103,31 +1110,4 @@ fun sourceForTestNewBoundStatementNumerous2(): Stream<Arguments> {
11031110
return result //
11041111
.map { it.toList() } //
11051112
.toArgumentsStream()
1106-
}
1107-
1108-
fun <A, B> Sequence<A>.cartesianProductTwo(other: Iterable<B>): Sequence<Pair<A, B>> = flatMap { a ->
1109-
other.asSequence().map { b -> a to b }
1110-
}
1111-
1112-
fun <A, B, C> Sequence<Pair<A, B>>.cartesianProductThree(other: Iterable<C>): Sequence<Triple<A, B, C>> = flatMap { abPair ->
1113-
other.asSequence().map { c -> Triple(abPair.first, abPair.second, c) }
1114-
}
1115-
1116-
fun <T> Sequence<Triple<T, T, T>>.cartesianProductFour(other: Iterable<T>): Sequence<List<T>> = flatMap { triple ->
1117-
other.asSequence().map { otherElement -> listOf(triple.first, triple.second, triple.third, otherElement) }
1118-
}
1119-
1120-
fun Sequence<List<Any?>>.toArgumentsStream(): Stream<Arguments> = map {
1121-
Arguments { it.toTypedArray() }
1122-
}.asStream()
1123-
1124-
private fun Iterable<Any?>?.nullCount(): Int = this?.count { it == null } ?: 0
1125-
1126-
private inline fun <reified T> Iterable<Any?>?.argCount(): Int = this?.asSequence()?.filterIsInstance<T>()?.count() ?: 0
1127-
1128-
private fun Iterable<Any?>?.toBindingsMap(): Map<Int, Any?> {
1129-
return this?.asSequence() //
1130-
?.map { if (it is Int) it.toLong() else it } // Required because java.lang.Integer.valueOf(x) != java.lang.Long.valueOf(x)
1131-
?.mapIndexed { index, value -> index + 1 to value } //
1132-
?.toMap() ?: emptyMap()
11331113
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.cryptomator.data.testing
2+
3+
import org.junit.jupiter.params.provider.Arguments
4+
import java.util.stream.Stream
5+
import kotlin.streams.asStream
6+
7+
fun <A, B> Sequence<A>.cartesianProductTwo(other: Iterable<B>): Sequence<Pair<A, B>> = flatMap { a ->
8+
other.asSequence().map { b -> a to b }
9+
}
10+
11+
fun <A, B, C> Sequence<Pair<A, B>>.cartesianProductThree(other: Iterable<C>): Sequence<Triple<A, B, C>> = flatMap { abPair ->
12+
other.asSequence().map { c -> Triple(abPair.first, abPair.second, c) }
13+
}
14+
15+
fun <T> Sequence<Triple<T, T, T>>.cartesianProductFour(other: Iterable<T>): Sequence<List<T>> = flatMap { triple ->
16+
other.asSequence().map { otherElement -> listOf(triple.first, triple.second, triple.third, otherElement) }
17+
}
18+
19+
fun Sequence<List<Any?>>.toArgumentsStream(): Stream<Arguments> = map {
20+
Arguments { it.toTypedArray() }
21+
}.asStream()
22+
23+
fun Iterable<Any?>?.nullCount(): Int = this?.count { it == null } ?: 0
24+
25+
inline fun <reified T> Iterable<Any?>?.argCount(): Int = this?.asSequence()?.filterIsInstance<T>()?.count() ?: 0
26+
27+
fun Iterable<Any?>?.toBindingsMap(): Map<Int, Any?> {
28+
return this?.asSequence() //
29+
?.map { if (it is Int) it.toLong() else it } // Required because java.lang.Integer.valueOf(x) != java.lang.Long.valueOf(x)
30+
?.mapIndexed { index, value -> index + 1 to value } //
31+
?.toMap() ?: emptyMap()
32+
}

0 commit comments

Comments
 (0)