|
|
|
@ -1,18 +1,27 @@ |
|
|
|
package net.pokeranalytics.android.model.filter |
|
|
|
package net.pokeranalytics.android.model.filter |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import io.realm.* |
|
|
|
import io.realm.* |
|
|
|
import io.realm.internal.Table |
|
|
|
|
|
|
|
import io.realm.kotlin.where |
|
|
|
import io.realm.kotlin.where |
|
|
|
import io.realm.RealmQuery |
|
|
|
import io.realm.RealmQuery |
|
|
|
|
|
|
|
import io.realm.internal.Table |
|
|
|
import net.pokeranalytics.android.exceptions.PokerAnalyticsException |
|
|
|
import net.pokeranalytics.android.exceptions.PokerAnalyticsException |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.Limit |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.TableSize |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.TournamentType |
|
|
|
import net.pokeranalytics.android.model.interfaces.Identifiable |
|
|
|
import net.pokeranalytics.android.model.interfaces.Identifiable |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Manageable |
|
|
|
import net.pokeranalytics.android.model.realm.* |
|
|
|
import net.pokeranalytics.android.model.realm.* |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow |
|
|
|
import net.pokeranalytics.android.util.extensions.endOfDay |
|
|
|
import net.pokeranalytics.android.util.extensions.endOfDay |
|
|
|
import net.pokeranalytics.android.util.extensions.startOfDay |
|
|
|
import net.pokeranalytics.android.util.extensions.startOfDay |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
|
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
|
|
|
|
|
|
|
fun List<QueryCondition>.name() : String { |
|
|
|
fun List<QueryCondition>.name() : String { |
|
|
|
return this.map { it.name }.joinToString(" / ") |
|
|
|
return this.map { it.id }.joinToString(" / ") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//inline fun <reified T : Filterable> List<QueryCondition>.query(realm: Realm): RealmQuery<T> { |
|
|
|
//inline fun <reified T : Filterable> List<QueryCondition>.query(realm: Realm): RealmQuery<T> { |
|
|
|
@ -34,17 +43,86 @@ inline fun <reified T : Filterable> List<QueryCondition>.queryWith(query: RealmQ |
|
|
|
* A new type should also set the expected numericValues required in the [filterValuesExpectedKeys] |
|
|
|
* A new type should also set the expected numericValues required in the [filterValuesExpectedKeys] |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
sealed class QueryCondition(var operator: Operator? = null) { |
|
|
|
sealed class QueryCondition : FilterElementRow { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface asListOfDouble { var doubleValues : ArrayList<Double> } |
|
|
|
|
|
|
|
interface asListOfBoolean { var booleanValues : ArrayList<Boolean> } |
|
|
|
|
|
|
|
interface asListOfString { var stringValues : ArrayList<String> } |
|
|
|
|
|
|
|
interface asDateValue { |
|
|
|
|
|
|
|
var dateValue: Date |
|
|
|
|
|
|
|
var showTime: Boolean |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface asListOfInt : asListOfDouble { |
|
|
|
|
|
|
|
var intValues : ArrayList<Int> |
|
|
|
|
|
|
|
get() { return ArrayList(doubleValues.map { it.toInt() }) } |
|
|
|
|
|
|
|
set(value) { doubleValues = ArrayList(value.map { it.toDouble() })} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface asIntValue : asListOfInt { |
|
|
|
|
|
|
|
var intValue: Int |
|
|
|
|
|
|
|
get() { return intValues.first() } |
|
|
|
|
|
|
|
set(value) { intValues = arrayListOf(value) } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface asDoubleValue : asListOfDouble { |
|
|
|
|
|
|
|
var doubleValue : Double |
|
|
|
|
|
|
|
get() { return doubleValues.first() } |
|
|
|
|
|
|
|
set(value) { doubleValues = arrayListOf(value) } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface Duration: asDoubleValue { |
|
|
|
|
|
|
|
var minutes: Int |
|
|
|
|
|
|
|
get() { return doubleValue.toInt() } |
|
|
|
|
|
|
|
set(value) { doubleValue = value.toDouble() } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface Amount: asDoubleValue { |
|
|
|
|
|
|
|
var amount: Double |
|
|
|
|
|
|
|
get() { return doubleValue } |
|
|
|
|
|
|
|
set(value) { doubleValue = value } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
abstract class QueryDataCondition < T: Identifiable> : QueryCondition() { |
|
|
|
interface More |
|
|
|
fun setObject(dataObject:T) { |
|
|
|
interface Less |
|
|
|
this.valueMap = mapOf("ids" to arrayListOf(dataObject.id)) |
|
|
|
interface Between : asListOfDouble { |
|
|
|
|
|
|
|
val leftValue: Double get() { return doubleValues.first() } |
|
|
|
|
|
|
|
val rightValue: Double get() { return doubleValues.last() } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface BetweenLeftExclusive : Between |
|
|
|
|
|
|
|
interface BetweenRightExclusive : Between |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val id: String get() { return this::class.simpleName ?: throw PokerAnalyticsException.FilterElementUnknownName } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override var filterSectionRow: FilterSectionRow = FilterSectionRow.CASH_TOURNAMENT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open class OperationQueryCondition : QueryCondition(), asDoubleValue { |
|
|
|
|
|
|
|
override var doubleValues = ArrayList<Double>() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open class BetweenQueryCondition : QueryCondition(), asListOfDouble { |
|
|
|
|
|
|
|
override var doubleValues = ArrayList<Double>() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class MoreQueryCondition : QueryCondition(Operator.MORE) |
|
|
|
abstract class QueryDataCondition < T: Identifiable> : QueryCondition(), asListOfString { |
|
|
|
class LessQueryCondition : QueryCondition(Operator.LESS) |
|
|
|
fun setObject(dataObject: T) { |
|
|
|
|
|
|
|
this.dataObject = dataObject |
|
|
|
|
|
|
|
this.stringValues.add(dataObject.id) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var dataObject: Identifiable? = null |
|
|
|
|
|
|
|
override var stringValues = ArrayList<String>() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val name: String |
|
|
|
|
|
|
|
get() { |
|
|
|
|
|
|
|
if (stringValues.size > 1) { |
|
|
|
|
|
|
|
return "multiple" |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return (dataObject as RowRepresentable).getDisplayName() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return "todo" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
fun valueOf(name:String) : QueryCondition { |
|
|
|
fun valueOf(name:String) : QueryCondition { |
|
|
|
@ -55,7 +133,11 @@ sealed class QueryCondition(var operator: Operator? = null) { |
|
|
|
|
|
|
|
|
|
|
|
inline fun <reified T:Identifiable>getInstance(): QueryCondition { |
|
|
|
inline fun <reified T:Identifiable>getInstance(): QueryCondition { |
|
|
|
return when (T::class.java) { |
|
|
|
return when (T::class.java) { |
|
|
|
is Bankroll -> BANKROLL() |
|
|
|
Bankroll::class.java -> BANKROLL() |
|
|
|
|
|
|
|
Game::class.java -> GAME() |
|
|
|
|
|
|
|
Location::class.java -> LOCATION() |
|
|
|
|
|
|
|
TournamentName::class.java -> TOURNAMENT_NAME() |
|
|
|
|
|
|
|
TournamentFeature::class.java -> ANY_TOURNAMENT_FEATURES() |
|
|
|
else -> throw PokerAnalyticsException.QueryTypeUnhandled |
|
|
|
else -> throw PokerAnalyticsException.QueryTypeUnhandled |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -73,21 +155,15 @@ sealed class QueryCondition(var operator: Operator? = null) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val name: String = this::class.simpleName ?: throw PokerAnalyticsException.FilterElementUnknownName |
|
|
|
//open val name: String = this::class.simpleName ?: throw PokerAnalyticsException.FilterElementUnknownName |
|
|
|
|
|
|
|
|
|
|
|
enum class Operator { |
|
|
|
abstract class SingleValueQueryCondition : QueryCondition(), asIntValue { |
|
|
|
BETWEEN, |
|
|
|
override var doubleValues = ArrayList<Double>() |
|
|
|
MORE, |
|
|
|
|
|
|
|
LESS, |
|
|
|
|
|
|
|
BETWEEN_RIGHT_EXCLUSIVE, |
|
|
|
|
|
|
|
BETWEEN_LEFT_EXCLUSIVE, |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
open class SingleValueQueryCondition : QueryCondition() { |
|
|
|
abstract class StaticDataQueryCondition : QueryCondition(), asListOfInt { |
|
|
|
fun setValue(value:Int) { |
|
|
|
var data : RowRepresentable? = null |
|
|
|
this.valueMap = mapOf("values" to arrayListOf(value)) |
|
|
|
override var doubleValues = ArrayList<Double>() |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
object LIVE : QueryCondition() |
|
|
|
object LIVE : QueryCondition() |
|
|
|
@ -100,82 +176,99 @@ sealed class QueryCondition(var operator: Operator? = null) { |
|
|
|
class ANY_TOURNAMENT_FEATURES: QueryDataCondition<TournamentFeature>() |
|
|
|
class ANY_TOURNAMENT_FEATURES: QueryDataCondition<TournamentFeature>() |
|
|
|
class ALL_TOURNAMENT_FEATURES: QueryDataCondition<TournamentFeature>() |
|
|
|
class ALL_TOURNAMENT_FEATURES: QueryDataCondition<TournamentFeature>() |
|
|
|
class LOCATION: QueryDataCondition<Location>() |
|
|
|
class LOCATION: QueryDataCondition<Location>() |
|
|
|
class LIMIT: SingleValueQueryCondition() { |
|
|
|
|
|
|
|
fun setLimitType(limitType: Int) { |
|
|
|
|
|
|
|
this.valueMap = mapOf("values" to limitType) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TABLE_SIZE: SingleValueQueryCondition() { |
|
|
|
class LIMIT: StaticDataQueryCondition() { |
|
|
|
fun setNumberOfPlayer(numberOfPlayer: Int) { |
|
|
|
val limit : Limit get() { return Limit.values()[intValues.first()] } |
|
|
|
this.valueMap = mapOf("values" to numberOfPlayer) |
|
|
|
val name: String |
|
|
|
|
|
|
|
get() { |
|
|
|
|
|
|
|
if (intValues.size > 1) { |
|
|
|
|
|
|
|
return "multiple" |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return Limit.values()[intValues.first()].longName |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return "todo" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class TOURNAMENT_TYPE: SingleValueQueryCondition() { |
|
|
|
class TABLE_SIZE: StaticDataQueryCondition() { |
|
|
|
fun setTournamentType(tournamentType:Int) { |
|
|
|
val tableSize: TableSize get() { return TableSize.all[intValues.first()] } |
|
|
|
this.valueMap = mapOf("values" to tournamentType) |
|
|
|
|
|
|
|
|
|
|
|
override fun localizedTitle(context: Context): String { |
|
|
|
|
|
|
|
return this.tableSize.localizedTitle(context) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class BLIND: QueryCondition() { |
|
|
|
class TOURNAMENT_TYPE: StaticDataQueryCondition() { |
|
|
|
fun setBlind(blind:String, hasDefaultCurrency:Boolean) { |
|
|
|
val name: String |
|
|
|
this.valueMap = mapOf( |
|
|
|
get() { |
|
|
|
"blinds" to blind, |
|
|
|
if (intValues.size > 1) { |
|
|
|
"hasDefaultCurrency" to hasDefaultCurrency) |
|
|
|
return "multiple" |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return TournamentType.values()[intValues.first()].getDisplayName() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return "todo" |
|
|
|
} |
|
|
|
} |
|
|
|
class LAST_GAMES: QueryCondition() |
|
|
|
|
|
|
|
class LAST_SESSIONS: QueryCondition() |
|
|
|
|
|
|
|
class MORE_NUMBER_OF_TABLE: QueryCondition(Operator.MORE) |
|
|
|
|
|
|
|
class LESS_NUMBER_OF_TABLE: QueryCondition(Operator.LESS) |
|
|
|
|
|
|
|
class BETWEEN_NUMBER_OF_TABLE: QueryCondition(Operator.BETWEEN) |
|
|
|
|
|
|
|
class MORE_THAN_NET_RESULT: QueryCondition(Operator.MORE) |
|
|
|
|
|
|
|
class LESS_THAN_NET_RESULT: QueryCondition(Operator.LESS) |
|
|
|
|
|
|
|
class MORE_THAN_BUY_IN: QueryCondition(Operator.MORE) |
|
|
|
|
|
|
|
class LESS_THAN_BUY_IN: QueryCondition(Operator.LESS) |
|
|
|
|
|
|
|
class MORE_THAN_CASH_OUT: QueryCondition(Operator.MORE) |
|
|
|
|
|
|
|
class LESS_THAN_CASH_OUT: QueryCondition(Operator.LESS) |
|
|
|
|
|
|
|
class MORE_THAN_TIPS: QueryCondition(Operator.MORE) |
|
|
|
|
|
|
|
class LESS_THAN_TIPS: QueryCondition(Operator.LESS) |
|
|
|
|
|
|
|
class MORE_THAN_NUMBER_OF_PLAYER: QueryCondition(Operator.MORE) |
|
|
|
|
|
|
|
class LESS_THAN_NUMBER_OF_PLAYER: QueryCondition(Operator.LESS) |
|
|
|
|
|
|
|
class BETWEEN_NUMBER_OF_PLAYER: QueryCondition(Operator.BETWEEN) |
|
|
|
|
|
|
|
class MORE_THAN_TOURNAMENT_FEE: QueryCondition(Operator.MORE) |
|
|
|
|
|
|
|
class LESS_THAN_TOURNAMENT_FEE: QueryCondition(Operator.LESS) |
|
|
|
|
|
|
|
class BETWEEN_TOURNAMENT_FEE: QueryCondition(Operator.BETWEEN_RIGHT_EXCLUSIVE) { |
|
|
|
|
|
|
|
fun between(leftValue:Double, rightValue:Double) { |
|
|
|
|
|
|
|
this.valueMap = mapOf( |
|
|
|
|
|
|
|
"leftValue" to leftValue, |
|
|
|
|
|
|
|
"rightValue" to rightValue |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BLIND: QueryCondition(), asListOfString, asListOfBoolean { |
|
|
|
|
|
|
|
var blind: String? = null |
|
|
|
|
|
|
|
var hasDefaultCurrency: Boolean = false |
|
|
|
|
|
|
|
override var booleanValues = ArrayList<Boolean>() |
|
|
|
|
|
|
|
override var stringValues = ArrayList<String>() |
|
|
|
} |
|
|
|
} |
|
|
|
class MIN_RE_BUY: QueryCondition(Operator.MORE) |
|
|
|
|
|
|
|
class MAX_RE_BUY: QueryCondition(Operator.LESS) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Dates |
|
|
|
class LAST_GAMES: SingleValueQueryCondition() |
|
|
|
class STARTED_FROM_DATE: QueryCondition() |
|
|
|
class LAST_SESSIONS: SingleValueQueryCondition() |
|
|
|
class STARTED_TO_DATE: QueryCondition() |
|
|
|
|
|
|
|
class ENDED_FROM_DATE: QueryCondition() |
|
|
|
|
|
|
|
class ENDED_TO_DATE: QueryCondition() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DAY_OF_WEEK: QueryCondition() { |
|
|
|
class MORE_NUMBER_OF_TABLE: OperationQueryCondition(), More |
|
|
|
fun setDay(dayOfWeek:Int) { |
|
|
|
class LESS_NUMBER_OF_TABLE: OperationQueryCondition(), Less |
|
|
|
this.valueMap = mapOf("dayOfWeek" to dayOfWeek) |
|
|
|
class BETWEEN_NUMBER_OF_TABLE: BetweenQueryCondition(), Between |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
class MORE_THAN_NET_RESULT: OperationQueryCondition(), More, Amount |
|
|
|
|
|
|
|
class LESS_THAN_NET_RESULT: OperationQueryCondition(), Less, Amount |
|
|
|
|
|
|
|
|
|
|
|
class MONTH: QueryCondition() { |
|
|
|
class MORE_THAN_BUY_IN: OperationQueryCondition(), More, Amount |
|
|
|
fun setMonth(month:Int) { |
|
|
|
class LESS_THAN_BUY_IN: OperationQueryCondition(), Less, Amount |
|
|
|
this.valueMap = mapOf("month" to month) |
|
|
|
|
|
|
|
|
|
|
|
class MORE_THAN_CASH_OUT: OperationQueryCondition(), More, Amount |
|
|
|
|
|
|
|
class LESS_THAN_CASH_OUT: OperationQueryCondition(), Less, Amount |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MORE_THAN_TIPS: OperationQueryCondition(), More, Amount |
|
|
|
|
|
|
|
class LESS_THAN_TIPS: OperationQueryCondition(), Less, Amount |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MORE_THAN_NUMBER_OF_PLAYER: OperationQueryCondition(), More |
|
|
|
|
|
|
|
class LESS_THAN_NUMBER_OF_PLAYER: OperationQueryCondition(), Less |
|
|
|
|
|
|
|
class BETWEEN_NUMBER_OF_PLAYER: BetweenQueryCondition(), Between |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MORE_THAN_TOURNAMENT_FEE: OperationQueryCondition(), More |
|
|
|
|
|
|
|
class LESS_THAN_TOURNAMENT_FEE: OperationQueryCondition(), Less |
|
|
|
|
|
|
|
class BETWEEN_TOURNAMENT_FEE: BetweenQueryCondition(), BetweenRightExclusive { |
|
|
|
|
|
|
|
fun between(leftValue:Double, rightValue:Double) { |
|
|
|
|
|
|
|
doubleValues.add(leftValue) |
|
|
|
|
|
|
|
doubleValues.add(rightValue) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
class YEAR: QueryCondition() { |
|
|
|
class MIN_RE_BUY: OperationQueryCondition(), More |
|
|
|
fun setYear(year:Int) { |
|
|
|
class MAX_RE_BUY: OperationQueryCondition(), Less |
|
|
|
this.valueMap = mapOf("year" to year) |
|
|
|
|
|
|
|
|
|
|
|
// Dates |
|
|
|
|
|
|
|
open class DateQuery: QueryCondition(), asDateValue { |
|
|
|
|
|
|
|
override var dateValue: Date = Date() |
|
|
|
|
|
|
|
override var showTime: Boolean = false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open class TimeQuery: DateQuery() { |
|
|
|
|
|
|
|
override var showTime: Boolean = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class STARTED_FROM_DATE: DateQuery() |
|
|
|
|
|
|
|
class STARTED_TO_DATE: DateQuery(), Less |
|
|
|
|
|
|
|
class ENDED_FROM_DATE: DateQuery() |
|
|
|
|
|
|
|
class ENDED_TO_DATE: DateQuery(), Less |
|
|
|
|
|
|
|
class DAY_OF_WEEK: SingleValueQueryCondition() |
|
|
|
|
|
|
|
class MONTH: SingleValueQueryCondition() |
|
|
|
|
|
|
|
class YEAR: SingleValueQueryCondition() |
|
|
|
object WEEK_DAY: QueryCondition() |
|
|
|
object WEEK_DAY: QueryCondition() |
|
|
|
object WEEK_END: QueryCondition() |
|
|
|
object WEEK_END: QueryCondition() |
|
|
|
object TODAY: QueryCondition() |
|
|
|
object TODAY: QueryCondition() |
|
|
|
@ -184,51 +277,14 @@ sealed class QueryCondition(var operator: Operator? = null) { |
|
|
|
object THIS_WEEK: QueryCondition() |
|
|
|
object THIS_WEEK: QueryCondition() |
|
|
|
object THIS_MONTH: QueryCondition() |
|
|
|
object THIS_MONTH: QueryCondition() |
|
|
|
object THIS_YEAR: QueryCondition() |
|
|
|
object THIS_YEAR: QueryCondition() |
|
|
|
class PAST_DAYS: QueryCondition() |
|
|
|
class PAST_DAYS: SingleValueQueryCondition() |
|
|
|
class MORE_THAN_DURATION: QueryCondition(Operator.MORE) |
|
|
|
class MORE_THAN_DURATION: OperationQueryCondition(), More, Duration |
|
|
|
class LESS_THAN_DURATION: QueryCondition(Operator.LESS) |
|
|
|
class LESS_THAN_DURATION: OperationQueryCondition(), Less, Duration |
|
|
|
class STARTED_FROM_TIME: QueryCondition() |
|
|
|
class STARTED_FROM_TIME: TimeQuery() |
|
|
|
class ENDED_TO_TIME: QueryCondition() |
|
|
|
class ENDED_TO_TIME: TimeQuery(), Less |
|
|
|
|
|
|
|
|
|
|
|
class COMMENT: QueryCondition() |
|
|
|
class COMMENT: QueryCondition() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var valueMap : Map<String, Any?>? = null |
|
|
|
|
|
|
|
get() { |
|
|
|
|
|
|
|
this.filterValuesExpectedKeys?.let { valueMapExceptedKeys -> |
|
|
|
|
|
|
|
field?.let { map -> |
|
|
|
|
|
|
|
val missingKeys = map.keys.filter { !valueMapExceptedKeys.contains(it) } |
|
|
|
|
|
|
|
if (map.keys.size == valueMapExceptedKeys.size && missingKeys.isNotEmpty()) { |
|
|
|
|
|
|
|
throw PokerAnalyticsException.QueryValueMapMissingKeys(missingKeys) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} ?: run { |
|
|
|
|
|
|
|
throw PokerAnalyticsException.QueryValueMapUnexpectedValue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return field |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
protected set |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val filterValuesExpectedKeys : Array<String>? |
|
|
|
|
|
|
|
get() { |
|
|
|
|
|
|
|
this.operator?.let { |
|
|
|
|
|
|
|
return when (it) { |
|
|
|
|
|
|
|
Operator.BETWEEN -> arrayOf("leftValue", "rightValue") |
|
|
|
|
|
|
|
else -> arrayOf("value") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return when (this) { |
|
|
|
|
|
|
|
is BANKROLL, is GAME, is LOCATION, is ANY_TOURNAMENT_FEATURES, is ALL_TOURNAMENT_FEATURES, is TOURNAMENT_NAME -> arrayOf("ids") |
|
|
|
|
|
|
|
is LIMIT, is TOURNAMENT_TYPE, is TABLE_SIZE -> arrayOf("values") |
|
|
|
|
|
|
|
is BLIND -> arrayOf("blinds", "hasDefaultCurrency") |
|
|
|
|
|
|
|
is STARTED_FROM_DATE, is STARTED_TO_DATE, is ENDED_FROM_DATE, is ENDED_TO_DATE -> arrayOf("date") |
|
|
|
|
|
|
|
is DAY_OF_WEEK -> arrayOf("dayOfWeek") |
|
|
|
|
|
|
|
is MONTH -> arrayOf("month") |
|
|
|
|
|
|
|
is YEAR -> arrayOf("year") |
|
|
|
|
|
|
|
else -> null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* main method of the enum |
|
|
|
* 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] |
|
|
|
* providing a base RealmQuery [realmQuery], the method is able to attached the corresponding query and returns the newly formed [RealmQuery] |
|
|
|
@ -236,50 +292,29 @@ sealed class QueryCondition(var operator: Operator? = null) { |
|
|
|
inline fun <reified T : Filterable> queryWith(realmQuery: RealmQuery<T>): RealmQuery<T> { |
|
|
|
inline fun <reified T : Filterable> queryWith(realmQuery: RealmQuery<T>): RealmQuery<T> { |
|
|
|
val fieldName = FilterHelper.fieldNameForQueryType<T>(this::class.java) |
|
|
|
val fieldName = FilterHelper.fieldNameForQueryType<T>(this::class.java) |
|
|
|
fieldName ?: throw PokerAnalyticsException.QueryValueMapUnknown |
|
|
|
fieldName ?: throw PokerAnalyticsException.QueryValueMapUnknown |
|
|
|
when (operator) { |
|
|
|
return when (this) { |
|
|
|
Operator.LESS -> { |
|
|
|
is Amount -> { |
|
|
|
val value: Double by valueMap |
|
|
|
if (this is Less) { |
|
|
|
return realmQuery.lessThanOrEqualTo(fieldName, value) |
|
|
|
realmQuery.lessThanOrEqualTo(fieldName, amount) |
|
|
|
} |
|
|
|
} else { |
|
|
|
Operator.MORE -> { |
|
|
|
realmQuery.greaterThanOrEqualTo(fieldName, amount) |
|
|
|
val value: Double by valueMap |
|
|
|
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, value) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Operator.BETWEEN -> { |
|
|
|
|
|
|
|
val leftValue: Double by valueMap |
|
|
|
|
|
|
|
val rightValue: Double by valueMap |
|
|
|
|
|
|
|
return realmQuery.between(fieldName, leftValue, rightValue) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Operator.BETWEEN_LEFT_EXCLUSIVE -> { |
|
|
|
|
|
|
|
val leftValue: Double by valueMap |
|
|
|
|
|
|
|
val rightValue: Double by valueMap |
|
|
|
|
|
|
|
return realmQuery.greaterThan(fieldName, leftValue).and().lessThanOrEqualTo(fieldName, rightValue) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Operator.BETWEEN_RIGHT_EXCLUSIVE-> { |
|
|
|
|
|
|
|
val leftValue: Double by valueMap |
|
|
|
|
|
|
|
val rightValue: Double by valueMap |
|
|
|
|
|
|
|
return realmQuery.greaterThanOrEqualTo(fieldName, leftValue).and().lessThan(fieldName, rightValue) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
is Between -> realmQuery.between(fieldName, leftValue, rightValue) |
|
|
|
return when (this) { |
|
|
|
is BetweenLeftExclusive -> realmQuery.greaterThan(fieldName, leftValue).and().lessThanOrEqualTo(fieldName, rightValue) |
|
|
|
|
|
|
|
is BetweenRightExclusive -> realmQuery.greaterThanOrEqualTo(fieldName, leftValue).and().lessThan(fieldName, rightValue) |
|
|
|
LIVE, ONLINE -> realmQuery.equalTo(fieldName, this == LIVE) |
|
|
|
LIVE, ONLINE -> realmQuery.equalTo(fieldName, this == LIVE) |
|
|
|
CASH -> realmQuery.equalTo(fieldName, Session.Type.CASH_GAME.ordinal) |
|
|
|
CASH -> realmQuery.equalTo(fieldName, Session.Type.CASH_GAME.ordinal) |
|
|
|
TOURNAMENT -> realmQuery.equalTo(fieldName, Session.Type.TOURNAMENT.ordinal) |
|
|
|
TOURNAMENT -> realmQuery.equalTo(fieldName, Session.Type.TOURNAMENT.ordinal) |
|
|
|
is ALL_TOURNAMENT_FEATURES -> { |
|
|
|
is ALL_TOURNAMENT_FEATURES -> { |
|
|
|
val ids: Array<String> by valueMap |
|
|
|
stringValues.forEach { |
|
|
|
ids.forEach { |
|
|
|
|
|
|
|
realmQuery.equalTo(fieldName, it) |
|
|
|
realmQuery.equalTo(fieldName, it) |
|
|
|
} |
|
|
|
} |
|
|
|
realmQuery |
|
|
|
realmQuery |
|
|
|
} |
|
|
|
} |
|
|
|
is ANY_TOURNAMENT_FEATURES -> { |
|
|
|
|
|
|
|
val ids: Array<String> by valueMap |
|
|
|
|
|
|
|
realmQuery.`in`(fieldName, ids) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
is BLIND -> { |
|
|
|
is BLIND -> { |
|
|
|
val blinds: Array<String> by valueMap |
|
|
|
val blinds: Array<String> = stringValues.toTypedArray() |
|
|
|
val hasDefaultCurrency: Array<Boolean> by valueMap |
|
|
|
val hasDefaultCurrency: Array<Boolean> = booleanValues.toTypedArray() |
|
|
|
//realmQuery.`in`(fieldName, blinds) |
|
|
|
//realmQuery.`in`(fieldName, blinds) |
|
|
|
blinds.forEachIndexed { index, s -> |
|
|
|
blinds.forEachIndexed { index, s -> |
|
|
|
val isUsingDefaultCurrency = hasDefaultCurrency[index] |
|
|
|
val isUsingDefaultCurrency = hasDefaultCurrency[index] |
|
|
|
@ -298,42 +333,18 @@ sealed class QueryCondition(var operator: Operator? = null) { |
|
|
|
} |
|
|
|
} |
|
|
|
realmQuery |
|
|
|
realmQuery |
|
|
|
} |
|
|
|
} |
|
|
|
is BANKROLL, is GAME, is LOCATION, is TOURNAMENT_NAME -> { |
|
|
|
is QueryDataCondition<*> -> realmQuery.`in`(fieldName, stringValues.toTypedArray()) |
|
|
|
val ids: Array<String> by valueMap |
|
|
|
is StaticDataQueryCondition -> { |
|
|
|
realmQuery.`in`(fieldName, ids) |
|
|
|
realmQuery.`in`(fieldName, intValues.toTypedArray()) |
|
|
|
} |
|
|
|
|
|
|
|
is LIMIT, is TOURNAMENT_TYPE, is TABLE_SIZE -> { |
|
|
|
|
|
|
|
val values: Array<Int?>? by valueMap |
|
|
|
|
|
|
|
realmQuery.`in`(fieldName, values) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
is STARTED_FROM_DATE -> { |
|
|
|
|
|
|
|
val date: Date by valueMap |
|
|
|
|
|
|
|
realmQuery.greaterThanOrEqualTo(fieldName, date) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
is STARTED_TO_DATE -> { |
|
|
|
is DateQuery -> { |
|
|
|
val date: Date by valueMap |
|
|
|
if (this is Less) { |
|
|
|
realmQuery.lessThanOrEqualTo(fieldName, date) |
|
|
|
realmQuery.lessThanOrEqualTo(fieldName, dateValue) |
|
|
|
} |
|
|
|
} else { |
|
|
|
is ENDED_FROM_DATE -> { |
|
|
|
realmQuery.greaterThanOrEqualTo(fieldName, dateValue) |
|
|
|
val date: Date by valueMap |
|
|
|
|
|
|
|
realmQuery.greaterThanOrEqualTo(fieldName, date) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
is ENDED_TO_DATE -> { |
|
|
|
|
|
|
|
val date: Date by valueMap |
|
|
|
|
|
|
|
realmQuery.lessThanOrEqualTo(fieldName, date) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
is DAY_OF_WEEK -> { |
|
|
|
|
|
|
|
val dayOfWeek: Int by valueMap |
|
|
|
|
|
|
|
realmQuery.equalTo(fieldName, dayOfWeek) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
is MONTH -> { |
|
|
|
|
|
|
|
val month: Int by valueMap |
|
|
|
|
|
|
|
realmQuery.equalTo(fieldName, month) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
is YEAR -> { |
|
|
|
|
|
|
|
val year: Int by valueMap |
|
|
|
|
|
|
|
realmQuery.equalTo(fieldName, year) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
is SingleValueQueryCondition -> realmQuery.equalTo(fieldName, intValue) |
|
|
|
WEEK_END, WEEK_DAY -> { |
|
|
|
WEEK_END, WEEK_DAY -> { |
|
|
|
var query = realmQuery |
|
|
|
var query = realmQuery |
|
|
|
if (this == WEEK_DAY) { |
|
|
|
if (this == WEEK_DAY) { |
|
|
|
@ -386,42 +397,13 @@ sealed class QueryCondition(var operator: Operator? = null) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun updateValueMap(filterCondition: FilterCondition) { |
|
|
|
fun updateValueMap(filterCondition: FilterCondition) { |
|
|
|
if (filterValuesExpectedKeys == null) { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.operator?.let { |
|
|
|
|
|
|
|
valueMap = mapOf("value" to filterCondition.value) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when (this) { |
|
|
|
when (this) { |
|
|
|
is BANKROLL -> valueMap = mapOf("ids" to filterCondition.ids) |
|
|
|
is asListOfDouble -> filterCondition.doubleValues.map { doubleValues.add(it) } |
|
|
|
is ALL_TOURNAMENT_FEATURES, is ANY_TOURNAMENT_FEATURES, is GAME, is LOCATION, is TOURNAMENT_NAME -> { |
|
|
|
is QueryDataCondition<*> -> filterCondition.ids.map { stringValues.add(it) } |
|
|
|
valueMap = mapOf("ids" to filterCondition.ids) |
|
|
|
is DateQuery -> dateValue = filterCondition.date |
|
|
|
} |
|
|
|
|
|
|
|
is LIMIT, is TOURNAMENT_TYPE, is TABLE_SIZE -> { |
|
|
|
|
|
|
|
valueMap = mapOf("values" to filterCondition.values) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
is BLIND -> { |
|
|
|
is BLIND -> { |
|
|
|
valueMap = mapOf( |
|
|
|
filterCondition.blinds.map { stringValues.add(it) } |
|
|
|
"blinds" to filterCondition.blinds, |
|
|
|
filterCondition.hasDefaultCurrency.map { booleanValues.add(it) } |
|
|
|
"hasDefaultCurrency" to filterCondition.hasDefaultCurrency) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
is STARTED_FROM_DATE, is STARTED_TO_DATE, is ENDED_FROM_DATE, is ENDED_TO_DATE -> { |
|
|
|
|
|
|
|
valueMap = mapOf("date" to filterCondition.date) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
is DAY_OF_WEEK -> { |
|
|
|
|
|
|
|
valueMap = mapOf("dayOfWeek" to filterCondition.dayOfWeek) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
is MONTH -> { |
|
|
|
|
|
|
|
valueMap = mapOf("month" to filterCondition.month) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
is YEAR -> { |
|
|
|
|
|
|
|
valueMap = mapOf("year" to filterCondition.year) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
|
|
|
|
throw PokerAnalyticsException.QueryValueMapUnexpectedValue |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|