Merge branch 'cleanup' into 'master'
Cleanup See merge request pheerai/rcdbquery!1
This commit is contained in:
commit
dfd6d5f405
57 changed files with 339 additions and 327 deletions
30
.gitlab-ci.yml
Normal file
30
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Based on https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Gradle.gitlab-ci.yml
|
||||||
|
image: gradle:jdk11
|
||||||
|
|
||||||
|
variables:
|
||||||
|
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- export GRADLE_USER_HOME=`pwd`/.gradle
|
||||||
|
|
||||||
|
build:
|
||||||
|
stage: build
|
||||||
|
script: gradle --build-cache assemble
|
||||||
|
cache:
|
||||||
|
key: "$CI_COMMIT_REF_NAME"
|
||||||
|
policy: push
|
||||||
|
paths:
|
||||||
|
- build
|
||||||
|
- .gradle
|
||||||
|
|
||||||
|
artifact:
|
||||||
|
stage: deploy
|
||||||
|
script: gradle publish
|
||||||
|
rules:
|
||||||
|
- if: '$CI_COMMIT_BRANCH == "master"'
|
||||||
|
cache:
|
||||||
|
key: "$CI_COMMIT_REF_NAME"
|
||||||
|
policy: pull-push
|
||||||
|
paths:
|
||||||
|
- build
|
||||||
|
- .gradle
|
|
@ -1,5 +1,16 @@
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
extra.apply {
|
||||||
|
set("pheeraiBomVersion", "0.0.3-SNAPSHOT")
|
||||||
|
set("kotlinApiVersion", "1.4")
|
||||||
|
set("javaVersion", JavaVersion.VERSION_11)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified T> getFromExtra(prop: String) = project.extra[prop] as T
|
||||||
|
|
||||||
// TODO: Documentation
|
// TODO: Documentation
|
||||||
// TODO: Source Jar
|
// TODO: Source Jar
|
||||||
// TODO: Doc Jar
|
// TODO: Doc Jar
|
||||||
|
@ -11,31 +22,42 @@ plugins {
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
jcenter()
|
||||||
|
google()
|
||||||
|
maven {
|
||||||
|
url = uri("https://git.f3l.de/api/v4/projects/160/packages/maven")
|
||||||
|
mavenContent {
|
||||||
|
includeGroup("de.pheerai")
|
||||||
|
includeGroup("de.pheerai.eap")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
project.version = "0.0.1"
|
project.version = "0.0.2"
|
||||||
project.group = "de.pheerai.rcdb"
|
project.group = "de.pheerai.rcdb"
|
||||||
|
|
||||||
|
|
||||||
java {
|
java {
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
targetCompatibility = getFromExtra("javaVersion")
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
sourceCompatibility = getFromExtra("javaVersion")
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
explicitApi = ExplicitApiMode.Strict
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin("stdlib-jdk8"))
|
implementation(enforcedPlatform("de.pheerai:kotlin-crawler-app-bom:${getFromExtra<String>("pheeraiBomVersion")}"))
|
||||||
|
|
||||||
testImplementation("io.kotest:kotest-runner-junit5-jvm:4.0.5")
|
testImplementation("io.kotest", "kotest-runner-junit5-jvm")
|
||||||
testImplementation("io.kotest:kotest-assertions-core-jvm:4.0.5")
|
testImplementation("io.kotest", "kotest-assertions-core-jvm")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
withType<KotlinCompile>().configureEach {
|
withType<KotlinCompile>().configureEach {
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
freeCompilerArgs = listOf("-XXLanguage:+InlineClasses")
|
apiVersion = getFromExtra("kotlinApiVersion")
|
||||||
apiVersion = "1.3"
|
languageVersion = getFromExtra("kotlinApiVersion")
|
||||||
languageVersion = "1.3"
|
jvmTarget = getFromExtra<JavaVersion>("javaVersion").toString()
|
||||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,13 +68,21 @@ tasks {
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
create<MavenPublication>("maven") {
|
create<MavenPublication>("QueryBuilder") {
|
||||||
groupId = project.group as String
|
|
||||||
artifactId = project.name as String
|
|
||||||
version = project.version as String
|
|
||||||
|
|
||||||
from(components["java"])
|
from(components["java"])
|
||||||
|
}
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url = uri("https://git.f3l.de/api/v4/projects/180/packages/maven")
|
||||||
|
name = "GitLab"
|
||||||
|
credentials(HttpHeaderCredentials::class.java) {
|
||||||
|
name = "Job-Token"
|
||||||
|
value = System.getenv("CI_JOB_TOKEN")
|
||||||
|
}
|
||||||
|
authentication {
|
||||||
|
create<HttpHeaderAuthentication>("header")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,5 +1,5 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
2
gradlew
vendored
2
gradlew
vendored
|
@ -82,6 +82,7 @@ esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
@ -129,6 +130,7 @@ fi
|
||||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||||
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
# We build the pattern for arguments to be converted via cygpath
|
||||||
|
|
1
gradlew.bat
vendored
1
gradlew.bat
vendored
|
@ -84,6 +84,7 @@ set CMD_LINE_ARGS=%*
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
pluginManagement {
|
pluginManagement {
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.3.72"
|
kotlin("jvm") version "1.4.30"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,38 +1,38 @@
|
||||||
package de.pheerai.rcdbquery
|
package de.pheerai.rcdbquery
|
||||||
|
|
||||||
|
import de.pheerai.rcdbquery.dataMappings.order.Order
|
||||||
import de.pheerai.rcdbquery.dataMappings.order.sortBy
|
import de.pheerai.rcdbquery.dataMappings.order.sortBy
|
||||||
import de.pheerai.rcdbquery.dataMappings.page.page
|
import de.pheerai.rcdbquery.dataMappings.page.page
|
||||||
import de.pheerai.rcdbquery.dataMappings.searchTerm.searchTerm
|
import de.pheerai.rcdbquery.dataMappings.searchTerm.searchTerm
|
||||||
import de.pheerai.rcdbquery.dataMappings.searchType.SearchType
|
import de.pheerai.rcdbquery.dataMappings.searchType.SearchType
|
||||||
import de.pheerai.rcdbquery.dataMappings.searchType.searchType
|
import de.pheerai.rcdbquery.dataMappings.searchType.searchType
|
||||||
import de.pheerai.rcdbquery.dataMappings.vendor.Vendor
|
import de.pheerai.rcdbquery.dataMappings.vendor.Vendor.*
|
||||||
import de.pheerai.rcdbquery.dataMappings.vendor.vendors
|
import de.pheerai.rcdbquery.dataMappings.vendor.vendors
|
||||||
import de.pheerai.rcdbquery.dsl.rcdbQuery
|
import de.pheerai.rcdbquery.dsl.rcdbQuery
|
||||||
|
|
||||||
fun main() {
|
public fun main() {
|
||||||
println(generateNameQueryUrl())
|
println(generateNameQueryUrl())
|
||||||
println(generatePageQueryUrl())
|
println(generatePageQueryUrl())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateNameQueryUrl() = rcdbQuery {
|
private fun generateNameQueryUrl() = rcdbQuery {
|
||||||
searchType(SearchType.COASTER)
|
searchType(SearchType.COASTER)
|
||||||
searchTerm("Dragon")
|
searchTerm("Dragon")
|
||||||
vendors {
|
vendors {
|
||||||
vekoma()
|
VEKOMA()
|
||||||
intamin()
|
INTAMIN()
|
||||||
mack()
|
MACK()
|
||||||
of(Vendor.PRESTON_AND_BARBIERI)
|
|
||||||
}
|
}
|
||||||
sortBy {
|
sortBy {
|
||||||
manufacturer()
|
Order.MANUFACTURER()
|
||||||
inversions()
|
Order.INVERSIONS()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generatePageQueryUrl() = rcdbQuery {
|
private fun generatePageQueryUrl() = rcdbQuery {
|
||||||
page(3)
|
page(3)
|
||||||
searchType(SearchType.COASTER)
|
searchType(SearchType.COASTER)
|
||||||
vendors {
|
vendors {
|
||||||
intamin()
|
INTAMIN()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.category
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
||||||
|
|
||||||
enum class Category(
|
public enum class Category(
|
||||||
override val prettyName: String,
|
override val prettyName: String,
|
||||||
override val fullName: String,
|
override val fullName: String,
|
||||||
override val paramValue: Long
|
override val paramValue: Long
|
||||||
|
@ -38,7 +38,7 @@ enum class Category(
|
||||||
|
|
||||||
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
|
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
|
||||||
|
|
||||||
companion object : StringGeneratable<Category> {
|
internal companion object : StringGeneratable<Category> {
|
||||||
override val paramKey = "ca"
|
override val paramKey = "ca"
|
||||||
override fun of(input: String): Category? = when (input) {
|
override fun of(input: String): Category? = when (input) {
|
||||||
"4th Dimension" -> FOURTH_DIMENSION
|
"4th Dimension" -> FOURTH_DIMENSION
|
||||||
|
|
|
@ -2,36 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.category
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
||||||
|
|
||||||
class CategoryBuilder: MultiParamBuilder<Long, Category>() {
|
public class CategoryBuilder : MultiParamBuilder<Long, Category>() {
|
||||||
override fun add(param: Category): CategoryBuilder {
|
override fun add(param: Category): CategoryBuilder {
|
||||||
super.add(param)
|
super.add(param)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fourthDimension() = this.add(Category.FOURTH_DIMENSION)
|
override fun Category.invoke(): CategoryBuilder = add(this)
|
||||||
fun brakeman() = this.add(Category.BRAKEMAN)
|
|
||||||
fun builtInhouse() = this.add(Category.BUILT_INHOUSE)
|
|
||||||
fun darkride() = this.add(Category.DARK_RIDE)
|
|
||||||
fun dualStation() = this.add(Category.DUAL_STATION)
|
|
||||||
fun enclosed() = this.add(Category.ENCLOSED)
|
|
||||||
fun floorless() = this.add(Category.FLOORLESS)
|
|
||||||
fun hybrid() = this.add(Category.HYBRID)
|
|
||||||
fun indoor() = this.add(Category.INDOOR)
|
|
||||||
fun mirror() = this.add(Category.MIRROR)
|
|
||||||
fun moebius() = this.add(Category.MOEBIUS)
|
|
||||||
fun onboardSound() = this.add(Category.ONBOARD_SOUND)
|
|
||||||
fun pendulum() = this.add(Category.PENDULUM)
|
|
||||||
fun quasiMoebius() = this.add(Category.QUASI_MOEBIUS)
|
|
||||||
fun rockingCars() = this.add(Category.ROCKING_CARS)
|
|
||||||
fun scenicRailway() = this.add(Category.SCENIC_RAILWAY)
|
|
||||||
fun shuttle() = this.add(Category.SHUTTLE)
|
|
||||||
fun sideFriction() = this.add(Category.SIDE_FRICTION)
|
|
||||||
fun singleRail() = this.add(Category.SINGLE_RAIL)
|
|
||||||
fun slidingStation() = this.add(Category.SLIDING_STATION)
|
|
||||||
fun spinningCars() = this.add(Category.SPINNING_CARS)
|
|
||||||
fun stackedStorage() = this.add(Category.STACKED_STORAGE)
|
|
||||||
fun turntableStation() = this.add(Category.TURNTABLE_STATION)
|
|
||||||
fun twin() = this.add(Category.TWIN)
|
|
||||||
fun virtualReality() = this.add(Category.VIRTUAL_REALITY)
|
|
||||||
fun waterCoaster() = this.add(Category.WATER_COASTER)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.category
|
package de.pheerai.rcdbquery.dataMappings.category
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
|
||||||
fun ParamsCollector.category(body: CategoryBuilder.() -> CategoryBuilder): ParamsCollector {
|
public fun ParamsCollector.category(body: CategoryBuilder.() -> CategoryBuilder): ParamsCollector {
|
||||||
val builder = CategoryBuilder()
|
val builder = CategoryBuilder()
|
||||||
builder.body()
|
builder.body()
|
||||||
this[Category.paramKey] = builder.build()
|
this[Category.paramKey] = builder.build()
|
||||||
|
|
|
@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.classification
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
||||||
|
|
||||||
enum class Classification(
|
public enum class Classification(
|
||||||
override val prettyName: String,
|
override val prettyName: String,
|
||||||
override val fullName: String,
|
override val fullName: String,
|
||||||
override val paramValue: Long
|
override val paramValue: Long
|
||||||
|
@ -15,8 +15,8 @@ enum class Classification(
|
||||||
|
|
||||||
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
|
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
|
||||||
|
|
||||||
companion object: StringGeneratable<Classification> {
|
public companion object: StringGeneratable<Classification> {
|
||||||
override fun of(input: String) = values().find { it.fullName == input }
|
override fun of(input: String): Classification? = values().find { it.fullName == input }
|
||||||
override val paramKey = "cs"
|
override val paramKey: String = "cs"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.classification
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
||||||
|
|
||||||
class ClassificationBuilder : MultiParamBuilder<Long, Classification>() {
|
public class ClassificationBuilder : MultiParamBuilder<Long, Classification>() {
|
||||||
override fun add(param: Classification): ClassificationBuilder {
|
override fun add(param: Classification): ClassificationBuilder {
|
||||||
super.add(param)
|
super.add(param)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rollerCoaster() = this.add(Classification.ROLLER_COASTER)
|
override fun Classification.invoke(): ClassificationBuilder = add(this)
|
||||||
fun poweredCoaster() = this.add(Classification.POWERED_COASTER)
|
|
||||||
fun mountainCoaster() = this.add(Classification.MOUNTAIN_COASTER)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.classification
|
package de.pheerai.rcdbquery.dataMappings.classification
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
|
||||||
fun ParamsCollector.classification(body: ClassificationBuilder.() -> ClassificationBuilder): ParamsCollector {
|
public fun ParamsCollector.classification(body: ClassificationBuilder.() -> ClassificationBuilder): ParamsCollector {
|
||||||
val builder = ClassificationBuilder()
|
val builder = ClassificationBuilder()
|
||||||
builder.body()
|
builder.body()
|
||||||
this[Classification.paramKey] = builder.build()
|
this[Classification.paramKey] = builder.build()
|
||||||
|
|
|
@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.design
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
||||||
|
|
||||||
enum class Design(
|
public enum class Design(
|
||||||
override val prettyName: String,
|
override val prettyName: String,
|
||||||
override val fullName: String,
|
override val fullName: String,
|
||||||
override val paramValue: Long
|
override val paramValue: Long
|
||||||
|
@ -20,8 +20,8 @@ enum class Design(
|
||||||
|
|
||||||
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
|
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
|
||||||
|
|
||||||
companion object : StringGeneratable<Design> {
|
public companion object : StringGeneratable<Design> {
|
||||||
override val paramKey = "de"
|
override val paramKey: String = "de"
|
||||||
override fun of(input: String): Design? = when (input) {
|
override fun of(input: String): Design? = when (input) {
|
||||||
"Sit Down" -> SIT_DOWN
|
"Sit Down" -> SIT_DOWN
|
||||||
"Inverted" -> INVERTED
|
"Inverted" -> INVERTED
|
||||||
|
|
|
@ -2,18 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.design
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
||||||
|
|
||||||
class DesignBuilder : MultiParamBuilder<Long, Design>() {
|
public class DesignBuilder : MultiParamBuilder<Long, Design>() {
|
||||||
override fun add(param: Design): DesignBuilder {
|
override fun add(param: Design): DesignBuilder {
|
||||||
super.add(param)
|
super.add(param)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sitDown() = Design.SIT_DOWN
|
override fun Design.invoke(): DesignBuilder = add(this)
|
||||||
fun inverted() = Design.INVERTED
|
|
||||||
fun suspended() = Design.SUSPENDED
|
|
||||||
fun wing() = Design.WING
|
|
||||||
fun flying() = Design.FLYING
|
|
||||||
fun standUp() = Design.STAND_UP
|
|
||||||
fun bobsled() = Design.BOBSLED
|
|
||||||
fun pipeline() = Design.PIPELINE
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.design
|
package de.pheerai.rcdbquery.dataMappings.design
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
|
||||||
fun ParamsCollector.design(body: DesignBuilder.() -> DesignBuilder): ParamsCollector {
|
public fun ParamsCollector.design(body: DesignBuilder.() -> DesignBuilder): ParamsCollector {
|
||||||
val builder = DesignBuilder()
|
val builder = DesignBuilder()
|
||||||
builder.body()
|
builder.body()
|
||||||
this[Design.paramKey] = builder.build()
|
this[Design.paramKey] = builder.build()
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.internal
|
package de.pheerai.rcdbquery.dataMappings.internal
|
||||||
|
|
||||||
open class MultiParamBuilder<out U : Any, T : RcdbParamOption<U>> {
|
public abstract class MultiParamBuilder<out U : Any, T : RcdbParamOption<U>> {
|
||||||
private val paramList: MutableList<T> = mutableListOf()
|
private val paramList: MutableList<T> = mutableListOf()
|
||||||
|
|
||||||
open fun add(param: T): MultiParamBuilder<U, T> {
|
public open fun add(param: T): MultiParamBuilder<U, T> {
|
||||||
paramList.add(param)
|
paramList.add(param)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ open class MultiParamBuilder<out U : Any, T : RcdbParamOption<U>> {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun build() = paramList.toList()
|
public fun build(): List<T> = paramList.toList()
|
||||||
}
|
|
||||||
|
|
||||||
|
public abstract operator fun T.invoke(): MultiParamBuilder<U, T>
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.internal
|
package de.pheerai.rcdbquery.dataMappings.internal
|
||||||
|
|
||||||
interface ParamKey {
|
internal interface ParamKey {
|
||||||
val paramKey: String
|
val paramKey: String
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.internal
|
package de.pheerai.rcdbquery.dataMappings.internal
|
||||||
|
|
||||||
interface RcdbItem {
|
internal interface RcdbItem {
|
||||||
val url: String
|
val url: String
|
||||||
get() ="https://www.rcdb.com/${id}.htm"
|
get() ="https://www.rcdb.com/${id}.htm"
|
||||||
val id: Long
|
val id: Long
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.internal
|
package de.pheerai.rcdbquery.dataMappings.internal
|
||||||
|
|
||||||
interface RcdbParamOption<out T> {
|
public interface RcdbParamOption<out T> {
|
||||||
val prettyName: String
|
public val prettyName: String
|
||||||
val fullName: String
|
public val fullName: String
|
||||||
val paramValue: T
|
public val paramValue: T
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.internal
|
package de.pheerai.rcdbquery.dataMappings.internal
|
||||||
|
|
||||||
interface RelevantForAll {
|
internal interface RelevantForAll {
|
||||||
val relevantForAll: Boolean
|
val relevantForAll: Boolean
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.internal
|
package de.pheerai.rcdbquery.dataMappings.internal
|
||||||
|
|
||||||
interface StringGeneratable<T>: ParamKey {
|
internal interface StringGeneratable<T>: ParamKey {
|
||||||
fun of(input: String): T?
|
fun of(input: String): T?
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.layout
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
||||||
|
|
||||||
enum class Layout(
|
public enum class Layout(
|
||||||
override val prettyName: String,
|
override val prettyName: String,
|
||||||
override val fullName: String,
|
override val fullName: String,
|
||||||
override val paramValue: Long
|
override val paramValue: Long
|
||||||
|
@ -37,8 +37,8 @@ enum class Layout(
|
||||||
|
|
||||||
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
|
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
|
||||||
|
|
||||||
companion object : StringGeneratable<Layout> {
|
public companion object : StringGeneratable<Layout> {
|
||||||
override val paramKey = "lo"
|
override val paramKey: String = "lo"
|
||||||
|
|
||||||
override fun of(input: String): Layout? = values().find { input == it.fullName }
|
override fun of(input: String): Layout? = values().find { input == it.fullName }
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,38 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.layout
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
||||||
|
|
||||||
class LayoutBuilder : MultiParamBuilder<Long, Layout>() {
|
public class LayoutBuilder : MultiParamBuilder<Long, Layout>() {
|
||||||
override fun add(param: Layout): LayoutBuilder {
|
override fun add(param: Layout): LayoutBuilder {
|
||||||
super.add(param)
|
super.add(param)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bigApple() = this.add(Layout.BIG_APPLE)
|
override operator fun Layout.invoke(): LayoutBuilder = add(this)
|
||||||
fun wackyWorm() = this.add(Layout.BIG_APPLE)
|
|
||||||
|
|
||||||
fun circleDip() = this.add(Layout.CIRCLE_DIP)
|
|
||||||
fun circularGravityRailway() = this.add(Layout.CIRCULAR_GRAVIY_RAILWAY)
|
|
||||||
fun cyclone() = this.add(Layout.CYCLONE)
|
|
||||||
fun doubleFigureEight() = this.add(Layout.DOUBLE_FIGURE_EIGHT)
|
|
||||||
fun doubleOutAndBack() = this.add(Layout.DOUBLE_OUT_AND_BACK)
|
|
||||||
fun figureEight() = this.add(Layout.FIGURE_EIGHT)
|
|
||||||
fun jungleMouse() = this.add(Layout.JUNGLE_MOUSE)
|
|
||||||
fun lShapedOutAndBack() = this.add(Layout.L_SHAPED_OUT_AND_BACK)
|
|
||||||
fun miteMouse() = this.add(Layout.MITE_MOUSE)
|
|
||||||
fun outAndBack() = this.add(Layout.OUT_AND_BACK)
|
|
||||||
fun oval() = this.add(Layout.OVAL)
|
|
||||||
fun shuttleLoop() = this.add(Layout.SHUTTLE_LOOP)
|
|
||||||
fun singleHelixCenter() = this.add(Layout.SINGLE_HELIX_CENTER)
|
|
||||||
fun singleHelixLeft() = this.add(Layout.SINGLE_HELIX_LEFT)
|
|
||||||
fun singleHelixRear() = this.add(Layout.SINGLE_HELIX_REAR)
|
|
||||||
fun singleHelixRight() = this.add(Layout.SINGLE_HELIX_RIGHT)
|
|
||||||
fun terrain() = this.add(Layout.TERRAIN)
|
|
||||||
fun triangle() = this.add(Layout.TRIANGLE)
|
|
||||||
fun tripleOutAndBack() = this.add(Layout.TRIPLE_OUT_AND_BACK)
|
|
||||||
fun twinHelix() = this.add(Layout.TWIN_HELIX)
|
|
||||||
fun twister() = this.add(Layout.TWISTER)
|
|
||||||
fun uShuttle() = this.add(Layout.U_SHUTTLE)
|
|
||||||
fun wildMouse() = this.add(Layout.WILD_MOUSE)
|
|
||||||
fun zyklon() = this.add(Layout.ZYKLON)
|
|
||||||
fun galaxy() = this.add(Layout.ZYKLON)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.layout
|
package de.pheerai.rcdbquery.dataMappings.layout
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
|
||||||
fun ParamsCollector.layout(body: LayoutBuilder.() -> LayoutBuilder): ParamsCollector {
|
public fun ParamsCollector.layout(body: LayoutBuilder.() -> LayoutBuilder): ParamsCollector {
|
||||||
val builder = LayoutBuilder()
|
val builder = LayoutBuilder()
|
||||||
|
with(Layout) {
|
||||||
builder.body()
|
builder.body()
|
||||||
|
}
|
||||||
this[Layout.paramKey] = builder.build()
|
this[Layout.paramKey] = builder.build()
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,13 @@ package de.pheerai.rcdbquery.dataMappings.order
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
|
import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.RelevantForAll
|
import de.pheerai.rcdbquery.dataMappings.internal.RelevantForAll
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
enum class Order(
|
public enum class Order(
|
||||||
override val prettyName: String,
|
override val prettyName: String,
|
||||||
override val fullName: String,
|
override val fullName: String,
|
||||||
override val paramValue: Long,
|
override val paramValue: Long,
|
||||||
override val relevantForAll: Boolean = true
|
override val relevantForAll: Boolean = true,
|
||||||
) : RcdbParamOption<Long>,
|
) : RcdbParamOption<Long>,
|
||||||
RelevantForAll {
|
RelevantForAll {
|
||||||
IMAGES("Images", "Amount of Images", 0),
|
IMAGES("Images", "Amount of Images", 0),
|
||||||
|
@ -50,7 +49,7 @@ enum class Order(
|
||||||
|
|
||||||
constructor(name: String, paramId: Long) : this(name, name, paramId)
|
constructor(name: String, paramId: Long) : this(name, name, paramId)
|
||||||
|
|
||||||
companion object: ParamKey {
|
public companion object : ParamKey {
|
||||||
override val paramKey = "order"
|
override val paramKey: String = "order"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package de.pheerai.rcdbquery.dataMappings.order
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
||||||
|
|
||||||
class OrderBuilder : MultiParamBuilder<Long, Order>() {
|
public class OrderBuilder : MultiParamBuilder<Long, Order>() {
|
||||||
override fun add(param: Order): OrderBuilder {
|
override fun add(param: Order): OrderBuilder {
|
||||||
super.add(param)
|
super.add(param)
|
||||||
return this
|
return this
|
||||||
|
@ -18,30 +18,6 @@ class OrderBuilder : MultiParamBuilder<Long, Order>() {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun of(order: Order) = this.add(order)
|
override operator fun Order.invoke(): OrderBuilder = add(this)
|
||||||
fun manufacturer() = this.add(Order.MANUFACTURER)
|
public fun allRelevant(): OrderBuilder = this.addAll(Order.values().filter { it.relevantForAll })
|
||||||
fun inversions() = this.add(Order.INVERSIONS)
|
|
||||||
fun name() = this.add(Order.NAME)
|
|
||||||
fun location() = this.add(Order.LOCATION)
|
|
||||||
fun park() = this.add(Order.PARK)
|
|
||||||
fun opened() = this.add(Order.OPENED)
|
|
||||||
fun closed() = this.add(Order.CLOSED)
|
|
||||||
fun entered() = this.add(Order.ENTERED)
|
|
||||||
fun type() = this.add(Order.TYPE)
|
|
||||||
fun design() = this.add(Order.DESIGN)
|
|
||||||
fun classification() = this.add(Order.CLASSIFICATION)
|
|
||||||
fun layout() = this.add(Order.LAYOUT)
|
|
||||||
fun model() = this.add(Order.MODEL)
|
|
||||||
fun modelLine() = this.add(Order.MODEL_LINE)
|
|
||||||
fun speed() = this.add(Order.SPEED)
|
|
||||||
fun height() = this.add(Order.HEIGHT)
|
|
||||||
fun drop() = this.add(Order.DROP)
|
|
||||||
fun length() = this.add(Order.LENGTH)
|
|
||||||
fun angle() = this.add(Order.ANGLE)
|
|
||||||
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.STATUS)
|
|
||||||
fun closing() = this.add(Order.CLOSING)
|
|
||||||
fun allRelevant() = this.addAll(Order.values().filter { it.relevantForAll })
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.order
|
package de.pheerai.rcdbquery.dataMappings.order
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
|
||||||
fun ParamsCollector.sortBy(body: OrderBuilder.() -> OrderBuilder): ParamsCollector {
|
public fun ParamsCollector.sortBy(body: OrderBuilder.() -> OrderBuilder): ParamsCollector {
|
||||||
val builder = OrderBuilder()
|
val builder = OrderBuilder()
|
||||||
builder.body()
|
builder.body()
|
||||||
this[Order.paramKey] = builder.build()
|
this[Order.paramKey] = builder.build()
|
||||||
|
|
|
@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.page
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
|
import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
|
|
||||||
class Page(override val paramValue: Long) :
|
internal class Page(override val paramValue: Long) :
|
||||||
RcdbParamOption<Long> {
|
RcdbParamOption<Long> {
|
||||||
override val fullName = "The page to show"
|
override val fullName = "The page to show"
|
||||||
override val prettyName = "Page"
|
override val prettyName = "Page"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.page
|
package de.pheerai.rcdbquery.dataMappings.page
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
|
||||||
fun ParamsCollector.page(page: Long) = also {
|
public fun ParamsCollector.page(page: Long): ParamsCollector = also {
|
||||||
this[Page.paramKey] =
|
this[Page.paramKey] =
|
||||||
Page(page)
|
Page(page)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.searchTerm
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
|
import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
|
|
||||||
class SearchTerm(override val paramValue: String) :
|
internal class SearchTerm(override val paramValue: String) :
|
||||||
RcdbParamOption<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"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.searchTerm
|
package de.pheerai.rcdbquery.dataMappings.searchTerm
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
|
||||||
fun ParamsCollector.searchTerm(term: String) = also {
|
public fun ParamsCollector.searchTerm(term: String): ParamsCollector = also {
|
||||||
it[SearchTerm.paramKey] = listOf(
|
it[SearchTerm.paramKey] = listOf(
|
||||||
SearchTerm(term)
|
SearchTerm(term)
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
enum class SearchType(
|
public enum class SearchType(
|
||||||
override val prettyName: String,
|
override val prettyName: String,
|
||||||
override val fullName: String,
|
override val fullName: String,
|
||||||
override val paramValue: Long
|
override val paramValue: Long
|
||||||
|
@ -15,7 +15,7 @@ enum class SearchType(
|
||||||
PERSON("Person", "Search for a person (designer, engineer,...)", 13)
|
PERSON("Person", "Search for a person (designer, engineer,...)", 13)
|
||||||
;
|
;
|
||||||
|
|
||||||
companion object: ParamKey {
|
public companion object: ParamKey {
|
||||||
override val paramKey = "ot"
|
override val paramKey: String = "ot"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.searchType
|
package de.pheerai.rcdbquery.dataMappings.searchType
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
|
||||||
fun ParamsCollector.searchType(searchType: SearchType) = also {
|
public fun ParamsCollector.searchType(searchType: SearchType): ParamsCollector = also {
|
||||||
it[SearchType.paramKey] = searchType
|
it[SearchType.paramKey] = searchType
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ package de.pheerai.rcdbquery.dataMappings.startsWith
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
|
import de.pheerai.rcdbquery.dataMappings.internal.ParamKey
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
|
|
||||||
class StartsWith(override val paramValue: String) :
|
internal class StartsWith(override val paramValue: String) :
|
||||||
RcdbParamOption<String> {
|
RcdbParamOption<String> {
|
||||||
override val prettyName = "Starts with"
|
override val prettyName = "Starts with"
|
||||||
override val fullName = "Name starting with term"
|
override val fullName = "Name starting with term"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.startsWith
|
package de.pheerai.rcdbquery.dataMappings.startsWith
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
|
||||||
fun ParamsCollector.startsWith(term: String) = also {
|
public fun ParamsCollector.startsWith(term: String): ParamsCollector = also {
|
||||||
this[StartsWith.paramKey] =
|
this[StartsWith.paramKey] =
|
||||||
StartsWith(term)
|
StartsWith(term)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
enum class Status(
|
public enum class Status(
|
||||||
override val prettyName: String,
|
override val prettyName: String,
|
||||||
override val fullName: String,
|
override val fullName: String,
|
||||||
override val paramValue: Long
|
override val paramValue: Long
|
||||||
|
@ -18,10 +18,10 @@ enum class Status(
|
||||||
|
|
||||||
constructor(name: String, paramId: Long) : this(name, name, paramId)
|
constructor(name: String, paramId: Long) : this(name, name, paramId)
|
||||||
|
|
||||||
companion object: StringGeneratable<Status> {
|
public companion object: StringGeneratable<Status> {
|
||||||
override val paramKey = "st"
|
override val paramKey: String = "st"
|
||||||
|
|
||||||
override fun of(input: String) = when (input) {
|
override fun of(input: String): Status? = when (input) {
|
||||||
"SBNO" -> SBNO
|
"SBNO" -> SBNO
|
||||||
"Operating" -> OPERATING
|
"Operating" -> OPERATING
|
||||||
"Under Construction" -> UNDER_CONSTRUCTION
|
"Under Construction" -> UNDER_CONSTRUCTION
|
||||||
|
|
|
@ -2,14 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.status
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
||||||
|
|
||||||
class StatusBuilder : MultiParamBuilder<Long, Status>() {
|
public class StatusBuilder : MultiParamBuilder<Long, Status>() {
|
||||||
override fun add(param: Status): StatusBuilder {
|
override fun add(param: Status): StatusBuilder {
|
||||||
super.add(param)
|
super.add(param)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sbno() = this.add(Status.SBNO)
|
override fun Status.invoke(): StatusBuilder = add(this)
|
||||||
fun operating() = this.add(Status.OPERATING)
|
|
||||||
fun underConstruction() = this.add(Status.UNDER_CONSTRUCTION)
|
|
||||||
fun stored() = this.add(Status.STORED)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.status
|
package de.pheerai.rcdbquery.dataMappings.status
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
|
||||||
fun ParamsCollector.status(body: StatusBuilder.() -> StatusBuilder): ParamsCollector {
|
public fun ParamsCollector.status(body: StatusBuilder.() -> StatusBuilder): ParamsCollector {
|
||||||
val builder = StatusBuilder()
|
val builder = StatusBuilder()
|
||||||
builder.body()
|
builder.body()
|
||||||
this[Status.paramKey] = builder.build()
|
this[Status.paramKey] = builder.build()
|
||||||
|
|
|
@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.thrill
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
||||||
|
|
||||||
enum class Thrill(
|
public enum class Thrill(
|
||||||
override val prettyName: String,
|
override val prettyName: String,
|
||||||
override val fullName: String,
|
override val fullName: String,
|
||||||
override val paramValue: Long
|
override val paramValue: Long
|
||||||
|
@ -16,8 +16,8 @@ enum class Thrill(
|
||||||
|
|
||||||
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
|
constructor(name: String, paramValue: Long) : this(name, name, paramValue)
|
||||||
|
|
||||||
companion object : StringGeneratable<Thrill> {
|
public companion object : StringGeneratable<Thrill> {
|
||||||
override val paramKey = "sc"
|
override val paramKey: String = "sc"
|
||||||
|
|
||||||
override fun of(input: String): Thrill? = when (input) {
|
override fun of(input: String): Thrill? = when (input) {
|
||||||
"Kiddie" -> KIDDIE
|
"Kiddie" -> KIDDIE
|
||||||
|
|
|
@ -2,14 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.thrill
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
||||||
|
|
||||||
class ThrillBuilder : MultiParamBuilder<Long, Thrill>() {
|
public class ThrillBuilder : MultiParamBuilder<Long, Thrill>() {
|
||||||
override fun add(param: Thrill): ThrillBuilder {
|
override fun add(param: Thrill): ThrillBuilder {
|
||||||
super.add(param)
|
super.add(param)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun kiddie() = this.add(Thrill.KIDDIE)
|
override fun Thrill.invoke(): ThrillBuilder = add(this)
|
||||||
fun family() = this.add(Thrill.FAMILY)
|
|
||||||
fun thrill() = this.add(Thrill.THRILL)
|
|
||||||
fun extreme() = this.add(Thrill.EXTREME)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.thrill
|
package de.pheerai.rcdbquery.dataMappings.thrill
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
|
||||||
fun ParamsCollector.type(body: ThrillBuilder.() -> ThrillBuilder): ParamsCollector {
|
public fun ParamsCollector.thrill(body: ThrillBuilder.() -> ThrillBuilder): ParamsCollector {
|
||||||
val builder = ThrillBuilder()
|
val builder = ThrillBuilder()
|
||||||
builder.body()
|
builder.body()
|
||||||
this[Thrill.paramKey] = builder.build()
|
this[Thrill.paramKey] = builder.build()
|
||||||
|
|
|
@ -3,7 +3,7 @@ package de.pheerai.rcdbquery.dataMappings.type
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
||||||
|
|
||||||
enum class Type(
|
public enum class Type(
|
||||||
override val prettyName: String,
|
override val prettyName: String,
|
||||||
override val fullName: String,
|
override val fullName: String,
|
||||||
override val paramValue: Long
|
override val paramValue: Long
|
||||||
|
@ -14,10 +14,10 @@ enum class Type(
|
||||||
|
|
||||||
constructor(name: String, paramValue: Long): this(name, name, paramValue)
|
constructor(name: String, paramValue: Long): this(name, name, paramValue)
|
||||||
|
|
||||||
companion object: StringGeneratable<Type> {
|
public companion object: StringGeneratable<Type> {
|
||||||
override val paramKey = "ty"
|
override val paramKey: String = "ty"
|
||||||
|
|
||||||
override fun of(input: String) = when(input) {
|
override fun of(input: String): Type? = when(input) {
|
||||||
"Steel" -> STEEL
|
"Steel" -> STEEL
|
||||||
"Wood" -> WOOD
|
"Wood" -> WOOD
|
||||||
else -> null
|
else -> null
|
||||||
|
|
|
@ -2,12 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.type
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
||||||
|
|
||||||
class TypeBuilder : MultiParamBuilder<Long, Type>() {
|
public class TypeBuilder : MultiParamBuilder<Long, Type>() {
|
||||||
override fun add(param: Type): TypeBuilder {
|
override fun add(param: Type): TypeBuilder {
|
||||||
super.add(param)
|
super.add(param)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun steel() = this.add(Type.STEEL)
|
override fun Type.invoke(): TypeBuilder = add(this)
|
||||||
fun wood() = this.add(Type.WOOD)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.type
|
package de.pheerai.rcdbquery.dataMappings.type
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.thrill.Thrill
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
import de.pheerai.rcdbquery.dataMappings.thrill.ThrillBuilder
|
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
|
||||||
|
|
||||||
fun ParamsCollector.thrill(body: ThrillBuilder.() -> ThrillBuilder): ParamsCollector {
|
public fun ParamsCollector.type(body: TypeBuilder.() -> TypeBuilder): ParamsCollector {
|
||||||
val builder = ThrillBuilder()
|
val builder = TypeBuilder()
|
||||||
builder.body()
|
builder.body()
|
||||||
this[Thrill.paramKey] = builder.build()
|
this[Type.paramKey] = builder.build()
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings
|
package de.pheerai.rcdbquery.dataMappings
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.order.Order
|
import de.pheerai.rcdbquery.dataMappings.order.Order
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
|
||||||
|
public const val EXTRA_COLUMNS_ERROR_MESSAGE: String =
|
||||||
|
"The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)"
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@Deprecated(
|
@Deprecated(
|
||||||
"The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)",
|
EXTRA_COLUMNS_ERROR_MESSAGE,
|
||||||
ReplaceWith("sortBy"), DeprecationLevel.ERROR
|
ReplaceWith("sortBy"), DeprecationLevel.ERROR
|
||||||
)
|
)
|
||||||
fun ParamsCollector.extraColumns(orders: List<Order>): Nothing =
|
public fun ParamsCollector.extraColumns(orders: List<Order>): Nothing =
|
||||||
error("The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)")
|
error(EXTRA_COLUMNS_ERROR_MESSAGE)
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@Deprecated(
|
@Deprecated(
|
||||||
"The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)",
|
EXTRA_COLUMNS_ERROR_MESSAGE,
|
||||||
ReplaceWith("sortBy"), DeprecationLevel.ERROR
|
ReplaceWith("sortBy"), DeprecationLevel.ERROR
|
||||||
)
|
)
|
||||||
fun ParamsCollector.extraColumns(vararg orders: Order): Nothing =
|
public fun ParamsCollector.extraColumns(vararg orders: Order): Nothing =
|
||||||
error("The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)")
|
error(EXTRA_COLUMNS_ERROR_MESSAGE)
|
||||||
|
|
|
@ -5,10 +5,10 @@ import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
enum class Vendor(
|
public enum class Vendor(
|
||||||
override val prettyName: String,
|
override val prettyName: String,
|
||||||
override val fullName: String,
|
override val fullName: String,
|
||||||
override val paramValue: Long
|
override val paramValue: Long,
|
||||||
) : RcdbParamOption<Long>, RcdbItem {
|
) : RcdbParamOption<Long>, RcdbItem {
|
||||||
YAQIAO_MACHINE("Yaqiao", "Yaqiao Machine", 6471),
|
YAQIAO_MACHINE("Yaqiao", "Yaqiao Machine", 6471),
|
||||||
CREDIBLE("Credible", 6584),
|
CREDIBLE("Credible", 6584),
|
||||||
|
@ -118,7 +118,7 @@ enum class Vendor(
|
||||||
TAKAHASHI_KIKAI_SANGYO("Takahashi Kikai Sangyo", 7472),
|
TAKAHASHI_KIKAI_SANGYO("Takahashi Kikai Sangyo", 7472),
|
||||||
DYNAMIC("Dynamic Attractions", 7489),
|
DYNAMIC("Dynamic Attractions", 7489),
|
||||||
GOLDEN_HORSE("Golden Horse", 7492),
|
GOLDEN_HORSE("Golden Horse", 7492),
|
||||||
WIEGAND("Wiegand", "Josef Wiegand GmbH & Co. KG", 7514),
|
WIEGAND("Wiegand", 7514),
|
||||||
ASCOT("Ascot Design", 7530),
|
ASCOT("Ascot Design", 7530),
|
||||||
DAL_AMUSEMENT_RIDES("DAL Amusement Rides Company", 7536),
|
DAL_AMUSEMENT_RIDES("DAL Amusement Rides Company", 7536),
|
||||||
CHILDRESS_COASTER("Childress Coaster", 7550),
|
CHILDRESS_COASTER("Childress Coaster", 7550),
|
||||||
|
@ -249,14 +249,17 @@ enum class Vendor(
|
||||||
|
|
||||||
constructor(name: String, paramId: Long) : this(name, name, paramId)
|
constructor(name: String, paramId: Long) : this(name, name, paramId)
|
||||||
|
|
||||||
companion object : StringGeneratable<Vendor> {
|
public companion object : StringGeneratable<Vendor> {
|
||||||
override val paramKey = "mk"
|
override val paramKey: String = "mk"
|
||||||
override fun of(input: String) = values().find { input == it.fullName }
|
override fun of(input: String): Vendor? = values().find { input == it.fullName }
|
||||||
|
|
||||||
fun searchByName(name: String): List<Vendor> {
|
public fun searchByName(name: String): List<Vendor> {
|
||||||
val searchName = name.toLowerCase()
|
val searchName = name.toLowerCase()
|
||||||
return values().filter {
|
return values()
|
||||||
it.fullName.toLowerCase().contains(searchName)
|
.filter {
|
||||||
|
it.fullName
|
||||||
|
.toLowerCase()
|
||||||
|
.contains(searchName)
|
||||||
}.toList()
|
}.toList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.vendor
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder
|
||||||
|
|
||||||
class VendorBuilder : MultiParamBuilder<Long, Vendor>() {
|
public class VendorBuilder : MultiParamBuilder<Long, Vendor>() {
|
||||||
override fun add(param: Vendor): VendorBuilder {
|
override fun add(param: Vendor): VendorBuilder {
|
||||||
super.add(param)
|
super.add(param)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun of(vendor: Vendor) = this.add(vendor)
|
override operator fun Vendor.invoke(): VendorBuilder = add(this)
|
||||||
fun vekoma() = this.add(Vendor.VEKOMA)
|
|
||||||
fun intamin() = this.add(Vendor.INTAMIN)
|
|
||||||
fun mack() = this.add(Vendor.MACK)
|
|
||||||
fun bandm() = this.add(Vendor.B_AND_M)
|
|
||||||
fun gerstlauer() = this.add(Vendor.GERSTLAUER)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings.vendor
|
package de.pheerai.rcdbquery.dataMappings.vendor
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dsl.ParamsCollector
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
|
||||||
// TODO: Try to generify. This is currently lacking some sort of "This interface requires a companion implementing that interface"
|
// TODO: Try to generify. This is currently lacking some sort of "This interface requires a companion implementing that interface"
|
||||||
fun ParamsCollector.vendors(body: VendorBuilder.() -> VendorBuilder): ParamsCollector {
|
public fun ParamsCollector.vendors(body: VendorBuilder.() -> VendorBuilder): ParamsCollector {
|
||||||
val builder = VendorBuilder()
|
val builder = VendorBuilder()
|
||||||
builder.body()
|
builder.body()
|
||||||
this[Vendor.paramKey] = builder.build()
|
this[Vendor.paramKey] = builder.build()
|
||||||
|
|
48
src/main/kotlin/de/pheerai/rcdbquery/dsl/params/Collector.kt
Normal file
48
src/main/kotlin/de/pheerai/rcdbquery/dsl/params/Collector.kt
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
package de.pheerai.rcdbquery.dsl.params
|
||||||
|
|
||||||
|
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
||||||
|
import de.pheerai.rcdbquery.dataMappings.searchType.SearchType
|
||||||
|
import de.pheerai.rcdbquery.dsl.RcdbParams
|
||||||
|
|
||||||
|
public class ParamsCollector {
|
||||||
|
private val multiParams: MutableMap<String, List<RcdbParamOption<Any>>> = mutableMapOf()
|
||||||
|
private val singleParams: MutableMap<String, RcdbParamOption<Any>> = mutableMapOf()
|
||||||
|
|
||||||
|
public fun build(): RcdbParams = RcdbParams(buildMulti(), buildSingle())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the Query Params from this builder.
|
||||||
|
* If no Search type has been set, this will default to "Coaster"
|
||||||
|
*/
|
||||||
|
private fun buildMulti() = multiParams.apply {
|
||||||
|
// Defaults go here, if any
|
||||||
|
}
|
||||||
|
.filter { it.value.isNotEmpty() }
|
||||||
|
.mapValues { e -> e.value.map { o -> o.paramValue.toString() } }
|
||||||
|
.let { MultiParams(it) }
|
||||||
|
|
||||||
|
private fun buildSingle() = singleParams.apply {
|
||||||
|
putIfAbsent(SearchType.paramKey, SearchType.COASTER)
|
||||||
|
}
|
||||||
|
.mapValues { e -> e.value.paramValue.toString() }
|
||||||
|
.let { SingleParams(it) }
|
||||||
|
|
||||||
|
public operator fun set(paramName: String, options: List<RcdbParamOption<Any>>) {
|
||||||
|
this.multiParams[paramName] = options
|
||||||
|
}
|
||||||
|
|
||||||
|
public operator fun set(paramName: String, option: RcdbParamOption<Any>) {
|
||||||
|
if (paramName !in singleParams && paramName !in multiParams) {
|
||||||
|
this.singleParams[paramName] = option
|
||||||
|
} else {
|
||||||
|
throw ParamAlreadySetException("Parameter $paramName already set.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun getSingle(paramName: String): Any? = this.multiParams[paramName] ?: this.singleParams[paramName]
|
||||||
|
public fun getMulti(paramName: String): List<RcdbParamOption<Any>>? = this.multiParams[paramName]
|
||||||
|
|
||||||
|
public fun keys(): Set<String> = this.multiKeys().plus(singleKeys())
|
||||||
|
private fun multiKeys() = this.multiParams.keys.toSet()
|
||||||
|
private fun singleKeys() = this.singleParams.keys.toSet()
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package de.pheerai.rcdbquery.dsl.params
|
||||||
|
|
||||||
|
public sealed class BaseParams<T> {
|
||||||
|
public abstract val params: Map<String, T>
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MultiParams(override val params: Map<String, List<String>>) : BaseParams<List<String>>()
|
||||||
|
public class SingleParams(override val params: Map<String, String>) : BaseParams<String>()
|
|
@ -0,0 +1,3 @@
|
||||||
|
package de.pheerai.rcdbquery.dsl.params
|
||||||
|
|
||||||
|
internal class ParamAlreadySetException(message: String) : IllegalArgumentException(message)
|
|
@ -1,19 +1,19 @@
|
||||||
package de.pheerai.rcdbquery.dsl
|
package de.pheerai.rcdbquery.dsl
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption
|
import de.pheerai.rcdbquery.dsl.params.MultiParams
|
||||||
import de.pheerai.rcdbquery.dataMappings.searchType.SearchType
|
import de.pheerai.rcdbquery.dsl.params.ParamsCollector
|
||||||
|
import de.pheerai.rcdbquery.dsl.params.SingleParams
|
||||||
|
|
||||||
// TODO: Restructure
|
public data class RcdbParams(
|
||||||
|
private val multiParams: MultiParams,
|
||||||
data class RcdbParams(
|
private val singleParams: SingleParams,
|
||||||
val multiParams: MultiParams,
|
|
||||||
val singleParams: SingleParams
|
|
||||||
) {
|
) {
|
||||||
fun toStrings(): List<String> {
|
public fun toStrings(): List<String> {
|
||||||
val multiParamSequence: Sequence<Pair<String, String>> = this.multiParams
|
val multiParamSequence: Sequence<Pair<String, String>> = this.multiParams
|
||||||
.params
|
.params
|
||||||
|
.mapValues { it.value.joinToString(separator = ",") }
|
||||||
|
.map { it.toPair() }
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.map { e -> e.key to e.value.joinToString(separator = ",") }
|
|
||||||
val singleParamSequence: Sequence<Pair<String, String>> = this.singleParams
|
val singleParamSequence: Sequence<Pair<String, String>> = this.singleParams
|
||||||
.params
|
.params
|
||||||
.asSequence()
|
.asSequence()
|
||||||
|
@ -24,62 +24,10 @@ data class RcdbParams(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class Params<T> {
|
public fun rcdbQuery(body: ParamsCollector.() -> ParamsCollector): String =
|
||||||
abstract val params: Map<String, T>
|
|
||||||
}
|
|
||||||
|
|
||||||
class ParamAlreadySetException(message: String) : IllegalArgumentException(message)
|
|
||||||
|
|
||||||
class MultiParams(override val params: Map<String, List<String>>) : Params<List<String>>()
|
|
||||||
class SingleParams(override val params: Map<String, String>) : Params<String>()
|
|
||||||
|
|
||||||
class ParamsCollector {
|
|
||||||
private val multiParams: MutableMap<String, List<RcdbParamOption<Any>>> = mutableMapOf()
|
|
||||||
private val singleParams: MutableMap<String, RcdbParamOption<Any>> = mutableMapOf()
|
|
||||||
|
|
||||||
fun build() = RcdbParams(buildMulti(), buildSingle())
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the Query Params from this builder.
|
|
||||||
* If no Search type has been set, this will default to "Coaster"
|
|
||||||
*/
|
|
||||||
private fun buildMulti() = multiParams.apply {
|
|
||||||
// Defaults go here, if any
|
|
||||||
}
|
|
||||||
.filter { it.value.isNotEmpty() }
|
|
||||||
.mapValues { e -> e.value.map { o -> o.paramValue.toString() } }
|
|
||||||
.let { MultiParams(it) }
|
|
||||||
|
|
||||||
private fun buildSingle() = singleParams.apply {
|
|
||||||
putIfAbsent(SearchType.paramKey, SearchType.COASTER)
|
|
||||||
}
|
|
||||||
.mapValues { e -> e.value.paramValue.toString() }
|
|
||||||
.let { SingleParams(it) }
|
|
||||||
|
|
||||||
operator fun set(paramName: String, options: List<RcdbParamOption<Any>>) {
|
|
||||||
this.multiParams[paramName] = options
|
|
||||||
}
|
|
||||||
|
|
||||||
operator fun set(paramName: String, option: RcdbParamOption<Any>) {
|
|
||||||
if (paramName !in singleParams && paramName !in multiParams) {
|
|
||||||
this.singleParams[paramName] = option
|
|
||||||
} else {
|
|
||||||
throw ParamAlreadySetException("Parameter $paramName already set.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getSingle(paramName: String) = this.multiParams[paramName] ?: this.singleParams[paramName]
|
|
||||||
fun getMulti(paramName: String) = this.multiParams[paramName]
|
|
||||||
|
|
||||||
fun keys() = this.multiKeys().plus(singleKeys())
|
|
||||||
private fun multiKeys() = this.multiParams.keys.toSet()
|
|
||||||
private fun singleKeys() = this.singleParams.keys.toSet()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun rcdbQuery(body: ParamsCollector.() -> ParamsCollector) =
|
|
||||||
RcdbUrlQuery("https://www.rcdb.com/r.htm?", rcdbQueryParams(body)).toString()
|
RcdbUrlQuery("https://www.rcdb.com/r.htm?", rcdbQueryParams(body)).toString()
|
||||||
|
|
||||||
data class RcdbUrlQuery(val baseUrl: String, val params: RcdbParams) {
|
private data class RcdbUrlQuery(val baseUrl: String, val params: RcdbParams) {
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return params.toStrings()
|
return params.toStrings()
|
||||||
.joinToString(prefix = baseUrl, separator = "&")
|
.joinToString(prefix = baseUrl, separator = "&")
|
||||||
|
@ -87,9 +35,9 @@ data class RcdbUrlQuery(val baseUrl: String, val params: RcdbParams) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for the parameters only (mainly because it might be possilbe in the future to have an API with a POST search object?
|
* Builder for the parameters only (mainly because it might be possible in the future to have an API with a POST search object?
|
||||||
*/
|
*/
|
||||||
fun rcdbQueryParams(body: ParamsCollector.() -> ParamsCollector): RcdbParams {
|
private fun rcdbQueryParams(body: ParamsCollector.() -> ParamsCollector): RcdbParams {
|
||||||
val builder = ParamsCollector()
|
val builder = ParamsCollector()
|
||||||
builder.body()
|
builder.body()
|
||||||
return builder.build()
|
return builder.build()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
module rcdbquery.main {
|
module rcdbquery.main {
|
||||||
exports de.pheerai.rcdbquery.dataMappings.category;
|
exports de.pheerai.rcdbquery.dataMappings.category;
|
||||||
exports de.pheerai.rcdbquery.dataMappings.classification;
|
exports de.pheerai.rcdbquery.dataMappings.classification;
|
||||||
|
exports de.pheerai.rcdbquery.dataMappings;
|
||||||
exports de.pheerai.rcdbquery.dataMappings.design;
|
exports de.pheerai.rcdbquery.dataMappings.design;
|
||||||
exports de.pheerai.rcdbquery.dataMappings.layout;
|
exports de.pheerai.rcdbquery.dataMappings.layout;
|
||||||
exports de.pheerai.rcdbquery.dataMappings.order;
|
exports de.pheerai.rcdbquery.dataMappings.order;
|
||||||
|
@ -13,6 +14,8 @@ module rcdbquery.main {
|
||||||
exports de.pheerai.rcdbquery.dataMappings.type;
|
exports de.pheerai.rcdbquery.dataMappings.type;
|
||||||
exports de.pheerai.rcdbquery.dataMappings.vendor;
|
exports de.pheerai.rcdbquery.dataMappings.vendor;
|
||||||
exports de.pheerai.rcdbquery.dsl;
|
exports de.pheerai.rcdbquery.dsl;
|
||||||
|
exports de.pheerai.rcdbquery.dsl.params;
|
||||||
|
|
||||||
requires kotlin.stdlib;
|
requires kotlin.stdlib;
|
||||||
|
requires java.base;
|
||||||
}
|
}
|
||||||
|
|
10
src/test/kotlin/de/pheerai/rcdbquery/TestConfig.kt
Normal file
10
src/test/kotlin/de/pheerai/rcdbquery/TestConfig.kt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package de.pheerai.rcdbquery
|
||||||
|
|
||||||
|
import io.kotest.core.config.AbstractProjectConfig
|
||||||
|
|
||||||
|
class TestConfig : AbstractProjectConfig() {
|
||||||
|
override val globalAssertSoftly = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just for IJ to stop whining about unused classes
|
||||||
|
annotation class Spec()
|
|
@ -1,38 +1,58 @@
|
||||||
package de.pheerai.rcdbquery.dsl
|
package de.pheerai.rcdbquery.dsl
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.vendor.Vendor
|
import de.pheerai.rcdbquery.Spec
|
||||||
|
import de.pheerai.rcdbquery.dataMappings.order.Order
|
||||||
import de.pheerai.rcdbquery.dataMappings.order.sortBy
|
import de.pheerai.rcdbquery.dataMappings.order.sortBy
|
||||||
|
import de.pheerai.rcdbquery.dataMappings.searchType.SearchType
|
||||||
|
import de.pheerai.rcdbquery.dataMappings.searchType.searchType
|
||||||
|
import de.pheerai.rcdbquery.dataMappings.type.Type
|
||||||
|
import de.pheerai.rcdbquery.dataMappings.type.type
|
||||||
|
import de.pheerai.rcdbquery.dataMappings.vendor.Vendor
|
||||||
import de.pheerai.rcdbquery.dataMappings.vendor.vendors
|
import de.pheerai.rcdbquery.dataMappings.vendor.vendors
|
||||||
|
import de.pheerai.rcdbquery.dsl.params.ParamAlreadySetException
|
||||||
|
import io.kotest.assertions.asClue
|
||||||
|
import io.kotest.assertions.throwables.shouldThrow
|
||||||
import io.kotest.core.spec.style.StringSpec
|
import io.kotest.core.spec.style.StringSpec
|
||||||
import io.kotest.matchers.shouldBe
|
|
||||||
import io.kotest.matchers.string.shouldContain
|
import io.kotest.matchers.string.shouldContain
|
||||||
|
import io.kotest.matchers.string.shouldHaveLength
|
||||||
|
|
||||||
|
@Spec
|
||||||
class RcdbQueryDslTest : StringSpec({
|
class RcdbQueryDslTest : StringSpec({
|
||||||
|
|
||||||
"should generate a proper URL" {
|
"should generate a proper URL" {
|
||||||
val actual = rcdbQuery {
|
rcdbQuery {
|
||||||
vendors {
|
vendors {
|
||||||
vekoma()
|
Vendor.VEKOMA()
|
||||||
mack()
|
Vendor.MACK()
|
||||||
of(Vendor.MAURER)
|
Vendor.MAURER()
|
||||||
}
|
}
|
||||||
sortBy {
|
sortBy {
|
||||||
inversions()
|
Order.INVERSIONS()
|
||||||
manufacturer()
|
Order.MANUFACTURER()
|
||||||
|
}
|
||||||
|
}.asClue {
|
||||||
|
it shouldHaveLength 61
|
||||||
|
it shouldContain "https://www.rcdb.com/r.htm?"
|
||||||
|
it shouldContain "mk="
|
||||||
|
it shouldContain "6836"
|
||||||
|
it shouldContain "6856"
|
||||||
|
it shouldContain "6905"
|
||||||
|
it shouldContain "order="
|
||||||
|
it shouldContain "24"
|
||||||
|
it shouldContain "30"
|
||||||
|
it shouldContain "ot=2"
|
||||||
|
it.filter { c -> c == '&' } shouldHaveLength 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
actual.length shouldBe 61
|
"Should throw if unique value is reset" {
|
||||||
actual.shouldContain("https://www.rcdb.com/r.htm?")
|
shouldThrow<ParamAlreadySetException> {
|
||||||
actual.shouldContain("mk=")
|
rcdbQuery {
|
||||||
actual.shouldContain("6836")
|
searchType(SearchType.COASTER)
|
||||||
actual.shouldContain("6856")
|
type {
|
||||||
actual.shouldContain("6905")
|
Type.WOOD()
|
||||||
actual.shouldContain("order=")
|
}
|
||||||
actual.shouldContain("24")
|
searchType(SearchType.AMUSEMENT_PARK)
|
||||||
actual.shouldContain("30")
|
}
|
||||||
actual.shouldContain("ot=2")
|
}
|
||||||
actual.filter { it == '&' }.length shouldBe 2
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue