KotlinEnum

Lightweight enum helper for Kotlin, written in Pure Kotlin. A convenient and performance utility library wrapping basic enum operation as an extensions.

kotlin-enum helper License: MIT

Lightweight enum helper for Kotlin, written in Pure Kotlin.
A convenient and performance utility library wrapping basic enum operation as an extensions.

Overview

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:

Getting started

**Implement interface EnumHelper**

enum class Money(override val key: String) : EnumHelper<String> {
    EURO("€"),
    DOLAR("$"),
    STERLING("£"),
    POLISH_ZLOTY("PLN")
}

Usage

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 }

Download

Maven

<dependency>
  <groupId>com.github.tribudirb</groupId>
  <artifactId>kotlin-enum-helper</artifactId>
  <version>1.0.0</version>
</dependency>

Gradle

compile group: 'com.github.tribudirb', name: 'kotlin-enum-helper', version: '1.0.0'

Or alternatively, download jar from github.

Contributors

Contributing

Pull requests are welcome