parent
c41b937933
commit
ea728a1cf2
@ -1,81 +0,0 @@ |
||||
package net.pokeranalytics.android.model.realm |
||||
|
||||
import io.realm.RealmList |
||||
import io.realm.RealmObject |
||||
import io.realm.annotations.Ignore |
||||
import net.pokeranalytics.android.model.filter.FilterType |
||||
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow |
||||
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.* |
||||
import java.util.* |
||||
import kotlin.collections.ArrayList |
||||
|
||||
open class FilterComponent(var filterName : String = "", var sectionName: String = "") : RealmObject() { |
||||
|
||||
constructor(filterElementRows: ArrayList<FilterElementRow>) : this(filterElementRows.first().filterName, filterElementRows.first().filterSectionRow.name) { |
||||
this.ids = when (FilterType.valueOf(this.filterName)) { |
||||
FilterType.GAME -> { |
||||
RealmList<String>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as FilterElementRow.Game).game.id |
||||
}) |
||||
} |
||||
} |
||||
else -> null |
||||
} |
||||
|
||||
this.values = when (FilterType.valueOf(filterName)) { |
||||
FilterType.LIMIT -> { |
||||
RealmList<Int>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as FilterElementRow.Limit).limit.ordinal |
||||
}) |
||||
} |
||||
} |
||||
else -> null |
||||
} |
||||
} |
||||
|
||||
constructor(filterElementRow:FilterElementRow) : this(filterElementRow.filterName, filterElementRow.filterSectionRow.name) { |
||||
when (filterElementRow) { |
||||
is From -> date = filterElementRow.date |
||||
is To -> date = filterElementRow.date |
||||
} |
||||
} |
||||
|
||||
val filterType : FilterType |
||||
get() = FilterType.valueOf(filterName) |
||||
.apply { |
||||
this.setValueFrom(this@FilterComponent) |
||||
} |
||||
|
||||
var date : Date? = null |
||||
var values : RealmList<Int>? = null |
||||
var ids : RealmList<String>? = null |
||||
|
||||
@Ignore |
||||
val value : Double? = null |
||||
|
||||
@Ignore |
||||
val leftValue : Double? = null |
||||
|
||||
@Ignore |
||||
val rightValue : Double? = null |
||||
|
||||
@Ignore |
||||
val blinds : Array<Map<String,Any?>>? = null |
||||
|
||||
@Ignore |
||||
val dayOfWeek : Int? = null |
||||
|
||||
@Ignore |
||||
val month : Int? = null |
||||
|
||||
@Ignore |
||||
val year : Int? = null |
||||
} |
||||
|
||||
open class BlindFilterComponent : RealmObject() { |
||||
var sb : Double? = null |
||||
var bb : Double? = null |
||||
var code : String? = null |
||||
} |
||||
@ -0,0 +1,144 @@ |
||||
package net.pokeranalytics.android.model.realm |
||||
|
||||
import io.realm.RealmList |
||||
import io.realm.RealmObject |
||||
import net.pokeranalytics.android.exceptions.FilterValueMapException |
||||
import net.pokeranalytics.android.model.filter.QueryType |
||||
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow |
||||
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow.* |
||||
import java.util.* |
||||
import kotlin.collections.ArrayList |
||||
|
||||
open class FilterElement(var filterName : String = "", var sectionName: String = "") : RealmObject() { |
||||
|
||||
constructor(filterElementRows: ArrayList<FilterElementRow>) : this(filterElementRows.first().filterName, filterElementRows.first().filterSectionRow.name) { |
||||
this.stringValues = when (QueryType.valueOf(this.filterName)) { |
||||
QueryType.GAME, QueryType.BANKROLL, QueryType.TOURNAMENT_NAME, QueryType.ALL_TOURNAMENT_FEATURES, QueryType.ANY_TOURNAMENT_FEATURES, QueryType.LOCATION -> { |
||||
RealmList<String>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as DataFilterElementRow).id |
||||
}) |
||||
} |
||||
} |
||||
else -> null |
||||
} |
||||
|
||||
this.numericValues = when (QueryType.valueOf(filterName)) { |
||||
QueryType.LIMIT -> { |
||||
RealmList<Double>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as FilterElementRow.Limit).limit.ordinal.toDouble() |
||||
}) |
||||
} |
||||
} |
||||
QueryType.TABLE_SIZE -> { |
||||
RealmList<Double>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as FilterElementRow.TableSize).tableSize.numberOfPlayer.toDouble() |
||||
}) |
||||
} |
||||
} |
||||
QueryType.YEAR, QueryType.MONTH, QueryType.DAY_OF_WEEK -> { |
||||
RealmList<Double>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as SingleValueFilterElementRow).value.toDouble() |
||||
}) |
||||
} |
||||
} |
||||
QueryType.LESS_THAN_NET_RESULT -> { |
||||
RealmList<Double>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as ResultLessThan).value |
||||
}) |
||||
} |
||||
} |
||||
QueryType.MORE_THAN_NET_RESULT -> { |
||||
RealmList<Double>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as ResultMoreThan).value |
||||
}) |
||||
} |
||||
} |
||||
else -> null |
||||
} |
||||
|
||||
this.blindValues = when (QueryType.valueOf(filterName)) { |
||||
QueryType.BLINDS -> { |
||||
RealmList<FilterElementBlind>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
FilterElementBlind((it as FilterElementRow.Blind).sb, it.bb, it.code) |
||||
}) |
||||
} |
||||
} |
||||
else -> null |
||||
} |
||||
} |
||||
|
||||
constructor(filterElementRow:FilterElementRow) : this(arrayListOf(filterElementRow)) { |
||||
when (filterElementRow) { |
||||
is From -> dateValue = filterElementRow.date |
||||
is To -> dateValue= filterElementRow.date |
||||
} |
||||
} |
||||
|
||||
val queryType : QueryType |
||||
get() = QueryType.valueOf(filterName) |
||||
.apply { |
||||
this.updateValueMap(this@FilterElement) |
||||
} |
||||
|
||||
private var numericValues: RealmList<Double>? = null |
||||
private var dateValue : Date? = null |
||||
private var stringValues : RealmList<String>? = null |
||||
private var blindValues : RealmList<FilterElementBlind>? = null |
||||
|
||||
val ids : Array<String> |
||||
get() = stringValues?.toTypedArray()?: throw FilterValueMapException("filter type not handled") |
||||
|
||||
val blinds : RealmList<FilterElementBlind> |
||||
get() { |
||||
blindValues?.let { |
||||
if (it.isNotEmpty()) { |
||||
return it |
||||
} else { |
||||
throw FilterValueMapException("filter is empty or null") |
||||
} |
||||
} |
||||
throw FilterValueMapException("filter is empty or null") |
||||
} |
||||
|
||||
|
||||
val date : Date |
||||
get() = dateValue?: throw FilterValueMapException("filter type not handled") |
||||
|
||||
|
||||
val values : Array<Int> |
||||
get() = numericValues?.map { |
||||
it.toInt() |
||||
}?.toTypedArray()?: throw FilterValueMapException("filter type not handled") |
||||
|
||||
|
||||
val value : Double |
||||
get() = numericValues?.first()?: throw FilterValueMapException("filter type not handled") |
||||
|
||||
|
||||
val leftValue : Double |
||||
get() = numericValues?.first()?: throw FilterValueMapException("filter type not handled") |
||||
|
||||
|
||||
val rightValue : Double |
||||
get() = numericValues?.last()?: throw FilterValueMapException("filter type not handled") |
||||
|
||||
|
||||
val dayOfWeek : Int |
||||
get() = numericValues?.first()?.toInt()?: throw FilterValueMapException("filter type not handled") |
||||
|
||||
|
||||
val month : Int |
||||
get() = numericValues?.first()?.toInt()?: throw FilterValueMapException("filter type not handled") |
||||
|
||||
|
||||
val year : Int |
||||
get() = numericValues?.first()?.toInt()?: throw FilterValueMapException("filter type not handled") |
||||
|
||||
} |
||||
@ -0,0 +1,8 @@ |
||||
package net.pokeranalytics.android.model.realm |
||||
|
||||
import io.realm.RealmObject |
||||
|
||||
open class FilterElementBlind(var sb : Double? = null, |
||||
var bb : Double? = null, |
||||
var code : String? = null |
||||
) : RealmObject() |
||||
Loading…
Reference in new issue