This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified T : Enum<T>> enumContains(name: String): Boolean { | |
return enumValues<T>().any { it.name == name} | |
} | |
inline fun <reified T : Enum<T>> enumValueOf(name: String, defaultValue: T): T { | |
return try { | |
enumValues<T>().first { it.name == name } | |
} catch (e: NoSuchElementException) { | |
defaultValue | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* genitivePlural - родительный падеж, множественное число (примеры: "часов", "минут", "секунд") | |
* nominativeSingular - именительный падеж, единственное число (примеры: "час", "минута", "секунда") | |
* genitiveSingular - родительный падеж, единственное число (примеры: "часа", "минуты", "секунды") | |
*/ | |
fun getCountNoun(count: Int, genitivePlural: String, nominativeSingular: String, genitiveSingular: String): String { | |
val lastDigit = count.toString().last().toString().toInt() | |
val word = if (count in 5..20) genitivePlural | |
else if (lastDigit == 0 || lastDigit >= 5) genitivePlural | |
else if (lastDigit == 1) nominativeSingular |
NewerOlder