# Conflicts: # app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt # app/src/main/java/net/pokeranalytics/android/model/realm/FilterCondition.ktfeature/top10
commit
5b776cb04e
@ -0,0 +1,161 @@ |
||||
package net.pokeranalytics.android.model.realm |
||||
|
||||
import io.realm.RealmList |
||||
import io.realm.RealmObject |
||||
import net.pokeranalytics.android.exceptions.PokerAnalyticsException |
||||
import net.pokeranalytics.android.model.filter.QueryCondition |
||||
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.* |
||||
|
||||
open class FilterCondition() : RealmObject() { |
||||
|
||||
private constructor(filterName:String, sectionName:String) : this() { |
||||
this.filterName = filterName |
||||
this.sectionName = sectionName |
||||
} |
||||
|
||||
constructor(filterElementRows: ArrayList<FilterElementRow>) : this(filterElementRows.first().filterName, filterElementRows.first().filterSectionRow.name) { |
||||
val filterName : String = this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName |
||||
this.stringValues = when (QueryCondition.valueOf(filterName)) { |
||||
QueryCondition.GAME, QueryCondition.BANKROLL, QueryCondition.TOURNAMENT_NAME, QueryCondition.ALL_TOURNAMENT_FEATURES, QueryCondition.ANY_TOURNAMENT_FEATURES, QueryCondition.LOCATION -> { |
||||
RealmList<String>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as DataFilterElementRow).id |
||||
}) |
||||
} |
||||
} |
||||
QueryCondition.LIMIT, QueryCondition.TABLE_SIZE -> { |
||||
RealmList<String>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as StaticDataFilterElementRow).id |
||||
}) |
||||
} |
||||
} |
||||
else -> null |
||||
} |
||||
|
||||
|
||||
this.numericValues = when (QueryCondition.valueOf(filterName)) { |
||||
QueryCondition.LIMIT -> { |
||||
RealmList<Double>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as FilterElementRow.Limit).limit.ordinal.toDouble() |
||||
}) |
||||
} |
||||
} |
||||
QueryCondition.TABLE_SIZE -> { |
||||
RealmList<Double>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as FilterElementRow.TableSize).tableSize.numberOfPlayer.toDouble() |
||||
}) |
||||
} |
||||
} |
||||
QueryCondition.YEAR, QueryCondition.MONTH, QueryCondition.DAY_OF_WEEK -> { |
||||
RealmList<Double>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as SingleValueFilterElementRow).value.toDouble() |
||||
}) |
||||
} |
||||
} |
||||
QueryCondition.LESS_THAN_NET_RESULT -> { |
||||
RealmList<Double>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as ResultLessThan).value |
||||
}) |
||||
} |
||||
} |
||||
QueryCondition.MORE_THAN_NET_RESULT -> { |
||||
RealmList<Double>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as ResultMoreThan).value |
||||
}) |
||||
} |
||||
} |
||||
else -> null |
||||
} |
||||
|
||||
this.blindValues = when (QueryCondition.valueOf(filterName)) { |
||||
QueryCondition.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 |
||||
} |
||||
} |
||||
|
||||
var filterName: String? = null |
||||
var sectionName: String? = null |
||||
|
||||
val queryCondition : QueryCondition |
||||
get() = QueryCondition.valueOf(this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName) |
||||
.apply { |
||||
this.updateValueMap(this@FilterCondition) |
||||
} |
||||
|
||||
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 PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
val blinds: RealmList<FilterElementBlind> |
||||
get() { |
||||
blindValues?.let { |
||||
if (it.isNotEmpty()) { |
||||
return it |
||||
} else { |
||||
throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
} |
||||
} |
||||
throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
} |
||||
|
||||
|
||||
val date: Date |
||||
get() = dateValue ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val values: Array<Int> |
||||
get() = numericValues?.map { |
||||
it.toInt() |
||||
}?.toTypedArray() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val value: Double |
||||
get() = numericValues?.first() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val leftValue: Double |
||||
get() = numericValues?.first() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val rightValue: Double |
||||
get() = numericValues?.last() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val dayOfWeek: Int |
||||
get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val month: Int |
||||
get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val year: Int |
||||
get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
} |
||||
@ -1,159 +0,0 @@ |
||||
package net.pokeranalytics.android.model.realm |
||||
|
||||
import io.realm.RealmList |
||||
import io.realm.RealmObject |
||||
import net.pokeranalytics.android.exceptions.PokerAnalyticsException |
||||
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.* |
||||
|
||||
open class FilterElement() : RealmObject() { |
||||
|
||||
private constructor(filterName: String, sectionName: String) : this() { |
||||
this.filterName = filterName |
||||
this.sectionName = sectionName |
||||
} |
||||
|
||||
constructor(filterElementRows: ArrayList<FilterElementRow>) : this(filterElementRows.first().filterName, filterElementRows.first().filterSectionRow.name) { |
||||
val filterName: String = this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName |
||||
this.stringValues = when (QueryType.valueOf(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 |
||||
}) |
||||
} |
||||
} |
||||
QueryType.LIMIT, QueryType.TABLE_SIZE -> { |
||||
RealmList<String>().apply { |
||||
this.addAll(filterElementRows.map { |
||||
(it as StaticDataFilterElementRow).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 |
||||
} |
||||
} |
||||
|
||||
var filterName: String? = null |
||||
var sectionName: String? = null |
||||
|
||||
val queryType: QueryType |
||||
get() = QueryType.valueOf(this.filterName ?: throw PokerAnalyticsException.FilterElementUnknownName) |
||||
.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 PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
val blinds: RealmList<FilterElementBlind> |
||||
get() { |
||||
blindValues?.let { |
||||
if (it.isNotEmpty()) { |
||||
return it |
||||
} else { |
||||
throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
} |
||||
} |
||||
throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
} |
||||
|
||||
|
||||
val date: Date |
||||
get() = dateValue ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val values: Array<Int> |
||||
get() = numericValues?.map { |
||||
it.toInt() |
||||
}?.toTypedArray() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val value: Double |
||||
get() = numericValues?.first() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val leftValue: Double |
||||
get() = numericValues?.first() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val rightValue: Double |
||||
get() = numericValues?.last() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val dayOfWeek: Int |
||||
get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val month: Int |
||||
get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
|
||||
val year: Int |
||||
get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing |
||||
|
||||
} |
||||
Loading…
Reference in new issue