summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-08-02 11:07:37 +0200
committerGitHub <noreply@github.com>2024-08-02 11:07:37 +0200
commitccdca342626e439f410f1de4bd5dc1a1790605f3 (patch)
treecf96bddf622411469d9b1e506cd402b67f4b382e /src/main/java/at/hannibal2/skyhanni/utils
parent171049f66ed122656c44e9c07eecc099fe8c6b99 (diff)
downloadskyhanni-ccdca342626e439f410f1de4bd5dc1a1790605f3.tar.gz
skyhanni-ccdca342626e439f410f1de4bd5dc1a1790605f3.tar.bz2
skyhanni-ccdca342626e439f410f1de4bd5dc1a1790605f3.zip
Fix: Odin Truffle (#2300)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt10
1 files changed, 10 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 33e85e2fe..9590ba5c1 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt
@@ -429,4 +429,14 @@ object CollectionUtils {
fun <K, V : Any> Map<K?, V>.filterNotNullKeys(): Map<K, V> {
return filterKeys { it != null } as Map<K, V>
}
+
+ /**
+ * Inserts the element at the index or appends it to the end if out of bounds of the list.
+ *
+ * @param index index to insert at, or append if >= size
+ * @param element element to insert or add
+ */
+ fun <E> MutableList<E>.addOrInsert(index: Int, element: E) {
+ if (index < size) add(index, element) else add(element)
+ }
}