|
|
|
|
@ -39,15 +39,15 @@ open class Filter : RealmObject() { |
|
|
|
|
return realm.where<Filter>().equalTo("id", filterId).findFirst() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@TestOnly |
|
|
|
|
inline fun <reified T : Filterable> queryOn(realm: Realm, queries: List<QueryCondition>): RealmResults<T> { |
|
|
|
|
var realmQuery = realm.where<T>() |
|
|
|
|
queries.forEach { |
|
|
|
|
realmQuery = it.filter<T>(realmQuery) |
|
|
|
|
} |
|
|
|
|
return realmQuery.findAll() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@TestOnly |
|
|
|
|
inline fun <reified T : Filterable> queryOn(realm: Realm, queries: List<QueryCondition>): RealmResults<T> { |
|
|
|
|
var realmQuery = realm.where<T>() |
|
|
|
|
queries.forEach { |
|
|
|
|
realmQuery = it.filter<T>(realmQuery) |
|
|
|
|
} |
|
|
|
|
return realmQuery.findAll() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@PrimaryKey |
|
|
|
|
var id = UUID.randomUUID().toString() |
|
|
|
|
@ -59,59 +59,70 @@ open class Filter : RealmObject() { |
|
|
|
|
// for MutableRealmInteger, see https://realm.io/docs/java/latest/#counters |
|
|
|
|
val usageCount: MutableRealmInteger = MutableRealmInteger.valueOf(0) |
|
|
|
|
|
|
|
|
|
var filterConditions: RealmList<FilterCondition> = RealmList() |
|
|
|
|
private set |
|
|
|
|
|
|
|
|
|
fun createOrUpdateFilterConditions(filterConditionRows: ArrayList<FilterElementRow>) { |
|
|
|
|
filterConditions.clear() |
|
|
|
|
filterConditionRows |
|
|
|
|
.map { |
|
|
|
|
it.filterSectionRow |
|
|
|
|
} |
|
|
|
|
.distinct() |
|
|
|
|
.forEach { section -> |
|
|
|
|
filterConditionRows |
|
|
|
|
.filter { |
|
|
|
|
it.filterSectionRow == section |
|
|
|
|
} |
|
|
|
|
.apply { |
|
|
|
|
|
|
|
|
|
if (this.size == 1) { |
|
|
|
|
filterConditions.add(FilterCondition(this.first())) |
|
|
|
|
} else { |
|
|
|
|
val casted = arrayListOf<FilterElementRow>() |
|
|
|
|
casted.addAll(this) |
|
|
|
|
filterConditions.add(FilterCondition(casted)) |
|
|
|
|
} |
|
|
|
|
var filterConditions: RealmList<FilterCondition> = RealmList() |
|
|
|
|
private set |
|
|
|
|
|
|
|
|
|
fun createOrUpdateFilterConditions(filterConditionRows: ArrayList<FilterElementRow>) { |
|
|
|
|
filterConditions.clear() |
|
|
|
|
filterConditionRows |
|
|
|
|
.map { |
|
|
|
|
it.filterSectionRow |
|
|
|
|
} |
|
|
|
|
.distinct() |
|
|
|
|
.forEach { section -> |
|
|
|
|
filterConditionRows |
|
|
|
|
.filter { |
|
|
|
|
it.filterSectionRow == section |
|
|
|
|
} |
|
|
|
|
.apply { |
|
|
|
|
if (this.size == 1) { |
|
|
|
|
filterConditions.add(FilterCondition(this.first())) |
|
|
|
|
} else { |
|
|
|
|
val casted = arrayListOf<FilterElementRow>() |
|
|
|
|
casted.addAll(this) |
|
|
|
|
filterConditions.add(FilterCondition(casted)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun countBy(filterCategoryRow: FilterCategoryRow) : Int { |
|
|
|
|
val sections = filterCategoryRow.filterSectionRows |
|
|
|
|
return filterConditions.count { |
|
|
|
|
sections.contains(FilterSectionRow.valueOf(it.sectionName ?: throw PokerAnalyticsException.FilterElementUnknownSectionName)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun contains(filterElementRow:FilterElementRow) : Boolean { |
|
|
|
|
val filtered = filterConditions.filter { |
|
|
|
|
it.filterName == filterElementRow.filterName |
|
|
|
|
} |
|
|
|
|
if (filtered.isEmpty()) { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
return filterElementRow.contains(filtered) |
|
|
|
|
} |
|
|
|
|
fun countBy(filterCategoryRow: FilterCategoryRow): Int { |
|
|
|
|
val sections = filterCategoryRow.filterSectionRows |
|
|
|
|
return filterConditions.count { |
|
|
|
|
sections.contains(FilterSectionRow.valueOf(it.sectionName ?: throw PokerAnalyticsException.FilterElementUnknownSectionName)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun contains(filterElementRow: FilterElementRow): Boolean { |
|
|
|
|
val filtered = filterConditions.filter { |
|
|
|
|
it.filterName == filterElementRow.filterName |
|
|
|
|
} |
|
|
|
|
if (filtered.isEmpty()) { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
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> { |
|
|
|
|
var realmQuery = realm.where<T>() |
|
|
|
|
this.filterConditions.map { |
|
|
|
|
it.queryCondition |
|
|
|
|
}.forEach { |
|
|
|
|
realmQuery = it.filter(realmQuery) |
|
|
|
|
} |
|
|
|
|
var realmQuery = realm.where<T>() |
|
|
|
|
this.filterConditions.map { |
|
|
|
|
it.queryCondition |
|
|
|
|
}.forEach { |
|
|
|
|
realmQuery = it.filter(realmQuery) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return realmQuery.findAll() |
|
|
|
|
} |
|
|
|
|
|