From 390affb319c77ae030ae711b66b4afc04276457f Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 28 Sep 2024 09:55:59 +0100 Subject: [PATCH] Replace fromOrdinal() with entries.getOrNull() Signed-off-by: Graham --- .../org/openrs2/archive/cache/CrossPollinator.kt | 2 +- .../main/kotlin/org/openrs2/cache/Js5Compression.kt | 6 +++--- .../kotlin/org/openrs2/cache/Js5CompressionType.kt | 11 ----------- cache/src/main/kotlin/org/openrs2/cache/Js5Pack.kt | 2 +- .../org/openrs2/protocol/common/AntiAliasingMode.kt | 12 +----------- .../org/openrs2/protocol/common/DisplayMode.kt | 12 +----------- .../protocol/login/upstream/GameLoginPayload.kt | 4 ++-- 7 files changed, 9 insertions(+), 40 deletions(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CrossPollinator.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CrossPollinator.kt index a0d72ca6..8c1e3065 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CrossPollinator.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CrossPollinator.kt @@ -197,7 +197,7 @@ public class CrossPollinator @Inject constructor( } private fun groupToFile(input: ByteBuf, expectedChecksum: Int): ByteBuf? { - val type = Js5CompressionType.fromOrdinal(input.readUnsignedByte().toInt()) + val type = Js5CompressionType.entries.getOrNull(input.readUnsignedByte().toInt()) if (type != Js5CompressionType.GZIP) { return null } diff --git a/cache/src/main/kotlin/org/openrs2/cache/Js5Compression.kt b/cache/src/main/kotlin/org/openrs2/cache/Js5Compression.kt index 67339b42..c9aa9533 100644 --- a/cache/src/main/kotlin/org/openrs2/cache/Js5Compression.kt +++ b/cache/src/main/kotlin/org/openrs2/cache/Js5Compression.kt @@ -115,7 +115,7 @@ public object Js5Compression { } val typeId = input.readUnsignedByte().toInt() - val type = Js5CompressionType.fromOrdinal(typeId) + val type = Js5CompressionType.entries.getOrNull(typeId) ?: throw IOException("Invalid compression type: $typeId") val len = input.readInt() @@ -178,7 +178,7 @@ public object Js5Compression { } val typeId = input.readUnsignedByte().toInt() - val type = Js5CompressionType.fromOrdinal(typeId) + val type = Js5CompressionType.entries.getOrNull(typeId) ?: throw IOException("Invalid compression type: $typeId") val len = input.readInt() @@ -377,7 +377,7 @@ public object Js5Compression { } val typeId = buf.readUnsignedByte().toInt() - val type = Js5CompressionType.fromOrdinal(typeId) + val type = Js5CompressionType.entries.getOrNull(typeId) ?: throw IOException("Invalid compression type: $typeId") val len = buf.readInt() diff --git a/cache/src/main/kotlin/org/openrs2/cache/Js5CompressionType.kt b/cache/src/main/kotlin/org/openrs2/cache/Js5CompressionType.kt index 77bce549..85b99795 100644 --- a/cache/src/main/kotlin/org/openrs2/cache/Js5CompressionType.kt +++ b/cache/src/main/kotlin/org/openrs2/cache/Js5CompressionType.kt @@ -37,15 +37,4 @@ public enum class Js5CompressionType { LZMA -> Lzma.createHeaderlessOutputStream(output, Lzma.DEFAULT_COMPRESSION) } } - - public companion object { - @JvmStatic - public fun fromOrdinal(ordinal: Int): Js5CompressionType? { - return if (ordinal >= 0 && ordinal < entries.size) { - entries[ordinal] - } else { - null - } - } - } } diff --git a/cache/src/main/kotlin/org/openrs2/cache/Js5Pack.kt b/cache/src/main/kotlin/org/openrs2/cache/Js5Pack.kt index 640a7048..7dfc7ebf 100644 --- a/cache/src/main/kotlin/org/openrs2/cache/Js5Pack.kt +++ b/cache/src/main/kotlin/org/openrs2/cache/Js5Pack.kt @@ -151,7 +151,7 @@ public class Js5Pack private constructor( private fun readCompressed(input: DataInputStream, alloc: ByteBufAllocator): ByteBuf { val typeId = input.readUnsignedByte() - val type = Js5CompressionType.fromOrdinal(typeId) + val type = Js5CompressionType.entries.getOrNull(typeId) ?: throw IOException("Invalid compression type: $typeId") val len = input.readInt() diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/common/AntiAliasingMode.kt b/protocol/src/main/kotlin/org/openrs2/protocol/common/AntiAliasingMode.kt index ffa46fce..643c4a26 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/common/AntiAliasingMode.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/common/AntiAliasingMode.kt @@ -3,15 +3,5 @@ package org.openrs2.protocol.common public enum class AntiAliasingMode { NONE, X2, - X4; - - public companion object { - public fun fromOrdinal(ordinal: Int): AntiAliasingMode? { - return if (ordinal >= 0 && ordinal < entries.size) { - entries[ordinal] - } else { - null - } - } - } + X4 } diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/common/DisplayMode.kt b/protocol/src/main/kotlin/org/openrs2/protocol/common/DisplayMode.kt index 378098bc..77431516 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/common/DisplayMode.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/common/DisplayMode.kt @@ -4,15 +4,5 @@ public enum class DisplayMode { SD, HD_SMALL, HD, - HD_FULLSCREEN; - - public companion object { - public fun fromOrdinal(ordinal: Int): DisplayMode? { - return if (ordinal >= 0 && ordinal < entries.size) { - entries[ordinal] - } else { - null - } - } - } + HD_FULLSCREEN } diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/GameLoginPayload.kt b/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/GameLoginPayload.kt index 04c30e97..a812a7c1 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/GameLoginPayload.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/login/upstream/GameLoginPayload.kt @@ -84,13 +84,13 @@ public data class GameLoginPayload( val advertSuppressed = buf.readBoolean() val clientSigned = buf.readBoolean() - val displayMode = DisplayMode.fromOrdinal(buf.readUnsignedByte().toInt()) + val displayMode = DisplayMode.entries.getOrNull(buf.readUnsignedByte().toInt()) ?: throw IllegalArgumentException("Invalid DisplayMode") val canvasWidth = buf.readUnsignedShort() val canvasHeight = buf.readUnsignedShort() - val antiAliasingMode = AntiAliasingMode.fromOrdinal(buf.readUnsignedByte().toInt()) + val antiAliasingMode = AntiAliasingMode.entries.getOrNull(buf.readUnsignedByte().toInt()) ?: throw IllegalArgumentException("Invalid AntiAliasingMode") val uid = Uid.read(buf)