objectbox / objectbox/objectbox-java
First Class Support for Enums
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Java
- Estrellas
- 4.6k
- Forks
- 311
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
I can see that there's limited support for enums here but this is such a huge barrier to getting started. I don't want to have to write a converter for each enum type that I use in my code.
I propose first class support for enums using the following mechanism:
This can be repeated for all the natively supported types, and should now be able to be handled internally.
interface EnumInt {
val value: Int
}
interface EnumString {
val value: String
}
inline fun <reified T> enumFromInt(value: Int?): T?
where T : EnumInt, T : Enum<T> =
value?.let { v ->
enumValues<T>().let { values ->
values.find {
v == it.value
} ?: throw IllegalArgumentException("Invalid int value: $v")
}
}
inline fun <reified T> enumFromString(value: String?): T?
where T : EnumString, T : Enum<T> =
value?.let { v ->
enumValues<T>().let { values ->
values.find {
v == it.value
} ?: throw IllegalArgumentException("Invalid string value: $v")
}
}
enum class Type(override val value: String) : EnumString {
UNKNOWN("unknown"),
IMAGE("image"),
VIDEO("video")
}
enum class Status(override val value: Int) : EnumInt {
ERROR(-3),
UNRECOVERABLE_ERROR(-2),
NONE(-1),
DOWNLOADING(1),
DOWNLOADED(2),
UPLOADING(3),
FINISHED(0)
}
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza revisando la documentación sobre tipos personalizados enlazada en el issue y el manejo existente de enums y tipos personalizados. Se considera completado cuando los enums reciben soporte de persistencia de primera clase sin un converter para cada tipo de enum, incluidas las asignaciones de valores enteros y de cadenas propuestas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- kotlin
- Área
- databases
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100