mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 01:45:05 +08:00
porting QueryStringValue to sealed interface with a sub category for the content based values
- allows for handling those cases separately for normalisation
This commit is contained in:
parent
54daee2798
commit
72508c61d9
@ -19,14 +19,17 @@ package org.matrix.android.sdk.api.query
|
||||
/**
|
||||
* Basic query language. All these cases are mutually exclusive.
|
||||
*/
|
||||
sealed class QueryStringValue {
|
||||
object NoCondition : QueryStringValue()
|
||||
object IsNull : QueryStringValue()
|
||||
object IsNotNull : QueryStringValue()
|
||||
object IsEmpty : QueryStringValue()
|
||||
object IsNotEmpty : QueryStringValue()
|
||||
data class Equals(val string: String, val case: Case = Case.SENSITIVE) : QueryStringValue()
|
||||
data class Contains(val string: String, val case: Case = Case.SENSITIVE) : QueryStringValue()
|
||||
sealed interface QueryStringValue {
|
||||
sealed interface ContentQueryStringValue : QueryStringValue
|
||||
|
||||
object NoCondition : QueryStringValue
|
||||
object IsNull : QueryStringValue
|
||||
object IsNotNull : QueryStringValue
|
||||
object IsEmpty : QueryStringValue
|
||||
object IsNotEmpty : QueryStringValue
|
||||
|
||||
data class Equals(val string: String, val case: Case = Case.SENSITIVE) : ContentQueryStringValue
|
||||
data class Contains(val string: String, val case: Case = Case.SENSITIVE) : ContentQueryStringValue
|
||||
|
||||
enum class Case {
|
||||
SENSITIVE,
|
||||
|
@ -20,19 +20,24 @@ import io.realm.Case
|
||||
import io.realm.RealmObject
|
||||
import io.realm.RealmQuery
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue
|
||||
import org.matrix.android.sdk.api.query.QueryStringValue.ContentQueryStringValue
|
||||
import timber.log.Timber
|
||||
|
||||
fun <T : RealmObject> RealmQuery<T>.process(field: String, queryStringValue: QueryStringValue): RealmQuery<T> {
|
||||
when (queryStringValue) {
|
||||
is QueryStringValue.NoCondition -> Timber.v("No condition to process")
|
||||
return when (queryStringValue) {
|
||||
is QueryStringValue.NoCondition -> {
|
||||
Timber.v("No condition to process")
|
||||
this
|
||||
}
|
||||
is QueryStringValue.IsNotNull -> isNotNull(field)
|
||||
is QueryStringValue.IsNull -> isNull(field)
|
||||
is QueryStringValue.IsEmpty -> isEmpty(field)
|
||||
is QueryStringValue.IsNotEmpty -> isNotEmpty(field)
|
||||
is QueryStringValue.Equals -> equalTo(field, queryStringValue.string, queryStringValue.case.toRealmCase())
|
||||
is QueryStringValue.Contains -> contains(field, queryStringValue.string, queryStringValue.case.toRealmCase())
|
||||
is ContentQueryStringValue -> when (queryStringValue) {
|
||||
is QueryStringValue.Equals -> equalTo(field, queryStringValue.string, queryStringValue.case.toRealmCase())
|
||||
is QueryStringValue.Contains -> contains(field, queryStringValue.string, queryStringValue.case.toRealmCase())
|
||||
}
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
private fun QueryStringValue.Case.toRealmCase(): Case {
|
||||
|
Loading…
Reference in New Issue
Block a user