Add getValue methods

feature/top10
Aurelien Hubert 7 years ago
parent 30c2b100c4
commit e5a454c4bd
  1. 13
      app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt
  2. 11
      app/src/main/java/net/pokeranalytics/android/model/realm/FilterCondition.kt

@ -75,7 +75,6 @@ open class Filter : RealmObject() {
it.filterSectionRow == section it.filterSectionRow == section
} }
.apply { .apply {
if (this.size == 1) { if (this.size == 1) {
filterConditions.add(FilterCondition(this.first())) filterConditions.add(FilterCondition(this.first()))
} else { } else {
@ -105,6 +104,18 @@ open class Filter : RealmObject() {
return filterElementRow.contains(filtered) return filterElementRow.contains(filtered)
} }
fun getValueForElement(filterElementRow: FilterElementRow): Any? {
val filtered = filterConditions.filter {
it.filterName == filterElementRow.filterName
}
if (filtered.isNotEmpty()) {
return filtered.first().getValue(filterElementRow)
}
return null
}
inline fun <reified T : Filterable> results(): RealmResults<T> { inline fun <reified T : Filterable> results(): RealmResults<T> {
var realmQuery = realm.where<T>() var realmQuery = realm.where<T>()
this.filterConditions.map { this.filterConditions.map {

@ -157,4 +157,15 @@ open class FilterCondition() : RealmObject() {
val year: Int val year: Int
get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing get() = numericValues?.first()?.toInt() ?: throw PokerAnalyticsException.FilterElementExpectedValueMissing
/**
* Return the value associated with the given filter element row
*/
fun getValue(filterElementRow: FilterElementRow): Any? {
return when (filterElementRow) {
is From, is To -> dateValue
else -> null
}
}
} }

Loading…
Cancel
Save