Restructure "relevancy", add missing returns.

This commit is contained in:
Oliver Rümpelein 2020-04-30 21:00:43 +02:00
parent d8412c32f2
commit 53def3bc00
6 changed files with 28 additions and 35 deletions

View file

@ -7,7 +7,7 @@ enum class Order(
override val prettyName: String,
override val fullName: String,
override val paramValue: Int,
override val relevantForAll: Boolean = false
override val relevantForAll: Boolean = true
) : RcdbParamOption<Int>, RelevantForAll {
IMAGES("Images", "Amount of Images", 0),
NAME("Name", "Name of the Coaster", 1),
@ -22,7 +22,7 @@ enum class Order(
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("Order.STATE")
)
STATE_2("State", "Operational State (legacy)", 10, relevantForAll = true),
STATE_2("State", "Operational State (legacy)", 10, relevantForAll = false),
ENTERED("Entered", 12),
TYPE("Type", "Construction Type (Wood, Steel)", 13),
DESIGN("Design", "Train Design (Sit-Down, Invert,...)", 14),

View file

@ -11,15 +11,13 @@ class Page(override val paramValue: Int) : RcdbParamOption<Int> {
}
}
fun RcdbQueryParamsBuilder.page(page: Int) {
if (Page.staticParamName !in this.keys()) {
this[Page.staticParamName] = listOf(Page(page))
} else {
fun RcdbQueryParamsBuilder.page(page: Int): RcdbQueryParamsBuilder = if (Page.staticParamName !in this.keys()) {
also { this[Page.staticParamName] = listOf(Page(page)) }
} else {
error(
"""Only one page must be given!
| Old page: ${this[Page.staticParamName]!![0].paramValue}
| New page: $page
""".trimMargin()
)
}
}

View file

@ -13,6 +13,7 @@ sealed class RcdbParamOptionBuilder<out U : Any, T : RcdbParamOption<U>> {
paramList.addAll(items)
return this
}
protected open fun addAll(items: Collection<T>): RcdbParamOptionBuilder<U, T> {
paramList.addAll(items)
return this
@ -45,6 +46,7 @@ class OrderBuilder : RcdbParamOptionBuilder<Int, Order>() {
super.addAll(items)
return this
}
override fun addAll(items: Collection<Order>): OrderBuilder {
super.addAll(items)
return this
@ -75,7 +77,7 @@ class OrderBuilder : RcdbParamOptionBuilder<Int, Order>() {
fun rideTime() = this.add(Order.RIDE_TIME)
fun state() = this.add(Order.STATUS)
fun closing() = this.add(Order.CLOSING)
fun all() = this.addAll(Order.values().filterNot { it.relevantForAll })
fun all() = this.addAll(Order.values().filter { it.relevantForAll })
}
class StatusBuilder : RcdbParamOptionBuilder<Int, Status>() {

View file

@ -2,19 +2,18 @@ package de.pheerai.rcdbquery.dataMappings
import de.pheerai.rcdbquery.dsl.RcdbQueryParamsBuilder
class SearchTerm(override val paramValue: String): RcdbParamOption<String> {
class SearchTerm(override val paramValue: String) : RcdbParamOption<String> {
override val prettyName = "Search Term"
override val fullName = "Search for elements whose name contain this term"
companion object {
const val staticParamName = "nc"
}
}
fun RcdbQueryParamsBuilder.searchTerm(term: String) {
fun RcdbQueryParamsBuilder.searchTerm(term: String): RcdbQueryParamsBuilder =
if (SearchTerm.staticParamName !in this.keys()) {
this[SearchTerm.staticParamName] = listOf(
SearchTerm(term)
)
also { this[SearchTerm.staticParamName] = listOf(SearchTerm(term)) }
} else {
error(
"""Only one search term must ever be set
@ -22,4 +21,3 @@ fun RcdbQueryParamsBuilder.searchTerm(term: String) {
| New term: $term""".trimMargin()
)
}
}

View file

@ -19,9 +19,9 @@ enum class SearchType(
}
}
fun RcdbQueryParamsBuilder.searchType(searchType: SearchType) {
fun RcdbQueryParamsBuilder.searchType(searchType: SearchType): RcdbQueryParamsBuilder =
if (SearchType.staticParamName !in this.keys()) {
this[SearchType.staticParamName] = listOf(searchType)
also { this[SearchType.staticParamName] = listOf(searchType) }
} else {
error(
"""Only one search type must ever be set
@ -29,4 +29,3 @@ fun RcdbQueryParamsBuilder.searchType(searchType: SearchType) {
| New type: ${searchType.prettyName}""".trimMargin()
)
}
}

View file

@ -13,16 +13,12 @@ class StartsWith(override val paramValue: String) : RcdbParamOption<String> {
}
}
fun RcdbQueryParamsBuilder.startsWith(term: String) {
if (StartsWith.staticParamName !in this.keys()) {
this[StartsWith.staticParamName] = listOf(
StartsWith(term)
)
} else {
fun RcdbQueryParamsBuilder.startsWith(term: String) = if (StartsWith.staticParamName !in this.keys()) {
also { this[StartsWith.staticParamName] = listOf(StartsWith(term)) }
} else {
error(
"""Only one starts with term must ever be set
| Old term: ${this[StartsWith.staticParamName]!![0].paramValue}
| New term: $term""".trimMargin()
)
}
}