mirror of
https://github.com/corda/corda.git
synced 2025-06-17 06:38:21 +00:00
CORDA-599 RPCSecurityManager is no longer lateinit (#2347)
This commit is contained in:
@ -242,10 +242,14 @@ private fun IntProgression.toSpliterator(): Spliterator.OfInt {
|
||||
}
|
||||
|
||||
fun IntProgression.stream(parallel: Boolean = false): IntStream = StreamSupport.intStream(toSpliterator(), parallel)
|
||||
|
||||
inline fun <reified T> Stream<out T>.toTypedArray() = toTypedArray(T::class.java)
|
||||
// When toArray has filled in the array, the component type is no longer T? but T (that may itself be nullable):
|
||||
inline fun <reified T> Stream<out T>.toTypedArray(): Array<T> = uncheckedCast(toArray { size -> arrayOfNulls<T>(size) })
|
||||
fun <T> Stream<out T>.toTypedArray(componentType: Class<T>): Array<T> = toArray { size ->
|
||||
uncheckedCast<Any, Array<T?>>(java.lang.reflect.Array.newInstance(componentType, size))
|
||||
}
|
||||
|
||||
fun <T> Stream<out T?>.filterNotNull(): Stream<T> = uncheckedCast(filter(Objects::nonNull))
|
||||
fun <K, V> Stream<out Pair<K, V>>.toMap(): Map<K, V> = collect<LinkedHashMap<K, V>>(::LinkedHashMap, { m, (k, v) -> m.put(k, v) }, { m, t -> m.putAll(t) })
|
||||
fun <T> Class<T>.castIfPossible(obj: Any): T? = if (isInstance(obj)) cast(obj) else null
|
||||
|
||||
/** Returns a [DeclaredField] wrapper around the declared (possibly non-public) static field of the receiver [Class]. */
|
||||
|
@ -3,6 +3,7 @@ package net.corda.core.internal
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Test
|
||||
import java.io.Serializable
|
||||
import java.util.stream.IntStream
|
||||
import java.util.stream.Stream
|
||||
import kotlin.test.assertEquals
|
||||
@ -87,5 +88,17 @@ class InternalUtilsTest {
|
||||
val b: Array<String?> = Stream.of("one", "two", null).toTypedArray()
|
||||
assertEquals(Array<String?>::class.java, b.javaClass)
|
||||
assertArrayEquals(arrayOf("one", "two", null), b)
|
||||
val c: Array<CharSequence> = Stream.of("x", "y").toTypedArray(CharSequence::class.java)
|
||||
assertEquals(Array<CharSequence>::class.java, c.javaClass)
|
||||
assertArrayEquals(arrayOf("x", "y"), c)
|
||||
val d: Array<CharSequence?> = Stream.of("x", "y", null).toTypedArray(uncheckedCast(CharSequence::class.java))
|
||||
assertEquals(Array<CharSequence?>::class.java, d.javaClass)
|
||||
assertArrayEquals(arrayOf("x", "y", null), d)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Stream of Pairs toMap works`() {
|
||||
val m: Map<Comparable<*>, Serializable> = Stream.of<Pair<Comparable<*>, Serializable>>("x" to "y", 0 to 1, "x" to '2').toMap()
|
||||
assertEquals<Map<*, *>>(mapOf("x" to '2', 0 to 1), m)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user