From a11a97d16a9aea4ed99d9039dbcd6445ea69bc22 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 3 Sep 2023 03:18:36 +0200 Subject: Fixed error in addOrPut --- .../at/hannibal2/skyhanni/utils/LorenzUtils.kt | 30 ++++++++++++++-------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 1bd3fa94d..27573a5c0 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -428,17 +428,25 @@ object LorenzUtils { fun IslandType.isInIsland() = inIsland(this) - fun MutableMap.addOrPut(item: K, amount: N): N { - val old = this[item] ?: 0 - val new = when (old) { - is Double -> old + amount.toDouble() - is Float -> old + amount.toFloat() - is Long -> old + amount.toLong() - else -> old.toInt() + amount.toInt() - } - @Suppress("UNCHECKED_CAST") - this[item] = new as N - return new + fun MutableMap.addOrPut(key: K, number: Int): Int { + val currentValue = this[key] ?: 0 + val newValue = currentValue + number + this[key] = newValue + return newValue + } + + fun MutableMap.addOrPut(key: K, number: Long): Long { + val currentValue = this[key] ?: 0L + val newValue = currentValue + number + this[key] = newValue + return newValue + } + + fun MutableMap.addOrPut(key: K, number: Double): Double { + val currentValue = this[key] ?: 0.0 + val newValue = currentValue + number + this[key] = newValue + return newValue } fun MutableMap.sumAllValues(): Double { -- cgit