aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-09-03 03:18:36 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-09-03 03:18:36 +0200
commita11a97d16a9aea4ed99d9039dbcd6445ea69bc22 (patch)
tree43b26c98bb5ec1c709939f03a75f9662211c1c94 /src/main/java/at/hannibal2
parent93ffe9c557852ea93db58f50a04faa1f4ca50d94 (diff)
downloadskyhanni-a11a97d16a9aea4ed99d9039dbcd6445ea69bc22.tar.gz
skyhanni-a11a97d16a9aea4ed99d9039dbcd6445ea69bc22.tar.bz2
skyhanni-a11a97d16a9aea4ed99d9039dbcd6445ea69bc22.zip
Fixed error in addOrPut
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt30
1 files changed, 19 insertions, 11 deletions
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 <K, N : Number> MutableMap<K, N>.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 <K> MutableMap<K, Int>.addOrPut(key: K, number: Int): Int {
+ val currentValue = this[key] ?: 0
+ val newValue = currentValue + number
+ this[key] = newValue
+ return newValue
+ }
+
+ fun <K> MutableMap<K, Long>.addOrPut(key: K, number: Long): Long {
+ val currentValue = this[key] ?: 0L
+ val newValue = currentValue + number
+ this[key] = newValue
+ return newValue
+ }
+
+ fun <K> MutableMap<K, Double>.addOrPut(key: K, number: Double): Double {
+ val currentValue = this[key] ?: 0.0
+ val newValue = currentValue + number
+ this[key] = newValue
+ return newValue
}
fun <K, N : Number> MutableMap<K, N>.sumAllValues(): Double {