|
|
|
|
@ -12,7 +12,7 @@ fun List<Query>.mapFirstCondition() : List<QueryCondition> { |
|
|
|
|
class Query { |
|
|
|
|
|
|
|
|
|
constructor(vararg elements: QueryCondition) { |
|
|
|
|
if (elements.size > 0) { |
|
|
|
|
if (elements.isNotEmpty()) { |
|
|
|
|
this.add(elements.asList()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -23,22 +23,25 @@ class Query { |
|
|
|
|
return this._conditions |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun add(vararg elements: QueryCondition) { |
|
|
|
|
if (elements.size > 0) { |
|
|
|
|
fun add(vararg elements: QueryCondition): Query { |
|
|
|
|
if (elements.isNotEmpty()) { |
|
|
|
|
this.add(elements.asList()) |
|
|
|
|
} |
|
|
|
|
return this |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun add(queryCondition: QueryCondition) { |
|
|
|
|
fun add(queryCondition: QueryCondition): Query { |
|
|
|
|
this._conditions.add(queryCondition) |
|
|
|
|
return this |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun remove(queryCondition: QueryCondition) { |
|
|
|
|
this._conditions.remove(queryCondition) |
|
|
|
|
fun add(queryConditions: List<QueryCondition>): Query{ |
|
|
|
|
this._conditions.addAll(queryConditions) |
|
|
|
|
return this |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun add(queryConditions: List<QueryCondition>) { |
|
|
|
|
this._conditions.addAll(queryConditions) |
|
|
|
|
fun remove(queryCondition: QueryCondition) { |
|
|
|
|
this._conditions.remove(queryCondition) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val defaultName: String |
|
|
|
|
@ -59,28 +62,32 @@ class Query { |
|
|
|
|
inline fun <reified T : Filterable> queryWith(query: RealmQuery<T>): RealmQuery<T> { |
|
|
|
|
var realmQuery = query |
|
|
|
|
|
|
|
|
|
val queryFromTime = this.conditions.filter { |
|
|
|
|
it is QueryCondition.StartedFromTime |
|
|
|
|
}.firstOrNull() |
|
|
|
|
val queryToTime = this.conditions.filter { |
|
|
|
|
it is QueryCondition.EndedToTime |
|
|
|
|
}.firstOrNull() |
|
|
|
|
|
|
|
|
|
this.conditions.forEach { |
|
|
|
|
if (it is QueryCondition.StartedFromTime) { |
|
|
|
|
realmQuery = it.queryWith(realmQuery, queryToTime) |
|
|
|
|
} else if (it is QueryCondition.EndedToTime) { |
|
|
|
|
realmQuery = it.queryWith(realmQuery, queryFromTime) |
|
|
|
|
} else { |
|
|
|
|
realmQuery = it.queryWith(realmQuery) |
|
|
|
|
} |
|
|
|
|
val queryFromTime = this.conditions.firstOrNull { |
|
|
|
|
it is QueryCondition.StartedFromTime |
|
|
|
|
} |
|
|
|
|
val queryToTime = this.conditions.firstOrNull { |
|
|
|
|
it is QueryCondition.EndedToTime |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.conditions.forEach { |
|
|
|
|
realmQuery = when (it) { |
|
|
|
|
is QueryCondition.StartedFromTime -> { |
|
|
|
|
it.queryWith(realmQuery, queryToTime) |
|
|
|
|
} |
|
|
|
|
is QueryCondition.EndedToTime -> { |
|
|
|
|
it.queryWith(realmQuery, queryFromTime) |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
it.queryWith(realmQuery) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// println("<<<<<< ${realmQuery.description}") |
|
|
|
|
val queryLast = this.conditions.filter { |
|
|
|
|
it is QueryCondition.Last |
|
|
|
|
}.firstOrNull() |
|
|
|
|
queryLast?.let {qc -> |
|
|
|
|
val queryLast = this.conditions.firstOrNull { |
|
|
|
|
it is QueryCondition.Last |
|
|
|
|
} |
|
|
|
|
queryLast?.let {qc -> |
|
|
|
|
(qc as QueryCondition.Last).singleValue?.let { |
|
|
|
|
return realmQuery.limit(it.toLong()) |
|
|
|
|
} |
|
|
|
|
|