ValueEnumFromValue

open class ValueEnumFromValue<Value, T : Enum<T>, ValueEnum<Value>>(default: T, enumEntries: <Error class: unknown class><T>) : EnumFromValue<Value, T> (source)

EnumFromValue implementation for enums that implement the ValueEnum interface.

fromValueOrNull is implemented to use the result of the following operation:

enumEntries.find { it.value == value }

Note that fromValueOrNull can still be overridden if the default implementation isn't desirable.

Since

0.2.0

Parameters

default

The default enum value to use if no such value was found from the List.find operation.

enumEntries

The list of entries present in the ValueEnum.

See also

Constructors

Link copied to clipboard
constructor(default: T, enumEntries: <Error class: unknown class><T>)

Functions

Link copied to clipboard
fun fromValue(value: Value): T

Gets the E representation of value, or default if no such representation exists.

Link copied to clipboard
fun fromValueOrElse(value: Value, default: T): T

Gets the E representation of value, or default if no such representation exists.

Link copied to clipboard
open override fun fromValueOrNull(value: Value): T?

Gets the E representation of value, or null if no such representation exists.

Link copied to clipboard
fun hasValue(value: Value): Boolean

Checks if an enum entry with the given value exists.

Link copied to clipboard
fun requireValue(value: Value): T

Gets the E representation of value, or throws an IllegalArgumentException if no such representation exists.