You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

25 lines
797 B

package net.aiterp.git.ykonsole2.domain.runtime
sealed class Value {
val name get() = "${javaClass.kotlin.simpleName}"
fun toInt() = when (this) {
is Time -> seconds
is Distance -> meters
is Calories -> kcal
is Level -> raw
is RpmSpeed -> rpm
is Pulse -> bpm
}
}
data class Time(val seconds: Int) : Value()
data class Distance(val meters: Int) : Value()
data class Calories(val kcal: Int) : Value()
data class Level(val raw: Int) : Value()
data class RpmSpeed(val rpm: Int) : Value()
data class Pulse(val bpm: Int) : Value()
inline fun <reified T : Value> Collection<Value>.find(): T? = find { it is T }?.let { it as T }
inline fun <reified T : Value> Collection<Value>.findInt(): Int = find { it is T }?.toInt() ?: 0
fun Value?.toInt(): Int = this?.toInt() ?: 0