diff --git a/build.gradle.kts b/build.gradle.kts index 61b8cea..3a270b6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,15 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +buildscript { + extra.apply { + set("kotestVersion", "4.2.0") + set("kotlinApiVersion", "1.4") + set("javaVersion", JavaVersion.VERSION_11) + } +} + +inline fun getFromExtra(prop: String) = project.extra[prop] as T + // TODO: Documentation // TODO: Source Jar // TODO: Doc Jar @@ -13,29 +23,36 @@ repositories { mavenCentral() } -project.version = "0.0.1" +project.version = "0.0.2" project.group = "de.pheerai.rcdb" - java { - targetCompatibility = JavaVersion.VERSION_11 - sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = getFromExtra("javaVersion") + sourceCompatibility = getFromExtra("javaVersion") } dependencies { implementation(kotlin("stdlib-jdk8")) - testImplementation("io.kotest:kotest-runner-junit5-jvm:4.0.5") - testImplementation("io.kotest:kotest-assertions-core-jvm:4.0.5") + testImplementation( + group = "io.kotest", + name = "kotest-runner-junit5-jvm", + version = getFromExtra("kotestVersion") + ) + testImplementation( + group = "io.kotest", + name = "kotest-assertions-core-jvm", + version = getFromExtra("kotestVersion") + ) } tasks { withType().configureEach { kotlinOptions { - freeCompilerArgs = listOf("-XXLanguage:+InlineClasses") - apiVersion = "1.3" - languageVersion = "1.3" - jvmTarget = JavaVersion.VERSION_11.toString() +// freeCompilerArgs = listOf("-XXLanguage:+InlineClasses") + apiVersion = getFromExtra("kotlinApiVersion") + languageVersion = getFromExtra("kotlinApiVersion") + jvmTarget = getFromExtra("javaVersion").toString() } } @@ -48,7 +65,7 @@ publishing { publications { create("maven") { groupId = project.group as String - artifactId = project.name as String + artifactId = project.name version = project.version as String from(components["java"]) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 490fda8..62d4c05 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6623300..bb8b2fc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 2fe81a7..fbd7c51 100755 --- a/gradlew +++ b/gradlew @@ -82,6 +82,7 @@ esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -129,6 +130,7 @@ fi if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath diff --git a/gradlew.bat b/gradlew.bat index 62bd9b9..5093609 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -84,6 +84,7 @@ set CMD_LINE_ARGS=%* set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @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% diff --git a/settings.gradle.kts b/settings.gradle.kts index d7cc2ed..abccebe 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,6 @@ pluginManagement { plugins { - kotlin("jvm") version "1.3.72" + kotlin("jvm") version "1.4.0" } } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/Sample.kt b/src/main/kotlin/de/pheerai/rcdbquery/Sample.kt index 1631acb..78b389d 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/Sample.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/Sample.kt @@ -1,11 +1,12 @@ package de.pheerai.rcdbquery +import de.pheerai.rcdbquery.dataMappings.order.Order import de.pheerai.rcdbquery.dataMappings.order.sortBy import de.pheerai.rcdbquery.dataMappings.page.page 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.vendor.Vendor +import de.pheerai.rcdbquery.dataMappings.vendor.Vendor.* import de.pheerai.rcdbquery.dataMappings.vendor.vendors import de.pheerai.rcdbquery.dsl.rcdbQuery @@ -18,14 +19,13 @@ fun generateNameQueryUrl() = rcdbQuery { searchType(SearchType.COASTER) searchTerm("Dragon") vendors { - vekoma() - intamin() - mack() - of(Vendor.PRESTON_AND_BARBIERI) + VEKOMA() + INTAMIN() + MACK() } sortBy { - manufacturer() - inversions() + Order.MANUFACTURER() + Order.INVERSIONS() } } @@ -33,6 +33,6 @@ fun generatePageQueryUrl() = rcdbQuery { page(3) searchType(SearchType.COASTER) vendors { - intamin() + INTAMIN() } } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/category/CategoryBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/category/CategoryBuilder.kt index 2332b46..9571d0f 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/category/CategoryBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/category/CategoryBuilder.kt @@ -2,36 +2,11 @@ package de.pheerai.rcdbquery.dataMappings.category import de.pheerai.rcdbquery.dataMappings.internal.MultiParamBuilder -class CategoryBuilder: MultiParamBuilder() { +class CategoryBuilder : MultiParamBuilder() { override fun add(param: Category): CategoryBuilder { super.add(param) return this } - fun fourthDimension() = this.add(Category.FOURTH_DIMENSION) - 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) + override fun Category.invoke() = add(this) } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/category/paramBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/category/paramBuilder.kt index 883c4fc..323cbcc 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/category/paramBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/category/paramBuilder.kt @@ -1,6 +1,6 @@ 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 { val builder = CategoryBuilder() diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/classification/ClassificationBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/classification/ClassificationBuilder.kt index 1b41907..9b8328b 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/classification/ClassificationBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/classification/ClassificationBuilder.kt @@ -8,7 +8,5 @@ class ClassificationBuilder : MultiParamBuilder() { return this } - fun rollerCoaster() = this.add(Classification.ROLLER_COASTER) - fun poweredCoaster() = this.add(Classification.POWERED_COASTER) - fun mountainCoaster() = this.add(Classification.MOUNTAIN_COASTER) + override fun Classification.invoke() = add(this) } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/classification/paramBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/classification/paramBuilder.kt index e79c401..14d7410 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/classification/paramBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/classification/paramBuilder.kt @@ -1,6 +1,6 @@ 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 { val builder = ClassificationBuilder() diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/design/DesignBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/design/DesignBuilder.kt index b340276..237130d 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/design/DesignBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/design/DesignBuilder.kt @@ -8,12 +8,5 @@ class DesignBuilder : MultiParamBuilder() { return this } - fun sitDown() = Design.SIT_DOWN - 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 + override fun Design.invoke() = add(this) } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/design/paramBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/design/paramBuilder.kt index 5fbd84c..e94d32c 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/design/paramBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/design/paramBuilder.kt @@ -1,6 +1,6 @@ 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 { val builder = DesignBuilder() diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/internal/MultiParamBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/internal/MultiParamBuilder.kt index 829f4b2..e1cbe56 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/internal/MultiParamBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/internal/MultiParamBuilder.kt @@ -1,6 +1,6 @@ package de.pheerai.rcdbquery.dataMappings.internal -open class MultiParamBuilder> { +abstract class MultiParamBuilder> { private val paramList: MutableList = mutableListOf() open fun add(param: T): MultiParamBuilder { @@ -19,5 +19,6 @@ open class MultiParamBuilder> { } fun build() = paramList.toList() -} + abstract operator fun T.invoke(): MultiParamBuilder +} diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/layout/LayoutBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/layout/LayoutBuilder.kt index c07957e..6f75765 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/layout/LayoutBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/layout/LayoutBuilder.kt @@ -8,32 +8,5 @@ class LayoutBuilder : MultiParamBuilder() { return this } - fun bigApple() = this.add(Layout.BIG_APPLE) - 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) + override operator fun Layout.invoke() = add(this) } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/layout/paramBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/layout/paramBuilder.kt index 2acab17..611b9e2 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/layout/paramBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/layout/paramBuilder.kt @@ -1,10 +1,12 @@ 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 { val builder = LayoutBuilder() - builder.body() + with(Layout) { + builder.body() + } this[Layout.paramKey] = builder.build() return this } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/order/OrderBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/order/OrderBuilder.kt index 3bc4bff..79570f2 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/order/OrderBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/order/OrderBuilder.kt @@ -18,30 +18,6 @@ class OrderBuilder : MultiParamBuilder() { return this } - fun of(order: Order) = this.add(order) - fun manufacturer() = this.add(Order.MANUFACTURER) - 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) + override fun Order.invoke() = add(this) fun allRelevant() = this.addAll(Order.values().filter { it.relevantForAll }) } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/order/paramBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/order/paramBuilder.kt index 5d6a094..2c205ee 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/order/paramBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/order/paramBuilder.kt @@ -1,6 +1,6 @@ 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 { val builder = OrderBuilder() diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/page/paramBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/page/paramBuilder.kt index 1848292..4cf3d14 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/page/paramBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/page/paramBuilder.kt @@ -1,6 +1,6 @@ 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 { this[Page.paramKey] = diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/searchTerm/paramBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/searchTerm/paramBuilder.kt index e4127ae..ab3d49f 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/searchTerm/paramBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/searchTerm/paramBuilder.kt @@ -1,6 +1,6 @@ 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 { it[SearchTerm.paramKey] = listOf( diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/searchType/paramBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/searchType/paramBuilder.kt index a5e1711..08fb494 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/searchType/paramBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/searchType/paramBuilder.kt @@ -1,6 +1,6 @@ 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 { it[SearchType.paramKey] = searchType diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/startsWith/paramBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/startsWith/paramBuilder.kt index 70e04f8..f23422a 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/startsWith/paramBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/startsWith/paramBuilder.kt @@ -1,6 +1,6 @@ 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 { this[StartsWith.paramKey] = diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/status/StatusBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/status/StatusBuilder.kt index 4a27274..752da5b 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/status/StatusBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/status/StatusBuilder.kt @@ -8,8 +8,5 @@ class StatusBuilder : MultiParamBuilder() { 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) + override fun Status.invoke() = add(this) } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/status/paramBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/status/paramBuilder.kt index 9d133b0..7fd8830 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/status/paramBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/status/paramBuilder.kt @@ -1,6 +1,6 @@ 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 { val builder = StatusBuilder() diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/thrill/ThrillBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/thrill/ThrillBuilder.kt index 7352839..7dab9e9 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/thrill/ThrillBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/thrill/ThrillBuilder.kt @@ -8,8 +8,5 @@ class ThrillBuilder : MultiParamBuilder() { return this } - fun kiddie() = this.add(Thrill.KIDDIE) - fun family() = this.add(Thrill.FAMILY) - fun thrill() = this.add(Thrill.THRILL) - fun extreme() = this.add(Thrill.EXTREME) + override fun Thrill.invoke() = add(this) } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/thrill/paramBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/thrill/paramBuilder.kt index bfac7c2..da3ba1b 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/thrill/paramBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/thrill/paramBuilder.kt @@ -1,8 +1,8 @@ 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 { +fun ParamsCollector.thrill(body: ThrillBuilder.() -> ThrillBuilder): ParamsCollector { val builder = ThrillBuilder() builder.body() this[Thrill.paramKey] = builder.build() diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/type/TypeBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/type/TypeBuilder.kt index 7d85e8f..fd0fccd 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/type/TypeBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/type/TypeBuilder.kt @@ -8,6 +8,5 @@ class TypeBuilder : MultiParamBuilder() { return this } - fun steel() = this.add(Type.STEEL) - fun wood() = this.add(Type.WOOD) + override fun Type.invoke() = add(this) } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/type/paramBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/type/paramBuilder.kt index 56b1895..db509eb 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/type/paramBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/type/paramBuilder.kt @@ -1,12 +1,10 @@ package de.pheerai.rcdbquery.dataMappings.type -import de.pheerai.rcdbquery.dataMappings.thrill.Thrill -import de.pheerai.rcdbquery.dataMappings.thrill.ThrillBuilder -import de.pheerai.rcdbquery.dsl.ParamsCollector +import de.pheerai.rcdbquery.dsl.params.ParamsCollector -fun ParamsCollector.thrill(body: ThrillBuilder.() -> ThrillBuilder): ParamsCollector { - val builder = ThrillBuilder() +fun ParamsCollector.type(body: TypeBuilder.() -> TypeBuilder): ParamsCollector { + val builder = TypeBuilder() builder.body() - this[Thrill.paramKey] = builder.build() + this[Type.paramKey] = builder.build() return this } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/unknownParams.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/unknownParams.kt index da1678c..fe72e91 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/unknownParams.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/unknownParams.kt @@ -1,20 +1,23 @@ package de.pheerai.rcdbquery.dataMappings import de.pheerai.rcdbquery.dataMappings.order.Order -import de.pheerai.rcdbquery.dsl.ParamsCollector +import de.pheerai.rcdbquery.dsl.params.ParamsCollector + +const val EXTRA_COLUMNS_ERROR_MESSAGE = + "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") @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 ) fun ParamsCollector.extraColumns(orders: List): 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") @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 ) 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) diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/vendor/Vendor.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/vendor/Vendor.kt index 4a16958..c53ebbe 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/vendor/Vendor.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/vendor/Vendor.kt @@ -8,7 +8,7 @@ import de.pheerai.rcdbquery.dataMappings.internal.StringGeneratable enum class Vendor( override val prettyName: String, override val fullName: String, - override val paramValue: Long + override val paramValue: Long, ) : RcdbParamOption, RcdbItem { YAQIAO_MACHINE("Yaqiao", "Yaqiao Machine", 6471), CREDIBLE("Credible", 6584), @@ -118,7 +118,7 @@ enum class Vendor( TAKAHASHI_KIKAI_SANGYO("Takahashi Kikai Sangyo", 7472), DYNAMIC("Dynamic Attractions", 7489), GOLDEN_HORSE("Golden Horse", 7492), - WIEGAND("Wiegand", "Josef Wiegand GmbH & Co. KG", 7514), + WIEGAND("Wiegand", 7514), ASCOT("Ascot Design", 7530), DAL_AMUSEMENT_RIDES("DAL Amusement Rides Company", 7536), CHILDRESS_COASTER("Childress Coaster", 7550), @@ -255,9 +255,12 @@ enum class Vendor( fun searchByName(name: String): List { val searchName = name.toLowerCase() - return values().filter { - it.fullName.toLowerCase().contains(searchName) - }.toList() + return values() + .filter { + it.fullName + .toLowerCase() + .contains(searchName) + }.toList() } } } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/vendor/VendorBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/vendor/VendorBuilder.kt index 66b866a..5a8986e 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/vendor/VendorBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/vendor/VendorBuilder.kt @@ -8,10 +8,5 @@ class VendorBuilder : MultiParamBuilder() { return this } - fun of(vendor: Vendor) = this.add(vendor) - 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) + override fun Vendor.invoke() = add(this) } diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/vendor/paramBuilder.kt b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/vendor/paramBuilder.kt index 0fe5f20..5a36515 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/vendor/paramBuilder.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dataMappings/vendor/paramBuilder.kt @@ -1,6 +1,6 @@ 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" fun ParamsCollector.vendors(body: VendorBuilder.() -> VendorBuilder): ParamsCollector { diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dsl/params/Collector.kt b/src/main/kotlin/de/pheerai/rcdbquery/dsl/params/Collector.kt new file mode 100644 index 0000000..cf591a0 --- /dev/null +++ b/src/main/kotlin/de/pheerai/rcdbquery/dsl/params/Collector.kt @@ -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 + +class ParamsCollector { + private val multiParams: MutableMap>> = mutableMapOf() + private val singleParams: MutableMap> = 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>) { + this.multiParams[paramName] = options + } + + operator fun set(paramName: String, option: RcdbParamOption) { + 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() +} diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dsl/params/Params.kt b/src/main/kotlin/de/pheerai/rcdbquery/dsl/params/Params.kt new file mode 100644 index 0000000..b144c14 --- /dev/null +++ b/src/main/kotlin/de/pheerai/rcdbquery/dsl/params/Params.kt @@ -0,0 +1,8 @@ +package de.pheerai.rcdbquery.dsl.params + +sealed class BaseParams { + abstract val params: Map +} + +class MultiParams(override val params: Map>) : BaseParams>() +class SingleParams(override val params: Map) : BaseParams() diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dsl/params/exceptions.kt b/src/main/kotlin/de/pheerai/rcdbquery/dsl/params/exceptions.kt new file mode 100644 index 0000000..f3c485d --- /dev/null +++ b/src/main/kotlin/de/pheerai/rcdbquery/dsl/params/exceptions.kt @@ -0,0 +1,3 @@ +package de.pheerai.rcdbquery.dsl.params + +class ParamAlreadySetException(message: String) : IllegalArgumentException(message) diff --git a/src/main/kotlin/de/pheerai/rcdbquery/dsl/rcdbQueryDsl.kt b/src/main/kotlin/de/pheerai/rcdbquery/dsl/rcdbQueryDsl.kt index 0ca5f9d..31a5217 100644 --- a/src/main/kotlin/de/pheerai/rcdbquery/dsl/rcdbQueryDsl.kt +++ b/src/main/kotlin/de/pheerai/rcdbquery/dsl/rcdbQueryDsl.kt @@ -1,19 +1,19 @@ package de.pheerai.rcdbquery.dsl -import de.pheerai.rcdbquery.dataMappings.internal.RcdbParamOption -import de.pheerai.rcdbquery.dataMappings.searchType.SearchType - -// TODO: Restructure +import de.pheerai.rcdbquery.dsl.params.MultiParams +import de.pheerai.rcdbquery.dsl.params.ParamsCollector +import de.pheerai.rcdbquery.dsl.params.SingleParams data class RcdbParams( val multiParams: MultiParams, - val singleParams: SingleParams + val singleParams: SingleParams, ) { fun toStrings(): List { val multiParamSequence: Sequence> = this.multiParams .params + .mapValues { it.value.joinToString(separator = ",") } + .map { it.toPair() } .asSequence() - .map { e -> e.key to e.value.joinToString(separator = ",") } val singleParamSequence: Sequence> = this.singleParams .params .asSequence() @@ -24,58 +24,6 @@ data class RcdbParams( } } -sealed class Params { - abstract val params: Map -} - -class ParamAlreadySetException(message: String) : IllegalArgumentException(message) - -class MultiParams(override val params: Map>) : Params>() -class SingleParams(override val params: Map) : Params() - -class ParamsCollector { - private val multiParams: MutableMap>> = mutableMapOf() - private val singleParams: MutableMap> = 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>) { - this.multiParams[paramName] = options - } - - operator fun set(paramName: String, option: RcdbParamOption) { - 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() diff --git a/src/test/kotlin/de/pheerai/rcdbquery/TestConfig.kt b/src/test/kotlin/de/pheerai/rcdbquery/TestConfig.kt new file mode 100644 index 0000000..c333aae --- /dev/null +++ b/src/test/kotlin/de/pheerai/rcdbquery/TestConfig.kt @@ -0,0 +1,7 @@ +package de.pheerai.rcdbquery + +import io.kotest.core.config.AbstractProjectConfig + +class TestConfig : AbstractProjectConfig() { + override val globalAssertSoftly = true +} diff --git a/src/test/kotlin/de/pheerai/rcdbquery/dsl/RcdbQueryDslTest.kt b/src/test/kotlin/de/pheerai/rcdbquery/dsl/RcdbQueryDslTest.kt index af911c3..71ab8e1 100644 --- a/src/test/kotlin/de/pheerai/rcdbquery/dsl/RcdbQueryDslTest.kt +++ b/src/test/kotlin/de/pheerai/rcdbquery/dsl/RcdbQueryDslTest.kt @@ -1,38 +1,57 @@ package de.pheerai.rcdbquery.dsl -import de.pheerai.rcdbquery.dataMappings.vendor.Vendor +import de.pheerai.rcdbquery.dataMappings.order.Order 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.dsl.params.ParamAlreadySetException +import io.kotest.assertions.asClue import io.kotest.core.spec.style.StringSpec -import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain +import io.kotest.matchers.string.shouldHaveLength +import org.junit.jupiter.api.assertThrows class RcdbQueryDslTest : StringSpec({ - "should generate a proper URL" { - val actual = rcdbQuery { + rcdbQuery { vendors { - vekoma() - mack() - of(Vendor.MAURER) + Vendor.VEKOMA() + Vendor.MACK() + Vendor.MAURER() } sortBy { - inversions() - manufacturer() + Order.INVERSIONS() + 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 + } + } + + "Should throw if unique value is reset" { + assertThrows { + rcdbQuery { + searchType(SearchType.COASTER) + type { + Type.WOOD() + } + searchType(SearchType.AMUSEMENT_PARK) } } - - actual.length shouldBe 61 - actual.shouldContain("https://www.rcdb.com/r.htm?") - actual.shouldContain("mk=") - actual.shouldContain("6836") - actual.shouldContain("6856") - actual.shouldContain("6905") - actual.shouldContain("order=") - actual.shouldContain("24") - actual.shouldContain("30") - actual.shouldContain("ot=2") - actual.filter { it == '&' }.length shouldBe 2 } })