parent
44c28971c2
commit
b615820315
@ -1,113 +0,0 @@ |
|||||||
package net.pokeranalytics.android.model.comparison |
|
||||||
|
|
||||||
import io.realm.Realm |
|
||||||
import io.realm.Sort |
|
||||||
import io.realm.kotlin.where |
|
||||||
import net.pokeranalytics.android.exceptions.PokerAnalyticsException |
|
||||||
import net.pokeranalytics.android.model.Criteria |
|
||||||
import net.pokeranalytics.android.model.filter.QueryCondition |
|
||||||
import net.pokeranalytics.android.model.realm.* |
|
||||||
import java.util.* |
|
||||||
import kotlin.collections.ArrayList |
|
||||||
|
|
||||||
enum class Comparator { |
|
||||||
DAY_OF_WEEK, |
|
||||||
MONTH_OF_YEAR, |
|
||||||
YEAR, |
|
||||||
BLIND, |
|
||||||
CASH, |
|
||||||
TOURNAMENT, |
|
||||||
LIVE, |
|
||||||
ONLINE, |
|
||||||
GAME, |
|
||||||
BANKROLL, |
|
||||||
LOCATION, |
|
||||||
TOURNAMENT_FEATURE, |
|
||||||
TOURNAMENT_NAME, |
|
||||||
DAY_PERIOD, |
|
||||||
LIMIT_TYPE, |
|
||||||
TABLE_SIZE, |
|
||||||
TOURNAMENT_TYPE, |
|
||||||
TOURNAMENT_ENTRY_FEE, |
|
||||||
; |
|
||||||
|
|
||||||
val queryConditions: List<QueryCondition> |
|
||||||
get() { |
|
||||||
return when (this) { |
|
||||||
TOURNAMENT_ENTRY_FEE -> { |
|
||||||
val fees = arrayListOf<QueryCondition.BetweenTournamentFee>() |
|
||||||
val realm = Realm.getDefaultInstance() |
|
||||||
val fieldName = Session.fieldNameForQueryType(QueryCondition.BetweenTournamentFee::class.java)!! |
|
||||||
realm.where<Session>().distinct(fieldName).findAll().sort(fieldName, Sort.ASCENDING).map { |
|
||||||
it.tournamentEntryFee?.let { fee -> |
|
||||||
fees.add(QueryCondition.BetweenTournamentFee().apply { between(fee, fee) }) |
|
||||||
} |
|
||||||
} |
|
||||||
realm.close() |
|
||||||
fees |
|
||||||
} |
|
||||||
MONTH_OF_YEAR -> Criteria.MonthsOfYear.queryConditions |
|
||||||
DAY_OF_WEEK -> Criteria.DaysOfWeek.queryConditions |
|
||||||
YEAR -> Criteria.Years.queryConditions |
|
||||||
DAY_PERIOD -> Criteria.DayPeriods.queryConditions |
|
||||||
CASH -> listOf(QueryCondition.IsCash) |
|
||||||
TOURNAMENT -> listOf(QueryCondition.IsTournament) |
|
||||||
LIVE -> listOf(QueryCondition.IsLive) |
|
||||||
ONLINE -> listOf(QueryCondition.IsOnline) |
|
||||||
BLIND -> Criteria.Blinds.queryConditions |
|
||||||
BANKROLL -> Criteria.Bankrolls.queryConditions |
|
||||||
GAME -> Criteria.Games.queryConditions |
|
||||||
TOURNAMENT_NAME-> Criteria.TournamentNames.queryConditions |
|
||||||
TOURNAMENT_FEATURE-> Criteria.TournamentFeatures.queryConditions |
|
||||||
LOCATION-> Criteria.Locations.queryConditions |
|
||||||
LIMIT_TYPE -> Criteria.Limits.queryConditions |
|
||||||
TABLE_SIZE -> Criteria.TableSizes.queryConditions |
|
||||||
TOURNAMENT_TYPE -> Criteria.TournamentTypes.queryConditions |
|
||||||
else -> throw PokerAnalyticsException.QueryTypeUnhandled |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
fun List<Comparator>.combined(): List<List<QueryCondition>> { |
|
||||||
val comparatorList = ArrayList<List<QueryCondition>>() |
|
||||||
this.forEach { |
|
||||||
comparatorList.add(it.queryConditions) |
|
||||||
} |
|
||||||
return getCombinations(comparatorList) |
|
||||||
} |
|
||||||
|
|
||||||
fun <T> getCombinations(lists: List<List<T>>): List<List<T>> { |
|
||||||
var combinations: MutableSet<List<T>> = LinkedHashSet() |
|
||||||
var newCombinations: MutableSet<List<T>> |
|
||||||
|
|
||||||
var index = 0 |
|
||||||
|
|
||||||
// extract each of the integers in the first list |
|
||||||
// and add each to ints as a new list |
|
||||||
if (lists.isNotEmpty()) { |
|
||||||
for (i in lists[0]) { |
|
||||||
val newList = ArrayList<T>() |
|
||||||
newList.add(i) |
|
||||||
combinations.add(newList) |
|
||||||
} |
|
||||||
index++ |
|
||||||
} |
|
||||||
while (index < lists.size) { |
|
||||||
val nextList = lists[index] |
|
||||||
newCombinations = LinkedHashSet() |
|
||||||
for (first in combinations) { |
|
||||||
for (second in nextList) { |
|
||||||
val newList = ArrayList<T>() |
|
||||||
newList.addAll(first) |
|
||||||
newList.add(second) |
|
||||||
newCombinations.add(newList) |
|
||||||
} |
|
||||||
} |
|
||||||
combinations = newCombinations |
|
||||||
|
|
||||||
index++ |
|
||||||
} |
|
||||||
|
|
||||||
return combinations.toList() |
|
||||||
} |
|
||||||
Loading…
Reference in new issue