Add more search types:

- Classification
 - Status
 - Make some `order` params invisible for `all` params
 - Solved some order types
This commit is contained in:
Oliver Rümpelein 2020-04-30 16:30:16 +02:00
parent d2dc84a17b
commit d8412c32f2
7 changed files with 115 additions and 15 deletions

View file

@ -0,0 +1,27 @@
package de.pheerai.rcdbquery.dataMappings
import de.pheerai.rcdbquery.dsl.RcdbQueryParamsBuilder
enum class Classification(
override val prettyName: String,
override val fullName: String,
override val paramValue: Int
) : RcdbParamOption<Int> {
ROLLERCOASTER("Roller Coaster", 277),
POWERED_COASTER("Powered Coaster", 278),
MOUNTAIN_COASTER("Mountain Coaster", 279)
;
constructor(name: String, paramValue: Int): this(name, name, paramValue)
companion object {
const val staticParamName = "cs";
}
}
fun RcdbQueryParamsBuilder.classification(body: ClassificationBuilder.() -> ClassificationBuilder): RcdbQueryParamsBuilder {
val builder = ClassificationBuilder()
builder.body()
this[Classification.staticParamName] = builder.build()
return this
}

View file

@ -6,11 +6,12 @@ import de.pheerai.rcdbquery.dsl.RcdbQueryParamsBuilder
enum class Order(
override val prettyName: String,
override val fullName: String,
override val paramValue: Int
) : RcdbParamOption<Int> {
override val paramValue: Int,
override val relevantForAll: Boolean = false
) : RcdbParamOption<Int>, RelevantForAll {
IMAGES("Images", "Amount of Images", 0),
NAME("Name", "Name of the Coaster", 1),
ORIGINAL_NAME("Original Name", "Original name of the Coaster, in local charset", 2),
AKA("AKA", "Is/was also known as", 2, relevantForAll = false),
LOCATION("Location", 3),
PARK("Park", 4),
OPENED("Opened", "Opening Date", 8),
@ -21,9 +22,9 @@ enum class Order(
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("Order.STATE")
)
STATE_2("State", "Operational State (legacy)", 10),
STATE_2("State", "Operational State (legacy)", 10, relevantForAll = true),
ENTERED("Entered", 12),
TYPE("Type", "Constrcution Type (Wood, Steel)", 13),
TYPE("Type", "Construction Type (Wood, Steel)", 13),
DESIGN("Design", "Train Design (Sit-Down, Invert,...)", 14),
CLASSIFICATION("Classification", "Coaster Classification (Coaster, Powered Coaster, Mountain Coaster)", 15),
LAYOUT("Layout", 16),
@ -35,15 +36,15 @@ enum class Order(
LENGTH("Length", 22),
ANGLE("Angle", 23),
INVERSIONS("Inversions", "Number of inversions", 24),
SERIAL_NO("Serial", "Serial number", 25),
SERIAL_NO("Serial", "Serial number", 25, relevantForAll = false),
SCALE("Scale", "Thrill factor", 26),
RIDE_TIME("Ride Time", 27),
STATE("State", "Operational state", 29),
STATUS("Status", "Operational state", 29),
MANUFACTURER("Manufacturer", 30),
CLOSING("Closing", "(Future) closign date for temporary installations", 31)
;
constructor(name: String, paramId: Int) : this(name, name, paramId)
constructor(name: String, paramId: Int, deprecated: Boolean = false) : this(name, name, paramId)
companion object {
const val staticParamName = "order"

View file

@ -3,10 +3,8 @@ package de.pheerai.rcdbquery.dataMappings
import de.pheerai.rcdbquery.dsl.RcdbQueryParamsBuilder
class Page(override val paramValue: Int) : RcdbParamOption<Int> {
override val fullName: String
get() = "The page to show"
override val prettyName: String
get() = "Page"
override val fullName = "The page to show"
override val prettyName = "Page"
companion object {
const val staticParamName = "page"

View file

@ -13,6 +13,10 @@ 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
}
fun build() = paramList.toList()
}
@ -41,6 +45,10 @@ class OrderBuilder : RcdbParamOptionBuilder<Int, Order>() {
super.addAll(items)
return this
}
override fun addAll(items: Collection<Order>): OrderBuilder {
super.addAll(items)
return this
}
fun of(order: Order) = this.add(order)
fun manufacturer() = this.add(Order.MANUFACTURER)
@ -65,7 +73,30 @@ class OrderBuilder : RcdbParamOptionBuilder<Int, Order>() {
fun serialNo() = this.add(Order.SERIAL_NO)
fun scale() = this.add(Order.SCALE)
fun rideTime() = this.add(Order.RIDE_TIME)
fun state() = this.add(Order.STATE)
fun state() = this.add(Order.STATUS)
fun closing() = this.add(Order.CLOSING)
fun all() = this.addAll(Order.values())
fun all() = this.addAll(Order.values().filterNot { it.relevantForAll })
}
class StatusBuilder : RcdbParamOptionBuilder<Int, Status>() {
override fun add(param: Status): StatusBuilder {
super.add(param)
return this
}
fun sbno() = this.add(Status.SBNO)
fun operating() = this.add(Status.OPERATING)
fun underConstruction() = this.add(Status.UNDER_CONSTRUCTION)
fun stored() = this.add(Status.STORED)
}
class ClassificationBuilder : RcdbParamOptionBuilder<Int, Classification>() {
override fun add(param: Classification): ClassificationBuilder {
super.add(param)
return this
}
fun rollerCoaster() = this.add(Classification.ROLLERCOASTER)
fun poweredCoaster() = this.add(Classification.POWERED_COASTER)
fun mountainCoaster() = this.add(Classification.MOUNTAIN_COASTER)
}

View file

@ -0,0 +1,5 @@
package de.pheerai.rcdbquery.dataMappings
interface RelevantForAll {
val relevantForAll: Boolean
}

View file

@ -4,9 +4,10 @@ package de.pheerai.rcdbquery.dataMappings
import de.pheerai.rcdbquery.dsl.RcdbQueryParamsBuilder
class StartsWith(override val paramValue: String): RcdbParamOption<String> {
class StartsWith(override val paramValue: String) : RcdbParamOption<String> {
override val prettyName = "Starts with"
override val fullName = "Name starting with term"
companion object {
const val staticParamName = "nl"
}

View file

@ -0,0 +1,37 @@
package de.pheerai.rcdbquery.dataMappings
import de.pheerai.rcdbquery.dsl.RcdbQueryParamsBuilder
@Suppress("unused")
enum class Status(
override val prettyName: String,
override val fullName: String,
override val paramValue: Int
) : RcdbParamOption<Int> {
SBNO("SBNO", "Standing, but not operating", 311),
OPERATING("Operating", "In operation", 93),
UNDER_CONSTRUCTION("Under Construction", 310),
STORED("Stored", "In storage", 312)
;
constructor(name: String, paramId: Int) : this(name, name, paramId)
companion object {
const val staticParamName = "st"
fun of(input: String) = when(input) {
"SBNO" -> SBNO
"Operating" -> OPERATING
"Under Construction" -> UNDER_CONSTRUCTION
"In Storage" -> STORED
else -> null
}
}
}
fun RcdbQueryParamsBuilder.status(body: StatusBuilder.() -> StatusBuilder): RcdbQueryParamsBuilder {
val builder = StatusBuilder()
builder.body()
this[Status.staticParamName] = builder.build()
return this
}