|
|
|
|
@ -1,12 +1,10 @@ |
|
|
|
|
package net.pokeranalytics.android.model.filter |
|
|
|
|
|
|
|
|
|
import io.realm.RealmList |
|
|
|
|
import io.realm.RealmObject |
|
|
|
|
import io.realm.RealmQuery |
|
|
|
|
import net.pokeranalytics.android.exceptions.FilterValueMapException |
|
|
|
|
import net.pokeranalytics.android.model.realm.FilterElementBlind |
|
|
|
|
import net.pokeranalytics.android.model.realm.FilterElement |
|
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
|
import net.pokeranalytics.android.model.realm.FilterElementBlind |
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -16,7 +14,7 @@ import java.util.* |
|
|
|
|
* To handle that, the enum has a public [valueMap] variable |
|
|
|
|
* A new type should also set the expected numericValues required in the [filterValuesExpectedKeys] |
|
|
|
|
*/ |
|
|
|
|
enum class QueryType(private var subType:SubType? = null) { |
|
|
|
|
enum class QueryType(var subType:SubType? = null) { |
|
|
|
|
LIVE, |
|
|
|
|
CASH, |
|
|
|
|
ONLINE, |
|
|
|
|
@ -68,7 +66,7 @@ enum class QueryType(private var subType:SubType? = null) { |
|
|
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
private enum class SubType { |
|
|
|
|
enum class SubType { |
|
|
|
|
BETWEEN, |
|
|
|
|
MORE, |
|
|
|
|
LESS; |
|
|
|
|
@ -98,18 +96,19 @@ enum class QueryType(private var subType:SubType? = null) { |
|
|
|
|
* main method of the enum |
|
|
|
|
* providing a base RealmQuery [realmQuery], the method is able to attached the corresponding query and returns the newly formed [RealmQuery] |
|
|
|
|
*/ |
|
|
|
|
fun filter(realmQuery: RealmQuery<out RealmObject>, filterable: Filterable): RealmQuery<out RealmObject> { |
|
|
|
|
inline fun <reified T : Filterable> filter(realmQuery: RealmQuery<T>): RealmQuery<T> { |
|
|
|
|
when { |
|
|
|
|
this == BLINDS -> { |
|
|
|
|
val smallBlindFieldName = filterable.fieldNameForQueryType(SMALL_BLIND) |
|
|
|
|
val bigBlindFieldName = filterable.fieldNameForQueryType(BIG_BLIND) |
|
|
|
|
val currencyCodeFieldName = filterable.fieldNameForQueryType(CURRENCY_CODE) |
|
|
|
|
|
|
|
|
|
val smallBlindFieldName = FilterHelper.fieldNameForQueryType<T>(queryType = SMALL_BLIND) |
|
|
|
|
val bigBlindFieldName = FilterHelper.fieldNameForQueryType<T>(queryType = BIG_BLIND) |
|
|
|
|
val currencyCodeFieldName = FilterHelper.fieldNameForQueryType<T>(CURRENCY_CODE) |
|
|
|
|
smallBlindFieldName ?: throw FilterValueMapException("fieldName is missing") |
|
|
|
|
bigBlindFieldName ?: throw FilterValueMapException("fieldName is missing") |
|
|
|
|
currencyCodeFieldName ?: throw FilterValueMapException("fieldName is missing") |
|
|
|
|
|
|
|
|
|
val blinds: RealmList<FilterElementBlind> by valueMap |
|
|
|
|
blinds.forEachIndexed {index, blind -> |
|
|
|
|
blinds.forEachIndexed { index, blind -> |
|
|
|
|
realmQuery |
|
|
|
|
.beginGroup() |
|
|
|
|
|
|
|
|
|
@ -137,11 +136,8 @@ enum class QueryType(private var subType:SubType? = null) { |
|
|
|
|
} |
|
|
|
|
return realmQuery |
|
|
|
|
} |
|
|
|
|
this == ONLINE -> return LIVE.filter(realmQuery.not(), filterable) |
|
|
|
|
this == TOURNAMENT -> return CASH.filter(realmQuery.not(), filterable) |
|
|
|
|
this == WEEK_DAY -> return WEEK_END.filter(realmQuery.not(), filterable) |
|
|
|
|
else -> { |
|
|
|
|
val fieldName = filterable.fieldNameForQueryType(this) |
|
|
|
|
val fieldName = FilterHelper.fieldNameForQueryType<T>(this) |
|
|
|
|
fieldName ?: throw FilterValueMapException("fieldName is missing") |
|
|
|
|
|
|
|
|
|
this.subType?.let { subType -> |
|
|
|
|
@ -163,8 +159,8 @@ enum class QueryType(private var subType:SubType? = null) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return when (this) { |
|
|
|
|
LIVE -> realmQuery.equalTo(fieldName, true) |
|
|
|
|
CASH -> realmQuery.equalTo(fieldName, Session.Type.CASH_GAME.ordinal) |
|
|
|
|
LIVE, ONLINE -> realmQuery.equalTo(fieldName, this == LIVE) |
|
|
|
|
CASH, TOURNAMENT -> realmQuery.equalTo(fieldName, this.ordinal) |
|
|
|
|
ALL_TOURNAMENT_FEATURES -> { |
|
|
|
|
val ids: Array<String> by valueMap |
|
|
|
|
ids.forEach { |
|
|
|
|
@ -212,8 +208,10 @@ enum class QueryType(private var subType:SubType? = null) { |
|
|
|
|
val year: Int by valueMap |
|
|
|
|
realmQuery.equalTo(fieldName, year) |
|
|
|
|
} |
|
|
|
|
WEEK_END -> { |
|
|
|
|
realmQuery.`in`(fieldName, arrayOf(Calendar.SATURDAY, Calendar.SUNDAY)) |
|
|
|
|
WEEK_END, WEEK_DAY -> { |
|
|
|
|
var query = realmQuery.`in`(fieldName, arrayOf(Calendar.SATURDAY, Calendar.SUNDAY)) |
|
|
|
|
if (this == WEEK_DAY) { query.not() } |
|
|
|
|
query |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
throw FilterValueMapException("filter type not handled") |
|
|
|
|
|