Skip to content

Commit f4f1f08

Browse files
committed
refactor(clearly-defined): Get enums for serial names directly
Look up enums for serial names directly instead of searching for them by string representation. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent f19867c commit f4f1f08

File tree

1 file changed

+3
-2
lines changed
  • clients/clearly-defined/src/main/kotlin

1 file changed

+3
-2
lines changed

clients/clearly-defined/src/main/kotlin/Enums.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ enum class ComponentType(val defaultProvider: Provider? = null) {
4343

4444
companion object {
4545
@JvmStatic
46-
fun fromString(value: String) = ComponentType.entries.single { it.toString() == value }
46+
fun fromString(value: String) =
47+
ComponentType.entries[ComponentType.serializer().descriptor.getElementIndex(value)]
4748
}
4849

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

7475
companion object {
7576
@JvmStatic
76-
fun fromString(value: String) = Provider.entries.single { it.toString() == value }
77+
fun fromString(value: String) = Provider.entries[Provider.serializer().descriptor.getElementIndex(value)]
7778
}
7879

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

0 commit comments

Comments
 (0)