diff --git a/common/src/main/kotlin/br/com/stonks/common/utils/KotlinUtils.kt b/common/src/main/kotlin/br/com/stonks/common/utils/KotlinUtils.kt deleted file mode 100644 index 39fb93d..0000000 --- a/common/src/main/kotlin/br/com/stonks/common/utils/KotlinUtils.kt +++ /dev/null @@ -1,12 +0,0 @@ -package br.com.stonks.common.utils - -@Suppress("SwallowedException") -inline fun > safeEnumValueOf(name: String): T? { - return try { - enumValueOf(name) - } catch (exception: IllegalArgumentException) { - null - } catch (exception: IllegalStateException) { - null - } -} diff --git a/feature/home/src/main/kotlin/br/com/stonks/feature/home/domain/types/PortfolioType.kt b/feature/home/src/main/kotlin/br/com/stonks/feature/home/domain/types/PortfolioType.kt index 197a6e2..9ff6030 100644 --- a/feature/home/src/main/kotlin/br/com/stonks/feature/home/domain/types/PortfolioType.kt +++ b/feature/home/src/main/kotlin/br/com/stonks/feature/home/domain/types/PortfolioType.kt @@ -1,6 +1,6 @@ package br.com.stonks.feature.home.domain.types -import br.com.stonks.common.utils.safeEnumValueOf +import timber.log.Timber enum class PortfolioType(val id: String) { UNKNOWN("unknown"), @@ -12,7 +12,12 @@ enum class PortfolioType(val id: String) { companion object { fun fromString(id: String): PortfolioType { - return safeEnumValueOf(id) ?: UNKNOWN + return try { + enumValues().find { it.id == id } ?: UNKNOWN + } catch (exception: IllegalArgumentException) { + Timber.e(exception, "Failure to find the enum value with ID '$id'") + UNKNOWN + } } } } diff --git a/feature/home/src/main/kotlin/br/com/stonks/feature/home/domain/types/TransactionType.kt b/feature/home/src/main/kotlin/br/com/stonks/feature/home/domain/types/TransactionType.kt index b199ca8..2cab127 100644 --- a/feature/home/src/main/kotlin/br/com/stonks/feature/home/domain/types/TransactionType.kt +++ b/feature/home/src/main/kotlin/br/com/stonks/feature/home/domain/types/TransactionType.kt @@ -1,6 +1,6 @@ package br.com.stonks.feature.home.domain.types -import br.com.stonks.common.utils.safeEnumValueOf +import timber.log.Timber enum class TransactionType(val id: String) { UNKNOWN("unknown"), @@ -10,7 +10,12 @@ enum class TransactionType(val id: String) { companion object { fun fromString(id: String): TransactionType { - return safeEnumValueOf(id) ?: UNKNOWN + return try { + enumValues().find { it.id == id } ?: UNKNOWN + } catch (exception: IllegalArgumentException) { + Timber.e(exception, "Failure to find the enum value with ID '$id'") + UNKNOWN + } } } }