Skip to content

Commit

Permalink
refactor(clearly-defined): Get enums for serial names directly
Browse files Browse the repository at this point in the history
Look up enums for serial names directly instead of searching for them by
string representation.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed May 27, 2024
1 parent f19867c commit 7b10a04
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clients/clearly-defined/src/main/kotlin/Enums.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ enum class ComponentType(val defaultProvider: Provider? = null) {

companion object {
@JvmStatic
fun fromString(value: String) = ComponentType.entries.single { it.toString() == value }
fun fromString(value: String) =
ComponentType.entries[ComponentType.serializer().descriptor.getElementIndex(value)]
}

// Align the string representation with the serial name to make Retrofit's GET request work. Also see:
Expand Down Expand Up @@ -73,7 +74,7 @@ enum class Provider {

companion object {
@JvmStatic
fun fromString(value: String) = Provider.entries.single { it.toString() == value }
fun fromString(value: String) = Provider.entries[Provider.serializer().descriptor.getElementIndex(value)]
}

// Align the string representation with the serial name to make Retrofit's GET request work. Also see:
Expand Down

0 comments on commit 7b10a04

Please sign in to comment.