de.miraculixx.mcommons.extensions.CollectionExtensions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mc-commons Show documentation
Show all versions of mc-commons Show documentation
Common utilities for Minecraft plugins
@file:Suppress("unused")
package de.miraculixx.mcommons.extensions
fun List.toMap(default: V): Map {
return buildMap {
[email protected] { put(it, default) }
}
}
/**
* Returns the value after the given value in the list.
* If the value is not found or the value is the last element, the first element is returned.
*/
fun List.nextValue(value: T): T {
val index = indexOf(value)
return if (index == -1 || index == size - 1) first() else this[index + 1]
}
/**
* Returns the value after the given value in the array.
* If the value is not found or the value is the last element, the first element is returned.
*/
fun Array.nextValue(value: T): T {
val index = indexOf(value)
return if (index == -1 || index == size - 1) first() else this[index + 1]
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy