From f3cbb6e485523d089db5e7ac868083d4cedba569 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 14 Dec 2019 22:57:34 +0800 Subject: [PATCH] Simplify --- .../MiraiHttpApplication.kt | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/mirai-api-http/src/main/kotlin/net.mamoe.mirai.api.http/MiraiHttpApplication.kt b/mirai-api-http/src/main/kotlin/net.mamoe.mirai.api.http/MiraiHttpApplication.kt index 7aad33d6b..09e220487 100644 --- a/mirai-api-http/src/main/kotlin/net.mamoe.mirai.api.http/MiraiHttpApplication.kt +++ b/mirai-api-http/src/main/kotlin/net.mamoe.mirai.api.http/MiraiHttpApplication.kt @@ -107,14 +107,14 @@ private inline fun PipelineContext.param(name @Suppress("IMPLICIT_CAST_TO_ANY") @UseExperimental(ExperimentalUnsignedTypes::class) private inline fun PipelineContext.paramOrNull(name: String): R? = - when { - R::class == Byte::class -> call.parameters[name]?.toByte() - R::class == Int::class -> call.parameters[name]?.toInt() - R::class == Short::class -> call.parameters[name]?.toShort() - R::class == Float::class -> call.parameters[name]?.toFloat() - R::class == Long::class -> call.parameters[name]?.toLong() - R::class == Double::class -> call.parameters[name]?.toDouble() - R::class == Boolean::class -> when (call.parameters[name]) { + when (R::class) { + Byte::class -> call.parameters[name]?.toByte() + Int::class -> call.parameters[name]?.toInt() + Short::class -> call.parameters[name]?.toShort() + Float::class -> call.parameters[name]?.toFloat() + Long::class -> call.parameters[name]?.toLong() + Double::class -> call.parameters[name]?.toDouble() + Boolean::class -> when (call.parameters[name]) { "true" -> true "false" -> false "0" -> false @@ -123,13 +123,13 @@ private inline fun PipelineContext.paramOrNul else -> illegalParam("boolean", name) } - R::class == String::class -> call.parameters[name] + String::class -> call.parameters[name] - R::class == UByte::class -> call.parameters[name]?.toUByte() - R::class == UInt::class -> call.parameters[name]?.toUInt() - R::class == UShort::class -> call.parameters[name]?.toUShort() + UByte::class -> call.parameters[name]?.toUByte() + UInt::class -> call.parameters[name]?.toUInt() + UShort::class -> call.parameters[name]?.toUShort() - R::class == UByteArray::class -> call.parameters[name]?.hexToUBytes() - R::class == ByteArray::class -> call.parameters[name]?.hexToBytes() + UByteArray::class -> call.parameters[name]?.hexToUBytes() + ByteArray::class -> call.parameters[name]?.hexToBytes() else -> error(name::class.simpleName + " is not supported") } as R?