diff options
author | J10a1n15 <45315647+j10a1n15@users.noreply.github.com> | 2024-03-12 19:59:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-12 19:59:55 +0100 |
commit | 4352ffb08d4bfffc06adad2a068f375ab9874333 (patch) | |
tree | b8ce745fca8ab82ffa04f6ab87334139a6b7192b /src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt | |
parent | eb863d60e82b5541a9f42d2608f61cb97ada209b (diff) | |
download | skyhanni-4352ffb08d4bfffc06adad2a068f375ab9874333.tar.gz skyhanni-4352ffb08d4bfffc06adad2a068f375ab9874333.tar.bz2 skyhanni-4352ffb08d4bfffc06adad2a068f375ab9874333.zip |
Feature: CustomScoreboard (#893)
Co-authored-by: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com>
Co-authored-by: Thunderblade73 <gaidermarkus@gmail.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt index b93f17fa4..21f731fc2 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt @@ -51,6 +51,9 @@ object CollectionUtils { fun <K> MutableMap<K, Double>.addOrPut(key: K, number: Double): Double = this.merge(key, number, Double::plus)!! // Never returns null since "plus" can't return null + fun <K> MutableMap<K, Float>.addOrPut(key: K, number: Float): Float = + this.merge(key, number, Float::plus)!! // Never returns null since "plus" can't return null + fun <K, N : Number> Map<K, N>.sumAllValues(): Double { if (values.isEmpty()) return 0.0 @@ -81,6 +84,30 @@ object CollectionUtils { return null } + fun List<String>.removeNextAfter(after: String, skip: Int = 1) = removeNextAfter({ it == after }, skip) + + fun List<String>.removeNextAfter(after: (String) -> Boolean, skip: Int = 1): List<String> { + val newList = mutableListOf<String>() + var missing = -1 + for (line in this) { + if (after(line)) { + missing = skip - 1 + continue + } + if (missing == 0) { + missing-- + continue + } + if (missing != -1) { + missing-- + } + newList.add(line) + } + return newList + } + + fun List<String>.addIfNotNull(element: String?) = element?.let { plus(it) } ?: this + fun <K, V> Map<K, V>.editCopy(function: MutableMap<K, V>.() -> Unit) = toMutableMap().also { function(it) }.toMap() |