public open class RemoteEnum<T : Enum<T>>(
internal val intValue: RemoteInt,
internal val enumEntries: EnumEntries<T>,
) : BaseRemoteState<T>(RemoteStateInstanceKey())
A class representing a remote enum value.
RemoteInt internally stores its state as a RemoteInt, using the Enum ordinal.
Secondary Constructors
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public constructor(value: T, enumEntries: EnumEntries<T>) : this(value.ordinal.ri, enumEntries)
Constructor for creating a RemoteEnum instance from a standard Enum.
It converts the standard enum value into a RemoteInt using the Enum ordinal.
Parameters
| value | The standard enum value to convert. |
Properties
ordinal
public val ordinal: RemoteInt
Converts this RemoteEnum to its underlying RemoteInt representation, using the Enum ordinal.
Returns
| The RemoteInt that holds the enum's value. |
Functions
toRemoteString
public fun toRemoteString(mapping: (T) -> RemoteString = { it.toString().rs }): RemoteString
Converts this RemoteEnum to a RemoteString representation.
This method maps each possible enum entry to a string using the provided mapping function. At runtime, the RemoteString will resolve to the string corresponding to the current value of the enum. Defaults to calling Any.toString on the enum entry.
Parameters
| mapping | A function that defines how each enum constant should be converted to a RemoteString. |
Returns
| A RemoteString that tracks the string value of this enum. |
toRemoteInt
public fun toRemoteInt(mapping: (T) -> RemoteInt): RemoteInt
Converts this RemoteEnum to a RemoteInt representation using a provided mapping.
This method maps each possible enum entry to a RemoteInt using the provided mapping function. At runtime, the resulting RemoteInt will resolve to the value corresponding to the current state of the enum.
Parameters
| mapping | A function that defines how each enum constant should be converted to a RemoteInt. |
Returns
| A RemoteInt that tracks the integer value associated with this enum. |
Companion Object
Methods
public inline operator fun <reified T : Enum<T>> invoke(value: T): RemoteEnum<T>
Creates a RemoteEnum from a literal constant.
Parameters
| value | The constant Enum value. |
Returns
| A RemoteEnum representing the constant enum. |
@JvmStatic
public inline fun <reified T : Enum<T>> createNamedRemoteEnum(
name: String,
defaultValue: T,
domain: RemoteState.Domain = RemoteState.Domain.User,
): RemoteEnum<T>
Creates a named RemoteEnum with an initial value.
Parameters
| name | The unique name for this remote enum. |
| domain | The domain of the named enum (defaults to RemoteState.Domain.User). |
| defaultValue | The initial Enum value for the named remote enum. |
Returns
| A RemoteEnum representing the named enum. |