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 prettyName: String,
override val fullName: String, override val fullName: String,
override val paramValue: Int, override val paramValue: Int,
override val relevantForAll: Boolean = false override val relevantForAll: Boolean = true
) : RcdbParamOption<Int>, RelevantForAll { ) : RcdbParamOption<Int>, RelevantForAll {
IMAGES("Images", "Amount of Images", 0), IMAGES("Images", "Amount of Images", 0),
NAME("Name", "Name of the Coaster", 1), NAME("Name", "Name of the Coaster", 1),
@ -22,7 +22,7 @@ enum class Order(
level = DeprecationLevel.WARNING, level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("Order.STATE") 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), ENTERED("Entered", 12),
TYPE("Type", "Construction Type (Wood, Steel)", 13), TYPE("Type", "Construction Type (Wood, Steel)", 13),
DESIGN("Design", "Train Design (Sit-Down, Invert,...)", 14), 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) { fun RcdbQueryParamsBuilder.page(page: Int): RcdbQueryParamsBuilder = if (Page.staticParamName !in this.keys()) {
if (Page.staticParamName !in this.keys()) { also { this[Page.staticParamName] = listOf(Page(page)) }
this[Page.staticParamName] = listOf(Page(page)) } else {
} else {
error( error(
"""Only one page must be given! """Only one page must be given!
| Old page: ${this[Page.staticParamName]!![0].paramValue} | Old page: ${this[Page.staticParamName]!![0].paramValue}
| New page: $page | New page: $page
""".trimMargin() """.trimMargin()
) )
}
} }

View file

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

View file

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

View file

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