Lightweight enum helper for Kotlin, written in Pure Kotlin. A convenient and performance utility library wrapping basic enum operation as an extensions.
Lightweight enum helper for Kotlin, written in .
A convenient and performance utility library wrapping basic enum operation as an extensions.
After seeing many weird implementations of getOrDefault()
, it seems like there should be a standard for converting to enum and obtaining basic information from it.
Kotlin-enum helper provide a generic implementation which can be easy applied to any enum:
getOrDefault()
or get()
.**Implement interface EnumHelper**
enum class Money(override val key: String) : EnumHelper<String> {
EURO("€"),
DOLAR("$"),
STERLING("£"),
POLISH_ZLOTY("PLN")
}
fun getOrDefaultCurrencyFrom(sign: String) : Money = Money::class.getOrDefault(key = sign, default = Money.POUND)
fun checkAllCurrencyAreValid(signs: List<String>) : Boolean = Money::class allExists signs
fun getCurrencyFrom(sign: String) : Money = Money::class get { sign }
<dependency>
<groupId>com.github.tribudirb</groupId>
<artifactId>kotlin-enum-helper</artifactId>
<version>1.0.0</version>
</dependency>
compile group: 'com.github.tribudirb', name: 'kotlin-enum-helper', version: '1.0.0'
Or alternatively, download jar from github.
Pull requests are welcome