From 009346cd30660ebe73341751a021507c2319608d Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Mon, 10 Jul 2017 06:08:20 +0200 Subject: [PATCH] Some improvements for Android compatibility --- build.gradle | 8 ++++++++ .../bitmessage/networking/nio/NioNetworkHandler.kt | 13 +++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 2169e2f..df0b9d4 100644 --- a/build.gradle +++ b/build.gradle @@ -50,6 +50,14 @@ subprojects { from sourceSets.main.allSource } + compileKotlin { + kotlinOptions.jvmTarget = "1.6" + } + + compileTestKotlin { + kotlinOptions.jvmTarget = "1.6" + } + artifacts { archives javadocJar, sourcesJar } diff --git a/networking/src/main/kotlin/ch/dissem/bitmessage/networking/nio/NioNetworkHandler.kt b/networking/src/main/kotlin/ch/dissem/bitmessage/networking/nio/NioNetworkHandler.kt index 3a0464a..b926d7d 100644 --- a/networking/src/main/kotlin/ch/dissem/bitmessage/networking/nio/NioNetworkHandler.kt +++ b/networking/src/main/kotlin/ch/dissem/bitmessage/networking/nio/NioNetworkHandler.kt @@ -134,7 +134,7 @@ class NioNetworkHandler : NetworkHandler, InternalContext.ContextHolder { starter = thread("connection manager") { while (selector.isOpen) { var missing = NETWORK_MAGIC_NUMBER - for (connection in connections.keys) { + for ((connection, _) in connections) { if (connection.state == Connection.State.ACTIVE) { missing-- if (missing == 0) break @@ -351,7 +351,7 @@ class NioNetworkHandler : NetworkHandler, InternalContext.ContextHolder { } val distribution = HashMap>() - for (connection in connections.keys) { + for ((connection, _) in connections) { if (connection.state == Connection.State.ACTIVE) { distribution.put(connection, mutableListOf()) } @@ -436,14 +436,7 @@ class NioNetworkHandler : NetworkHandler, InternalContext.ContextHolder { ) } - private fun isConnectedTo(address: NetworkAddress): Boolean { - for (c in connections.keys) { - if (c.node == address) { - return true - } - } - return false - } + private fun isConnectedTo(address: NetworkAddress): Boolean = connections.any { it.key.node == address } override val isRunning: Boolean get() = selector?.isOpen ?: false && starter?.isAlive ?: false