diff --git a/.github/workflows/publish-sonatype.yml b/.github/workflows/publish-sonatype.yml index 1247fe9..cabf487 100644 --- a/.github/workflows/publish-sonatype.yml +++ b/.github/workflows/publish-sonatype.yml @@ -29,11 +29,13 @@ jobs: uses: gradle/gradle-build-action@v2 - name: Publish to Sonatype - run: | + run: |- + export -- GPG_SIGNING_KEY_ID + printenv -- GPG_SIGNING_KEY | gpg --batch --passphrase-fd 3 --import 3<<< "$GPG_SIGNING_PASSWORD" + GPG_SIGNING_KEY_ID="$(gpg --with-colons --list-keys | awk -F : -- '/^pub:/ { getline; print "0x" substr($10, length($10) - 7) }')" ./gradlew publishAndReleaseToMavenCentral --stacktrace -PmavenCentralUsername="$SONATYPE_USERNAME" -PmavenCentralPassword="$SONATYPE_PASSWORD" env: SONATYPE_USERNAME: ${{ secrets.ONEBUSAWAY_SDK_SONATYPE_USERNAME || secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.ONEBUSAWAY_SDK_SONATYPE_PASSWORD || secrets.SONATYPE_PASSWORD }} - GPG_SIGNING_KEY_ID: ${{ secrets.ONEBUSAWAY_SDK_SONATYPE_GPG_SIGNING_KEY_ID || secrets.GPG_SIGNING_KEY_ID }} GPG_SIGNING_KEY: ${{ secrets.ONEBUSAWAY_SDK_SONATYPE_GPG_SIGNING_KEY || secrets.GPG_SIGNING_KEY }} GPG_SIGNING_PASSWORD: ${{ secrets.ONEBUSAWAY_SDK_SONATYPE_GPG_SIGNING_PASSWORD || secrets.GPG_SIGNING_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml index f328321..fac0542 100644 --- a/.github/workflows/release-doctor.yml +++ b/.github/workflows/release-doctor.yml @@ -20,6 +20,5 @@ jobs: env: SONATYPE_USERNAME: ${{ secrets.ONEBUSAWAY_SDK_SONATYPE_USERNAME || secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.ONEBUSAWAY_SDK_SONATYPE_PASSWORD || secrets.SONATYPE_PASSWORD }} - GPG_SIGNING_KEY_ID: ${{ secrets.ONEBUSAWAY_SDK_SONATYPE_GPG_SIGNING_KEY_ID || secrets.GPG_SIGNING_KEY_ID }} GPG_SIGNING_KEY: ${{ secrets.ONEBUSAWAY_SDK_SONATYPE_GPG_SIGNING_KEY || secrets.GPG_SIGNING_KEY }} GPG_SIGNING_PASSWORD: ${{ secrets.ONEBUSAWAY_SDK_SONATYPE_GPG_SIGNING_PASSWORD || secrets.GPG_SIGNING_PASSWORD }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 1c0bb88..380b6f9 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.23" + ".": "0.1.0-alpha.24" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index d4b713b..3928277 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 29 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/open-transit%2Fopen-transit-6f08502508c8ad25235971add3124a1cde4f1c3ec705d5df455d750e0adcb90b.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/open-transit%2Fopen-transit-4fcbe9547537b22a2d68329e1d94e0c1a6f81b5af734ca213f7b95eef5da7adb.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 6abeafe..50ee9fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,25 @@ # Changelog +## 0.1.0-alpha.24 (2025-05-21) + +Full Changelog: [v0.1.0-alpha.23...v0.1.0-alpha.24](https://github.com/OneBusAway/java-sdk/compare/v0.1.0-alpha.23...v0.1.0-alpha.24) + +### Features + +* **api:** api update ([a9266bd](https://github.com/OneBusAway/java-sdk/commit/a9266bd3053952157431e4aee9b36aae6b637164)) +* **api:** manual updates ([#74](https://github.com/OneBusAway/java-sdk/issues/74)) ([ddda17b](https://github.com/OneBusAway/java-sdk/commit/ddda17b7186ef701720740c946250b5fa902a4cc)) + + +### Chores + +* **internal:** codegen related update ([#71](https://github.com/OneBusAway/java-sdk/issues/71)) ([c5e90c0](https://github.com/OneBusAway/java-sdk/commit/c5e90c0cda29a9131fd81e60d22711794a2f0a71)) +* **internal:** codegen related update ([#73](https://github.com/OneBusAway/java-sdk/issues/73)) ([a45c6b0](https://github.com/OneBusAway/java-sdk/commit/a45c6b0bc2f45328c1365db12b9ed2fca0d85ce6)) +* **internal:** codegen related update ([#75](https://github.com/OneBusAway/java-sdk/issues/75)) ([a433a99](https://github.com/OneBusAway/java-sdk/commit/a433a99937fdc1729f36a4e7d16a8d90137758e8)) +* **internal:** codegen related update ([#76](https://github.com/OneBusAway/java-sdk/issues/76)) ([a8f595e](https://github.com/OneBusAway/java-sdk/commit/a8f595e2ee1038f8161ab784fd189d074f375d07)) +* **internal:** codegen related update ([#77](https://github.com/OneBusAway/java-sdk/issues/77)) ([14ea7b7](https://github.com/OneBusAway/java-sdk/commit/14ea7b7438268138410dca70f28807ec06f5c5b0)) +* **internal:** codegen related update ([#78](https://github.com/OneBusAway/java-sdk/issues/78)) ([51a4c8c](https://github.com/OneBusAway/java-sdk/commit/51a4c8cab3782706a773525083c4b17da4543064)) +* **internal:** update example values ([#72](https://github.com/OneBusAway/java-sdk/issues/72)) ([9f7aadf](https://github.com/OneBusAway/java-sdk/commit/9f7aadf0b9229f441f1dbfed4b64035f195c3b1e)) + ## 0.1.0-alpha.23 (2024-11-29) Full Changelog: [v0.1.0-alpha.22...v0.1.0-alpha.23](https://github.com/OneBusAway/java-sdk/compare/v0.1.0-alpha.22...v0.1.0-alpha.23) diff --git a/LICENSE b/LICENSE index 9e6f6ec..443d70c 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2024 Onebusaway SDK + Copyright 2025 Onebusaway SDK Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 7dd1dc3..f771e77 100644 --- a/README.md +++ b/README.md @@ -2,46 +2,46 @@ -[![Maven Central](https://img.shields.io/maven-central/v/org.onebusaway/onebusaway-sdk-java)](https://central.sonatype.com/artifact/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.23) +[![Maven Central](https://img.shields.io/maven-central/v/org.onebusaway/onebusaway-sdk-java)](https://central.sonatype.com/artifact/org.onebusaway/onebusaway-sdk-java/0.1.0-alpha.24) -The Onebusaway SDK Java SDK provides convenient access to the Onebusaway SDK REST API from applications written in Java. It includes helper classes with helpful types and documentation for every request and response property. +The Onebusaway SDK Java SDK provides convenient access to the Onebusaway SDK REST API from applications written in Java. The Onebusaway SDK Java SDK is similar to the Onebusaway SDK Kotlin SDK but with minor differences that make it more ergonomic for use in Java, such as `Optional` instead of nullable values, `Stream` instead of `Sequence`, and `CompletableFuture` instead of suspend functions. It is generated with [Stainless](https://www.stainlessapi.com/). -## Documentation +The REST API documentation can be found on [developer.onebusaway.org](https://developer.onebusaway.org). -The REST API documentation can be found on [developer.onebusaway.org](https://developer.onebusaway.org). - ---- - -## Getting started - -### Install dependencies - -#### Gradle +## Installation +### Gradle + ```kotlin -implementation("org.onebusaway:onebusaway-sdk-java:0.1.0-alpha.23") +implementation("org.onebusaway:onebusaway-sdk-java:0.1.0-alpha.24") ``` -#### Maven +### Maven ```xml org.onebusaway onebusaway-sdk-java - 0.1.0-alpha.23 + 0.1.0-alpha.24 ``` +## Requirements + +This library requires Java 8 or later. + +## Usage + ### Configure the client Use `OnebusawaySdkOkHttpClient.builder()` to configure the client. At a minimum you need to set `.apiKey()`: @@ -58,6 +58,9 @@ OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() Alternately, set the environment with `ONEBUSAWAY_API_KEY`, and use `OnebusawaySdkOkHttpClient.fromEnv()` to read from the environment. ```java +import org.onebusaway.client.OnebusawaySdkClient; +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient; + OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.fromEnv(); // Note: you can also call fromEnv() from the client builder, for example if you need to set additional properties @@ -77,8 +80,7 @@ Read the documentation for more configuration options. ### Example: creating a resource -To create a new current time, first use the `CurrentTimeRetrieveParams` builder to specify attributes, -then pass that to the `retrieve` method of the `currentTime` service. +To create a new current time, first use the `CurrentTimeRetrieveParams` builder to specify attributes, then pass that to the `retrieve` method of the `currentTime` service. ```java import org.onebusaway.models.CurrentTimeRetrieveParams; @@ -96,19 +98,7 @@ CurrentTimeRetrieveResponse currentTime = client.currentTime().retrieve(params); To make a request to the Onebusaway SDK API, you generally build an instance of the appropriate `Params` class. -In [Example: creating a resource](#example-creating-a-resource) above, we used the `CurrentTimeRetrieveParams.builder()` to pass to -the `retrieve` method of the `currentTime` service. - -Sometimes, the API may support other properties that are not yet supported in the Java SDK types. In that case, -you can attach them using the `putAdditionalProperty` method. - -```java -import org.onebusaway.models.core.JsonValue; -CurrentTimeRetrieveParams params = CurrentTimeRetrieveParams.builder() - // ... normal properties - .putAdditionalProperty("secret_param", JsonValue.from("4242")) - .build(); -``` +See [Undocumented request params](#undocumented-request-params) for how to send arbitrary parameters. ## Responses @@ -117,15 +107,19 @@ CurrentTimeRetrieveParams params = CurrentTimeRetrieveParams.builder() When receiving a response, the Onebusaway SDK Java SDK will deserialize it into instances of the typed model classes. In rare cases, the API may return a response property that doesn't match the expected Java type. If you directly access the mistaken property, the SDK will throw an unchecked `OnebusawaySdkInvalidDataException` at runtime. If you would prefer to check in advance that that response is completely well-typed, call `.validate()` on the returned model. ```java +import org.onebusaway.models.CurrentTimeRetrieveResponse; + CurrentTimeRetrieveResponse currentTime = client.currentTime().retrieve().validate(); ``` ### Response properties as JSON -In rare cases, you may want to access the underlying JSON value for a response property rather than using the typed version provided by -this SDK. Each model property has a corresponding JSON version, with an underscore before the method name, which returns a `JsonField` value. +In rare cases, you may want to access the underlying JSON value for a response property rather than using the typed version provided by this SDK. Each model property has a corresponding JSON version, with an underscore before the method name, which returns a `JsonField` value. ```java +import java.util.Optional; +import org.onebusaway.core.JsonField; + JsonField field = responseObj._field(); if (field.isMissing()) { @@ -147,6 +141,8 @@ if (field.isMissing()) { Sometimes, the server response may include additional properties that are not yet available in this library's types. You can access them using the model's `_additionalProperties` method: ```java +import org.onebusaway.core.JsonValue; + JsonValue secret = references._additionalProperties().get("secret_field"); ``` @@ -160,31 +156,33 @@ This library throws exceptions in a single hierarchy for easy handling: - **`OnebusawaySdkException`** - Base exception for all exceptions - - **`OnebusawaySdkServiceException`** - HTTP errors with a well-formed response body we were able to parse. The exception message and the `.debuggingRequestId()` will be set by the server. +- **`OnebusawaySdkServiceException`** - HTTP errors with a well-formed response body we were able to parse. The exception message and the `.debuggingRequestId()` will be set by the server. - | 400 | BadRequestException | - | ------ | ----------------------------- | - | 401 | AuthenticationException | - | 403 | PermissionDeniedException | - | 404 | NotFoundException | - | 422 | UnprocessableEntityException | - | 429 | RateLimitException | - | 5xx | InternalServerException | - | others | UnexpectedStatusCodeException | + | 400 | BadRequestException | + | ------ | ----------------------------- | + | 401 | AuthenticationException | + | 403 | PermissionDeniedException | + | 404 | NotFoundException | + | 422 | UnprocessableEntityException | + | 429 | RateLimitException | + | 5xx | InternalServerException | + | others | UnexpectedStatusCodeException | - - **`OnebusawaySdkIoException`** - I/O networking errors - - **`OnebusawaySdkInvalidDataException`** - any other exceptions on the client side, e.g.: - - We failed to serialize the request body - - We failed to parse the response body (has access to response code and body) +- **`OnebusawaySdkIoException`** - I/O networking errors +- **`OnebusawaySdkInvalidDataException`** - any other exceptions on the client side, e.g.: + - We failed to serialize the request body + - We failed to parse the response body (has access to response code and body) ## Network options ### Retries -Requests that experience certain errors are automatically retried 2 times by default, with a short exponential backoff. Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors will all be retried by default. -You can provide a `maxRetries` on the client builder to configure this: +Requests that experience certain errors are automatically retried 2 times by default, with a short exponential backoff. Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors will all be retried by default. You can provide a `maxRetries` on the client builder to configure this: ```java +import org.onebusaway.client.OnebusawaySdkClient; +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient; + OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() .fromEnv() .maxRetries(4) @@ -196,6 +194,10 @@ OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() Requests time out after 1 minute by default. You can configure this on the client builder: ```java +import java.time.Duration; +import org.onebusaway.client.OnebusawaySdkClient; +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient; + OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() .fromEnv() .timeout(Duration.ofSeconds(30)) @@ -207,50 +209,67 @@ OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() Requests can be routed through a proxy. You can configure this on the client builder: ```java +import java.net.InetSocketAddress; +import java.net.Proxy; +import org.onebusaway.client.OnebusawaySdkClient; +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient; + OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() .fromEnv() - .proxy(new Proxy( - Type.HTTP, - new InetSocketAddress("proxy.com", 8080) - )) + .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("example.com", 8080))) .build(); ``` ## Making custom/undocumented requests -This library is typed for convenient access to the documented API. If you need to access undocumented -params or response properties, the library can still be used. +This library is typed for convenient access to the documented API. If you need to access undocumented params or response properties, the library can still be used. ### Undocumented request params -To make requests using undocumented parameters, you can provide or override parameters on the params object -while building it. +In [Example: creating a resource](#example-creating-a-resource) above, we used the `CurrentTimeRetrieveParams.builder()` to pass to the `retrieve` method of the `currentTime` service. -```kotlin -FooCreateParams address = FooCreateParams.builder() - .id("my_id") - .putAdditionalProperty("secret_prop", JsonValue.from("hello")) +Sometimes, the API may support other properties that are not yet supported in the Java SDK types. In that case, you can attach them using raw setters: + +```java +import org.onebusaway.core.JsonValue; +import org.onebusaway.models.CurrentTimeRetrieveParams; + +CurrentTimeRetrieveParams params = CurrentTimeRetrieveParams.builder() + .putAdditionalHeader("Secret-Header", "42") + .putAdditionalQueryParam("secret_query_param", "42") + .putAdditionalBodyProperty("secretProperty", JsonValue.from("42")) .build(); ``` +You can also use the `putAdditionalProperty` method on nested headers, query params, or body objects. + ### Undocumented response properties -To access undocumented response properties, you can use `res._additionalProperties()` on a response object to -get a map of untyped fields of type `Map`. You can then access fields like -`._additionalProperties().get("secret_prop").asString()` or use other helpers defined on the `JsonValue` class -to extract it to a desired type. +To access undocumented response properties, you can use `res._additionalProperties()` on a response object to get a map of untyped fields of type `Map`. You can then access fields like `res._additionalProperties().get("secret_prop").asString()` or use other helpers defined on the `JsonValue` class to extract it to a desired type. + +## Logging + +We use the standard [OkHttp logging interceptor](https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor). + +You can enable logging by setting the environment variable `ONEBUSAWAY_SDK_LOG` to `info`. + +```sh +$ export ONEBUSAWAY_SDK_LOG=info +``` + +Or to `debug` for more verbose logging. + +```sh +$ export ONEBUSAWAY_SDK_LOG=debug +``` ## Semantic versioning This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions: -1. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_. +1. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_ 2. Changes that we do not expect to impact the vast majority of users in practice. We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience. We are keen for your feedback; please open an [issue](https://www.github.com/OneBusAway/java-sdk/issues) with questions, bugs, or suggestions. - -## Requirements - -This library requires Java 8 or later. diff --git a/build.gradle.kts b/build.gradle.kts index 8c8ea48..cc7e656 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,4 @@ -plugins { - -} - allprojects { group = "org.onebusaway" - version = "0.1.0-alpha.23" // x-release-please-version + version = "0.1.0-alpha.24" // x-release-please-version } - - diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 493cb32..8a1d7a1 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,6 +1,6 @@ plugins { `kotlin-dsl` - kotlin("jvm") version "1.9.22" + kotlin("jvm") version "2.1.0" id("com.vanniktech.maven.publish") version "0.28.0" } diff --git a/buildSrc/src/main/kotlin/onebusaway-sdk.java.gradle.kts b/buildSrc/src/main/kotlin/onebusaway-sdk.java.gradle.kts index 32a150e..a2c35b9 100644 --- a/buildSrc/src/main/kotlin/onebusaway-sdk.java.gradle.kts +++ b/buildSrc/src/main/kotlin/onebusaway-sdk.java.gradle.kts @@ -1,9 +1,5 @@ import com.diffplug.gradle.spotless.SpotlessExtension import org.gradle.api.tasks.testing.logging.TestExceptionFormat -import com.vanniktech.maven.publish.JavaLibrary -import com.vanniktech.maven.publish.JavadocJar -import com.vanniktech.maven.publish.MavenPublishBaseExtension -import com.vanniktech.maven.publish.SonatypeHost plugins { `java-library` diff --git a/buildSrc/src/main/kotlin/onebusaway-sdk.kotlin.gradle.kts b/buildSrc/src/main/kotlin/onebusaway-sdk.kotlin.gradle.kts index 6da1ac7..5eecc1c 100644 --- a/buildSrc/src/main/kotlin/onebusaway-sdk.kotlin.gradle.kts +++ b/buildSrc/src/main/kotlin/onebusaway-sdk.kotlin.gradle.kts @@ -1,6 +1,5 @@ import com.diffplug.gradle.spotless.SpotlessExtension import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import com.vanniktech.maven.publish.* plugins { id("onebusaway-sdk.java") @@ -22,8 +21,12 @@ configure { tasks.withType().configureEach { kotlinOptions { - allWarningsAsErrors = true - freeCompilerArgs = listOf("-Xjvm-default=all", "-Xjdk-release=1.8") + freeCompilerArgs = listOf( + "-Xjvm-default=all", + "-Xjdk-release=1.8", + // Suppress deprecation warnings because we may still reference and test deprecated members. + "-Xsuppress-warning=DEPRECATION" + ) jvmTarget = "1.8" } } diff --git a/buildSrc/src/main/kotlin/onebusaway-sdk.publish.gradle.kts b/buildSrc/src/main/kotlin/onebusaway-sdk.publish.gradle.kts index 4c6d7fa..457c5c2 100644 --- a/buildSrc/src/main/kotlin/onebusaway-sdk.publish.gradle.kts +++ b/buildSrc/src/main/kotlin/onebusaway-sdk.publish.gradle.kts @@ -1,10 +1,3 @@ -import org.gradle.api.publish.PublishingExtension -import org.gradle.api.publish.maven.MavenPublication -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.register -import org.gradle.kotlin.dsl.get -import com.vanniktech.maven.publish.JavaLibrary -import com.vanniktech.maven.publish.JavadocJar import com.vanniktech.maven.publish.MavenPublishBaseExtension import com.vanniktech.maven.publish.SonatypeHost @@ -25,7 +18,7 @@ configure { signAllPublications() publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) - this.coordinates(project.group.toString(), project.name, project.version.toString()) + coordinates(project.group.toString(), project.name, project.version.toString()) pom { name.set("OneBusAway") diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e644113..a4b76b9 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 b82aa23..cea7a79 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 1aa94a4..f3b75f3 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -84,7 +86,7 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum diff --git a/gradlew.bat b/gradlew.bat index 25da30d..9d21a21 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## diff --git a/onebusaway-sdk-java-client-okhttp/build.gradle.kts b/onebusaway-sdk-java-client-okhttp/build.gradle.kts index 037ef81..2fd0abf 100644 --- a/onebusaway-sdk-java-client-okhttp/build.gradle.kts +++ b/onebusaway-sdk-java-client-okhttp/build.gradle.kts @@ -6,10 +6,9 @@ plugins { dependencies { api(project(":onebusaway-sdk-java-core")) - implementation("com.google.guava:guava:33.0.0-jre") implementation("com.squareup.okhttp3:okhttp:4.12.0") + implementation("com.squareup.okhttp3:logging-interceptor:4.12.0") testImplementation(kotlin("test")) testImplementation("org.assertj:assertj-core:3.25.3") - testImplementation("org.slf4j:slf4j-simple:2.0.12") } diff --git a/onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OkHttpClient.kt b/onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OkHttpClient.kt index 427df17..16d85ce 100644 --- a/onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OkHttpClient.kt +++ b/onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OkHttpClient.kt @@ -1,7 +1,5 @@ package org.onebusaway.client.okhttp -import com.google.common.collect.ListMultimap -import com.google.common.collect.MultimapBuilder import java.io.IOException import java.io.InputStream import java.net.Proxy @@ -9,17 +7,20 @@ import java.time.Duration import java.util.concurrent.CompletableFuture import okhttp3.Call import okhttp3.Callback -import okhttp3.Headers import okhttp3.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl +import okhttp3.Interceptor import okhttp3.MediaType import okhttp3.MediaType.Companion.toMediaType import okhttp3.Request import okhttp3.RequestBody import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response +import okhttp3.logging.HttpLoggingInterceptor import okio.BufferedSink import org.onebusaway.core.RequestOptions +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers import org.onebusaway.core.http.HttpClient import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest @@ -31,22 +32,11 @@ class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val baseUrl: HttpUrl) : HttpClient { - private fun getClient(requestOptions: RequestOptions): okhttp3.OkHttpClient { - val timeout = requestOptions.timeout ?: return okHttpClient - return okHttpClient - .newBuilder() - .connectTimeout(timeout) - .readTimeout(timeout) - .writeTimeout(timeout) - .callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30)) - .build() - } - override fun execute( request: HttpRequest, requestOptions: RequestOptions, ): HttpResponse { - val call = getClient(requestOptions).newCall(request.toRequest()) + val call = newCall(request, requestOptions) return try { call.execute().toResponse() @@ -65,18 +55,18 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val request.body?.run { future.whenComplete { _, _ -> close() } } - val call = getClient(requestOptions).newCall(request.toRequest()) - call.enqueue( - object : Callback { - override fun onResponse(call: Call, response: Response) { - future.complete(response.toResponse()) - } + newCall(request, requestOptions) + .enqueue( + object : Callback { + override fun onResponse(call: Call, response: Response) { + future.complete(response.toResponse()) + } - override fun onFailure(call: Call, e: IOException) { - future.completeExceptionally(OnebusawaySdkIoException("Request failed", e)) + override fun onFailure(call: Call, e: IOException) { + future.completeExceptionally(OnebusawaySdkIoException("Request failed", e)) + } } - } - ) + ) return future } @@ -87,19 +77,73 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val okHttpClient.cache?.close() } - private fun HttpRequest.toRequest(): Request { + private fun newCall(request: HttpRequest, requestOptions: RequestOptions): Call { + val clientBuilder = okHttpClient.newBuilder() + + // Custom logging interceptor for URL logging + clientBuilder.addNetworkInterceptor(LoggingInterceptor()) + + val logLevel = + when (System.getenv("ONEBUSAWAY_SDK_LOG")?.lowercase()) { + "info" -> HttpLoggingInterceptor.Level.BASIC + "debug" -> HttpLoggingInterceptor.Level.BODY + else -> null + } + if (logLevel != null) { + clientBuilder.addNetworkInterceptor(HttpLoggingInterceptor().setLevel(logLevel)) + } + + val timeout = requestOptions.timeout + if (timeout != null) { + clientBuilder + .connectTimeout(timeout) + .readTimeout(timeout) + .writeTimeout(timeout) + .callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30)) + } + + val client = clientBuilder.build() + return client.newCall(request.toRequest(client)) + } + + private fun HttpRequest.toRequest(client: okhttp3.OkHttpClient): Request { var body: RequestBody? = body?.toRequestBody() - // OkHttpClient always requires a request body for PUT and POST methods. - if (body == null && (method == HttpMethod.PUT || method == HttpMethod.POST)) { + if (body == null && requiresBody(method)) { body = "".toRequestBody() } val builder = Request.Builder().url(toUrl()).method(method.name, body) - headers.forEach(builder::header) + headers.names().forEach { name -> + headers.values(name).forEach { builder.header(name, it) } + } + + if ( + !headers.names().contains("X-Stainless-Read-Timeout") && client.readTimeoutMillis != 0 + ) { + builder.header( + "X-Stainless-Read-Timeout", + Duration.ofMillis(client.readTimeoutMillis.toLong()).seconds.toString() + ) + } + if (!headers.names().contains("X-Stainless-Timeout") && client.callTimeoutMillis != 0) { + builder.header( + "X-Stainless-Timeout", + Duration.ofMillis(client.callTimeoutMillis.toLong()).seconds.toString() + ) + } return builder.build() } + /** `OkHttpClient` always requires a request body for some methods. */ + private fun requiresBody(method: HttpMethod): Boolean = + when (method) { + HttpMethod.POST, + HttpMethod.PUT, + HttpMethod.PATCH -> true + else -> false + } + private fun HttpRequest.toUrl(): String { url?.let { return it @@ -107,7 +151,9 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val val builder = baseUrl.newBuilder() pathSegments.forEach(builder::addPathSegment) - queryParams.forEach(builder::addQueryParameter) + queryParams.keys().forEach { key -> + queryParams.values(key).forEach { builder.addQueryParameter(key, it) } + } return builder.toString() } @@ -133,7 +179,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val return object : HttpResponse { override fun statusCode(): Int = code - override fun headers(): ListMultimap = headers + override fun headers(): Headers = headers override fun body(): InputStream = body!!.byteStream() @@ -141,20 +187,17 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val } } - private fun Headers.toHeaders(): ListMultimap { - val headers = - MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER) - .arrayListValues() - .build() - forEach { pair -> headers.put(pair.first, pair.second) } - return headers + private fun okhttp3.Headers.toHeaders(): Headers { + val headersBuilder = Headers.builder() + forEach { (name, value) -> headersBuilder.put(name, value) } + return headersBuilder.build() } companion object { @JvmStatic fun builder() = Builder() } - class Builder { + class Builder internal constructor() { private var baseUrl: HttpUrl? = null // The default timeout is 1 minute. @@ -176,7 +219,18 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val .callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30)) .proxy(proxy) .build(), - checkNotNull(baseUrl) { "`baseUrl` is required but was not set" }, + checkRequired("baseUrl", baseUrl), ) } } + +// --- ✅ New class added below --- +class LoggingInterceptor : Interceptor { + override fun intercept(chain: Interceptor.Chain): Response { + val request = chain.request() + println("➡️ Sending request: ${request.method} ${request.url}") + val response = chain.proceed(request) + println("⬅️ Received response: ${response.code} ${response.request.url}") + return response + } +} diff --git a/onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OnebusawaySdkOkHttpClient.kt b/onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OnebusawaySdkOkHttpClient.kt index 4c71daa..807aa13 100644 --- a/onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OnebusawaySdkOkHttpClient.kt +++ b/onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OnebusawaySdkOkHttpClient.kt @@ -9,6 +9,8 @@ import java.time.Duration import org.onebusaway.client.OnebusawaySdkClient import org.onebusaway.client.OnebusawaySdkClientImpl import org.onebusaway.core.ClientOptions +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams class OnebusawaySdkOkHttpClient private constructor() { @@ -19,7 +21,8 @@ class OnebusawaySdkOkHttpClient private constructor() { @JvmStatic fun fromEnv(): OnebusawaySdkClient = builder().fromEnv().build() } - class Builder { + /** A builder for [OnebusawaySdkOkHttpClient]. */ + class Builder internal constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() private var baseUrl: String = ClientOptions.PRODUCTION_URL @@ -36,6 +39,8 @@ class OnebusawaySdkOkHttpClient private constructor() { fun clock(clock: Clock) = apply { clientOptions.clock(clock) } + fun headers(headers: Headers) = apply { clientOptions.headers(headers) } + fun headers(headers: Map>) = apply { clientOptions.headers(headers) } @@ -46,6 +51,8 @@ class OnebusawaySdkOkHttpClient private constructor() { clientOptions.putHeaders(name, values) } + fun putAllHeaders(headers: Headers) = apply { clientOptions.putAllHeaders(headers) } + fun putAllHeaders(headers: Map>) = apply { clientOptions.putAllHeaders(headers) } @@ -58,6 +65,8 @@ class OnebusawaySdkOkHttpClient private constructor() { clientOptions.replaceHeaders(name, values) } + fun replaceAllHeaders(headers: Headers) = apply { clientOptions.replaceAllHeaders(headers) } + fun replaceAllHeaders(headers: Map>) = apply { clientOptions.replaceAllHeaders(headers) } @@ -66,6 +75,8 @@ class OnebusawaySdkOkHttpClient private constructor() { fun removeAllHeaders(names: Set) = apply { clientOptions.removeAllHeaders(names) } + fun queryParams(queryParams: QueryParams) = apply { clientOptions.queryParams(queryParams) } + fun queryParams(queryParams: Map>) = apply { clientOptions.queryParams(queryParams) } @@ -78,6 +89,10 @@ class OnebusawaySdkOkHttpClient private constructor() { clientOptions.putQueryParams(key, values) } + fun putAllQueryParams(queryParams: QueryParams) = apply { + clientOptions.putAllQueryParams(queryParams) + } + fun putAllQueryParams(queryParams: Map>) = apply { clientOptions.putAllQueryParams(queryParams) } @@ -90,6 +105,10 @@ class OnebusawaySdkOkHttpClient private constructor() { clientOptions.replaceQueryParams(key, values) } + fun replaceAllQueryParams(queryParams: QueryParams) = apply { + clientOptions.replaceAllQueryParams(queryParams) + } + fun replaceAllQueryParams(queryParams: Map>) = apply { clientOptions.replaceAllQueryParams(queryParams) } diff --git a/onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OnebusawaySdkOkHttpClientAsync.kt b/onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OnebusawaySdkOkHttpClientAsync.kt index 00ea3d2..6611264 100644 --- a/onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OnebusawaySdkOkHttpClientAsync.kt +++ b/onebusaway-sdk-java-client-okhttp/src/main/kotlin/org/onebusaway/client/okhttp/OnebusawaySdkOkHttpClientAsync.kt @@ -9,6 +9,8 @@ import java.time.Duration import org.onebusaway.client.OnebusawaySdkClientAsync import org.onebusaway.client.OnebusawaySdkClientAsyncImpl import org.onebusaway.core.ClientOptions +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams class OnebusawaySdkOkHttpClientAsync private constructor() { @@ -19,7 +21,8 @@ class OnebusawaySdkOkHttpClientAsync private constructor() { @JvmStatic fun fromEnv(): OnebusawaySdkClientAsync = builder().fromEnv().build() } - class Builder { + /** A builder for [OnebusawaySdkOkHttpClientAsync]. */ + class Builder internal constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() private var baseUrl: String = ClientOptions.PRODUCTION_URL @@ -36,6 +39,8 @@ class OnebusawaySdkOkHttpClientAsync private constructor() { fun clock(clock: Clock) = apply { clientOptions.clock(clock) } + fun headers(headers: Headers) = apply { clientOptions.headers(headers) } + fun headers(headers: Map>) = apply { clientOptions.headers(headers) } @@ -46,6 +51,8 @@ class OnebusawaySdkOkHttpClientAsync private constructor() { clientOptions.putHeaders(name, values) } + fun putAllHeaders(headers: Headers) = apply { clientOptions.putAllHeaders(headers) } + fun putAllHeaders(headers: Map>) = apply { clientOptions.putAllHeaders(headers) } @@ -58,6 +65,8 @@ class OnebusawaySdkOkHttpClientAsync private constructor() { clientOptions.replaceHeaders(name, values) } + fun replaceAllHeaders(headers: Headers) = apply { clientOptions.replaceAllHeaders(headers) } + fun replaceAllHeaders(headers: Map>) = apply { clientOptions.replaceAllHeaders(headers) } @@ -66,6 +75,8 @@ class OnebusawaySdkOkHttpClientAsync private constructor() { fun removeAllHeaders(names: Set) = apply { clientOptions.removeAllHeaders(names) } + fun queryParams(queryParams: QueryParams) = apply { clientOptions.queryParams(queryParams) } + fun queryParams(queryParams: Map>) = apply { clientOptions.queryParams(queryParams) } @@ -78,6 +89,10 @@ class OnebusawaySdkOkHttpClientAsync private constructor() { clientOptions.putQueryParams(key, values) } + fun putAllQueryParams(queryParams: QueryParams) = apply { + clientOptions.putAllQueryParams(queryParams) + } + fun putAllQueryParams(queryParams: Map>) = apply { clientOptions.putAllQueryParams(queryParams) } @@ -90,6 +105,10 @@ class OnebusawaySdkOkHttpClientAsync private constructor() { clientOptions.replaceQueryParams(key, values) } + fun replaceAllQueryParams(queryParams: QueryParams) = apply { + clientOptions.replaceAllQueryParams(queryParams) + } + fun replaceAllQueryParams(queryParams: Map>) = apply { clientOptions.replaceAllQueryParams(queryParams) } diff --git a/onebusaway-sdk-java-core/build.gradle.kts b/onebusaway-sdk-java-core/build.gradle.kts index 8f52193..6a0859b 100644 --- a/onebusaway-sdk-java-core/build.gradle.kts +++ b/onebusaway-sdk-java-core/build.gradle.kts @@ -4,14 +4,13 @@ plugins { } dependencies { - api("com.fasterxml.jackson.core:jackson-core:2.14.3") - api("com.fasterxml.jackson.core:jackson-databind:2.14.3") - api("com.google.guava:guava:33.0.0-jre") + api("com.fasterxml.jackson.core:jackson-core:2.18.1") + api("com.fasterxml.jackson.core:jackson-databind:2.18.1") - implementation("com.fasterxml.jackson.core:jackson-annotations:2.14.3") - implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.14.3") - implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.3") - implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.3") + implementation("com.fasterxml.jackson.core:jackson-annotations:2.18.1") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.1") + implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.1") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.1") implementation("org.apache.httpcomponents.core5:httpcore5:5.2.4") implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1") @@ -19,8 +18,9 @@ dependencies { testImplementation(project(":onebusaway-sdk-java-client-okhttp")) testImplementation("com.github.tomakehurst:wiremock-jre8:2.35.2") testImplementation("org.assertj:assertj-core:3.25.3") - testImplementation("org.assertj:assertj-guava:3.25.3") - testImplementation("org.slf4j:slf4j-simple:2.0.12") testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3") testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.3") + testImplementation("org.mockito:mockito-core:5.14.2") + testImplementation("org.mockito:mockito-junit-jupiter:5.14.2") + testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0") } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClient.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClient.kt index 44afaea..b09d68b 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClient.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClient.kt @@ -2,11 +2,57 @@ package org.onebusaway.client -import org.onebusaway.models.* -import org.onebusaway.services.blocking.* - +import org.onebusaway.services.blocking.AgenciesWithCoverageService +import org.onebusaway.services.blocking.AgencyService +import org.onebusaway.services.blocking.ArrivalAndDepartureService +import org.onebusaway.services.blocking.BlockService +import org.onebusaway.services.blocking.ConfigService +import org.onebusaway.services.blocking.CurrentTimeService +import org.onebusaway.services.blocking.ReportProblemWithStopService +import org.onebusaway.services.blocking.ReportProblemWithTripService +import org.onebusaway.services.blocking.RouteIdsForAgencyService +import org.onebusaway.services.blocking.RouteService +import org.onebusaway.services.blocking.RoutesForAgencyService +import org.onebusaway.services.blocking.RoutesForLocationService +import org.onebusaway.services.blocking.ScheduleForRouteService +import org.onebusaway.services.blocking.ScheduleForStopService +import org.onebusaway.services.blocking.SearchForRouteService +import org.onebusaway.services.blocking.SearchForStopService +import org.onebusaway.services.blocking.ShapeService +import org.onebusaway.services.blocking.StopIdsForAgencyService +import org.onebusaway.services.blocking.StopService +import org.onebusaway.services.blocking.StopsForAgencyService +import org.onebusaway.services.blocking.StopsForLocationService +import org.onebusaway.services.blocking.StopsForRouteService +import org.onebusaway.services.blocking.TripDetailService +import org.onebusaway.services.blocking.TripForVehicleService +import org.onebusaway.services.blocking.TripService +import org.onebusaway.services.blocking.TripsForLocationService +import org.onebusaway.services.blocking.TripsForRouteService +import org.onebusaway.services.blocking.VehiclesForAgencyService + +/** + * A client for interacting with the Onebusaway SDK REST API synchronously. You can also switch to + * asynchronous execution via the [async] method. + * + * This client performs best when you create a single instance and reuse it for all interactions + * with the REST API. This is because each client holds its own connection pool and thread pools. + * Reusing connections and threads reduces latency and saves memory. The client also handles rate + * limiting per client. This means that creating and using multiple instances at the same time will + * not respect rate limits. + * + * The threads and connections that are held will be released automatically if they remain idle. But + * if you are writing an application that needs to aggressively release unused resources, then you + * may call [close]. + */ interface OnebusawaySdkClient { + /** + * Returns a version of this client that uses asynchronous execution. + * + * The returned client shares its resources, like its connection pool and thread pools, with + * this client. + */ fun async(): OnebusawaySdkClientAsync fun agenciesWithCoverage(): AgenciesWithCoverageService @@ -64,4 +110,17 @@ interface OnebusawaySdkClient { fun block(): BlockService fun shape(): ShapeService + + /** + * Closes this client, relinquishing any underlying resources. + * + * This is purposefully not inherited from [AutoCloseable] because the client is long-lived and + * usually should not be synchronously closed via try-with-resources. + * + * It's also usually not necessary to call this method at all. the default HTTP client + * automatically releases threads and connections if they remain idle, but if you are writing an + * application that needs to aggressively release unused resources, then you may call this + * method. + */ + fun close() } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientAsync.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientAsync.kt index 0029e0f..aee0c2e 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientAsync.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientAsync.kt @@ -2,11 +2,57 @@ package org.onebusaway.client -import org.onebusaway.models.* -import org.onebusaway.services.async.* - +import org.onebusaway.services.async.AgenciesWithCoverageServiceAsync +import org.onebusaway.services.async.AgencyServiceAsync +import org.onebusaway.services.async.ArrivalAndDepartureServiceAsync +import org.onebusaway.services.async.BlockServiceAsync +import org.onebusaway.services.async.ConfigServiceAsync +import org.onebusaway.services.async.CurrentTimeServiceAsync +import org.onebusaway.services.async.ReportProblemWithStopServiceAsync +import org.onebusaway.services.async.ReportProblemWithTripServiceAsync +import org.onebusaway.services.async.RouteIdsForAgencyServiceAsync +import org.onebusaway.services.async.RouteServiceAsync +import org.onebusaway.services.async.RoutesForAgencyServiceAsync +import org.onebusaway.services.async.RoutesForLocationServiceAsync +import org.onebusaway.services.async.ScheduleForRouteServiceAsync +import org.onebusaway.services.async.ScheduleForStopServiceAsync +import org.onebusaway.services.async.SearchForRouteServiceAsync +import org.onebusaway.services.async.SearchForStopServiceAsync +import org.onebusaway.services.async.ShapeServiceAsync +import org.onebusaway.services.async.StopIdsForAgencyServiceAsync +import org.onebusaway.services.async.StopServiceAsync +import org.onebusaway.services.async.StopsForAgencyServiceAsync +import org.onebusaway.services.async.StopsForLocationServiceAsync +import org.onebusaway.services.async.StopsForRouteServiceAsync +import org.onebusaway.services.async.TripDetailServiceAsync +import org.onebusaway.services.async.TripForVehicleServiceAsync +import org.onebusaway.services.async.TripServiceAsync +import org.onebusaway.services.async.TripsForLocationServiceAsync +import org.onebusaway.services.async.TripsForRouteServiceAsync +import org.onebusaway.services.async.VehiclesForAgencyServiceAsync + +/** + * A client for interacting with the Onebusaway SDK REST API asynchronously. You can also switch to + * synchronous execution via the [sync] method. + * + * This client performs best when you create a single instance and reuse it for all interactions + * with the REST API. This is because each client holds its own connection pool and thread pools. + * Reusing connections and threads reduces latency and saves memory. The client also handles rate + * limiting per client. This means that creating and using multiple instances at the same time will + * not respect rate limits. + * + * The threads and connections that are held will be released automatically if they remain idle. But + * if you are writing an application that needs to aggressively release unused resources, then you + * may call [close]. + */ interface OnebusawaySdkClientAsync { + /** + * Returns a version of this client that uses synchronous execution. + * + * The returned client shares its resources, like its connection pool and thread pools, with + * this client. + */ fun sync(): OnebusawaySdkClient fun agenciesWithCoverage(): AgenciesWithCoverageServiceAsync @@ -64,4 +110,17 @@ interface OnebusawaySdkClientAsync { fun block(): BlockServiceAsync fun shape(): ShapeServiceAsync + + /** + * Closes this client, relinquishing any underlying resources. + * + * This is purposefully not inherited from [AutoCloseable] because the client is long-lived and + * usually should not be synchronously closed via try-with-resources. + * + * It's also usually not necessary to call this method at all. the default HTTP client + * automatically releases threads and connections if they remain idle, but if you are writing an + * application that needs to aggressively release unused resources, then you may call this + * method. + */ + fun close() } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientAsyncImpl.kt index f930dc9..5c218c1 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientAsyncImpl.kt @@ -4,16 +4,69 @@ package org.onebusaway.client import org.onebusaway.core.ClientOptions import org.onebusaway.core.getPackageVersion -import org.onebusaway.models.* -import org.onebusaway.services.async.* - -class OnebusawaySdkClientAsyncImpl -constructor( +import org.onebusaway.services.async.AgenciesWithCoverageServiceAsync +import org.onebusaway.services.async.AgenciesWithCoverageServiceAsyncImpl +import org.onebusaway.services.async.AgencyServiceAsync +import org.onebusaway.services.async.AgencyServiceAsyncImpl +import org.onebusaway.services.async.ArrivalAndDepartureServiceAsync +import org.onebusaway.services.async.ArrivalAndDepartureServiceAsyncImpl +import org.onebusaway.services.async.BlockServiceAsync +import org.onebusaway.services.async.BlockServiceAsyncImpl +import org.onebusaway.services.async.ConfigServiceAsync +import org.onebusaway.services.async.ConfigServiceAsyncImpl +import org.onebusaway.services.async.CurrentTimeServiceAsync +import org.onebusaway.services.async.CurrentTimeServiceAsyncImpl +import org.onebusaway.services.async.ReportProblemWithStopServiceAsync +import org.onebusaway.services.async.ReportProblemWithStopServiceAsyncImpl +import org.onebusaway.services.async.ReportProblemWithTripServiceAsync +import org.onebusaway.services.async.ReportProblemWithTripServiceAsyncImpl +import org.onebusaway.services.async.RouteIdsForAgencyServiceAsync +import org.onebusaway.services.async.RouteIdsForAgencyServiceAsyncImpl +import org.onebusaway.services.async.RouteServiceAsync +import org.onebusaway.services.async.RouteServiceAsyncImpl +import org.onebusaway.services.async.RoutesForAgencyServiceAsync +import org.onebusaway.services.async.RoutesForAgencyServiceAsyncImpl +import org.onebusaway.services.async.RoutesForLocationServiceAsync +import org.onebusaway.services.async.RoutesForLocationServiceAsyncImpl +import org.onebusaway.services.async.ScheduleForRouteServiceAsync +import org.onebusaway.services.async.ScheduleForRouteServiceAsyncImpl +import org.onebusaway.services.async.ScheduleForStopServiceAsync +import org.onebusaway.services.async.ScheduleForStopServiceAsyncImpl +import org.onebusaway.services.async.SearchForRouteServiceAsync +import org.onebusaway.services.async.SearchForRouteServiceAsyncImpl +import org.onebusaway.services.async.SearchForStopServiceAsync +import org.onebusaway.services.async.SearchForStopServiceAsyncImpl +import org.onebusaway.services.async.ShapeServiceAsync +import org.onebusaway.services.async.ShapeServiceAsyncImpl +import org.onebusaway.services.async.StopIdsForAgencyServiceAsync +import org.onebusaway.services.async.StopIdsForAgencyServiceAsyncImpl +import org.onebusaway.services.async.StopServiceAsync +import org.onebusaway.services.async.StopServiceAsyncImpl +import org.onebusaway.services.async.StopsForAgencyServiceAsync +import org.onebusaway.services.async.StopsForAgencyServiceAsyncImpl +import org.onebusaway.services.async.StopsForLocationServiceAsync +import org.onebusaway.services.async.StopsForLocationServiceAsyncImpl +import org.onebusaway.services.async.StopsForRouteServiceAsync +import org.onebusaway.services.async.StopsForRouteServiceAsyncImpl +import org.onebusaway.services.async.TripDetailServiceAsync +import org.onebusaway.services.async.TripDetailServiceAsyncImpl +import org.onebusaway.services.async.TripForVehicleServiceAsync +import org.onebusaway.services.async.TripForVehicleServiceAsyncImpl +import org.onebusaway.services.async.TripServiceAsync +import org.onebusaway.services.async.TripServiceAsyncImpl +import org.onebusaway.services.async.TripsForLocationServiceAsync +import org.onebusaway.services.async.TripsForLocationServiceAsyncImpl +import org.onebusaway.services.async.TripsForRouteServiceAsync +import org.onebusaway.services.async.TripsForRouteServiceAsyncImpl +import org.onebusaway.services.async.VehiclesForAgencyServiceAsync +import org.onebusaway.services.async.VehiclesForAgencyServiceAsyncImpl + +class OnebusawaySdkClientAsyncImpl( private val clientOptions: ClientOptions, ) : OnebusawaySdkClientAsync { private val clientOptionsWithUserAgent = - if (clientOptions.headers.containsKey("User-Agent")) clientOptions + if (clientOptions.headers.names().contains("User-Agent")) clientOptions else clientOptions .toBuilder() @@ -188,4 +241,6 @@ constructor( override fun block(): BlockServiceAsync = block override fun shape(): ShapeServiceAsync = shape + + override fun close() = clientOptions.httpClient.close() } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientImpl.kt index 1183849..bcc58db 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/client/OnebusawaySdkClientImpl.kt @@ -4,16 +4,69 @@ package org.onebusaway.client import org.onebusaway.core.ClientOptions import org.onebusaway.core.getPackageVersion -import org.onebusaway.models.* -import org.onebusaway.services.blocking.* - -class OnebusawaySdkClientImpl -constructor( +import org.onebusaway.services.blocking.AgenciesWithCoverageService +import org.onebusaway.services.blocking.AgenciesWithCoverageServiceImpl +import org.onebusaway.services.blocking.AgencyService +import org.onebusaway.services.blocking.AgencyServiceImpl +import org.onebusaway.services.blocking.ArrivalAndDepartureService +import org.onebusaway.services.blocking.ArrivalAndDepartureServiceImpl +import org.onebusaway.services.blocking.BlockService +import org.onebusaway.services.blocking.BlockServiceImpl +import org.onebusaway.services.blocking.ConfigService +import org.onebusaway.services.blocking.ConfigServiceImpl +import org.onebusaway.services.blocking.CurrentTimeService +import org.onebusaway.services.blocking.CurrentTimeServiceImpl +import org.onebusaway.services.blocking.ReportProblemWithStopService +import org.onebusaway.services.blocking.ReportProblemWithStopServiceImpl +import org.onebusaway.services.blocking.ReportProblemWithTripService +import org.onebusaway.services.blocking.ReportProblemWithTripServiceImpl +import org.onebusaway.services.blocking.RouteIdsForAgencyService +import org.onebusaway.services.blocking.RouteIdsForAgencyServiceImpl +import org.onebusaway.services.blocking.RouteService +import org.onebusaway.services.blocking.RouteServiceImpl +import org.onebusaway.services.blocking.RoutesForAgencyService +import org.onebusaway.services.blocking.RoutesForAgencyServiceImpl +import org.onebusaway.services.blocking.RoutesForLocationService +import org.onebusaway.services.blocking.RoutesForLocationServiceImpl +import org.onebusaway.services.blocking.ScheduleForRouteService +import org.onebusaway.services.blocking.ScheduleForRouteServiceImpl +import org.onebusaway.services.blocking.ScheduleForStopService +import org.onebusaway.services.blocking.ScheduleForStopServiceImpl +import org.onebusaway.services.blocking.SearchForRouteService +import org.onebusaway.services.blocking.SearchForRouteServiceImpl +import org.onebusaway.services.blocking.SearchForStopService +import org.onebusaway.services.blocking.SearchForStopServiceImpl +import org.onebusaway.services.blocking.ShapeService +import org.onebusaway.services.blocking.ShapeServiceImpl +import org.onebusaway.services.blocking.StopIdsForAgencyService +import org.onebusaway.services.blocking.StopIdsForAgencyServiceImpl +import org.onebusaway.services.blocking.StopService +import org.onebusaway.services.blocking.StopServiceImpl +import org.onebusaway.services.blocking.StopsForAgencyService +import org.onebusaway.services.blocking.StopsForAgencyServiceImpl +import org.onebusaway.services.blocking.StopsForLocationService +import org.onebusaway.services.blocking.StopsForLocationServiceImpl +import org.onebusaway.services.blocking.StopsForRouteService +import org.onebusaway.services.blocking.StopsForRouteServiceImpl +import org.onebusaway.services.blocking.TripDetailService +import org.onebusaway.services.blocking.TripDetailServiceImpl +import org.onebusaway.services.blocking.TripForVehicleService +import org.onebusaway.services.blocking.TripForVehicleServiceImpl +import org.onebusaway.services.blocking.TripService +import org.onebusaway.services.blocking.TripServiceImpl +import org.onebusaway.services.blocking.TripsForLocationService +import org.onebusaway.services.blocking.TripsForLocationServiceImpl +import org.onebusaway.services.blocking.TripsForRouteService +import org.onebusaway.services.blocking.TripsForRouteServiceImpl +import org.onebusaway.services.blocking.VehiclesForAgencyService +import org.onebusaway.services.blocking.VehiclesForAgencyServiceImpl + +class OnebusawaySdkClientImpl( private val clientOptions: ClientOptions, ) : OnebusawaySdkClient { private val clientOptionsWithUserAgent = - if (clientOptions.headers.containsKey("User-Agent")) clientOptions + if (clientOptions.headers.names().contains("User-Agent")) clientOptions else clientOptions .toBuilder() @@ -180,4 +233,6 @@ constructor( override fun block(): BlockService = block override fun shape(): ShapeService = shape + + override fun close() = clientOptions.httpClient.close() } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Check.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Check.kt new file mode 100644 index 0000000..b6fd22d --- /dev/null +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Check.kt @@ -0,0 +1,29 @@ +@file:JvmName("Check") + +package org.onebusaway.core + +fun checkRequired(name: String, value: T?): T = + checkNotNull(value) { "`$name` is required, but was not set" } + +@JvmSynthetic +internal fun checkLength(name: String, value: String, length: Int): String = + value.also { + check(it.length == length) { "`$name` must have length $length, but was ${it.length}" } + } + +@JvmSynthetic +internal fun checkMinLength(name: String, value: String, minLength: Int): String = + value.also { + check(it.length >= minLength) { + if (minLength == 1) "`$name` must be non-empty, but was empty" + else "`$name` must have at least length $minLength, but was ${it.length}" + } + } + +@JvmSynthetic +internal fun checkMaxLength(name: String, value: String, maxLength: Int): String = + value.also { + check(it.length <= maxLength) { + "`$name` must have at most length $maxLength, but was ${it.length}" + } + } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/ClientOptions.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/ClientOptions.kt index 370b3f4..2e214a5 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/ClientOptions.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/ClientOptions.kt @@ -3,11 +3,11 @@ package org.onebusaway.core import com.fasterxml.jackson.databind.json.JsonMapper -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.time.Clock +import org.onebusaway.core.http.Headers import org.onebusaway.core.http.HttpClient import org.onebusaway.core.http.PhantomReachableClosingHttpClient +import org.onebusaway.core.http.QueryParams import org.onebusaway.core.http.RetryingHttpClient class ClientOptions @@ -17,8 +17,8 @@ private constructor( @get:JvmName("jsonMapper") val jsonMapper: JsonMapper, @get:JvmName("clock") val clock: Clock, @get:JvmName("baseUrl") val baseUrl: String, - @get:JvmName("headers") val headers: ListMultimap, - @get:JvmName("queryParams") val queryParams: ListMultimap, + @get:JvmName("headers") val headers: Headers, + @get:JvmName("queryParams") val queryParams: QueryParams, @get:JvmName("responseValidation") val responseValidation: Boolean, @get:JvmName("maxRetries") val maxRetries: Int, @get:JvmName("apiKey") val apiKey: String, @@ -35,14 +35,15 @@ private constructor( @JvmStatic fun fromEnv(): ClientOptions = builder().fromEnv().build() } - class Builder { + /** A builder for [ClientOptions]. */ + class Builder internal constructor() { private var httpClient: HttpClient? = null private var jsonMapper: JsonMapper = jsonMapper() private var clock: Clock = Clock.systemUTC() private var baseUrl: String = PRODUCTION_URL - private var headers: ListMultimap = ArrayListMultimap.create() - private var queryParams: ListMultimap = ArrayListMultimap.create() + private var headers: Headers.Builder = Headers.builder() + private var queryParams: QueryParams.Builder = QueryParams.builder() private var responseValidation: Boolean = false private var maxRetries: Int = 2 private var apiKey: String? = null @@ -53,8 +54,8 @@ private constructor( jsonMapper = clientOptions.jsonMapper clock = clientOptions.clock baseUrl = clientOptions.baseUrl - headers = ArrayListMultimap.create(clientOptions.headers) - queryParams = ArrayListMultimap.create(clientOptions.queryParams) + headers = clientOptions.headers.toBuilder() + queryParams = clientOptions.queryParams.toBuilder() responseValidation = clientOptions.responseValidation maxRetries = clientOptions.maxRetries apiKey = clientOptions.apiKey @@ -68,6 +69,19 @@ private constructor( fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl } + fun responseValidation(responseValidation: Boolean) = apply { + this.responseValidation = responseValidation + } + + fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries } + + fun apiKey(apiKey: String) = apply { this.apiKey = apiKey } + + fun headers(headers: Headers) = apply { + this.headers.clear() + putAllHeaders(headers) + } + fun headers(headers: Map>) = apply { this.headers.clear() putAllHeaders(headers) @@ -75,29 +89,34 @@ private constructor( fun putHeader(name: String, value: String) = apply { headers.put(name, value) } - fun putHeaders(name: String, values: Iterable) = apply { - headers.putAll(name, values) - } + fun putHeaders(name: String, values: Iterable) = apply { headers.put(name, values) } + + fun putAllHeaders(headers: Headers) = apply { this.headers.putAll(headers) } fun putAllHeaders(headers: Map>) = apply { - headers.forEach(::putHeaders) + this.headers.putAll(headers) } - fun replaceHeaders(name: String, value: String) = apply { - headers.replaceValues(name, listOf(value)) - } + fun replaceHeaders(name: String, value: String) = apply { headers.replace(name, value) } fun replaceHeaders(name: String, values: Iterable) = apply { - headers.replaceValues(name, values) + headers.replace(name, values) } + fun replaceAllHeaders(headers: Headers) = apply { this.headers.replaceAll(headers) } + fun replaceAllHeaders(headers: Map>) = apply { - headers.forEach(::replaceHeaders) + this.headers.replaceAll(headers) } - fun removeHeaders(name: String) = apply { headers.removeAll(name) } + fun removeHeaders(name: String) = apply { headers.remove(name) } + + fun removeAllHeaders(names: Set) = apply { headers.removeAll(names) } - fun removeAllHeaders(names: Set) = apply { names.forEach(::removeHeaders) } + fun queryParams(queryParams: QueryParams) = apply { + this.queryParams.clear() + putAllQueryParams(queryParams) + } fun queryParams(queryParams: Map>) = apply { this.queryParams.clear() @@ -107,45 +126,45 @@ private constructor( fun putQueryParam(key: String, value: String) = apply { queryParams.put(key, value) } fun putQueryParams(key: String, values: Iterable) = apply { - queryParams.putAll(key, values) + queryParams.put(key, values) + } + + fun putAllQueryParams(queryParams: QueryParams) = apply { + this.queryParams.putAll(queryParams) } fun putAllQueryParams(queryParams: Map>) = apply { - queryParams.forEach(::putQueryParams) + this.queryParams.putAll(queryParams) } fun replaceQueryParams(key: String, value: String) = apply { - queryParams.replaceValues(key, listOf(value)) + queryParams.replace(key, value) } fun replaceQueryParams(key: String, values: Iterable) = apply { - queryParams.replaceValues(key, values) + queryParams.replace(key, values) } - fun replaceAllQueryParams(queryParams: Map>) = apply { - queryParams.forEach(::replaceQueryParams) + fun replaceAllQueryParams(queryParams: QueryParams) = apply { + this.queryParams.replaceAll(queryParams) } - fun removeQueryParams(key: String) = apply { queryParams.removeAll(key) } - - fun removeAllQueryParams(keys: Set) = apply { keys.forEach(::removeQueryParams) } - - fun responseValidation(responseValidation: Boolean) = apply { - this.responseValidation = responseValidation + fun replaceAllQueryParams(queryParams: Map>) = apply { + this.queryParams.replaceAll(queryParams) } - fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries } + fun removeQueryParams(key: String) = apply { queryParams.remove(key) } - fun apiKey(apiKey: String) = apply { this.apiKey = apiKey } + fun removeAllQueryParams(keys: Set) = apply { queryParams.removeAll(keys) } fun fromEnv() = apply { System.getenv("ONEBUSAWAY_API_KEY")?.let { apiKey(it) } } fun build(): ClientOptions { - checkNotNull(httpClient) { "`httpClient` is required but was not set" } - checkNotNull(apiKey) { "`apiKey` is required but was not set" } + val httpClient = checkRequired("httpClient", httpClient) + val apiKey = checkRequired("apiKey", apiKey) - val headers = ArrayListMultimap.create() - val queryParams = ArrayListMultimap.create() + val headers = Headers.builder() + val queryParams = QueryParams.builder() headers.put("X-Stainless-Lang", "java") headers.put("X-Stainless-Arch", getOsArch()) headers.put("X-Stainless-OS", getOsName()) @@ -153,17 +172,19 @@ private constructor( headers.put("X-Stainless-Package-Version", getPackageVersion()) headers.put("X-Stainless-Runtime", "JRE") headers.put("X-Stainless-Runtime-Version", getJavaVersion()) - if (!apiKey.isNullOrEmpty()) { - queryParams.put("key", apiKey) + apiKey.let { + if (!it.isEmpty()) { + headers.put("key", it) + } } - this.headers.asMap().forEach(headers::replaceValues) - this.queryParams.asMap().forEach(queryParams::replaceValues) + headers.replaceAll(this.headers.build()) + queryParams.replaceAll(this.queryParams.build()) return ClientOptions( - httpClient!!, + httpClient, PhantomReachableClosingHttpClient( RetryingHttpClient.builder() - .httpClient(httpClient!!) + .httpClient(httpClient) .clock(clock) .maxRetries(maxRetries) .build() @@ -171,11 +192,11 @@ private constructor( jsonMapper, clock, baseUrl, - headers.toImmutable(), - queryParams.toImmutable(), + headers.build(), + queryParams.build(), responseValidation, maxRetries, - apiKey!!, + apiKey, ) } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Params.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Params.kt new file mode 100644 index 0000000..48d18a8 --- /dev/null +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Params.kt @@ -0,0 +1,16 @@ +package org.onebusaway.core + +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams + +/** An interface representing parameters passed to a service method. */ +interface Params { + /** The full set of headers in the parameters, including both fixed and additional headers. */ + fun _headers(): Headers + + /** + * The full set of query params in the parameters, including both fixed and additional query + * params. + */ + fun _queryParams(): QueryParams +} diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/PhantomReachable.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/PhantomReachable.kt index e35ca9a..8391e58 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/PhantomReachable.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/PhantomReachable.kt @@ -15,10 +15,20 @@ internal fun closeWhenPhantomReachable(observed: Any, closeable: AutoCloseable) check(observed !== closeable) { "`observed` cannot be the same object as `closeable` because it would never become phantom reachable" } - closeWhenPhantomReachable?.let { it(observed, closeable::close) } + closeWhenPhantomReachable(observed, closeable::close) } -private val closeWhenPhantomReachable: ((Any, AutoCloseable) -> Unit)? by lazy { +/** + * Calls [close] when [observed] becomes only phantom reachable. + * + * This is a wrapper around a Java 9+ [java.lang.ref.Cleaner], or a no-op in older Java versions. + */ +@JvmSynthetic +internal fun closeWhenPhantomReachable(observed: Any, close: () -> Unit) { + closeWhenPhantomReachable?.let { it(observed, close) } +} + +private val closeWhenPhantomReachable: ((Any, () -> Unit) -> Unit)? by lazy { try { val cleanerClass = Class.forName("java.lang.ref.Cleaner") val cleanerCreate = cleanerClass.getMethod("create") @@ -26,9 +36,9 @@ private val closeWhenPhantomReachable: ((Any, AutoCloseable) -> Unit)? by lazy { cleanerClass.getMethod("register", Any::class.java, Runnable::class.java) val cleanerObject = cleanerCreate.invoke(null); - { observed, closeable -> + { observed, close -> try { - cleanerRegister.invoke(cleanerObject, observed, Runnable { closeable.close() }) + cleanerRegister.invoke(cleanerObject, observed, Runnable { close() }) } catch (e: ReflectiveOperationException) { if (e is InvocationTargetException) { when (val cause = e.cause) { diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/PrepareRequest.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/PrepareRequest.kt new file mode 100644 index 0000000..b78d6b6 --- /dev/null +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/PrepareRequest.kt @@ -0,0 +1,24 @@ +@file:JvmName("PrepareRequest") + +package org.onebusaway.core + +import java.util.concurrent.CompletableFuture +import org.onebusaway.core.http.HttpRequest + +@JvmSynthetic +internal fun HttpRequest.prepare(clientOptions: ClientOptions, params: Params): HttpRequest = + toBuilder() + .putAllQueryParams(clientOptions.queryParams) + .replaceAllQueryParams(params._queryParams()) + .putAllHeaders(clientOptions.headers) + .replaceAllHeaders(params._headers()) + .build() + +@JvmSynthetic +internal fun HttpRequest.prepareAsync( + clientOptions: ClientOptions, + params: Params +): CompletableFuture = + // This async version exists to make it easier to add async specific preparation logic in the + // future. + CompletableFuture.completedFuture(prepare(clientOptions, params)) diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/RequestOptions.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/RequestOptions.kt index ec2f645..653da53 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/RequestOptions.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/RequestOptions.kt @@ -23,7 +23,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + class Builder internal constructor() { + private var responseValidation: Boolean? = null private var timeout: Duration? = null diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Utils.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Utils.kt index 4ccb63c..31e1d87 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Utils.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Utils.kt @@ -2,8 +2,6 @@ package org.onebusaway.core -import com.google.common.collect.ImmutableListMultimap -import com.google.common.collect.ListMultimap import java.util.Collections import java.util.SortedMap import org.onebusaway.errors.OnebusawaySdkInvalidDataException @@ -18,15 +16,13 @@ internal fun List.toImmutable(): List = @JvmSynthetic internal fun Map.toImmutable(): Map = - if (isEmpty()) Collections.emptyMap() else Collections.unmodifiableMap(toMap()) + if (isEmpty()) immutableEmptyMap() else Collections.unmodifiableMap(toMap()) + +@JvmSynthetic internal fun immutableEmptyMap(): Map = Collections.emptyMap() @JvmSynthetic internal fun , V> SortedMap.toImmutable(): SortedMap = if (isEmpty()) Collections.emptySortedMap() else Collections.unmodifiableSortedMap(toSortedMap(comparator())) -@JvmSynthetic -internal fun ListMultimap.toImmutable(): ListMultimap = - ImmutableListMultimap.copyOf(this) - internal interface Enum diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Values.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Values.kt index f5d6cde..387b30b 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Values.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Values.kt @@ -119,6 +119,8 @@ sealed class JsonField { is JsonValue -> this } + @JvmSynthetic fun accept(consume: (T) -> Unit) = asKnown().ifPresent(consume) + fun accept(visitor: Visitor): R = when (this) { is KnownValue -> visitor.visitKnown(value) diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/handlers/ErrorHandler.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/handlers/ErrorHandler.kt index f7938ba..621d820 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/handlers/ErrorHandler.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/handlers/ErrorHandler.kt @@ -3,9 +3,9 @@ package org.onebusaway.core.handlers import com.fasterxml.jackson.databind.json.JsonMapper -import com.google.common.collect.ListMultimap import java.io.ByteArrayInputStream import java.io.InputStream +import org.onebusaway.core.http.Headers import org.onebusaway.core.http.HttpResponse import org.onebusaway.core.http.HttpResponse.Handler import org.onebusaway.errors.BadRequestException @@ -118,7 +118,7 @@ private fun HttpResponse.buffered(): HttpResponse { return object : HttpResponse { override fun statusCode(): Int = this@buffered.statusCode() - override fun headers(): ListMultimap = this@buffered.headers() + override fun headers(): Headers = this@buffered.headers() override fun body(): InputStream = ByteArrayInputStream(body) diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/Headers.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/Headers.kt index 1e17303..e6f6448 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/Headers.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/Headers.kt @@ -22,7 +22,7 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + class Builder internal constructor() { private val map: MutableMap> = TreeMap(String.CASE_INSENSITIVE_ORDER) diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/HttpRequest.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/HttpRequest.kt index 9139930..1b4396b 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/HttpRequest.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/HttpRequest.kt @@ -1,8 +1,6 @@ package org.onebusaway.core.http -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap -import com.google.common.collect.MultimapBuilder +import org.onebusaway.core.checkRequired import org.onebusaway.core.toImmutable class HttpRequest @@ -10,11 +8,13 @@ private constructor( @get:JvmName("method") val method: HttpMethod, @get:JvmName("url") val url: String?, @get:JvmName("pathSegments") val pathSegments: List, - @get:JvmName("headers") val headers: ListMultimap, - @get:JvmName("queryParams") val queryParams: ListMultimap, + @get:JvmName("headers") val headers: Headers, + @get:JvmName("queryParams") val queryParams: QueryParams, @get:JvmName("body") val body: HttpRequestBody?, ) { + fun toBuilder(): Builder = Builder().from(this) + override fun toString(): String = "HttpRequest{method=$method, url=$url, pathSegments=$pathSegments, headers=$headers, queryParams=$queryParams, body=$body}" @@ -22,16 +22,25 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + class Builder internal constructor() { private var method: HttpMethod? = null private var url: String? = null private var pathSegments: MutableList = mutableListOf() - private var headers: ListMultimap = - MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER).arrayListValues().build() - private var queryParams: ListMultimap = ArrayListMultimap.create() + private var headers: Headers.Builder = Headers.builder() + private var queryParams: QueryParams.Builder = QueryParams.builder() private var body: HttpRequestBody? = null + @JvmSynthetic + internal fun from(request: HttpRequest) = apply { + method = request.method + url = request.url + pathSegments = request.pathSegments.toMutableList() + headers = request.headers.toBuilder() + queryParams = request.queryParams.toBuilder() + body = request.body + } + fun method(method: HttpMethod) = apply { this.method = method } fun url(url: String) = apply { this.url = url } @@ -42,6 +51,11 @@ private constructor( this.pathSegments.addAll(pathSegments) } + fun headers(headers: Headers) = apply { + this.headers.clear() + putAllHeaders(headers) + } + fun headers(headers: Map>) = apply { this.headers.clear() putAllHeaders(headers) @@ -49,29 +63,34 @@ private constructor( fun putHeader(name: String, value: String) = apply { headers.put(name, value) } - fun putHeaders(name: String, values: Iterable) = apply { - headers.putAll(name, values) - } + fun putHeaders(name: String, values: Iterable) = apply { headers.put(name, values) } + + fun putAllHeaders(headers: Headers) = apply { this.headers.putAll(headers) } fun putAllHeaders(headers: Map>) = apply { - headers.forEach(::putHeaders) + this.headers.putAll(headers) } - fun replaceHeaders(name: String, value: String) = apply { - headers.replaceValues(name, listOf(value)) - } + fun replaceHeaders(name: String, value: String) = apply { headers.replace(name, value) } fun replaceHeaders(name: String, values: Iterable) = apply { - headers.replaceValues(name, values) + headers.replace(name, values) } + fun replaceAllHeaders(headers: Headers) = apply { this.headers.replaceAll(headers) } + fun replaceAllHeaders(headers: Map>) = apply { - headers.forEach(::replaceHeaders) + this.headers.replaceAll(headers) } - fun removeHeaders(name: String) = apply { headers.removeAll(name) } + fun removeHeaders(name: String) = apply { headers.remove(name) } + + fun removeAllHeaders(names: Set) = apply { headers.removeAll(names) } - fun removeAllHeaders(names: Set) = apply { names.forEach(::removeHeaders) } + fun queryParams(queryParams: QueryParams) = apply { + this.queryParams.clear() + putAllQueryParams(queryParams) + } fun queryParams(queryParams: Map>) = apply { this.queryParams.clear() @@ -81,38 +100,46 @@ private constructor( fun putQueryParam(key: String, value: String) = apply { queryParams.put(key, value) } fun putQueryParams(key: String, values: Iterable) = apply { - queryParams.putAll(key, values) + queryParams.put(key, values) + } + + fun putAllQueryParams(queryParams: QueryParams) = apply { + this.queryParams.putAll(queryParams) } fun putAllQueryParams(queryParams: Map>) = apply { - queryParams.forEach(::putQueryParams) + this.queryParams.putAll(queryParams) } fun replaceQueryParams(key: String, value: String) = apply { - queryParams.replaceValues(key, listOf(value)) + queryParams.replace(key, value) } fun replaceQueryParams(key: String, values: Iterable) = apply { - queryParams.replaceValues(key, values) + queryParams.replace(key, values) + } + + fun replaceAllQueryParams(queryParams: QueryParams) = apply { + this.queryParams.replaceAll(queryParams) } fun replaceAllQueryParams(queryParams: Map>) = apply { - queryParams.forEach(::replaceQueryParams) + this.queryParams.replaceAll(queryParams) } - fun removeQueryParams(key: String) = apply { queryParams.removeAll(key) } + fun removeQueryParams(key: String) = apply { queryParams.remove(key) } - fun removeAllQueryParams(keys: Set) = apply { keys.forEach(::removeQueryParams) } + fun removeAllQueryParams(keys: Set) = apply { queryParams.removeAll(keys) } fun body(body: HttpRequestBody) = apply { this.body = body } fun build(): HttpRequest = HttpRequest( - checkNotNull(method) { "`method` is required but was not set" }, + checkRequired("method", method), url, pathSegments.toImmutable(), - headers, - queryParams.toImmutable(), + headers.build(), + queryParams.build(), body, ) } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/HttpResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/HttpResponse.kt index b2870ca..1a3f27d 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/HttpResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/HttpResponse.kt @@ -1,6 +1,5 @@ package org.onebusaway.core.http -import com.google.common.collect.ListMultimap import java.io.InputStream import java.lang.AutoCloseable @@ -8,7 +7,7 @@ interface HttpResponse : AutoCloseable { fun statusCode(): Int - fun headers(): ListMultimap + fun headers(): Headers fun body(): InputStream diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/PhantomReachableClosingHttpClient.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/PhantomReachableClosingHttpClient.kt index f923a21..756f8a2 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/PhantomReachableClosingHttpClient.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/PhantomReachableClosingHttpClient.kt @@ -4,6 +4,11 @@ import java.util.concurrent.CompletableFuture import org.onebusaway.core.RequestOptions import org.onebusaway.core.closeWhenPhantomReachable +/** + * A delegating wrapper around an `HttpClient` that closes it once it's only phantom reachable. + * + * This class ensures the `HttpClient` is closed even if the user forgets to close it. + */ internal class PhantomReachableClosingHttpClient(private val httpClient: HttpClient) : HttpClient { init { closeWhenPhantomReachable(this, httpClient) diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/QueryParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/QueryParams.kt index a5e7ddf..1e9bbb7 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/QueryParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/QueryParams.kt @@ -21,7 +21,7 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + class Builder internal constructor() { private val map: MutableMap> = mutableMapOf() private var size: Int = 0 diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/RetryingHttpClient.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/RetryingHttpClient.kt index 37bc637..eb4f5ed 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/RetryingHttpClient.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/RetryingHttpClient.kt @@ -17,6 +17,7 @@ import java.util.function.Function import kotlin.math.min import kotlin.math.pow import org.onebusaway.core.RequestOptions +import org.onebusaway.core.checkRequired import org.onebusaway.errors.OnebusawaySdkIoException class RetryingHttpClient @@ -35,35 +36,38 @@ private constructor( return httpClient.execute(request, requestOptions) } - maybeAddIdempotencyHeader(request) + var modifiedRequest = maybeAddIdempotencyHeader(request) // Don't send the current retry count in the headers if the caller set their own value. - val shouldSendRetryCount = !request.headers.containsKey("x-stainless-retry-count") + val shouldSendRetryCount = + !modifiedRequest.headers.names().contains("X-Stainless-Retry-Count") var retries = 0 while (true) { if (shouldSendRetryCount) { - setRetryCountHeader(request, retries) + modifiedRequest = setRetryCountHeader(modifiedRequest, retries) } val response = try { - val response = httpClient.execute(request, requestOptions) + val response = httpClient.execute(modifiedRequest, requestOptions) if (++retries > maxRetries || !shouldRetry(response)) { return response } response - } catch (t: Throwable) { - if (++retries > maxRetries || !shouldRetry(t)) { - throw t + } catch (throwable: Throwable) { + if (++retries > maxRetries || !shouldRetry(throwable)) { + throw throwable } null } val backoffMillis = getRetryBackoffMillis(retries, response) + // All responses must be closed, so close the failed one before retrying. + response?.close() Thread.sleep(backoffMillis.toMillis()) } } @@ -76,10 +80,11 @@ private constructor( return httpClient.executeAsync(request, requestOptions) } - maybeAddIdempotencyHeader(request) + val modifiedRequest = maybeAddIdempotencyHeader(request) // Don't send the current retry count in the headers if the caller set their own value. - val shouldSendRetryCount = !request.headers.containsKey("x-stainless-retry-count") + val shouldSendRetryCount = + !modifiedRequest.headers.names().contains("X-Stainless-Retry-Count") var retries = 0 @@ -87,12 +92,11 @@ private constructor( request: HttpRequest, requestOptions: RequestOptions, ): CompletableFuture { - if (shouldSendRetryCount) { - setRetryCountHeader(request, retries) - } + val requestWithRetryCount = + if (shouldSendRetryCount) setRetryCountHeader(request, retries) else request return httpClient - .executeAsync(request, requestOptions) + .executeAsync(requestWithRetryCount, requestOptions) .handleAsync( fun( response: HttpResponse?, @@ -111,8 +115,10 @@ private constructor( } val backoffMillis = getRetryBackoffMillis(retries, response) + // All responses must be closed, so close the failed one before retrying. + response?.close() return sleepAsync(backoffMillis.toMillis()).thenCompose { - executeWithRetries(request, requestOptions) + executeWithRetries(requestWithRetryCount, requestOptions) } }, ) { @@ -122,7 +128,7 @@ private constructor( .thenCompose(Function.identity()) } - return executeWithRetries(request, requestOptions) + return executeWithRetries(modifiedRequest, requestOptions) } override fun close() = httpClient.close() @@ -132,23 +138,26 @@ private constructor( // the body data aren't available on subsequent attempts. request.body?.repeatable() ?: true - private fun setRetryCountHeader(request: HttpRequest, retries: Int) { - request.headers.removeAll("x-stainless-retry-count") - request.headers.put("x-stainless-retry-count", retries.toString()) - } + private fun setRetryCountHeader(request: HttpRequest, retries: Int): HttpRequest = + request.toBuilder().replaceHeaders("X-Stainless-Retry-Count", retries.toString()).build() private fun idempotencyKey(): String = "stainless-java-retry-${UUID.randomUUID()}" - private fun maybeAddIdempotencyHeader(request: HttpRequest) { - if (idempotencyHeader != null && !request.headers.containsKey(idempotencyHeader)) { - // Set a header to uniquely identify the request when retried - request.headers.put(idempotencyHeader, idempotencyKey()) + private fun maybeAddIdempotencyHeader(request: HttpRequest): HttpRequest { + if (idempotencyHeader == null || request.headers.names().contains(idempotencyHeader)) { + return request } + + return request + .toBuilder() + // Set a header to uniquely identify the request when retried. + .putHeader(idempotencyHeader, idempotencyKey()) + .build() } private fun shouldRetry(response: HttpResponse): Boolean { // Note: this is not a standard header - val shouldRetryHeader = response.headers().get("x-should-retry").getOrNull(0) + val shouldRetryHeader = response.headers().values("X-Should-Retry").getOrNull(0) val statusCode = response.statusCode() return when { @@ -181,11 +190,11 @@ private constructor( ?.headers() ?.let { headers -> headers - .get("Retry-After-Ms") + .values("Retry-After-Ms") .getOrNull(0) ?.toFloatOrNull() ?.times(TimeUnit.MILLISECONDS.toNanos(1)) - ?: headers.get("Retry-After").getOrNull(0)?.let { retryAfter -> + ?: headers.values("Retry-After").getOrNull(0)?.let { retryAfter -> retryAfter.toFloatOrNull()?.times(TimeUnit.SECONDS.toNanos(1)) ?: try { ChronoUnit.MILLIS.between( @@ -219,27 +228,27 @@ private constructor( return Duration.ofNanos((TimeUnit.SECONDS.toNanos(1) * backoffSeconds * jitter).toLong()) } - private fun sleepAsync(millis: Long): CompletableFuture { - val future = CompletableFuture() - TIMER.schedule( - object : TimerTask() { - override fun run() { - future.complete(null) - } - }, - millis - ) - return future - } - companion object { private val TIMER = Timer("RetryingHttpClient", true) + private fun sleepAsync(millis: Long): CompletableFuture { + val future = CompletableFuture() + TIMER.schedule( + object : TimerTask() { + override fun run() { + future.complete(null) + } + }, + millis + ) + return future + } + @JvmStatic fun builder() = Builder() } - class Builder { + class Builder internal constructor() { private var httpClient: HttpClient? = null private var clock: Clock = Clock.systemUTC() @@ -256,7 +265,7 @@ private constructor( fun build(): HttpClient = RetryingHttpClient( - checkNotNull(httpClient) { "`httpClient` is required but was not set" }, + checkRequired("httpClient", httpClient), clock, maxRetries, idempotencyHeader, diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/BadRequestException.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/BadRequestException.kt index dee8196..036562b 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/BadRequestException.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/BadRequestException.kt @@ -1,9 +1,9 @@ package org.onebusaway.errors -import com.google.common.collect.ListMultimap +import org.onebusaway.core.http.Headers class BadRequestException( - headers: ListMultimap, + headers: Headers, body: String, error: OnebusawaySdkError, ) : OnebusawaySdkServiceException(400, headers, body, error) diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/InternalServerException.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/InternalServerException.kt index 5c3229f..b99d5f0 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/InternalServerException.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/InternalServerException.kt @@ -1,10 +1,10 @@ package org.onebusaway.errors -import com.google.common.collect.ListMultimap +import org.onebusaway.core.http.Headers class InternalServerException( statusCode: Int, - headers: ListMultimap, + headers: Headers, body: String, error: OnebusawaySdkError, ) : OnebusawaySdkServiceException(statusCode, headers, body, error) diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/NotFoundException.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/NotFoundException.kt index 35e69c4..d7215fd 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/NotFoundException.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/NotFoundException.kt @@ -1,9 +1,9 @@ package org.onebusaway.errors -import com.google.common.collect.ListMultimap +import org.onebusaway.core.http.Headers class NotFoundException( - headers: ListMultimap, + headers: Headers, body: String, error: OnebusawaySdkError, ) : OnebusawaySdkServiceException(404, headers, body, error) diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/OnebusawaySdkError.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/OnebusawaySdkError.kt index 6f0a191..bf85359 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/OnebusawaySdkError.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/OnebusawaySdkError.kt @@ -4,64 +4,73 @@ package org.onebusaway.errors import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter -import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import com.fasterxml.jackson.annotation.JsonCreator import java.util.Objects +import org.onebusaway.core.ExcludeMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = OnebusawaySdkError.Builder::class) @NoAutoDetect class OnebusawaySdkError -constructor( - private val additionalProperties: Map, +@JsonCreator +private constructor( + @JsonAnyGetter + @ExcludeMissing + @JsonAnySetter + @get:JvmName("additionalProperties") + val additionalProperties: Map = immutableEmptyMap(), ) { - @JsonAnyGetter fun additionalProperties(): Map = additionalProperties - - fun toBuilder() = Builder() - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is OnebusawaySdkError && this.additionalProperties == other.additionalProperties /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(additionalProperties) /* spotless:on */ - } - - override fun toString() = "OnebusawaySdkError{additionalProperties=$additionalProperties}" + fun toBuilder() = Builder().from(this) companion object { @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [OnebusawaySdkError]. */ + class Builder internal constructor() { private var additionalProperties: MutableMap = mutableMapOf() - fun from(error: OnebusawaySdkError) = apply { - additionalProperties(error.additionalProperties) + @JvmSynthetic + internal fun from(onebusawaySdkError: OnebusawaySdkError) = apply { + additionalProperties = onebusawaySdkError.additionalProperties.toMutableMap() } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): OnebusawaySdkError = OnebusawaySdkError(additionalProperties.toImmutable()) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is OnebusawaySdkError && additionalProperties == other.additionalProperties /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(additionalProperties) /* spotless:on */ + + override fun toString() = "OnebusawaySdkError{additionalProperties=$additionalProperties}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/OnebusawaySdkServiceException.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/OnebusawaySdkServiceException.kt index 96d7d2d..e65331d 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/OnebusawaySdkServiceException.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/OnebusawaySdkServiceException.kt @@ -1,12 +1,12 @@ package org.onebusaway.errors -import com.google.common.collect.ListMultimap +import org.onebusaway.core.http.Headers abstract class OnebusawaySdkServiceException @JvmOverloads constructor( private val statusCode: Int, - private val headers: ListMultimap, + private val headers: Headers, private val body: String, private val error: OnebusawaySdkError, message: String = "$statusCode: $error", @@ -15,7 +15,7 @@ constructor( fun statusCode(): Int = statusCode - fun headers(): ListMultimap = headers + fun headers(): Headers = headers fun body(): String = body diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/PermissionDeniedException.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/PermissionDeniedException.kt index bb06e6a..7c70b0b 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/PermissionDeniedException.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/PermissionDeniedException.kt @@ -1,9 +1,9 @@ package org.onebusaway.errors -import com.google.common.collect.ListMultimap +import org.onebusaway.core.http.Headers class PermissionDeniedException( - headers: ListMultimap, + headers: Headers, body: String, error: OnebusawaySdkError, ) : OnebusawaySdkServiceException(403, headers, body, error) diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/RateLimitException.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/RateLimitException.kt index c210a32..314ad3b 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/RateLimitException.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/RateLimitException.kt @@ -1,9 +1,9 @@ package org.onebusaway.errors -import com.google.common.collect.ListMultimap +import org.onebusaway.core.http.Headers class RateLimitException( - headers: ListMultimap, + headers: Headers, body: String, error: OnebusawaySdkError, ) : OnebusawaySdkServiceException(429, headers, body, error) diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/UnauthorizedException.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/UnauthorizedException.kt index dc34495..7b6a7a3 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/UnauthorizedException.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/UnauthorizedException.kt @@ -1,9 +1,9 @@ package org.onebusaway.errors -import com.google.common.collect.ListMultimap +import org.onebusaway.core.http.Headers class UnauthorizedException( - headers: ListMultimap, + headers: Headers, body: String, error: OnebusawaySdkError, ) : OnebusawaySdkServiceException(401, headers, body, error) diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/UnexpectedStatusCodeException.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/UnexpectedStatusCodeException.kt index a54c02d..192fed6 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/UnexpectedStatusCodeException.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/UnexpectedStatusCodeException.kt @@ -1,10 +1,10 @@ package org.onebusaway.errors -import com.google.common.collect.ListMultimap +import org.onebusaway.core.http.Headers class UnexpectedStatusCodeException( statusCode: Int, - headers: ListMultimap, + headers: Headers, body: String, error: OnebusawaySdkError, ) : OnebusawaySdkServiceException(statusCode, headers, body, error) diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/UnprocessableEntityException.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/UnprocessableEntityException.kt index a30211a..bc0e0a7 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/UnprocessableEntityException.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/UnprocessableEntityException.kt @@ -1,9 +1,9 @@ package org.onebusaway.errors -import com.google.common.collect.ListMultimap +import org.onebusaway.core.http.Headers class UnprocessableEntityException( - headers: ListMultimap, + headers: Headers, body: String, error: OnebusawaySdkError, ) : OnebusawaySdkServiceException(422, headers, body, error) diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgenciesWithCoverageListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgenciesWithCoverageListParams.kt index 6e8ed63..ed0199c 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgenciesWithCoverageListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgenciesWithCoverageListParams.kt @@ -2,41 +2,29 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* - +import org.onebusaway.core.Params +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams + +/** + * Returns a list of all transit agencies currently supported by OneBusAway along with the center of + * their coverage area. + */ class AgenciesWithCoverageListParams -constructor( - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { - - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders +private constructor( + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalQueryParams(): Map> = additionalQueryParams + override fun _headers(): Headers = additionalHeaders - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is AgenciesWithCoverageListParams && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "AgenciesWithCoverageListParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -45,16 +33,22 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [AgenciesWithCoverageListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(agenciesWithCoverageListParams: AgenciesWithCoverageListParams) = apply { - additionalHeaders(agenciesWithCoverageListParams.additionalHeaders) - additionalQueryParams(agenciesWithCoverageListParams.additionalQueryParams) + additionalHeaders = agenciesWithCoverageListParams.additionalHeaders.toBuilder() + additionalQueryParams = agenciesWithCoverageListParams.additionalQueryParams.toBuilder() + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } fun additionalHeaders(additionalHeaders: Map>) = apply { @@ -67,29 +61,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -102,45 +109,55 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): AgenciesWithCoverageListParams = - AgenciesWithCoverageListParams( - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable() - ) + AgenciesWithCoverageListParams(additionalHeaders.build(), additionalQueryParams.build()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AgenciesWithCoverageListParams && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "AgenciesWithCoverageListParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgenciesWithCoverageListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgenciesWithCoverageListResponse.kt index 0349ee9..b2224d0 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgenciesWithCoverageListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgenciesWithCoverageListResponse.kt @@ -4,30 +4,34 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import org.onebusaway.core.ExcludeMissing import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = AgenciesWithCoverageListResponse.Builder::class) @NoAutoDetect class AgenciesWithCoverageListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -38,37 +42,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("version") @ExcludeMissing fun _version() = version - - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): AgenciesWithCoverageListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -78,116 +86,128 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [AgenciesWithCoverageListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(agenciesWithCoverageListResponse: AgenciesWithCoverageListResponse) = apply { - this.code = agenciesWithCoverageListResponse.code - this.currentTime = agenciesWithCoverageListResponse.currentTime - this.text = agenciesWithCoverageListResponse.text - this.version = agenciesWithCoverageListResponse.version - this.data = agenciesWithCoverageListResponse.data - additionalProperties(agenciesWithCoverageListResponse.additionalProperties) + code = agenciesWithCoverageListResponse.code + currentTime = agenciesWithCoverageListResponse.currentTime + text = agenciesWithCoverageListResponse.text + version = agenciesWithCoverageListResponse.version + data = agenciesWithCoverageListResponse.data + additionalProperties = + agenciesWithCoverageListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): AgenciesWithCoverageListResponse = AgenciesWithCoverageListResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val limitExceeded: JsonField, - private val list: JsonField>, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("limitExceeded") + @ExcludeMissing + private val limitExceeded: JsonField = JsonMissing.of(), + @JsonProperty("list") + @ExcludeMissing + private val list: JsonField> = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") fun list(): kotlin.collections.List = list.getRequired("list") fun references(): References = references.getRequired("references") - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + @JsonProperty("limitExceeded") + @ExcludeMissing + fun _limitExceeded(): JsonField = limitExceeded - @JsonProperty("list") @ExcludeMissing fun _list() = list + @JsonProperty("list") + @ExcludeMissing + fun _list(): JsonField> = list - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - limitExceeded() - list().forEach { it.validate() } - references().validate() - validated = true + if (validated) { + return@apply } + + limitExceeded() + list().forEach { it.validate() } + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -197,80 +217,104 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var limitExceeded: JsonField = JsonMissing.of() - private var list: JsonField> = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var limitExceeded: JsonField? = null + private var list: JsonField>? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.limitExceeded = data.limitExceeded - this.list = data.list - this.references = data.references - additionalProperties(data.additionalProperties) + limitExceeded = data.limitExceeded + list = data.list.map { it.toMutableList() } + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) - @JsonProperty("limitExceeded") - @ExcludeMissing fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } fun list(list: kotlin.collections.List) = list(JsonField.of(list)) - @JsonProperty("list") - @ExcludeMissing - fun list(list: JsonField>) = apply { this.list = list } + fun list(list: JsonField>) = apply { + this.list = list.map { it.toMutableList() } + } + + fun addList(list: List) = apply { + this.list = + (this.list ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(list) + } + } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = List.Builder::class) @NoAutoDetect class List + @JsonCreator private constructor( - private val agencyId: JsonField, - private val lat: JsonField, - private val latSpan: JsonField, - private val lon: JsonField, - private val lonSpan: JsonField, - private val additionalProperties: Map, + @JsonProperty("agencyId") + @ExcludeMissing + private val agencyId: JsonField = JsonMissing.of(), + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("latSpan") + @ExcludeMissing + private val latSpan: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonProperty("lonSpan") + @ExcludeMissing + private val lonSpan: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun agencyId(): String = agencyId.getRequired("agencyId") fun lat(): Double = lat.getRequired("lat") @@ -281,29 +325,33 @@ private constructor( fun lonSpan(): Double = lonSpan.getRequired("lonSpan") - @JsonProperty("agencyId") @ExcludeMissing fun _agencyId() = agencyId + @JsonProperty("agencyId") @ExcludeMissing fun _agencyId(): JsonField = agencyId - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat - @JsonProperty("latSpan") @ExcludeMissing fun _latSpan() = latSpan + @JsonProperty("latSpan") @ExcludeMissing fun _latSpan(): JsonField = latSpan - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon - @JsonProperty("lonSpan") @ExcludeMissing fun _lonSpan() = lonSpan + @JsonProperty("lonSpan") @ExcludeMissing fun _lonSpan(): JsonField = lonSpan @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): List = apply { - if (!validated) { - agencyId() - lat() - latSpan() - lon() - lonSpan() - validated = true + if (validated) { + return@apply } + + agencyId() + lat() + latSpan() + lon() + lonSpan() + validated = true } fun toBuilder() = Builder().from(this) @@ -313,63 +361,53 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [List]. */ + class Builder internal constructor() { - private var agencyId: JsonField = JsonMissing.of() - private var lat: JsonField = JsonMissing.of() - private var latSpan: JsonField = JsonMissing.of() - private var lon: JsonField = JsonMissing.of() - private var lonSpan: JsonField = JsonMissing.of() + private var agencyId: JsonField? = null + private var lat: JsonField? = null + private var latSpan: JsonField? = null + private var lon: JsonField? = null + private var lonSpan: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(list: List) = apply { - this.agencyId = list.agencyId - this.lat = list.lat - this.latSpan = list.latSpan - this.lon = list.lon - this.lonSpan = list.lonSpan - additionalProperties(list.additionalProperties) + agencyId = list.agencyId + lat = list.lat + latSpan = list.latSpan + lon = list.lon + lonSpan = list.lonSpan + additionalProperties = list.additionalProperties.toMutableMap() } fun agencyId(agencyId: String) = agencyId(JsonField.of(agencyId)) - @JsonProperty("agencyId") - @ExcludeMissing fun agencyId(agencyId: JsonField) = apply { this.agencyId = agencyId } fun lat(lat: Double) = lat(JsonField.of(lat)) - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } fun latSpan(latSpan: Double) = latSpan(JsonField.of(latSpan)) - @JsonProperty("latSpan") - @ExcludeMissing fun latSpan(latSpan: JsonField) = apply { this.latSpan = latSpan } fun lon(lon: Double) = lon(JsonField.of(lon)) - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun lonSpan(lonSpan: Double) = lonSpan(JsonField.of(lonSpan)) - @JsonProperty("lonSpan") - @ExcludeMissing fun lonSpan(lonSpan: JsonField) = apply { this.lonSpan = lonSpan } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -377,13 +415,21 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): List = List( - agencyId, - lat, - latSpan, - lon, - lonSpan, + checkRequired("agencyId", agencyId), + checkRequired("lat", lat), + checkRequired("latSpan", latSpan), + checkRequired("lon", lon), + checkRequired("lonSpan", lonSpan), additionalProperties.toImmutable(), ) } @@ -393,17 +439,14 @@ private constructor( return true } - return /* spotless:off */ other is List && this.agencyId == other.agencyId && this.lat == other.lat && this.latSpan == other.latSpan && this.lon == other.lon && this.lonSpan == other.lonSpan && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is List && agencyId == other.agencyId && lat == other.lat && latSpan == other.latSpan && lon == other.lon && lonSpan == other.lonSpan && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(agencyId, lat, latSpan, lon, lonSpan, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(agencyId, lat, latSpan, lon, lonSpan, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "List{agencyId=$agencyId, lat=$lat, latSpan=$latSpan, lon=$lon, lonSpan=$lonSpan, additionalProperties=$additionalProperties}" @@ -414,17 +457,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.limitExceeded == other.limitExceeded && this.list == other.list && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && list == other.list && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(limitExceeded, list, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{limitExceeded=$limitExceeded, list=$list, references=$references, additionalProperties=$additionalProperties}" @@ -435,17 +475,14 @@ private constructor( return true } - return /* spotless:off */ other is AgenciesWithCoverageListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is AgenciesWithCoverageListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "AgenciesWithCoverageListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgencyRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgencyRetrieveParams.kt index 69a140e..3dbe375 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgencyRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgencyRetrieveParams.kt @@ -2,25 +2,30 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Retrieve information for a specific transit agency identified by its unique ID. */ class AgencyRetrieveParams -constructor( +private constructor( private val agencyId: String, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun agencyId(): String = agencyId - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -29,25 +34,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is AgencyRetrieveParams && this.agencyId == other.agencyId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(agencyId, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "AgencyRetrieveParams{agencyId=$agencyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -55,22 +41,28 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [AgencyRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var agencyId: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(agencyRetrieveParams: AgencyRetrieveParams) = apply { - this.agencyId = agencyRetrieveParams.agencyId - additionalHeaders(agencyRetrieveParams.additionalHeaders) - additionalQueryParams(agencyRetrieveParams.additionalQueryParams) + agencyId = agencyRetrieveParams.agencyId + additionalHeaders = agencyRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = agencyRetrieveParams.additionalQueryParams.toBuilder() } fun agencyId(agencyId: String) = apply { this.agencyId = agencyId } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -81,29 +73,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -116,46 +121,59 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): AgencyRetrieveParams = AgencyRetrieveParams( - checkNotNull(agencyId) { "`agencyId` is required but was not set" }, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + checkRequired("agencyId", agencyId), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is AgencyRetrieveParams && agencyId == other.agencyId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(agencyId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "AgencyRetrieveParams{agencyId=$agencyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgencyRetrieveResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgencyRetrieveResponse.kt index 3dbad5f..15b8791 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgencyRetrieveResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgencyRetrieveResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = AgencyRetrieveResponse.Builder::class) @NoAutoDetect class AgencyRetrieveResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): AgencyRetrieveResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,115 +87,124 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [AgencyRetrieveResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(agencyRetrieveResponse: AgencyRetrieveResponse) = apply { - this.code = agencyRetrieveResponse.code - this.currentTime = agencyRetrieveResponse.currentTime - this.text = agencyRetrieveResponse.text - this.version = agencyRetrieveResponse.version - this.data = agencyRetrieveResponse.data - additionalProperties(agencyRetrieveResponse.additionalProperties) + code = agencyRetrieveResponse.code + currentTime = agencyRetrieveResponse.currentTime + text = agencyRetrieveResponse.text + version = agencyRetrieveResponse.version + data = agencyRetrieveResponse.data + additionalProperties = agencyRetrieveResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): AgencyRetrieveResponse = AgencyRetrieveResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val limitExceeded: JsonField, - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("limitExceeded") + @ExcludeMissing + private val limitExceeded: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun entry(): Entry = entry.getRequired("entry") fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") - fun entry(): Entry = entry.getRequired("entry") - fun references(): References = references.getRequired("references") - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("limitExceeded") + @ExcludeMissing + fun _limitExceeded(): JsonField = limitExceeded - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - limitExceeded() - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + limitExceeded() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -197,84 +214,111 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var limitExceeded: JsonField = JsonMissing.of() - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var limitExceeded: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.limitExceeded = data.limitExceeded - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + limitExceeded = data.limitExceeded + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } + fun entry(entry: Entry) = entry(JsonField.of(entry)) + + fun entry(entry: JsonField) = apply { this.entry = entry } + fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) - @JsonProperty("limitExceeded") - @ExcludeMissing fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } - fun entry(entry: Entry) = entry(JsonField.of(entry)) - - @JsonProperty("entry") - @ExcludeMissing - fun entry(entry: JsonField) = apply { this.entry = entry } - fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - limitExceeded, - entry, - references, + checkRequired("entry", entry), + checkRequired("limitExceeded", limitExceeded), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val disclaimer: JsonField, - private val email: JsonField, - private val fareUrl: JsonField, - private val id: JsonField, - private val lang: JsonField, - private val name: JsonField, - private val phone: JsonField, - private val privateService: JsonField, - private val timezone: JsonField, - private val url: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + private val name: JsonField = JsonMissing.of(), + @JsonProperty("timezone") + @ExcludeMissing + private val timezone: JsonField = JsonMissing.of(), + @JsonProperty("url") + @ExcludeMissing + private val url: JsonField = JsonMissing.of(), + @JsonProperty("disclaimer") + @ExcludeMissing + private val disclaimer: JsonField = JsonMissing.of(), + @JsonProperty("email") + @ExcludeMissing + private val email: JsonField = JsonMissing.of(), + @JsonProperty("fareUrl") + @ExcludeMissing + private val fareUrl: JsonField = JsonMissing.of(), + @JsonProperty("lang") + @ExcludeMissing + private val lang: JsonField = JsonMissing.of(), + @JsonProperty("phone") + @ExcludeMissing + private val phone: JsonField = JsonMissing.of(), + @JsonProperty("privateService") + @ExcludeMissing + private val privateService: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun id(): String = id.getRequired("id") + + fun name(): String = name.getRequired("name") + + fun timezone(): String = timezone.getRequired("timezone") + + fun url(): String = url.getRequired("url") fun disclaimer(): Optional = Optional.ofNullable(disclaimer.getNullable("disclaimer")) @@ -283,59 +327,59 @@ private constructor( fun fareUrl(): Optional = Optional.ofNullable(fareUrl.getNullable("fareUrl")) - fun id(): String = id.getRequired("id") - fun lang(): Optional = Optional.ofNullable(lang.getNullable("lang")) - fun name(): String = name.getRequired("name") - fun phone(): Optional = Optional.ofNullable(phone.getNullable("phone")) fun privateService(): Optional = Optional.ofNullable(privateService.getNullable("privateService")) - fun timezone(): String = timezone.getRequired("timezone") - - fun url(): String = url.getRequired("url") + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("disclaimer") @ExcludeMissing fun _disclaimer() = disclaimer + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("email") @ExcludeMissing fun _email() = email + @JsonProperty("timezone") @ExcludeMissing fun _timezone(): JsonField = timezone - @JsonProperty("fareUrl") @ExcludeMissing fun _fareUrl() = fareUrl + @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url - @JsonProperty("id") @ExcludeMissing fun _id() = id - - @JsonProperty("lang") @ExcludeMissing fun _lang() = lang + @JsonProperty("disclaimer") + @ExcludeMissing + fun _disclaimer(): JsonField = disclaimer - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("email") @ExcludeMissing fun _email(): JsonField = email - @JsonProperty("phone") @ExcludeMissing fun _phone() = phone + @JsonProperty("fareUrl") @ExcludeMissing fun _fareUrl(): JsonField = fareUrl - @JsonProperty("privateService") @ExcludeMissing fun _privateService() = privateService + @JsonProperty("lang") @ExcludeMissing fun _lang(): JsonField = lang - @JsonProperty("timezone") @ExcludeMissing fun _timezone() = timezone + @JsonProperty("phone") @ExcludeMissing fun _phone(): JsonField = phone - @JsonProperty("url") @ExcludeMissing fun _url() = url + @JsonProperty("privateService") + @ExcludeMissing + fun _privateService(): JsonField = privateService @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - disclaimer() - email() - fareUrl() - id() - lang() - name() - phone() - privateService() - timezone() - url() - validated = true + if (validated) { + return@apply } + + id() + name() + timezone() + url() + disclaimer() + email() + fareUrl() + lang() + phone() + privateService() + validated = true } fun toBuilder() = Builder().from(this) @@ -345,108 +389,88 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Entry]. */ + class Builder internal constructor() { + private var id: JsonField? = null + private var name: JsonField? = null + private var timezone: JsonField? = null + private var url: JsonField? = null private var disclaimer: JsonField = JsonMissing.of() private var email: JsonField = JsonMissing.of() private var fareUrl: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() private var lang: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() private var phone: JsonField = JsonMissing.of() private var privateService: JsonField = JsonMissing.of() - private var timezone: JsonField = JsonMissing.of() - private var url: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(entry: Entry) = apply { - this.disclaimer = entry.disclaimer - this.email = entry.email - this.fareUrl = entry.fareUrl - this.id = entry.id - this.lang = entry.lang - this.name = entry.name - this.phone = entry.phone - this.privateService = entry.privateService - this.timezone = entry.timezone - this.url = entry.url - additionalProperties(entry.additionalProperties) + id = entry.id + name = entry.name + timezone = entry.timezone + url = entry.url + disclaimer = entry.disclaimer + email = entry.email + fareUrl = entry.fareUrl + lang = entry.lang + phone = entry.phone + privateService = entry.privateService + additionalProperties = entry.additionalProperties.toMutableMap() } + fun id(id: String) = id(JsonField.of(id)) + + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + fun name(name: JsonField) = apply { this.name = name } + + fun timezone(timezone: String) = timezone(JsonField.of(timezone)) + + fun timezone(timezone: JsonField) = apply { this.timezone = timezone } + + fun url(url: String) = url(JsonField.of(url)) + + fun url(url: JsonField) = apply { this.url = url } + fun disclaimer(disclaimer: String) = disclaimer(JsonField.of(disclaimer)) - @JsonProperty("disclaimer") - @ExcludeMissing fun disclaimer(disclaimer: JsonField) = apply { this.disclaimer = disclaimer } fun email(email: String) = email(JsonField.of(email)) - @JsonProperty("email") - @ExcludeMissing fun email(email: JsonField) = apply { this.email = email } fun fareUrl(fareUrl: String) = fareUrl(JsonField.of(fareUrl)) - @JsonProperty("fareUrl") - @ExcludeMissing fun fareUrl(fareUrl: JsonField) = apply { this.fareUrl = fareUrl } - fun id(id: String) = id(JsonField.of(id)) - - @JsonProperty("id") - @ExcludeMissing - fun id(id: JsonField) = apply { this.id = id } - fun lang(lang: String) = lang(JsonField.of(lang)) - @JsonProperty("lang") - @ExcludeMissing fun lang(lang: JsonField) = apply { this.lang = lang } - fun name(name: String) = name(JsonField.of(name)) - - @JsonProperty("name") - @ExcludeMissing - fun name(name: JsonField) = apply { this.name = name } - fun phone(phone: String) = phone(JsonField.of(phone)) - @JsonProperty("phone") - @ExcludeMissing fun phone(phone: JsonField) = apply { this.phone = phone } fun privateService(privateService: Boolean) = privateService(JsonField.of(privateService)) - @JsonProperty("privateService") - @ExcludeMissing fun privateService(privateService: JsonField) = apply { this.privateService = privateService } - fun timezone(timezone: String) = timezone(JsonField.of(timezone)) - - @JsonProperty("timezone") - @ExcludeMissing - fun timezone(timezone: JsonField) = apply { this.timezone = timezone } - - fun url(url: String) = url(JsonField.of(url)) - - @JsonProperty("url") - @ExcludeMissing - fun url(url: JsonField) = apply { this.url = url } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -454,18 +478,26 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( + checkRequired("id", id), + checkRequired("name", name), + checkRequired("timezone", timezone), + checkRequired("url", url), disclaimer, email, fareUrl, - id, lang, - name, phone, privateService, - timezone, - url, additionalProperties.toImmutable(), ) } @@ -475,20 +507,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.disclaimer == other.disclaimer && this.email == other.email && this.fareUrl == other.fareUrl && this.id == other.id && this.lang == other.lang && this.name == other.name && this.phone == other.phone && this.privateService == other.privateService && this.timezone == other.timezone && this.url == other.url && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && id == other.id && name == other.name && timezone == other.timezone && url == other.url && disclaimer == other.disclaimer && email == other.email && fareUrl == other.fareUrl && lang == other.lang && phone == other.phone && privateService == other.privateService && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, name, timezone, url, disclaimer, email, fareUrl, lang, phone, privateService, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(disclaimer, email, fareUrl, id, lang, name, phone, privateService, timezone, url, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Entry{disclaimer=$disclaimer, email=$email, fareUrl=$fareUrl, id=$id, lang=$lang, name=$name, phone=$phone, privateService=$privateService, timezone=$timezone, url=$url, additionalProperties=$additionalProperties}" + "Entry{id=$id, name=$name, timezone=$timezone, url=$url, disclaimer=$disclaimer, email=$email, fareUrl=$fareUrl, lang=$lang, phone=$phone, privateService=$privateService, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -496,20 +525,17 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.limitExceeded == other.limitExceeded && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && limitExceeded == other.limitExceeded && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, limitExceeded, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(limitExceeded, entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Data{limitExceeded=$limitExceeded, entry=$entry, references=$references, additionalProperties=$additionalProperties}" + "Data{entry=$entry, limitExceeded=$limitExceeded, references=$references, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -517,17 +543,14 @@ private constructor( return true } - return /* spotless:off */ other is AgencyRetrieveResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is AgencyRetrieveResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "AgencyRetrieveResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureListParams.kt index 10d7678..8264ee2 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureListParams.kt @@ -2,46 +2,53 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.time.OffsetDateTime import java.time.format.DateTimeFormatter import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** arrivals-and-departures-for-stop */ class ArrivalAndDepartureListParams -constructor( +private constructor( private val stopId: String, private val minutesAfter: Long?, private val minutesBefore: Long?, private val time: OffsetDateTime?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun stopId(): String = stopId + /** Include vehicles arriving or departing in the next n minutes. */ fun minutesAfter(): Optional = Optional.ofNullable(minutesAfter) + /** Include vehicles having arrived or departed in the previous n minutes. */ fun minutesBefore(): Optional = Optional.ofNullable(minutesBefore) + /** The specific time for querying the system status. */ fun time(): Optional = Optional.ofNullable(time) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.minutesAfter?.let { params.put("minutesAfter", listOf(it.toString())) } - this.minutesBefore?.let { params.put("minutesBefore", listOf(it.toString())) } + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.minutesAfter?.let { queryParams.put("minutesAfter", listOf(it.toString())) } + this.minutesBefore?.let { queryParams.put("minutesBefore", listOf(it.toString())) } this.time?.let { - params.put("time", listOf(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(it))) + queryParams.put("time", listOf(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(it))) } - params.putAll(additionalQueryParams) - return params.toImmutable() + queryParams.putAll(additionalQueryParams) + return queryParams.build() } fun getPathParam(index: Int): String { @@ -51,25 +58,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ArrivalAndDepartureListParams && this.stopId == other.stopId && this.minutesAfter == other.minutesAfter && this.minutesBefore == other.minutesBefore && this.time == other.time && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(stopId, minutesAfter, minutesBefore, time, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "ArrivalAndDepartureListParams{stopId=$stopId, minutesAfter=$minutesAfter, minutesBefore=$minutesBefore, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -77,36 +65,61 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [ArrivalAndDepartureListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var stopId: String? = null private var minutesAfter: Long? = null private var minutesBefore: Long? = null private var time: OffsetDateTime? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(arrivalAndDepartureListParams: ArrivalAndDepartureListParams) = apply { - this.stopId = arrivalAndDepartureListParams.stopId - this.minutesAfter = arrivalAndDepartureListParams.minutesAfter - this.minutesBefore = arrivalAndDepartureListParams.minutesBefore - this.time = arrivalAndDepartureListParams.time - additionalHeaders(arrivalAndDepartureListParams.additionalHeaders) - additionalQueryParams(arrivalAndDepartureListParams.additionalQueryParams) + stopId = arrivalAndDepartureListParams.stopId + minutesAfter = arrivalAndDepartureListParams.minutesAfter + minutesBefore = arrivalAndDepartureListParams.minutesBefore + time = arrivalAndDepartureListParams.time + additionalHeaders = arrivalAndDepartureListParams.additionalHeaders.toBuilder() + additionalQueryParams = arrivalAndDepartureListParams.additionalQueryParams.toBuilder() } fun stopId(stopId: String) = apply { this.stopId = stopId } /** Include vehicles arriving or departing in the next n minutes. */ - fun minutesAfter(minutesAfter: Long) = apply { this.minutesAfter = minutesAfter } + fun minutesAfter(minutesAfter: Long?) = apply { this.minutesAfter = minutesAfter } + + /** Include vehicles arriving or departing in the next n minutes. */ + fun minutesAfter(minutesAfter: Long) = minutesAfter(minutesAfter as Long?) + + /** Include vehicles arriving or departing in the next n minutes. */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun minutesAfter(minutesAfter: Optional) = + minutesAfter(minutesAfter.orElse(null) as Long?) /** Include vehicles having arrived or departed in the previous n minutes. */ - fun minutesBefore(minutesBefore: Long) = apply { this.minutesBefore = minutesBefore } + fun minutesBefore(minutesBefore: Long?) = apply { this.minutesBefore = minutesBefore } + + /** Include vehicles having arrived or departed in the previous n minutes. */ + fun minutesBefore(minutesBefore: Long) = minutesBefore(minutesBefore as Long?) + + /** Include vehicles having arrived or departed in the previous n minutes. */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun minutesBefore(minutesBefore: Optional) = + minutesBefore(minutesBefore.orElse(null) as Long?) /** The specific time for querying the system status. */ - fun time(time: OffsetDateTime) = apply { this.time = time } + fun time(time: OffsetDateTime?) = apply { this.time = time } + + /** The specific time for querying the system status. */ + fun time(time: Optional) = time(time.orElse(null)) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -118,29 +131,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -153,49 +179,62 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): ArrivalAndDepartureListParams = ArrivalAndDepartureListParams( - checkNotNull(stopId) { "`stopId` is required but was not set" }, + checkRequired("stopId", stopId), minutesAfter, minutesBefore, time, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ArrivalAndDepartureListParams && stopId == other.stopId && minutesAfter == other.minutesAfter && minutesBefore == other.minutesBefore && time == other.time && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(stopId, minutesAfter, minutesBefore, time, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "ArrivalAndDepartureListParams{stopId=$stopId, minutesAfter=$minutesAfter, minutesBefore=$minutesBefore, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureListResponse.kt index 1bd13ba..a5dff47 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureListResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = ArrivalAndDepartureListResponse.Builder::class) @NoAutoDetect class ArrivalAndDepartureListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): ArrivalAndDepartureListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,110 +87,116 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [ArrivalAndDepartureListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(arrivalAndDepartureListResponse: ArrivalAndDepartureListResponse) = apply { - this.code = arrivalAndDepartureListResponse.code - this.currentTime = arrivalAndDepartureListResponse.currentTime - this.text = arrivalAndDepartureListResponse.text - this.version = arrivalAndDepartureListResponse.version - this.data = arrivalAndDepartureListResponse.data - additionalProperties(arrivalAndDepartureListResponse.additionalProperties) + code = arrivalAndDepartureListResponse.code + currentTime = arrivalAndDepartureListResponse.currentTime + text = arrivalAndDepartureListResponse.text + version = arrivalAndDepartureListResponse.version + data = arrivalAndDepartureListResponse.data + additionalProperties = + arrivalAndDepartureListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): ArrivalAndDepartureListResponse = ArrivalAndDepartureListResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") fun references(): References = references.getRequired("references") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -192,81 +206,90 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val arrivalsAndDepartures: JsonField>, - private val additionalProperties: Map, + @JsonProperty("arrivalsAndDepartures") + @ExcludeMissing + private val arrivalsAndDepartures: JsonField> = + JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun arrivalsAndDepartures(): List = arrivalsAndDepartures.getRequired("arrivalsAndDepartures") @JsonProperty("arrivalsAndDepartures") @ExcludeMissing - fun _arrivalsAndDepartures() = arrivalsAndDepartures + fun _arrivalsAndDepartures(): JsonField> = + arrivalsAndDepartures @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - arrivalsAndDepartures().forEach { it.validate() } - validated = true + if (validated) { + return@apply } + + arrivalsAndDepartures().forEach { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -276,35 +299,48 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Entry]. */ + class Builder internal constructor() { - private var arrivalsAndDepartures: JsonField> = - JsonMissing.of() + private var arrivalsAndDepartures: JsonField>? = + null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(entry: Entry) = apply { - this.arrivalsAndDepartures = entry.arrivalsAndDepartures - additionalProperties(entry.additionalProperties) + arrivalsAndDepartures = entry.arrivalsAndDepartures.map { it.toMutableList() } + additionalProperties = entry.additionalProperties.toMutableMap() } fun arrivalsAndDepartures(arrivalsAndDepartures: List) = arrivalsAndDepartures(JsonField.of(arrivalsAndDepartures)) - @JsonProperty("arrivalsAndDepartures") - @ExcludeMissing fun arrivalsAndDepartures( arrivalsAndDepartures: JsonField> - ) = apply { this.arrivalsAndDepartures = arrivalsAndDepartures } + ) = apply { + this.arrivalsAndDepartures = arrivalsAndDepartures.map { it.toMutableList() } + } + + fun addArrivalsAndDeparture(arrivalsAndDeparture: ArrivalsAndDeparture) = apply { + arrivalsAndDepartures = + (arrivalsAndDepartures ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(arrivalsAndDeparture) + } + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -312,60 +348,133 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( - arrivalsAndDepartures.map { it.toImmutable() }, + checkRequired("arrivalsAndDepartures", arrivalsAndDepartures).map { + it.toImmutable() + }, additionalProperties.toImmutable() ) } - @JsonDeserialize(builder = ArrivalsAndDeparture.Builder::class) @NoAutoDetect class ArrivalsAndDeparture + @JsonCreator private constructor( - private val actualTrack: JsonField, - private val arrivalEnabled: JsonField, - private val blockTripSequence: JsonField, - private val departureEnabled: JsonField, - private val distanceFromStop: JsonField, - private val frequency: JsonField, - private val historicalOccupancy: JsonField, - private val lastUpdateTime: JsonField, - private val numberOfStopsAway: JsonField, - private val occupancyStatus: JsonField, - private val predicted: JsonField, - private val predictedArrivalInterval: JsonField, - private val predictedArrivalTime: JsonField, - private val predictedDepartureInterval: JsonField, - private val predictedDepartureTime: JsonField, - private val predictedOccupancy: JsonField, - private val routeId: JsonField, - private val routeLongName: JsonField, - private val routeShortName: JsonField, - private val scheduledArrivalInterval: JsonField, - private val scheduledArrivalTime: JsonField, - private val scheduledDepartureInterval: JsonField, - private val scheduledDepartureTime: JsonField, - private val scheduledTrack: JsonField, - private val serviceDate: JsonField, - private val situationIds: JsonField>, - private val status: JsonField, - private val stopId: JsonField, - private val stopSequence: JsonField, - private val totalStopsInTrip: JsonField, - private val tripHeadsign: JsonField, - private val tripId: JsonField, - private val tripStatus: JsonField, - private val vehicleId: JsonField, - private val additionalProperties: Map, + @JsonProperty("arrivalEnabled") + @ExcludeMissing + private val arrivalEnabled: JsonField = JsonMissing.of(), + @JsonProperty("blockTripSequence") + @ExcludeMissing + private val blockTripSequence: JsonField = JsonMissing.of(), + @JsonProperty("departureEnabled") + @ExcludeMissing + private val departureEnabled: JsonField = JsonMissing.of(), + @JsonProperty("numberOfStopsAway") + @ExcludeMissing + private val numberOfStopsAway: JsonField = JsonMissing.of(), + @JsonProperty("predictedArrivalTime") + @ExcludeMissing + private val predictedArrivalTime: JsonField = JsonMissing.of(), + @JsonProperty("predictedDepartureTime") + @ExcludeMissing + private val predictedDepartureTime: JsonField = JsonMissing.of(), + @JsonProperty("routeId") + @ExcludeMissing + private val routeId: JsonField = JsonMissing.of(), + @JsonProperty("scheduledArrivalTime") + @ExcludeMissing + private val scheduledArrivalTime: JsonField = JsonMissing.of(), + @JsonProperty("scheduledDepartureTime") + @ExcludeMissing + private val scheduledDepartureTime: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonProperty("stopId") + @ExcludeMissing + private val stopId: JsonField = JsonMissing.of(), + @JsonProperty("stopSequence") + @ExcludeMissing + private val stopSequence: JsonField = JsonMissing.of(), + @JsonProperty("totalStopsInTrip") + @ExcludeMissing + private val totalStopsInTrip: JsonField = JsonMissing.of(), + @JsonProperty("tripHeadsign") + @ExcludeMissing + private val tripHeadsign: JsonField = JsonMissing.of(), + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), + @JsonProperty("vehicleId") + @ExcludeMissing + private val vehicleId: JsonField = JsonMissing.of(), + @JsonProperty("actualTrack") + @ExcludeMissing + private val actualTrack: JsonField = JsonMissing.of(), + @JsonProperty("distanceFromStop") + @ExcludeMissing + private val distanceFromStop: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonProperty("historicalOccupancy") + @ExcludeMissing + private val historicalOccupancy: JsonField = JsonMissing.of(), + @JsonProperty("lastUpdateTime") + @ExcludeMissing + private val lastUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("occupancyStatus") + @ExcludeMissing + private val occupancyStatus: JsonField = JsonMissing.of(), + @JsonProperty("predicted") + @ExcludeMissing + private val predicted: JsonField = JsonMissing.of(), + @JsonProperty("predictedArrivalInterval") + @ExcludeMissing + private val predictedArrivalInterval: JsonField = JsonMissing.of(), + @JsonProperty("predictedDepartureInterval") + @ExcludeMissing + private val predictedDepartureInterval: JsonField = JsonMissing.of(), + @JsonProperty("predictedOccupancy") + @ExcludeMissing + private val predictedOccupancy: JsonField = JsonMissing.of(), + @JsonProperty("routeLongName") + @ExcludeMissing + private val routeLongName: JsonField = JsonMissing.of(), + @JsonProperty("routeShortName") + @ExcludeMissing + private val routeShortName: JsonField = JsonMissing.of(), + @JsonProperty("scheduledArrivalInterval") + @ExcludeMissing + private val scheduledArrivalInterval: JsonField = JsonMissing.of(), + @JsonProperty("scheduledDepartureInterval") + @ExcludeMissing + private val scheduledDepartureInterval: JsonField = JsonMissing.of(), + @JsonProperty("scheduledTrack") + @ExcludeMissing + private val scheduledTrack: JsonField = JsonMissing.of(), + @JsonProperty("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonProperty("tripStatus") + @ExcludeMissing + private val tripStatus: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - /** The actual track information of the arriving transit vehicle. */ - fun actualTrack(): Optional = - Optional.ofNullable(actualTrack.getNullable("actualTrack")) - /** Indicates if riders can arrive on this transit vehicle. */ fun arrivalEnabled(): Boolean = arrivalEnabled.getRequired("arrivalEnabled") @@ -375,6 +484,71 @@ private constructor( /** Indicates if riders can depart from this transit vehicle. */ fun departureEnabled(): Boolean = departureEnabled.getRequired("departureEnabled") + /** + * Number of stops between the arriving transit vehicle and the current stop + * (excluding the current stop). + */ + fun numberOfStopsAway(): Long = numberOfStopsAway.getRequired("numberOfStopsAway") + + /** + * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time + * available). + */ + fun predictedArrivalTime(): Long = + predictedArrivalTime.getRequired("predictedArrivalTime") + + /** + * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time + * available). + */ + fun predictedDepartureTime(): Long = + predictedDepartureTime.getRequired("predictedDepartureTime") + + /** The ID of the route for the arriving vehicle. */ + fun routeId(): String = routeId.getRequired("routeId") + + /** Scheduled arrival time, in milliseconds since Unix epoch. */ + fun scheduledArrivalTime(): Long = + scheduledArrivalTime.getRequired("scheduledArrivalTime") + + /** Scheduled departure time, in milliseconds since Unix epoch. */ + fun scheduledDepartureTime(): Long = + scheduledDepartureTime.getRequired("scheduledDepartureTime") + + /** + * Time, in milliseconds since the Unix epoch, of midnight for the start of the + * service date for the trip. + */ + fun serviceDate(): Long = serviceDate.getRequired("serviceDate") + + /** The ID of the stop the vehicle is arriving at. */ + fun stopId(): String = stopId.getRequired("stopId") + + /** + * Index of the stop into the sequence of stops that make up the trip for this + * arrival. + */ + fun stopSequence(): Long = stopSequence.getRequired("stopSequence") + + /** Total number of stops visited on the trip for this arrival. */ + fun totalStopsInTrip(): Long = totalStopsInTrip.getRequired("totalStopsInTrip") + + /** + * Optional trip headsign that potentially overrides the trip headsign in the + * referenced trip element. + */ + fun tripHeadsign(): String = tripHeadsign.getRequired("tripHeadsign") + + /** The ID of the trip for the arriving vehicle. */ + fun tripId(): String = tripId.getRequired("tripId") + + /** ID of the transit vehicle serving this trip. */ + fun vehicleId(): String = vehicleId.getRequired("vehicleId") + + /** The actual track information of the arriving transit vehicle. */ + fun actualTrack(): Optional = + Optional.ofNullable(actualTrack.getNullable("actualTrack")) + /** Distance of the arriving transit vehicle from the stop, in meters. */ fun distanceFromStop(): Optional = Optional.ofNullable(distanceFromStop.getNullable("distanceFromStop")) @@ -391,12 +565,6 @@ private constructor( fun lastUpdateTime(): Optional = Optional.ofNullable(lastUpdateTime.getNullable("lastUpdateTime")) - /** - * Number of stops between the arriving transit vehicle and the current stop - * (excluding the current stop). - */ - fun numberOfStopsAway(): Long = numberOfStopsAway.getRequired("numberOfStopsAway") - /** Current occupancy status of the transit vehicle. */ fun occupancyStatus(): Optional = Optional.ofNullable(occupancyStatus.getNullable("occupancyStatus")) @@ -411,33 +579,16 @@ private constructor( predictedArrivalInterval.getNullable("predictedArrivalInterval") ) - /** - * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time - * available). - */ - fun predictedArrivalTime(): Long = - predictedArrivalTime.getRequired("predictedArrivalTime") - /** Interval for predicted departure time, if available. */ fun predictedDepartureInterval(): Optional = Optional.ofNullable( predictedDepartureInterval.getNullable("predictedDepartureInterval") ) - /** - * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time - * available). - */ - fun predictedDepartureTime(): Long = - predictedDepartureTime.getRequired("predictedDepartureTime") - /** Predicted occupancy status of the transit vehicle. */ fun predictedOccupancy(): Optional = Optional.ofNullable(predictedOccupancy.getNullable("predictedOccupancy")) - /** The ID of the route for the arriving vehicle. */ - fun routeId(): String = routeId.getRequired("routeId") - /** * Optional route long name that potentially overrides the route long name in the * referenced route element. @@ -458,30 +609,16 @@ private constructor( scheduledArrivalInterval.getNullable("scheduledArrivalInterval") ) - /** Scheduled arrival time, in milliseconds since Unix epoch. */ - fun scheduledArrivalTime(): Long = - scheduledArrivalTime.getRequired("scheduledArrivalTime") - /** Interval for scheduled departure time. */ fun scheduledDepartureInterval(): Optional = Optional.ofNullable( scheduledDepartureInterval.getNullable("scheduledDepartureInterval") ) - /** Scheduled departure time, in milliseconds since Unix epoch. */ - fun scheduledDepartureTime(): Long = - scheduledDepartureTime.getRequired("scheduledDepartureTime") - /** Scheduled track information of the arriving transit vehicle. */ fun scheduledTrack(): Optional = Optional.ofNullable(scheduledTrack.getNullable("scheduledTrack")) - /** - * Time, in milliseconds since the Unix epoch, of midnight for the start of the - * service date for the trip. - */ - fun serviceDate(): Long = serviceDate.getRequired("serviceDate") - /** References to situation elements (if any) applicable to this arrival. */ fun situationIds(): Optional> = Optional.ofNullable(situationIds.getNullable("situationIds")) @@ -489,125 +626,159 @@ private constructor( /** Current status of the arrival. */ fun status(): Optional = Optional.ofNullable(status.getNullable("status")) - /** The ID of the stop the vehicle is arriving at. */ - fun stopId(): String = stopId.getRequired("stopId") + /** Trip-specific status for the arriving transit vehicle. */ + fun tripStatus(): Optional = + Optional.ofNullable(tripStatus.getNullable("tripStatus")) - /** - * Index of the stop into the sequence of stops that make up the trip for this - * arrival. - */ - fun stopSequence(): Long = stopSequence.getRequired("stopSequence") + /** Indicates if riders can arrive on this transit vehicle. */ + @JsonProperty("arrivalEnabled") + @ExcludeMissing + fun _arrivalEnabled(): JsonField = arrivalEnabled - /** Total number of stops visited on the trip for this arrival. */ - fun totalStopsInTrip(): Long = totalStopsInTrip.getRequired("totalStopsInTrip") + /** Index of this arrival’s trip into the sequence of trips for the active block. */ + @JsonProperty("blockTripSequence") + @ExcludeMissing + fun _blockTripSequence(): JsonField = blockTripSequence - /** - * Optional trip headsign that potentially overrides the trip headsign in the - * referenced trip element. + /** Indicates if riders can depart from this transit vehicle. */ + @JsonProperty("departureEnabled") + @ExcludeMissing + fun _departureEnabled(): JsonField = departureEnabled + + /** + * Number of stops between the arriving transit vehicle and the current stop + * (excluding the current stop). */ - fun tripHeadsign(): String = tripHeadsign.getRequired("tripHeadsign") + @JsonProperty("numberOfStopsAway") + @ExcludeMissing + fun _numberOfStopsAway(): JsonField = numberOfStopsAway - /** The ID of the trip for the arriving vehicle. */ - fun tripId(): String = tripId.getRequired("tripId") + /** + * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time + * available). + */ + @JsonProperty("predictedArrivalTime") + @ExcludeMissing + fun _predictedArrivalTime(): JsonField = predictedArrivalTime - /** Trip-specific status for the arriving transit vehicle. */ - fun tripStatus(): Optional = - Optional.ofNullable(tripStatus.getNullable("tripStatus")) + /** + * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time + * available). + */ + @JsonProperty("predictedDepartureTime") + @ExcludeMissing + fun _predictedDepartureTime(): JsonField = predictedDepartureTime - /** ID of the transit vehicle serving this trip. */ - fun vehicleId(): String = vehicleId.getRequired("vehicleId") + /** The ID of the route for the arriving vehicle. */ + @JsonProperty("routeId") @ExcludeMissing fun _routeId(): JsonField = routeId - /** The actual track information of the arriving transit vehicle. */ - @JsonProperty("actualTrack") @ExcludeMissing fun _actualTrack() = actualTrack + /** Scheduled arrival time, in milliseconds since Unix epoch. */ + @JsonProperty("scheduledArrivalTime") + @ExcludeMissing + fun _scheduledArrivalTime(): JsonField = scheduledArrivalTime - /** Indicates if riders can arrive on this transit vehicle. */ - @JsonProperty("arrivalEnabled") + /** Scheduled departure time, in milliseconds since Unix epoch. */ + @JsonProperty("scheduledDepartureTime") @ExcludeMissing - fun _arrivalEnabled() = arrivalEnabled + fun _scheduledDepartureTime(): JsonField = scheduledDepartureTime - /** Index of this arrival’s trip into the sequence of trips for the active block. */ - @JsonProperty("blockTripSequence") + /** + * Time, in milliseconds since the Unix epoch, of midnight for the start of the + * service date for the trip. + */ + @JsonProperty("serviceDate") @ExcludeMissing - fun _blockTripSequence() = blockTripSequence + fun _serviceDate(): JsonField = serviceDate - /** Indicates if riders can depart from this transit vehicle. */ - @JsonProperty("departureEnabled") + /** The ID of the stop the vehicle is arriving at. */ + @JsonProperty("stopId") @ExcludeMissing fun _stopId(): JsonField = stopId + + /** + * Index of the stop into the sequence of stops that make up the trip for this + * arrival. + */ + @JsonProperty("stopSequence") + @ExcludeMissing + fun _stopSequence(): JsonField = stopSequence + + /** Total number of stops visited on the trip for this arrival. */ + @JsonProperty("totalStopsInTrip") + @ExcludeMissing + fun _totalStopsInTrip(): JsonField = totalStopsInTrip + + /** + * Optional trip headsign that potentially overrides the trip headsign in the + * referenced trip element. + */ + @JsonProperty("tripHeadsign") + @ExcludeMissing + fun _tripHeadsign(): JsonField = tripHeadsign + + /** The ID of the trip for the arriving vehicle. */ + @JsonProperty("tripId") @ExcludeMissing fun _tripId(): JsonField = tripId + + /** ID of the transit vehicle serving this trip. */ + @JsonProperty("vehicleId") @ExcludeMissing - fun _departureEnabled() = departureEnabled + fun _vehicleId(): JsonField = vehicleId + + /** The actual track information of the arriving transit vehicle. */ + @JsonProperty("actualTrack") + @ExcludeMissing + fun _actualTrack(): JsonField = actualTrack /** Distance of the arriving transit vehicle from the stop, in meters. */ @JsonProperty("distanceFromStop") @ExcludeMissing - fun _distanceFromStop() = distanceFromStop + fun _distanceFromStop(): JsonField = distanceFromStop /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency /** Historical occupancy information of the transit vehicle. */ @JsonProperty("historicalOccupancy") @ExcludeMissing - fun _historicalOccupancy() = historicalOccupancy + fun _historicalOccupancy(): JsonField = historicalOccupancy /** Timestamp of the last update time for this arrival. */ @JsonProperty("lastUpdateTime") @ExcludeMissing - fun _lastUpdateTime() = lastUpdateTime - - /** - * Number of stops between the arriving transit vehicle and the current stop - * (excluding the current stop). - */ - @JsonProperty("numberOfStopsAway") - @ExcludeMissing - fun _numberOfStopsAway() = numberOfStopsAway + fun _lastUpdateTime(): JsonField = lastUpdateTime /** Current occupancy status of the transit vehicle. */ @JsonProperty("occupancyStatus") @ExcludeMissing - fun _occupancyStatus() = occupancyStatus + fun _occupancyStatus(): JsonField = occupancyStatus /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") @ExcludeMissing fun _predicted() = predicted + @JsonProperty("predicted") + @ExcludeMissing + fun _predicted(): JsonField = predicted /** Interval for predicted arrival time, if available. */ @JsonProperty("predictedArrivalInterval") @ExcludeMissing - fun _predictedArrivalInterval() = predictedArrivalInterval - - /** - * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time - * available). - */ - @JsonProperty("predictedArrivalTime") - @ExcludeMissing - fun _predictedArrivalTime() = predictedArrivalTime + fun _predictedArrivalInterval(): JsonField = predictedArrivalInterval /** Interval for predicted departure time, if available. */ @JsonProperty("predictedDepartureInterval") @ExcludeMissing - fun _predictedDepartureInterval() = predictedDepartureInterval - - /** - * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time - * available). - */ - @JsonProperty("predictedDepartureTime") - @ExcludeMissing - fun _predictedDepartureTime() = predictedDepartureTime + fun _predictedDepartureInterval(): JsonField = predictedDepartureInterval /** Predicted occupancy status of the transit vehicle. */ @JsonProperty("predictedOccupancy") @ExcludeMissing - fun _predictedOccupancy() = predictedOccupancy - - /** The ID of the route for the arriving vehicle. */ - @JsonProperty("routeId") @ExcludeMissing fun _routeId() = routeId + fun _predictedOccupancy(): JsonField = predictedOccupancy /** * Optional route long name that potentially overrides the route long name in the * referenced route element. */ - @JsonProperty("routeLongName") @ExcludeMissing fun _routeLongName() = routeLongName + @JsonProperty("routeLongName") + @ExcludeMissing + fun _routeLongName(): JsonField = routeLongName /** * Optional route short name that potentially overrides the route short name in the @@ -615,116 +786,82 @@ private constructor( */ @JsonProperty("routeShortName") @ExcludeMissing - fun _routeShortName() = routeShortName + fun _routeShortName(): JsonField = routeShortName /** Interval for scheduled arrival time. */ @JsonProperty("scheduledArrivalInterval") @ExcludeMissing - fun _scheduledArrivalInterval() = scheduledArrivalInterval - - /** Scheduled arrival time, in milliseconds since Unix epoch. */ - @JsonProperty("scheduledArrivalTime") - @ExcludeMissing - fun _scheduledArrivalTime() = scheduledArrivalTime + fun _scheduledArrivalInterval(): JsonField = scheduledArrivalInterval /** Interval for scheduled departure time. */ @JsonProperty("scheduledDepartureInterval") @ExcludeMissing - fun _scheduledDepartureInterval() = scheduledDepartureInterval - - /** Scheduled departure time, in milliseconds since Unix epoch. */ - @JsonProperty("scheduledDepartureTime") - @ExcludeMissing - fun _scheduledDepartureTime() = scheduledDepartureTime + fun _scheduledDepartureInterval(): JsonField = scheduledDepartureInterval /** Scheduled track information of the arriving transit vehicle. */ @JsonProperty("scheduledTrack") @ExcludeMissing - fun _scheduledTrack() = scheduledTrack - - /** - * Time, in milliseconds since the Unix epoch, of midnight for the start of the - * service date for the trip. - */ - @JsonProperty("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate + fun _scheduledTrack(): JsonField = scheduledTrack /** References to situation elements (if any) applicable to this arrival. */ - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds - - /** Current status of the arrival. */ - @JsonProperty("status") @ExcludeMissing fun _status() = status - - /** The ID of the stop the vehicle is arriving at. */ - @JsonProperty("stopId") @ExcludeMissing fun _stopId() = stopId - - /** - * Index of the stop into the sequence of stops that make up the trip for this - * arrival. - */ - @JsonProperty("stopSequence") @ExcludeMissing fun _stopSequence() = stopSequence - - /** Total number of stops visited on the trip for this arrival. */ - @JsonProperty("totalStopsInTrip") + @JsonProperty("situationIds") @ExcludeMissing - fun _totalStopsInTrip() = totalStopsInTrip - - /** - * Optional trip headsign that potentially overrides the trip headsign in the - * referenced trip element. - */ - @JsonProperty("tripHeadsign") @ExcludeMissing fun _tripHeadsign() = tripHeadsign + fun _situationIds(): JsonField> = situationIds - /** The ID of the trip for the arriving vehicle. */ - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + /** Current status of the arrival. */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status /** Trip-specific status for the arriving transit vehicle. */ - @JsonProperty("tripStatus") @ExcludeMissing fun _tripStatus() = tripStatus - - /** ID of the transit vehicle serving this trip. */ - @JsonProperty("vehicleId") @ExcludeMissing fun _vehicleId() = vehicleId + @JsonProperty("tripStatus") + @ExcludeMissing + fun _tripStatus(): JsonField = tripStatus @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ArrivalsAndDeparture = apply { - if (!validated) { - actualTrack() - arrivalEnabled() - blockTripSequence() - departureEnabled() - distanceFromStop() - frequency() - historicalOccupancy() - lastUpdateTime() - numberOfStopsAway() - occupancyStatus() - predicted() - predictedArrivalInterval() - predictedArrivalTime() - predictedDepartureInterval() - predictedDepartureTime() - predictedOccupancy() - routeId() - routeLongName() - routeShortName() - scheduledArrivalInterval() - scheduledArrivalTime() - scheduledDepartureInterval() - scheduledDepartureTime() - scheduledTrack() - serviceDate() - situationIds() - status() - stopId() - stopSequence() - totalStopsInTrip() - tripHeadsign() - tripId() - tripStatus().map { it.validate() } - vehicleId() - validated = true + if (validated) { + return@apply } + + arrivalEnabled() + blockTripSequence() + departureEnabled() + numberOfStopsAway() + predictedArrivalTime() + predictedDepartureTime() + routeId() + scheduledArrivalTime() + scheduledDepartureTime() + serviceDate() + stopId() + stopSequence() + totalStopsInTrip() + tripHeadsign() + tripId() + vehicleId() + actualTrack() + distanceFromStop() + frequency() + historicalOccupancy() + lastUpdateTime() + occupancyStatus() + predicted() + predictedArrivalInterval() + predictedDepartureInterval() + predictedOccupancy() + routeLongName() + routeShortName() + scheduledArrivalInterval() + scheduledDepartureInterval() + scheduledTrack() + situationIds() + status() + tripStatus().ifPresent { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -734,95 +871,83 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - + /** A builder for [ArrivalsAndDeparture]. */ + class Builder internal constructor() { + + private var arrivalEnabled: JsonField? = null + private var blockTripSequence: JsonField? = null + private var departureEnabled: JsonField? = null + private var numberOfStopsAway: JsonField? = null + private var predictedArrivalTime: JsonField? = null + private var predictedDepartureTime: JsonField? = null + private var routeId: JsonField? = null + private var scheduledArrivalTime: JsonField? = null + private var scheduledDepartureTime: JsonField? = null + private var serviceDate: JsonField? = null + private var stopId: JsonField? = null + private var stopSequence: JsonField? = null + private var totalStopsInTrip: JsonField? = null + private var tripHeadsign: JsonField? = null + private var tripId: JsonField? = null + private var vehicleId: JsonField? = null private var actualTrack: JsonField = JsonMissing.of() - private var arrivalEnabled: JsonField = JsonMissing.of() - private var blockTripSequence: JsonField = JsonMissing.of() - private var departureEnabled: JsonField = JsonMissing.of() private var distanceFromStop: JsonField = JsonMissing.of() private var frequency: JsonField = JsonMissing.of() private var historicalOccupancy: JsonField = JsonMissing.of() private var lastUpdateTime: JsonField = JsonMissing.of() - private var numberOfStopsAway: JsonField = JsonMissing.of() private var occupancyStatus: JsonField = JsonMissing.of() private var predicted: JsonField = JsonMissing.of() private var predictedArrivalInterval: JsonField = JsonMissing.of() - private var predictedArrivalTime: JsonField = JsonMissing.of() private var predictedDepartureInterval: JsonField = JsonMissing.of() - private var predictedDepartureTime: JsonField = JsonMissing.of() private var predictedOccupancy: JsonField = JsonMissing.of() - private var routeId: JsonField = JsonMissing.of() private var routeLongName: JsonField = JsonMissing.of() private var routeShortName: JsonField = JsonMissing.of() private var scheduledArrivalInterval: JsonField = JsonMissing.of() - private var scheduledArrivalTime: JsonField = JsonMissing.of() private var scheduledDepartureInterval: JsonField = JsonMissing.of() - private var scheduledDepartureTime: JsonField = JsonMissing.of() private var scheduledTrack: JsonField = JsonMissing.of() - private var serviceDate: JsonField = JsonMissing.of() - private var situationIds: JsonField> = JsonMissing.of() + private var situationIds: JsonField>? = null private var status: JsonField = JsonMissing.of() - private var stopId: JsonField = JsonMissing.of() - private var stopSequence: JsonField = JsonMissing.of() - private var totalStopsInTrip: JsonField = JsonMissing.of() - private var tripHeadsign: JsonField = JsonMissing.of() - private var tripId: JsonField = JsonMissing.of() private var tripStatus: JsonField = JsonMissing.of() - private var vehicleId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(arrivalsAndDeparture: ArrivalsAndDeparture) = apply { - this.actualTrack = arrivalsAndDeparture.actualTrack - this.arrivalEnabled = arrivalsAndDeparture.arrivalEnabled - this.blockTripSequence = arrivalsAndDeparture.blockTripSequence - this.departureEnabled = arrivalsAndDeparture.departureEnabled - this.distanceFromStop = arrivalsAndDeparture.distanceFromStop - this.frequency = arrivalsAndDeparture.frequency - this.historicalOccupancy = arrivalsAndDeparture.historicalOccupancy - this.lastUpdateTime = arrivalsAndDeparture.lastUpdateTime - this.numberOfStopsAway = arrivalsAndDeparture.numberOfStopsAway - this.occupancyStatus = arrivalsAndDeparture.occupancyStatus - this.predicted = arrivalsAndDeparture.predicted - this.predictedArrivalInterval = - arrivalsAndDeparture.predictedArrivalInterval - this.predictedArrivalTime = arrivalsAndDeparture.predictedArrivalTime - this.predictedDepartureInterval = - arrivalsAndDeparture.predictedDepartureInterval - this.predictedDepartureTime = arrivalsAndDeparture.predictedDepartureTime - this.predictedOccupancy = arrivalsAndDeparture.predictedOccupancy - this.routeId = arrivalsAndDeparture.routeId - this.routeLongName = arrivalsAndDeparture.routeLongName - this.routeShortName = arrivalsAndDeparture.routeShortName - this.scheduledArrivalInterval = - arrivalsAndDeparture.scheduledArrivalInterval - this.scheduledArrivalTime = arrivalsAndDeparture.scheduledArrivalTime - this.scheduledDepartureInterval = - arrivalsAndDeparture.scheduledDepartureInterval - this.scheduledDepartureTime = arrivalsAndDeparture.scheduledDepartureTime - this.scheduledTrack = arrivalsAndDeparture.scheduledTrack - this.serviceDate = arrivalsAndDeparture.serviceDate - this.situationIds = arrivalsAndDeparture.situationIds - this.status = arrivalsAndDeparture.status - this.stopId = arrivalsAndDeparture.stopId - this.stopSequence = arrivalsAndDeparture.stopSequence - this.totalStopsInTrip = arrivalsAndDeparture.totalStopsInTrip - this.tripHeadsign = arrivalsAndDeparture.tripHeadsign - this.tripId = arrivalsAndDeparture.tripId - this.tripStatus = arrivalsAndDeparture.tripStatus - this.vehicleId = arrivalsAndDeparture.vehicleId - additionalProperties(arrivalsAndDeparture.additionalProperties) - } - - /** The actual track information of the arriving transit vehicle. */ - fun actualTrack(actualTrack: String) = actualTrack(JsonField.of(actualTrack)) - - /** The actual track information of the arriving transit vehicle. */ - @JsonProperty("actualTrack") - @ExcludeMissing - fun actualTrack(actualTrack: JsonField) = apply { - this.actualTrack = actualTrack + arrivalEnabled = arrivalsAndDeparture.arrivalEnabled + blockTripSequence = arrivalsAndDeparture.blockTripSequence + departureEnabled = arrivalsAndDeparture.departureEnabled + numberOfStopsAway = arrivalsAndDeparture.numberOfStopsAway + predictedArrivalTime = arrivalsAndDeparture.predictedArrivalTime + predictedDepartureTime = arrivalsAndDeparture.predictedDepartureTime + routeId = arrivalsAndDeparture.routeId + scheduledArrivalTime = arrivalsAndDeparture.scheduledArrivalTime + scheduledDepartureTime = arrivalsAndDeparture.scheduledDepartureTime + serviceDate = arrivalsAndDeparture.serviceDate + stopId = arrivalsAndDeparture.stopId + stopSequence = arrivalsAndDeparture.stopSequence + totalStopsInTrip = arrivalsAndDeparture.totalStopsInTrip + tripHeadsign = arrivalsAndDeparture.tripHeadsign + tripId = arrivalsAndDeparture.tripId + vehicleId = arrivalsAndDeparture.vehicleId + actualTrack = arrivalsAndDeparture.actualTrack + distanceFromStop = arrivalsAndDeparture.distanceFromStop + frequency = arrivalsAndDeparture.frequency + historicalOccupancy = arrivalsAndDeparture.historicalOccupancy + lastUpdateTime = arrivalsAndDeparture.lastUpdateTime + occupancyStatus = arrivalsAndDeparture.occupancyStatus + predicted = arrivalsAndDeparture.predicted + predictedArrivalInterval = arrivalsAndDeparture.predictedArrivalInterval + predictedDepartureInterval = arrivalsAndDeparture.predictedDepartureInterval + predictedOccupancy = arrivalsAndDeparture.predictedOccupancy + routeLongName = arrivalsAndDeparture.routeLongName + routeShortName = arrivalsAndDeparture.routeShortName + scheduledArrivalInterval = arrivalsAndDeparture.scheduledArrivalInterval + scheduledDepartureInterval = arrivalsAndDeparture.scheduledDepartureInterval + scheduledTrack = arrivalsAndDeparture.scheduledTrack + situationIds = arrivalsAndDeparture.situationIds.map { it.toMutableList() } + status = arrivalsAndDeparture.status + tripStatus = arrivalsAndDeparture.tripStatus + additionalProperties = + arrivalsAndDeparture.additionalProperties.toMutableMap() } /** Indicates if riders can arrive on this transit vehicle. */ @@ -830,8 +955,6 @@ private constructor( arrivalEnabled(JsonField.of(arrivalEnabled)) /** Indicates if riders can arrive on this transit vehicle. */ - @JsonProperty("arrivalEnabled") - @ExcludeMissing fun arrivalEnabled(arrivalEnabled: JsonField) = apply { this.arrivalEnabled = arrivalEnabled } @@ -845,8 +968,6 @@ private constructor( /** * Index of this arrival’s trip into the sequence of trips for the active block. */ - @JsonProperty("blockTripSequence") - @ExcludeMissing fun blockTripSequence(blockTripSequence: JsonField) = apply { this.blockTripSequence = blockTripSequence } @@ -856,55 +977,10 @@ private constructor( departureEnabled(JsonField.of(departureEnabled)) /** Indicates if riders can depart from this transit vehicle. */ - @JsonProperty("departureEnabled") - @ExcludeMissing fun departureEnabled(departureEnabled: JsonField) = apply { this.departureEnabled = departureEnabled } - /** Distance of the arriving transit vehicle from the stop, in meters. */ - fun distanceFromStop(distanceFromStop: Double) = - distanceFromStop(JsonField.of(distanceFromStop)) - - /** Distance of the arriving transit vehicle from the stop, in meters. */ - @JsonProperty("distanceFromStop") - @ExcludeMissing - fun distanceFromStop(distanceFromStop: JsonField) = apply { - this.distanceFromStop = distanceFromStop - } - - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") - @ExcludeMissing - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - - /** Historical occupancy information of the transit vehicle. */ - fun historicalOccupancy(historicalOccupancy: String) = - historicalOccupancy(JsonField.of(historicalOccupancy)) - - /** Historical occupancy information of the transit vehicle. */ - @JsonProperty("historicalOccupancy") - @ExcludeMissing - fun historicalOccupancy(historicalOccupancy: JsonField) = apply { - this.historicalOccupancy = historicalOccupancy - } - - /** Timestamp of the last update time for this arrival. */ - fun lastUpdateTime(lastUpdateTime: Long) = - lastUpdateTime(JsonField.of(lastUpdateTime)) - - /** Timestamp of the last update time for this arrival. */ - @JsonProperty("lastUpdateTime") - @ExcludeMissing - fun lastUpdateTime(lastUpdateTime: JsonField) = apply { - this.lastUpdateTime = lastUpdateTime - } - /** * Number of stops between the arriving transit vehicle and the current stop * (excluding the current stop). @@ -916,45 +992,10 @@ private constructor( * Number of stops between the arriving transit vehicle and the current stop * (excluding the current stop). */ - @JsonProperty("numberOfStopsAway") - @ExcludeMissing fun numberOfStopsAway(numberOfStopsAway: JsonField) = apply { this.numberOfStopsAway = numberOfStopsAway } - /** Current occupancy status of the transit vehicle. */ - fun occupancyStatus(occupancyStatus: String) = - occupancyStatus(JsonField.of(occupancyStatus)) - - /** Current occupancy status of the transit vehicle. */ - @JsonProperty("occupancyStatus") - @ExcludeMissing - fun occupancyStatus(occupancyStatus: JsonField) = apply { - this.occupancyStatus = occupancyStatus - } - - /** Indicates if real-time arrival info is available for this trip. */ - fun predicted(predicted: Boolean) = predicted(JsonField.of(predicted)) - - /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") - @ExcludeMissing - fun predicted(predicted: JsonField) = apply { - this.predicted = predicted - } - - /** Interval for predicted arrival time, if available. */ - fun predictedArrivalInterval(predictedArrivalInterval: String) = - predictedArrivalInterval(JsonField.of(predictedArrivalInterval)) - - /** Interval for predicted arrival time, if available. */ - @JsonProperty("predictedArrivalInterval") - @ExcludeMissing - fun predictedArrivalInterval(predictedArrivalInterval: JsonField) = - apply { - this.predictedArrivalInterval = predictedArrivalInterval - } - /** * Predicted arrival time, in milliseconds since Unix epoch (zero if no * real-time available). @@ -966,24 +1007,10 @@ private constructor( * Predicted arrival time, in milliseconds since Unix epoch (zero if no * real-time available). */ - @JsonProperty("predictedArrivalTime") - @ExcludeMissing fun predictedArrivalTime(predictedArrivalTime: JsonField) = apply { this.predictedArrivalTime = predictedArrivalTime } - /** Interval for predicted departure time, if available. */ - fun predictedDepartureInterval(predictedDepartureInterval: String) = - predictedDepartureInterval(JsonField.of(predictedDepartureInterval)) - - /** Interval for predicted departure time, if available. */ - @JsonProperty("predictedDepartureInterval") - @ExcludeMissing - fun predictedDepartureInterval(predictedDepartureInterval: JsonField) = - apply { - this.predictedDepartureInterval = predictedDepartureInterval - } - /** * Predicted departure time, in milliseconds since Unix epoch (zero if no * real-time available). @@ -995,122 +1022,34 @@ private constructor( * Predicted departure time, in milliseconds since Unix epoch (zero if no * real-time available). */ - @JsonProperty("predictedDepartureTime") - @ExcludeMissing fun predictedDepartureTime(predictedDepartureTime: JsonField) = apply { this.predictedDepartureTime = predictedDepartureTime } - /** Predicted occupancy status of the transit vehicle. */ - fun predictedOccupancy(predictedOccupancy: String) = - predictedOccupancy(JsonField.of(predictedOccupancy)) - - /** Predicted occupancy status of the transit vehicle. */ - @JsonProperty("predictedOccupancy") - @ExcludeMissing - fun predictedOccupancy(predictedOccupancy: JsonField) = apply { - this.predictedOccupancy = predictedOccupancy - } + /** The ID of the route for the arriving vehicle. */ + fun routeId(routeId: String) = routeId(JsonField.of(routeId)) /** The ID of the route for the arriving vehicle. */ - fun routeId(routeId: String) = routeId(JsonField.of(routeId)) - - /** The ID of the route for the arriving vehicle. */ - @JsonProperty("routeId") - @ExcludeMissing fun routeId(routeId: JsonField) = apply { this.routeId = routeId } - /** - * Optional route long name that potentially overrides the route long name in - * the referenced route element. - */ - fun routeLongName(routeLongName: String) = - routeLongName(JsonField.of(routeLongName)) - - /** - * Optional route long name that potentially overrides the route long name in - * the referenced route element. - */ - @JsonProperty("routeLongName") - @ExcludeMissing - fun routeLongName(routeLongName: JsonField) = apply { - this.routeLongName = routeLongName - } - - /** - * Optional route short name that potentially overrides the route short name in - * the referenced route element. - */ - fun routeShortName(routeShortName: String) = - routeShortName(JsonField.of(routeShortName)) - - /** - * Optional route short name that potentially overrides the route short name in - * the referenced route element. - */ - @JsonProperty("routeShortName") - @ExcludeMissing - fun routeShortName(routeShortName: JsonField) = apply { - this.routeShortName = routeShortName - } - - /** Interval for scheduled arrival time. */ - fun scheduledArrivalInterval(scheduledArrivalInterval: String) = - scheduledArrivalInterval(JsonField.of(scheduledArrivalInterval)) - - /** Interval for scheduled arrival time. */ - @JsonProperty("scheduledArrivalInterval") - @ExcludeMissing - fun scheduledArrivalInterval(scheduledArrivalInterval: JsonField) = - apply { - this.scheduledArrivalInterval = scheduledArrivalInterval - } - /** Scheduled arrival time, in milliseconds since Unix epoch. */ fun scheduledArrivalTime(scheduledArrivalTime: Long) = scheduledArrivalTime(JsonField.of(scheduledArrivalTime)) /** Scheduled arrival time, in milliseconds since Unix epoch. */ - @JsonProperty("scheduledArrivalTime") - @ExcludeMissing fun scheduledArrivalTime(scheduledArrivalTime: JsonField) = apply { this.scheduledArrivalTime = scheduledArrivalTime } - /** Interval for scheduled departure time. */ - fun scheduledDepartureInterval(scheduledDepartureInterval: String) = - scheduledDepartureInterval(JsonField.of(scheduledDepartureInterval)) - - /** Interval for scheduled departure time. */ - @JsonProperty("scheduledDepartureInterval") - @ExcludeMissing - fun scheduledDepartureInterval(scheduledDepartureInterval: JsonField) = - apply { - this.scheduledDepartureInterval = scheduledDepartureInterval - } - /** Scheduled departure time, in milliseconds since Unix epoch. */ fun scheduledDepartureTime(scheduledDepartureTime: Long) = scheduledDepartureTime(JsonField.of(scheduledDepartureTime)) /** Scheduled departure time, in milliseconds since Unix epoch. */ - @JsonProperty("scheduledDepartureTime") - @ExcludeMissing fun scheduledDepartureTime(scheduledDepartureTime: JsonField) = apply { this.scheduledDepartureTime = scheduledDepartureTime } - /** Scheduled track information of the arriving transit vehicle. */ - fun scheduledTrack(scheduledTrack: String) = - scheduledTrack(JsonField.of(scheduledTrack)) - - /** Scheduled track information of the arriving transit vehicle. */ - @JsonProperty("scheduledTrack") - @ExcludeMissing - fun scheduledTrack(scheduledTrack: JsonField) = apply { - this.scheduledTrack = scheduledTrack - } - /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. @@ -1121,37 +1060,14 @@ private constructor( * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") - @ExcludeMissing fun serviceDate(serviceDate: JsonField) = apply { this.serviceDate = serviceDate } - /** References to situation elements (if any) applicable to this arrival. */ - fun situationIds(situationIds: List) = - situationIds(JsonField.of(situationIds)) - - /** References to situation elements (if any) applicable to this arrival. */ - @JsonProperty("situationIds") - @ExcludeMissing - fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds - } - - /** Current status of the arrival. */ - fun status(status: String) = status(JsonField.of(status)) - - /** Current status of the arrival. */ - @JsonProperty("status") - @ExcludeMissing - fun status(status: JsonField) = apply { this.status = status } - /** The ID of the stop the vehicle is arriving at. */ fun stopId(stopId: String) = stopId(JsonField.of(stopId)) /** The ID of the stop the vehicle is arriving at. */ - @JsonProperty("stopId") - @ExcludeMissing fun stopId(stopId: JsonField) = apply { this.stopId = stopId } /** @@ -1164,8 +1080,6 @@ private constructor( * Index of the stop into the sequence of stops that make up the trip for this * arrival. */ - @JsonProperty("stopSequence") - @ExcludeMissing fun stopSequence(stopSequence: JsonField) = apply { this.stopSequence = stopSequence } @@ -1175,8 +1089,6 @@ private constructor( totalStopsInTrip(JsonField.of(totalStopsInTrip)) /** Total number of stops visited on the trip for this arrival. */ - @JsonProperty("totalStopsInTrip") - @ExcludeMissing fun totalStopsInTrip(totalStopsInTrip: JsonField) = apply { this.totalStopsInTrip = totalStopsInTrip } @@ -1192,8 +1104,6 @@ private constructor( * Optional trip headsign that potentially overrides the trip headsign in the * referenced trip element. */ - @JsonProperty("tripHeadsign") - @ExcludeMissing fun tripHeadsign(tripHeadsign: JsonField) = apply { this.tripHeadsign = tripHeadsign } @@ -1202,38 +1112,208 @@ private constructor( fun tripId(tripId: String) = tripId(JsonField.of(tripId)) /** The ID of the trip for the arriving vehicle. */ - @JsonProperty("tripId") - @ExcludeMissing fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - /** Trip-specific status for the arriving transit vehicle. */ - fun tripStatus(tripStatus: TripStatus) = tripStatus(JsonField.of(tripStatus)) - - /** Trip-specific status for the arriving transit vehicle. */ - @JsonProperty("tripStatus") - @ExcludeMissing - fun tripStatus(tripStatus: JsonField) = apply { - this.tripStatus = tripStatus - } - /** ID of the transit vehicle serving this trip. */ fun vehicleId(vehicleId: String) = vehicleId(JsonField.of(vehicleId)) /** ID of the transit vehicle serving this trip. */ - @JsonProperty("vehicleId") - @ExcludeMissing fun vehicleId(vehicleId: JsonField) = apply { this.vehicleId = vehicleId } + /** The actual track information of the arriving transit vehicle. */ + fun actualTrack(actualTrack: String) = actualTrack(JsonField.of(actualTrack)) + + /** The actual track information of the arriving transit vehicle. */ + fun actualTrack(actualTrack: JsonField) = apply { + this.actualTrack = actualTrack + } + + /** Distance of the arriving transit vehicle from the stop, in meters. */ + fun distanceFromStop(distanceFromStop: Double) = + distanceFromStop(JsonField.of(distanceFromStop)) + + /** Distance of the arriving transit vehicle from the stop, in meters. */ + fun distanceFromStop(distanceFromStop: JsonField) = apply { + this.distanceFromStop = distanceFromStop + } + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: String) = frequency(JsonField.of(frequency)) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: JsonField) = apply { + this.frequency = frequency + } + + /** Historical occupancy information of the transit vehicle. */ + fun historicalOccupancy(historicalOccupancy: String) = + historicalOccupancy(JsonField.of(historicalOccupancy)) + + /** Historical occupancy information of the transit vehicle. */ + fun historicalOccupancy(historicalOccupancy: JsonField) = apply { + this.historicalOccupancy = historicalOccupancy + } + + /** Timestamp of the last update time for this arrival. */ + fun lastUpdateTime(lastUpdateTime: Long) = + lastUpdateTime(JsonField.of(lastUpdateTime)) + + /** Timestamp of the last update time for this arrival. */ + fun lastUpdateTime(lastUpdateTime: JsonField) = apply { + this.lastUpdateTime = lastUpdateTime + } + + /** Current occupancy status of the transit vehicle. */ + fun occupancyStatus(occupancyStatus: String) = + occupancyStatus(JsonField.of(occupancyStatus)) + + /** Current occupancy status of the transit vehicle. */ + fun occupancyStatus(occupancyStatus: JsonField) = apply { + this.occupancyStatus = occupancyStatus + } + + /** Indicates if real-time arrival info is available for this trip. */ + fun predicted(predicted: Boolean) = predicted(JsonField.of(predicted)) + + /** Indicates if real-time arrival info is available for this trip. */ + fun predicted(predicted: JsonField) = apply { + this.predicted = predicted + } + + /** Interval for predicted arrival time, if available. */ + fun predictedArrivalInterval(predictedArrivalInterval: String) = + predictedArrivalInterval(JsonField.of(predictedArrivalInterval)) + + /** Interval for predicted arrival time, if available. */ + fun predictedArrivalInterval(predictedArrivalInterval: JsonField) = + apply { + this.predictedArrivalInterval = predictedArrivalInterval + } + + /** Interval for predicted departure time, if available. */ + fun predictedDepartureInterval(predictedDepartureInterval: String) = + predictedDepartureInterval(JsonField.of(predictedDepartureInterval)) + + /** Interval for predicted departure time, if available. */ + fun predictedDepartureInterval(predictedDepartureInterval: JsonField) = + apply { + this.predictedDepartureInterval = predictedDepartureInterval + } + + /** Predicted occupancy status of the transit vehicle. */ + fun predictedOccupancy(predictedOccupancy: String) = + predictedOccupancy(JsonField.of(predictedOccupancy)) + + /** Predicted occupancy status of the transit vehicle. */ + fun predictedOccupancy(predictedOccupancy: JsonField) = apply { + this.predictedOccupancy = predictedOccupancy + } + + /** + * Optional route long name that potentially overrides the route long name in + * the referenced route element. + */ + fun routeLongName(routeLongName: String) = + routeLongName(JsonField.of(routeLongName)) + + /** + * Optional route long name that potentially overrides the route long name in + * the referenced route element. + */ + fun routeLongName(routeLongName: JsonField) = apply { + this.routeLongName = routeLongName + } + + /** + * Optional route short name that potentially overrides the route short name in + * the referenced route element. + */ + fun routeShortName(routeShortName: String) = + routeShortName(JsonField.of(routeShortName)) + + /** + * Optional route short name that potentially overrides the route short name in + * the referenced route element. + */ + fun routeShortName(routeShortName: JsonField) = apply { + this.routeShortName = routeShortName + } + + /** Interval for scheduled arrival time. */ + fun scheduledArrivalInterval(scheduledArrivalInterval: String) = + scheduledArrivalInterval(JsonField.of(scheduledArrivalInterval)) + + /** Interval for scheduled arrival time. */ + fun scheduledArrivalInterval(scheduledArrivalInterval: JsonField) = + apply { + this.scheduledArrivalInterval = scheduledArrivalInterval + } + + /** Interval for scheduled departure time. */ + fun scheduledDepartureInterval(scheduledDepartureInterval: String) = + scheduledDepartureInterval(JsonField.of(scheduledDepartureInterval)) + + /** Interval for scheduled departure time. */ + fun scheduledDepartureInterval(scheduledDepartureInterval: JsonField) = + apply { + this.scheduledDepartureInterval = scheduledDepartureInterval + } + + /** Scheduled track information of the arriving transit vehicle. */ + fun scheduledTrack(scheduledTrack: String) = + scheduledTrack(JsonField.of(scheduledTrack)) + + /** Scheduled track information of the arriving transit vehicle. */ + fun scheduledTrack(scheduledTrack: JsonField) = apply { + this.scheduledTrack = scheduledTrack + } + + /** References to situation elements (if any) applicable to this arrival. */ + fun situationIds(situationIds: List) = + situationIds(JsonField.of(situationIds)) + + /** References to situation elements (if any) applicable to this arrival. */ + fun situationIds(situationIds: JsonField>) = apply { + this.situationIds = situationIds.map { it.toMutableList() } + } + + /** References to situation elements (if any) applicable to this arrival. */ + fun addSituationId(situationId: String) = apply { + situationIds = + (situationIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situationId) + } + } + + /** Current status of the arrival. */ + fun status(status: String) = status(JsonField.of(status)) + + /** Current status of the arrival. */ + fun status(status: JsonField) = apply { this.status = status } + + /** Trip-specific status for the arriving transit vehicle. */ + fun tripStatus(tripStatus: TripStatus) = tripStatus(JsonField.of(tripStatus)) + + /** Trip-specific status for the arriving transit vehicle. */ + fun tripStatus(tripStatus: JsonField) = apply { + this.tripStatus = tripStatus + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1241,83 +1321,144 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): ArrivalsAndDeparture = ArrivalsAndDeparture( + checkRequired("arrivalEnabled", arrivalEnabled), + checkRequired("blockTripSequence", blockTripSequence), + checkRequired("departureEnabled", departureEnabled), + checkRequired("numberOfStopsAway", numberOfStopsAway), + checkRequired("predictedArrivalTime", predictedArrivalTime), + checkRequired("predictedDepartureTime", predictedDepartureTime), + checkRequired("routeId", routeId), + checkRequired("scheduledArrivalTime", scheduledArrivalTime), + checkRequired("scheduledDepartureTime", scheduledDepartureTime), + checkRequired("serviceDate", serviceDate), + checkRequired("stopId", stopId), + checkRequired("stopSequence", stopSequence), + checkRequired("totalStopsInTrip", totalStopsInTrip), + checkRequired("tripHeadsign", tripHeadsign), + checkRequired("tripId", tripId), + checkRequired("vehicleId", vehicleId), actualTrack, - arrivalEnabled, - blockTripSequence, - departureEnabled, distanceFromStop, frequency, historicalOccupancy, lastUpdateTime, - numberOfStopsAway, occupancyStatus, predicted, predictedArrivalInterval, - predictedArrivalTime, predictedDepartureInterval, - predictedDepartureTime, predictedOccupancy, - routeId, routeLongName, routeShortName, scheduledArrivalInterval, - scheduledArrivalTime, scheduledDepartureInterval, - scheduledDepartureTime, scheduledTrack, - serviceDate, - situationIds.map { it.toImmutable() }, + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, status, - stopId, - stopSequence, - totalStopsInTrip, - tripHeadsign, - tripId, tripStatus, - vehicleId, additionalProperties.toImmutable(), ) } /** Trip-specific status for the arriving transit vehicle. */ - @JsonDeserialize(builder = TripStatus.Builder::class) @NoAutoDetect class TripStatus + @JsonCreator private constructor( - private val activeTripId: JsonField, - private val blockTripSequence: JsonField, - private val closestStop: JsonField, - private val closestStopTimeOffset: JsonField, - private val distanceAlongTrip: JsonField, - private val frequency: JsonField, - private val lastKnownDistanceAlongTrip: JsonField, - private val lastKnownLocation: JsonField, - private val lastKnownOrientation: JsonField, - private val lastLocationUpdateTime: JsonField, - private val lastUpdateTime: JsonField, - private val nextStop: JsonField, - private val nextStopTimeOffset: JsonField, - private val occupancyCapacity: JsonField, - private val occupancyCount: JsonField, - private val occupancyStatus: JsonField, - private val orientation: JsonField, - private val phase: JsonField, - private val position: JsonField, - private val predicted: JsonField, - private val scheduleDeviation: JsonField, - private val scheduledDistanceAlongTrip: JsonField, - private val serviceDate: JsonField, - private val situationIds: JsonField>, - private val status: JsonField, - private val totalDistanceAlongTrip: JsonField, - private val vehicleId: JsonField, - private val additionalProperties: Map, + @JsonProperty("activeTripId") + @ExcludeMissing + private val activeTripId: JsonField = JsonMissing.of(), + @JsonProperty("blockTripSequence") + @ExcludeMissing + private val blockTripSequence: JsonField = JsonMissing.of(), + @JsonProperty("closestStop") + @ExcludeMissing + private val closestStop: JsonField = JsonMissing.of(), + @JsonProperty("distanceAlongTrip") + @ExcludeMissing + private val distanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownDistanceAlongTrip") + @ExcludeMissing + private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastLocationUpdateTime") + @ExcludeMissing + private val lastLocationUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("lastUpdateTime") + @ExcludeMissing + private val lastUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCapacity") + @ExcludeMissing + private val occupancyCapacity: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCount") + @ExcludeMissing + private val occupancyCount: JsonField = JsonMissing.of(), + @JsonProperty("occupancyStatus") + @ExcludeMissing + private val occupancyStatus: JsonField = JsonMissing.of(), + @JsonProperty("phase") + @ExcludeMissing + private val phase: JsonField = JsonMissing.of(), + @JsonProperty("predicted") + @ExcludeMissing + private val predicted: JsonField = JsonMissing.of(), + @JsonProperty("scheduleDeviation") + @ExcludeMissing + private val scheduleDeviation: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonProperty("totalDistanceAlongTrip") + @ExcludeMissing + private val totalDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + private val closestStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownLocation") + @ExcludeMissing + private val lastKnownLocation: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + private val lastKnownOrientation: JsonField = JsonMissing.of(), + @JsonProperty("nextStop") + @ExcludeMissing + private val nextStop: JsonField = JsonMissing.of(), + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + private val nextStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("orientation") + @ExcludeMissing + private val orientation: JsonField = JsonMissing.of(), + @JsonProperty("position") + @ExcludeMissing + private val position: JsonField = JsonMissing.of(), + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + private val scheduledDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), + @JsonProperty("vehicleId") + @ExcludeMissing + private val vehicleId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Trip ID of the trip the vehicle is actively serving. */ fun activeTripId(): String = activeTripId.getRequired("activeTripId") @@ -1328,15 +1469,6 @@ private constructor( /** ID of the closest stop to the current location of the transit vehicle. */ fun closestStop(): String = closestStop.getRequired("closestStop") - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - fun closestStopTimeOffset(): Optional = - Optional.ofNullable( - closestStopTimeOffset.getNullable("closestStopTimeOffset") - ) - /** * Distance, in meters, the transit vehicle has progressed along the active * trip. @@ -1344,10 +1476,6 @@ private constructor( fun distanceAlongTrip(): Double = distanceAlongTrip.getRequired("distanceAlongTrip") - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1355,18 +1483,6 @@ private constructor( fun lastKnownDistanceAlongTrip(): Double = lastKnownDistanceAlongTrip.getRequired("lastKnownDistanceAlongTrip") - /** Last known location of the transit vehicle. */ - fun lastKnownLocation(): Optional = - Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - fun lastKnownOrientation(): Optional = - Optional.ofNullable( - lastKnownOrientation.getNullable("lastKnownOrientation") - ) - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1377,17 +1493,6 @@ private constructor( /** Timestamp of the last known real-time update from the transit vehicle. */ fun lastUpdateTime(): Long = lastUpdateTime.getRequired("lastUpdateTime") - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - fun nextStop(): Optional = - Optional.ofNullable(nextStop.getNullable("nextStop")) - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - fun nextStopTimeOffset(): Optional = - Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(): Long = occupancyCapacity.getRequired("occupancyCapacity") @@ -1398,17 +1503,9 @@ private constructor( /** Current occupancy status of the transit vehicle. */ fun occupancyStatus(): String = occupancyStatus.getRequired("occupancyStatus") - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - fun orientation(): Optional = - Optional.ofNullable(orientation.getNullable("orientation")) - /** Current journey phase of the trip. */ fun phase(): String = phase.getRequired("phase") - /** Current position of the transit vehicle. */ - fun position(): Optional = - Optional.ofNullable(position.getNullable("position")) - /** Indicates if real-time arrival info is available for this trip. */ fun predicted(): Boolean = predicted.getRequired("predicted") @@ -1419,6 +1516,63 @@ private constructor( fun scheduleDeviation(): Long = scheduleDeviation.getRequired("scheduleDeviation") + /** + * Time, in milliseconds since the Unix epoch, of midnight for the start of the + * service date for the trip. + */ + fun serviceDate(): Long = serviceDate.getRequired("serviceDate") + + /** Current status modifiers for the trip. */ + fun status(): String = status.getRequired("status") + + /** Total length of the trip, in meters. */ + fun totalDistanceAlongTrip(): Double = + totalDistanceAlongTrip.getRequired("totalDistanceAlongTrip") + + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + fun closestStopTimeOffset(): Optional = + Optional.ofNullable( + closestStopTimeOffset.getNullable("closestStopTimeOffset") + ) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(): Optional = + Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + fun lastKnownOrientation(): Optional = + Optional.ofNullable( + lastKnownOrientation.getNullable("lastKnownOrientation") + ) + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(): Optional = + Optional.ofNullable(nextStop.getNullable("nextStop")) + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + fun nextStopTimeOffset(): Optional = + Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(): Optional = + Optional.ofNullable(orientation.getNullable("orientation")) + + /** Current position of the transit vehicle. */ + fun position(): Optional = + Optional.ofNullable(position.getNullable("position")) + /** * Distance, in meters, the transit vehicle is scheduled to have progressed * along the active trip. @@ -1428,45 +1582,28 @@ private constructor( scheduledDistanceAlongTrip.getNullable("scheduledDistanceAlongTrip") ) - /** - * Time, in milliseconds since the Unix epoch, of midnight for the start of the - * service date for the trip. - */ - fun serviceDate(): Long = serviceDate.getRequired("serviceDate") - /** References to situation elements (if any) applicable to this trip. */ fun situationIds(): Optional> = Optional.ofNullable(situationIds.getNullable("situationIds")) - /** Current status modifiers for the trip. */ - fun status(): String = status.getRequired("status") - - /** Total length of the trip, in meters. */ - fun totalDistanceAlongTrip(): Double = - totalDistanceAlongTrip.getRequired("totalDistanceAlongTrip") - /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(): Optional = Optional.ofNullable(vehicleId.getNullable("vehicleId")) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") @ExcludeMissing fun _activeTripId() = activeTripId + @JsonProperty("activeTripId") + @ExcludeMissing + fun _activeTripId(): JsonField = activeTripId /** Index of the active trip into the sequence of trips for the active block. */ @JsonProperty("blockTripSequence") @ExcludeMissing - fun _blockTripSequence() = blockTripSequence + fun _blockTripSequence(): JsonField = blockTripSequence /** ID of the closest stop to the current location of the transit vehicle. */ - @JsonProperty("closestStop") @ExcludeMissing fun _closestStop() = closestStop - - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - @JsonProperty("closestStopTimeOffset") + @JsonProperty("closestStop") @ExcludeMissing - fun _closestStopTimeOffset() = closestStopTimeOffset + fun _closestStop(): JsonField = closestStop /** * Distance, in meters, the transit vehicle has progressed along the active @@ -1474,10 +1611,7 @@ private constructor( */ @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + fun _distanceAlongTrip(): JsonField = distanceAlongTrip /** * Last known distance along the trip received in real-time from the transit @@ -1485,19 +1619,8 @@ private constructor( */ @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing - fun _lastKnownDistanceAlongTrip() = lastKnownDistanceAlongTrip - - /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun _lastKnownLocation() = lastKnownLocation - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun _lastKnownOrientation() = lastKnownOrientation + fun _lastKnownDistanceAlongTrip(): JsonField = + lastKnownDistanceAlongTrip /** * Timestamp of the last known real-time location update from the transit @@ -1505,50 +1628,35 @@ private constructor( */ @JsonProperty("lastLocationUpdateTime") @ExcludeMissing - fun _lastLocationUpdateTime() = lastLocationUpdateTime + fun _lastLocationUpdateTime(): JsonField = lastLocationUpdateTime /** Timestamp of the last known real-time update from the transit vehicle. */ @JsonProperty("lastUpdateTime") @ExcludeMissing - fun _lastUpdateTime() = lastUpdateTime - - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") @ExcludeMissing fun _nextStop() = nextStop - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - fun _nextStopTimeOffset() = nextStopTimeOffset + fun _lastUpdateTime(): JsonField = lastUpdateTime /** Capacity of the transit vehicle in terms of occupancy. */ @JsonProperty("occupancyCapacity") @ExcludeMissing - fun _occupancyCapacity() = occupancyCapacity + fun _occupancyCapacity(): JsonField = occupancyCapacity /** Current count of occupants in the transit vehicle. */ @JsonProperty("occupancyCount") @ExcludeMissing - fun _occupancyCount() = occupancyCount + fun _occupancyCount(): JsonField = occupancyCount /** Current occupancy status of the transit vehicle. */ @JsonProperty("occupancyStatus") @ExcludeMissing - fun _occupancyStatus() = occupancyStatus - - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") @ExcludeMissing fun _orientation() = orientation + fun _occupancyStatus(): JsonField = occupancyStatus /** Current journey phase of the trip. */ - @JsonProperty("phase") @ExcludeMissing fun _phase() = phase - - /** Current position of the transit vehicle. */ - @JsonProperty("position") @ExcludeMissing fun _position() = position + @JsonProperty("phase") @ExcludeMissing fun _phase(): JsonField = phase /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") @ExcludeMissing fun _predicted() = predicted + @JsonProperty("predicted") + @ExcludeMissing + fun _predicted(): JsonField = predicted /** * Deviation from the schedule in seconds (positive for late, negative for @@ -1556,71 +1664,132 @@ private constructor( */ @JsonProperty("scheduleDeviation") @ExcludeMissing - fun _scheduleDeviation() = scheduleDeviation - - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed - * along the active trip. - */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - fun _scheduledDistanceAlongTrip() = scheduledDistanceAlongTrip + fun _scheduleDeviation(): JsonField = scheduleDeviation /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate - - /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate /** Current status modifiers for the trip. */ - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("status") + @ExcludeMissing + fun _status(): JsonField = status /** Total length of the trip, in meters. */ @JsonProperty("totalDistanceAlongTrip") @ExcludeMissing - fun _totalDistanceAlongTrip() = totalDistanceAlongTrip + fun _totalDistanceAlongTrip(): JsonField = totalDistanceAlongTrip + + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + fun _closestStopTimeOffset(): JsonField = closestStopTimeOffset + + /** Information about frequency-based scheduling, if applicable to the trip. */ + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency + + /** Last known location of the transit vehicle. */ + @JsonProperty("lastKnownLocation") + @ExcludeMissing + fun _lastKnownLocation(): JsonField = lastKnownLocation + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + fun _lastKnownOrientation(): JsonField = lastKnownOrientation + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + @JsonProperty("nextStop") + @ExcludeMissing + fun _nextStop(): JsonField = nextStop + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + fun _nextStopTimeOffset(): JsonField = nextStopTimeOffset + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + @JsonProperty("orientation") + @ExcludeMissing + fun _orientation(): JsonField = orientation + + /** Current position of the transit vehicle. */ + @JsonProperty("position") + @ExcludeMissing + fun _position(): JsonField = position + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed + * along the active trip. + */ + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + fun _scheduledDistanceAlongTrip(): JsonField = + scheduledDistanceAlongTrip + + /** References to situation elements (if any) applicable to this trip. */ + @JsonProperty("situationIds") + @ExcludeMissing + fun _situationIds(): JsonField> = situationIds /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") @ExcludeMissing fun _vehicleId() = vehicleId + @JsonProperty("vehicleId") + @ExcludeMissing + fun _vehicleId(): JsonField = vehicleId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): TripStatus = apply { - if (!validated) { - activeTripId() - blockTripSequence() - closestStop() - closestStopTimeOffset() - distanceAlongTrip() - frequency() - lastKnownDistanceAlongTrip() - lastKnownLocation().map { it.validate() } - lastKnownOrientation() - lastLocationUpdateTime() - lastUpdateTime() - nextStop() - nextStopTimeOffset() - occupancyCapacity() - occupancyCount() - occupancyStatus() - orientation() - phase() - position().map { it.validate() } - predicted() - scheduleDeviation() - scheduledDistanceAlongTrip() - serviceDate() - situationIds() - status() - totalDistanceAlongTrip() - vehicleId() - validated = true + if (validated) { + return@apply } + + activeTripId() + blockTripSequence() + closestStop() + distanceAlongTrip() + lastKnownDistanceAlongTrip() + lastLocationUpdateTime() + lastUpdateTime() + occupancyCapacity() + occupancyCount() + occupancyStatus() + phase() + predicted() + scheduleDeviation() + serviceDate() + status() + totalDistanceAlongTrip() + closestStopTimeOffset() + frequency() + lastKnownLocation().ifPresent { it.validate() } + lastKnownOrientation() + nextStop() + nextStopTimeOffset() + orientation() + position().ifPresent { it.validate() } + scheduledDistanceAlongTrip() + situationIds() + vehicleId() + validated = true } fun toBuilder() = Builder().from(this) @@ -1630,69 +1799,70 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - - private var activeTripId: JsonField = JsonMissing.of() - private var blockTripSequence: JsonField = JsonMissing.of() - private var closestStop: JsonField = JsonMissing.of() + /** A builder for [TripStatus]. */ + class Builder internal constructor() { + + private var activeTripId: JsonField? = null + private var blockTripSequence: JsonField? = null + private var closestStop: JsonField? = null + private var distanceAlongTrip: JsonField? = null + private var lastKnownDistanceAlongTrip: JsonField? = null + private var lastLocationUpdateTime: JsonField? = null + private var lastUpdateTime: JsonField? = null + private var occupancyCapacity: JsonField? = null + private var occupancyCount: JsonField? = null + private var occupancyStatus: JsonField? = null + private var phase: JsonField? = null + private var predicted: JsonField? = null + private var scheduleDeviation: JsonField? = null + private var serviceDate: JsonField? = null + private var status: JsonField? = null + private var totalDistanceAlongTrip: JsonField? = null private var closestStopTimeOffset: JsonField = JsonMissing.of() - private var distanceAlongTrip: JsonField = JsonMissing.of() private var frequency: JsonField = JsonMissing.of() - private var lastKnownDistanceAlongTrip: JsonField = JsonMissing.of() private var lastKnownLocation: JsonField = JsonMissing.of() private var lastKnownOrientation: JsonField = JsonMissing.of() - private var lastLocationUpdateTime: JsonField = JsonMissing.of() - private var lastUpdateTime: JsonField = JsonMissing.of() private var nextStop: JsonField = JsonMissing.of() private var nextStopTimeOffset: JsonField = JsonMissing.of() - private var occupancyCapacity: JsonField = JsonMissing.of() - private var occupancyCount: JsonField = JsonMissing.of() - private var occupancyStatus: JsonField = JsonMissing.of() private var orientation: JsonField = JsonMissing.of() - private var phase: JsonField = JsonMissing.of() private var position: JsonField = JsonMissing.of() - private var predicted: JsonField = JsonMissing.of() - private var scheduleDeviation: JsonField = JsonMissing.of() private var scheduledDistanceAlongTrip: JsonField = JsonMissing.of() - private var serviceDate: JsonField = JsonMissing.of() - private var situationIds: JsonField> = JsonMissing.of() - private var status: JsonField = JsonMissing.of() - private var totalDistanceAlongTrip: JsonField = JsonMissing.of() + private var situationIds: JsonField>? = null private var vehicleId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(tripStatus: TripStatus) = apply { - this.activeTripId = tripStatus.activeTripId - this.blockTripSequence = tripStatus.blockTripSequence - this.closestStop = tripStatus.closestStop - this.closestStopTimeOffset = tripStatus.closestStopTimeOffset - this.distanceAlongTrip = tripStatus.distanceAlongTrip - this.frequency = tripStatus.frequency - this.lastKnownDistanceAlongTrip = tripStatus.lastKnownDistanceAlongTrip - this.lastKnownLocation = tripStatus.lastKnownLocation - this.lastKnownOrientation = tripStatus.lastKnownOrientation - this.lastLocationUpdateTime = tripStatus.lastLocationUpdateTime - this.lastUpdateTime = tripStatus.lastUpdateTime - this.nextStop = tripStatus.nextStop - this.nextStopTimeOffset = tripStatus.nextStopTimeOffset - this.occupancyCapacity = tripStatus.occupancyCapacity - this.occupancyCount = tripStatus.occupancyCount - this.occupancyStatus = tripStatus.occupancyStatus - this.orientation = tripStatus.orientation - this.phase = tripStatus.phase - this.position = tripStatus.position - this.predicted = tripStatus.predicted - this.scheduleDeviation = tripStatus.scheduleDeviation - this.scheduledDistanceAlongTrip = tripStatus.scheduledDistanceAlongTrip - this.serviceDate = tripStatus.serviceDate - this.situationIds = tripStatus.situationIds - this.status = tripStatus.status - this.totalDistanceAlongTrip = tripStatus.totalDistanceAlongTrip - this.vehicleId = tripStatus.vehicleId - additionalProperties(tripStatus.additionalProperties) + activeTripId = tripStatus.activeTripId + blockTripSequence = tripStatus.blockTripSequence + closestStop = tripStatus.closestStop + distanceAlongTrip = tripStatus.distanceAlongTrip + lastKnownDistanceAlongTrip = tripStatus.lastKnownDistanceAlongTrip + lastLocationUpdateTime = tripStatus.lastLocationUpdateTime + lastUpdateTime = tripStatus.lastUpdateTime + occupancyCapacity = tripStatus.occupancyCapacity + occupancyCount = tripStatus.occupancyCount + occupancyStatus = tripStatus.occupancyStatus + phase = tripStatus.phase + predicted = tripStatus.predicted + scheduleDeviation = tripStatus.scheduleDeviation + serviceDate = tripStatus.serviceDate + status = tripStatus.status + totalDistanceAlongTrip = tripStatus.totalDistanceAlongTrip + closestStopTimeOffset = tripStatus.closestStopTimeOffset + frequency = tripStatus.frequency + lastKnownLocation = tripStatus.lastKnownLocation + lastKnownOrientation = tripStatus.lastKnownOrientation + nextStop = tripStatus.nextStop + nextStopTimeOffset = tripStatus.nextStopTimeOffset + orientation = tripStatus.orientation + position = tripStatus.position + scheduledDistanceAlongTrip = tripStatus.scheduledDistanceAlongTrip + situationIds = tripStatus.situationIds.map { it.toMutableList() } + vehicleId = tripStatus.vehicleId + additionalProperties = tripStatus.additionalProperties.toMutableMap() } /** Trip ID of the trip the vehicle is actively serving. */ @@ -1700,8 +1870,6 @@ private constructor( activeTripId(JsonField.of(activeTripId)) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") - @ExcludeMissing fun activeTripId(activeTripId: JsonField) = apply { this.activeTripId = activeTripId } @@ -1713,29 +1881,170 @@ private constructor( blockTripSequence(JsonField.of(blockTripSequence)) /** - * Index of the active trip into the sequence of trips for the active block. + * Index of the active trip into the sequence of trips for the active block. + */ + fun blockTripSequence(blockTripSequence: JsonField) = apply { + this.blockTripSequence = blockTripSequence + } + + /** + * ID of the closest stop to the current location of the transit vehicle. + */ + fun closestStop(closestStop: String) = + closestStop(JsonField.of(closestStop)) + + /** + * ID of the closest stop to the current location of the transit vehicle. + */ + fun closestStop(closestStop: JsonField) = apply { + this.closestStop = closestStop + } + + /** + * Distance, in meters, the transit vehicle has progressed along the active + * trip. + */ + fun distanceAlongTrip(distanceAlongTrip: Double) = + distanceAlongTrip(JsonField.of(distanceAlongTrip)) + + /** + * Distance, in meters, the transit vehicle has progressed along the active + * trip. + */ + fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { + this.distanceAlongTrip = distanceAlongTrip + } + + /** + * Last known distance along the trip received in real-time from the transit + * vehicle. + */ + fun lastKnownDistanceAlongTrip(lastKnownDistanceAlongTrip: Double) = + lastKnownDistanceAlongTrip(JsonField.of(lastKnownDistanceAlongTrip)) + + /** + * Last known distance along the trip received in real-time from the transit + * vehicle. + */ + fun lastKnownDistanceAlongTrip( + lastKnownDistanceAlongTrip: JsonField + ) = apply { this.lastKnownDistanceAlongTrip = lastKnownDistanceAlongTrip } + + /** + * Timestamp of the last known real-time location update from the transit + * vehicle. + */ + fun lastLocationUpdateTime(lastLocationUpdateTime: Long) = + lastLocationUpdateTime(JsonField.of(lastLocationUpdateTime)) + + /** + * Timestamp of the last known real-time location update from the transit + * vehicle. + */ + fun lastLocationUpdateTime(lastLocationUpdateTime: JsonField) = + apply { + this.lastLocationUpdateTime = lastLocationUpdateTime + } + + /** + * Timestamp of the last known real-time update from the transit vehicle. + */ + fun lastUpdateTime(lastUpdateTime: Long) = + lastUpdateTime(JsonField.of(lastUpdateTime)) + + /** + * Timestamp of the last known real-time update from the transit vehicle. + */ + fun lastUpdateTime(lastUpdateTime: JsonField) = apply { + this.lastUpdateTime = lastUpdateTime + } + + /** Capacity of the transit vehicle in terms of occupancy. */ + fun occupancyCapacity(occupancyCapacity: Long) = + occupancyCapacity(JsonField.of(occupancyCapacity)) + + /** Capacity of the transit vehicle in terms of occupancy. */ + fun occupancyCapacity(occupancyCapacity: JsonField) = apply { + this.occupancyCapacity = occupancyCapacity + } + + /** Current count of occupants in the transit vehicle. */ + fun occupancyCount(occupancyCount: Long) = + occupancyCount(JsonField.of(occupancyCount)) + + /** Current count of occupants in the transit vehicle. */ + fun occupancyCount(occupancyCount: JsonField) = apply { + this.occupancyCount = occupancyCount + } + + /** Current occupancy status of the transit vehicle. */ + fun occupancyStatus(occupancyStatus: String) = + occupancyStatus(JsonField.of(occupancyStatus)) + + /** Current occupancy status of the transit vehicle. */ + fun occupancyStatus(occupancyStatus: JsonField) = apply { + this.occupancyStatus = occupancyStatus + } + + /** Current journey phase of the trip. */ + fun phase(phase: String) = phase(JsonField.of(phase)) + + /** Current journey phase of the trip. */ + fun phase(phase: JsonField) = apply { this.phase = phase } + + /** Indicates if real-time arrival info is available for this trip. */ + fun predicted(predicted: Boolean) = predicted(JsonField.of(predicted)) + + /** Indicates if real-time arrival info is available for this trip. */ + fun predicted(predicted: JsonField) = apply { + this.predicted = predicted + } + + /** + * Deviation from the schedule in seconds (positive for late, negative for + * early). + */ + fun scheduleDeviation(scheduleDeviation: Long) = + scheduleDeviation(JsonField.of(scheduleDeviation)) + + /** + * Deviation from the schedule in seconds (positive for late, negative for + * early). */ - @JsonProperty("blockTripSequence") - @ExcludeMissing - fun blockTripSequence(blockTripSequence: JsonField) = apply { - this.blockTripSequence = blockTripSequence + fun scheduleDeviation(scheduleDeviation: JsonField) = apply { + this.scheduleDeviation = scheduleDeviation } /** - * ID of the closest stop to the current location of the transit vehicle. + * Time, in milliseconds since the Unix epoch, of midnight for the start of + * the service date for the trip. */ - fun closestStop(closestStop: String) = - closestStop(JsonField.of(closestStop)) + fun serviceDate(serviceDate: Long) = serviceDate(JsonField.of(serviceDate)) /** - * ID of the closest stop to the current location of the transit vehicle. + * Time, in milliseconds since the Unix epoch, of midnight for the start of + * the service date for the trip. */ - @JsonProperty("closestStop") - @ExcludeMissing - fun closestStop(closestStop: JsonField) = apply { - this.closestStop = closestStop + fun serviceDate(serviceDate: JsonField) = apply { + this.serviceDate = serviceDate } + /** Current status modifiers for the trip. */ + fun status(status: String) = status(JsonField.of(status)) + + /** Current status modifiers for the trip. */ + fun status(status: JsonField) = apply { this.status = status } + + /** Total length of the trip, in meters. */ + fun totalDistanceAlongTrip(totalDistanceAlongTrip: Double) = + totalDistanceAlongTrip(JsonField.of(totalDistanceAlongTrip)) + + /** Total length of the trip, in meters. */ + fun totalDistanceAlongTrip(totalDistanceAlongTrip: JsonField) = + apply { + this.totalDistanceAlongTrip = totalDistanceAlongTrip + } + /** * Time offset from the closest stop to the current position of the transit * vehicle (in seconds). @@ -1747,29 +2056,10 @@ private constructor( * Time offset from the closest stop to the current position of the transit * vehicle (in seconds). */ - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { this.closestStopTimeOffset = closestStopTimeOffset } - /** - * Distance, in meters, the transit vehicle has progressed along the active - * trip. - */ - fun distanceAlongTrip(distanceAlongTrip: Double) = - distanceAlongTrip(JsonField.of(distanceAlongTrip)) - - /** - * Distance, in meters, the transit vehicle has progressed along the active - * trip. - */ - @JsonProperty("distanceAlongTrip") - @ExcludeMissing - fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { - this.distanceAlongTrip = distanceAlongTrip - } - /** * Information about frequency-based scheduling, if applicable to the trip. */ @@ -1778,36 +2068,15 @@ private constructor( /** * Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") - @ExcludeMissing fun frequency(frequency: JsonField) = apply { this.frequency = frequency } - /** - * Last known distance along the trip received in real-time from the transit - * vehicle. - */ - fun lastKnownDistanceAlongTrip(lastKnownDistanceAlongTrip: Double) = - lastKnownDistanceAlongTrip(JsonField.of(lastKnownDistanceAlongTrip)) - - /** - * Last known distance along the trip received in real-time from the transit - * vehicle. - */ - @JsonProperty("lastKnownDistanceAlongTrip") - @ExcludeMissing - fun lastKnownDistanceAlongTrip( - lastKnownDistanceAlongTrip: JsonField - ) = apply { this.lastKnownDistanceAlongTrip = lastKnownDistanceAlongTrip } - /** Last known location of the transit vehicle. */ fun lastKnownLocation(lastKnownLocation: LastKnownLocation) = lastKnownLocation(JsonField.of(lastKnownLocation)) /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing fun lastKnownLocation(lastKnownLocation: JsonField) = apply { this.lastKnownLocation = lastKnownLocation @@ -1824,51 +2093,14 @@ private constructor( * Last known orientation value received in real-time from the transit * vehicle. */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing fun lastKnownOrientation(lastKnownOrientation: JsonField) = apply { this.lastKnownOrientation = lastKnownOrientation } - /** - * Timestamp of the last known real-time location update from the transit - * vehicle. - */ - fun lastLocationUpdateTime(lastLocationUpdateTime: Long) = - lastLocationUpdateTime(JsonField.of(lastLocationUpdateTime)) - - /** - * Timestamp of the last known real-time location update from the transit - * vehicle. - */ - @JsonProperty("lastLocationUpdateTime") - @ExcludeMissing - fun lastLocationUpdateTime(lastLocationUpdateTime: JsonField) = - apply { - this.lastLocationUpdateTime = lastLocationUpdateTime - } - - /** - * Timestamp of the last known real-time update from the transit vehicle. - */ - fun lastUpdateTime(lastUpdateTime: Long) = - lastUpdateTime(JsonField.of(lastUpdateTime)) - - /** - * Timestamp of the last known real-time update from the transit vehicle. - */ - @JsonProperty("lastUpdateTime") - @ExcludeMissing - fun lastUpdateTime(lastUpdateTime: JsonField) = apply { - this.lastUpdateTime = lastUpdateTime - } - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ fun nextStop(nextStop: String) = nextStop(JsonField.of(nextStop)) /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") - @ExcludeMissing fun nextStop(nextStop: JsonField) = apply { this.nextStop = nextStop } @@ -1884,45 +2116,10 @@ private constructor( * Time offset from the next stop to the current position of the transit * vehicle (in seconds). */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing fun nextStopTimeOffset(nextStopTimeOffset: JsonField) = apply { this.nextStopTimeOffset = nextStopTimeOffset } - /** Capacity of the transit vehicle in terms of occupancy. */ - fun occupancyCapacity(occupancyCapacity: Long) = - occupancyCapacity(JsonField.of(occupancyCapacity)) - - /** Capacity of the transit vehicle in terms of occupancy. */ - @JsonProperty("occupancyCapacity") - @ExcludeMissing - fun occupancyCapacity(occupancyCapacity: JsonField) = apply { - this.occupancyCapacity = occupancyCapacity - } - - /** Current count of occupants in the transit vehicle. */ - fun occupancyCount(occupancyCount: Long) = - occupancyCount(JsonField.of(occupancyCount)) - - /** Current count of occupants in the transit vehicle. */ - @JsonProperty("occupancyCount") - @ExcludeMissing - fun occupancyCount(occupancyCount: JsonField) = apply { - this.occupancyCount = occupancyCount - } - - /** Current occupancy status of the transit vehicle. */ - fun occupancyStatus(occupancyStatus: String) = - occupancyStatus(JsonField.of(occupancyStatus)) - - /** Current occupancy status of the transit vehicle. */ - @JsonProperty("occupancyStatus") - @ExcludeMissing - fun occupancyStatus(occupancyStatus: JsonField) = apply { - this.occupancyStatus = occupancyStatus - } - /** * Orientation of the transit vehicle, represented as an angle in degrees. */ @@ -1932,57 +2129,18 @@ private constructor( /** * Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") - @ExcludeMissing fun orientation(orientation: JsonField) = apply { this.orientation = orientation } - /** Current journey phase of the trip. */ - fun phase(phase: String) = phase(JsonField.of(phase)) - - /** Current journey phase of the trip. */ - @JsonProperty("phase") - @ExcludeMissing - fun phase(phase: JsonField) = apply { this.phase = phase } - /** Current position of the transit vehicle. */ fun position(position: Position) = position(JsonField.of(position)) /** Current position of the transit vehicle. */ - @JsonProperty("position") - @ExcludeMissing fun position(position: JsonField) = apply { this.position = position } - /** Indicates if real-time arrival info is available for this trip. */ - fun predicted(predicted: Boolean) = predicted(JsonField.of(predicted)) - - /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") - @ExcludeMissing - fun predicted(predicted: JsonField) = apply { - this.predicted = predicted - } - - /** - * Deviation from the schedule in seconds (positive for late, negative for - * early). - */ - fun scheduleDeviation(scheduleDeviation: Long) = - scheduleDeviation(JsonField.of(scheduleDeviation)) - - /** - * Deviation from the schedule in seconds (positive for late, negative for - * early). - */ - @JsonProperty("scheduleDeviation") - @ExcludeMissing - fun scheduleDeviation(scheduleDeviation: JsonField) = apply { - this.scheduleDeviation = scheduleDeviation - } - /** * Distance, in meters, the transit vehicle is scheduled to have progressed * along the active trip. @@ -1994,65 +2152,37 @@ private constructor( * Distance, in meters, the transit vehicle is scheduled to have progressed * along the active trip. */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing fun scheduledDistanceAlongTrip( scheduledDistanceAlongTrip: JsonField ) = apply { this.scheduledDistanceAlongTrip = scheduledDistanceAlongTrip } - /** - * Time, in milliseconds since the Unix epoch, of midnight for the start of - * the service date for the trip. - */ - fun serviceDate(serviceDate: Long) = serviceDate(JsonField.of(serviceDate)) - - /** - * Time, in milliseconds since the Unix epoch, of midnight for the start of - * the service date for the trip. - */ - @JsonProperty("serviceDate") - @ExcludeMissing - fun serviceDate(serviceDate: JsonField) = apply { - this.serviceDate = serviceDate - } - /** References to situation elements (if any) applicable to this trip. */ fun situationIds(situationIds: List) = situationIds(JsonField.of(situationIds)) /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") - @ExcludeMissing fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds + this.situationIds = situationIds.map { it.toMutableList() } } - /** Current status modifiers for the trip. */ - fun status(status: String) = status(JsonField.of(status)) - - /** Current status modifiers for the trip. */ - @JsonProperty("status") - @ExcludeMissing - fun status(status: JsonField) = apply { this.status = status } - - /** Total length of the trip, in meters. */ - fun totalDistanceAlongTrip(totalDistanceAlongTrip: Double) = - totalDistanceAlongTrip(JsonField.of(totalDistanceAlongTrip)) - - /** Total length of the trip, in meters. */ - @JsonProperty("totalDistanceAlongTrip") - @ExcludeMissing - fun totalDistanceAlongTrip(totalDistanceAlongTrip: JsonField) = - apply { - this.totalDistanceAlongTrip = totalDistanceAlongTrip - } + /** References to situation elements (if any) applicable to this trip. */ + fun addSituationId(situationId: String) = apply { + situationIds = + (situationIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situationId) + } + } /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(vehicleId: String) = vehicleId(JsonField.of(vehicleId)) /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") - @ExcludeMissing fun vehicleId(vehicleId: JsonField) = apply { this.vehicleId = vehicleId } @@ -2060,63 +2190,77 @@ private constructor( fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): TripStatus = TripStatus( - activeTripId, - blockTripSequence, - closestStop, + checkRequired("activeTripId", activeTripId), + checkRequired("blockTripSequence", blockTripSequence), + checkRequired("closestStop", closestStop), + checkRequired("distanceAlongTrip", distanceAlongTrip), + checkRequired( + "lastKnownDistanceAlongTrip", + lastKnownDistanceAlongTrip + ), + checkRequired("lastLocationUpdateTime", lastLocationUpdateTime), + checkRequired("lastUpdateTime", lastUpdateTime), + checkRequired("occupancyCapacity", occupancyCapacity), + checkRequired("occupancyCount", occupancyCount), + checkRequired("occupancyStatus", occupancyStatus), + checkRequired("phase", phase), + checkRequired("predicted", predicted), + checkRequired("scheduleDeviation", scheduleDeviation), + checkRequired("serviceDate", serviceDate), + checkRequired("status", status), + checkRequired("totalDistanceAlongTrip", totalDistanceAlongTrip), closestStopTimeOffset, - distanceAlongTrip, frequency, - lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, - lastLocationUpdateTime, - lastUpdateTime, nextStop, nextStopTimeOffset, - occupancyCapacity, - occupancyCount, - occupancyStatus, orientation, - phase, position, - predicted, - scheduleDeviation, scheduledDistanceAlongTrip, - serviceDate, - situationIds.map { it.toImmutable() }, - status, - totalDistanceAlongTrip, + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, vehicleId, additionalProperties.toImmutable(), ) } /** Last known location of the transit vehicle. */ - @JsonDeserialize(builder = LastKnownLocation.Builder::class) @NoAutoDetect class LastKnownLocation + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = + immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the last known location of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -2124,21 +2268,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): LastKnownLocation = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -2148,7 +2296,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [LastKnownLocation]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -2157,42 +2306,46 @@ private constructor( @JvmSynthetic internal fun from(lastKnownLocation: LastKnownLocation) = apply { - this.lat = lastKnownLocation.lat - this.lon = lastKnownLocation.lon - additionalProperties(lastKnownLocation.additionalProperties) + lat = lastKnownLocation.lat + lon = lastKnownLocation.lon + additionalProperties = + lastKnownLocation.additionalProperties.toMutableMap() } /** Latitude of the last known location of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the last known location of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): LastKnownLocation = LastKnownLocation( lat, @@ -2206,34 +2359,35 @@ private constructor( return true } - return /* spotless:off */ other is LastKnownLocation && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is LastKnownLocation && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "LastKnownLocation{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" } /** Current position of the transit vehicle. */ - @JsonDeserialize(builder = Position.Builder::class) @NoAutoDetect class Position + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = + immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the current position of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -2241,21 +2395,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Position = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -2265,7 +2423,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Position]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -2274,42 +2433,45 @@ private constructor( @JvmSynthetic internal fun from(position: Position) = apply { - this.lat = position.lat - this.lon = position.lon - additionalProperties(position.additionalProperties) + lat = position.lat + lon = position.lon + additionalProperties = position.additionalProperties.toMutableMap() } /** Latitude of the current position of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the current position of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Position = Position( lat, @@ -2323,17 +2485,14 @@ private constructor( return true } - return /* spotless:off */ other is Position && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Position && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Position{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" @@ -2344,20 +2503,17 @@ private constructor( return true } - return /* spotless:off */ other is TripStatus && this.activeTripId == other.activeTripId && this.blockTripSequence == other.blockTripSequence && this.closestStop == other.closestStop && this.closestStopTimeOffset == other.closestStopTimeOffset && this.distanceAlongTrip == other.distanceAlongTrip && this.frequency == other.frequency && this.lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && this.lastKnownLocation == other.lastKnownLocation && this.lastKnownOrientation == other.lastKnownOrientation && this.lastLocationUpdateTime == other.lastLocationUpdateTime && this.lastUpdateTime == other.lastUpdateTime && this.nextStop == other.nextStop && this.nextStopTimeOffset == other.nextStopTimeOffset && this.occupancyCapacity == other.occupancyCapacity && this.occupancyCount == other.occupancyCount && this.occupancyStatus == other.occupancyStatus && this.orientation == other.orientation && this.phase == other.phase && this.position == other.position && this.predicted == other.predicted && this.scheduleDeviation == other.scheduleDeviation && this.scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && this.serviceDate == other.serviceDate && this.situationIds == other.situationIds && this.status == other.status && this.totalDistanceAlongTrip == other.totalDistanceAlongTrip && this.vehicleId == other.vehicleId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is TripStatus && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && distanceAlongTrip == other.distanceAlongTrip && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && phase == other.phase && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && serviceDate == other.serviceDate && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && closestStopTimeOffset == other.closestStopTimeOffset && frequency == other.frequency && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && orientation == other.orientation && position == other.position && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && situationIds == other.situationIds && vehicleId == other.vehicleId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(activeTripId, blockTripSequence, closestStop, distanceAlongTrip, lastKnownDistanceAlongTrip, lastLocationUpdateTime, lastUpdateTime, occupancyCapacity, occupancyCount, occupancyStatus, phase, predicted, scheduleDeviation, serviceDate, status, totalDistanceAlongTrip, closestStopTimeOffset, frequency, lastKnownLocation, lastKnownOrientation, nextStop, nextStopTimeOffset, orientation, position, scheduledDistanceAlongTrip, situationIds, vehicleId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(activeTripId, blockTripSequence, closestStop, closestStopTimeOffset, distanceAlongTrip, frequency, lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, lastLocationUpdateTime, lastUpdateTime, nextStop, nextStopTimeOffset, occupancyCapacity, occupancyCount, occupancyStatus, orientation, phase, position, predicted, scheduleDeviation, scheduledDistanceAlongTrip, serviceDate, situationIds, status, totalDistanceAlongTrip, vehicleId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "TripStatus{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, closestStopTimeOffset=$closestStopTimeOffset, distanceAlongTrip=$distanceAlongTrip, frequency=$frequency, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, orientation=$orientation, phase=$phase, position=$position, predicted=$predicted, scheduleDeviation=$scheduleDeviation, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, serviceDate=$serviceDate, situationIds=$situationIds, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" + "TripStatus{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, distanceAlongTrip=$distanceAlongTrip, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, phase=$phase, predicted=$predicted, scheduleDeviation=$scheduleDeviation, serviceDate=$serviceDate, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, closestStopTimeOffset=$closestStopTimeOffset, frequency=$frequency, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, orientation=$orientation, position=$position, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, situationIds=$situationIds, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -2365,20 +2521,17 @@ private constructor( return true } - return /* spotless:off */ other is ArrivalsAndDeparture && this.actualTrack == other.actualTrack && this.arrivalEnabled == other.arrivalEnabled && this.blockTripSequence == other.blockTripSequence && this.departureEnabled == other.departureEnabled && this.distanceFromStop == other.distanceFromStop && this.frequency == other.frequency && this.historicalOccupancy == other.historicalOccupancy && this.lastUpdateTime == other.lastUpdateTime && this.numberOfStopsAway == other.numberOfStopsAway && this.occupancyStatus == other.occupancyStatus && this.predicted == other.predicted && this.predictedArrivalInterval == other.predictedArrivalInterval && this.predictedArrivalTime == other.predictedArrivalTime && this.predictedDepartureInterval == other.predictedDepartureInterval && this.predictedDepartureTime == other.predictedDepartureTime && this.predictedOccupancy == other.predictedOccupancy && this.routeId == other.routeId && this.routeLongName == other.routeLongName && this.routeShortName == other.routeShortName && this.scheduledArrivalInterval == other.scheduledArrivalInterval && this.scheduledArrivalTime == other.scheduledArrivalTime && this.scheduledDepartureInterval == other.scheduledDepartureInterval && this.scheduledDepartureTime == other.scheduledDepartureTime && this.scheduledTrack == other.scheduledTrack && this.serviceDate == other.serviceDate && this.situationIds == other.situationIds && this.status == other.status && this.stopId == other.stopId && this.stopSequence == other.stopSequence && this.totalStopsInTrip == other.totalStopsInTrip && this.tripHeadsign == other.tripHeadsign && this.tripId == other.tripId && this.tripStatus == other.tripStatus && this.vehicleId == other.vehicleId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is ArrivalsAndDeparture && arrivalEnabled == other.arrivalEnabled && blockTripSequence == other.blockTripSequence && departureEnabled == other.departureEnabled && numberOfStopsAway == other.numberOfStopsAway && predictedArrivalTime == other.predictedArrivalTime && predictedDepartureTime == other.predictedDepartureTime && routeId == other.routeId && scheduledArrivalTime == other.scheduledArrivalTime && scheduledDepartureTime == other.scheduledDepartureTime && serviceDate == other.serviceDate && stopId == other.stopId && stopSequence == other.stopSequence && totalStopsInTrip == other.totalStopsInTrip && tripHeadsign == other.tripHeadsign && tripId == other.tripId && vehicleId == other.vehicleId && actualTrack == other.actualTrack && distanceFromStop == other.distanceFromStop && frequency == other.frequency && historicalOccupancy == other.historicalOccupancy && lastUpdateTime == other.lastUpdateTime && occupancyStatus == other.occupancyStatus && predicted == other.predicted && predictedArrivalInterval == other.predictedArrivalInterval && predictedDepartureInterval == other.predictedDepartureInterval && predictedOccupancy == other.predictedOccupancy && routeLongName == other.routeLongName && routeShortName == other.routeShortName && scheduledArrivalInterval == other.scheduledArrivalInterval && scheduledDepartureInterval == other.scheduledDepartureInterval && scheduledTrack == other.scheduledTrack && situationIds == other.situationIds && status == other.status && tripStatus == other.tripStatus && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(arrivalEnabled, blockTripSequence, departureEnabled, numberOfStopsAway, predictedArrivalTime, predictedDepartureTime, routeId, scheduledArrivalTime, scheduledDepartureTime, serviceDate, stopId, stopSequence, totalStopsInTrip, tripHeadsign, tripId, vehicleId, actualTrack, distanceFromStop, frequency, historicalOccupancy, lastUpdateTime, occupancyStatus, predicted, predictedArrivalInterval, predictedDepartureInterval, predictedOccupancy, routeLongName, routeShortName, scheduledArrivalInterval, scheduledDepartureInterval, scheduledTrack, situationIds, status, tripStatus, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(actualTrack, arrivalEnabled, blockTripSequence, departureEnabled, distanceFromStop, frequency, historicalOccupancy, lastUpdateTime, numberOfStopsAway, occupancyStatus, predicted, predictedArrivalInterval, predictedArrivalTime, predictedDepartureInterval, predictedDepartureTime, predictedOccupancy, routeId, routeLongName, routeShortName, scheduledArrivalInterval, scheduledArrivalTime, scheduledDepartureInterval, scheduledDepartureTime, scheduledTrack, serviceDate, situationIds, status, stopId, stopSequence, totalStopsInTrip, tripHeadsign, tripId, tripStatus, vehicleId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "ArrivalsAndDeparture{actualTrack=$actualTrack, arrivalEnabled=$arrivalEnabled, blockTripSequence=$blockTripSequence, departureEnabled=$departureEnabled, distanceFromStop=$distanceFromStop, frequency=$frequency, historicalOccupancy=$historicalOccupancy, lastUpdateTime=$lastUpdateTime, numberOfStopsAway=$numberOfStopsAway, occupancyStatus=$occupancyStatus, predicted=$predicted, predictedArrivalInterval=$predictedArrivalInterval, predictedArrivalTime=$predictedArrivalTime, predictedDepartureInterval=$predictedDepartureInterval, predictedDepartureTime=$predictedDepartureTime, predictedOccupancy=$predictedOccupancy, routeId=$routeId, routeLongName=$routeLongName, routeShortName=$routeShortName, scheduledArrivalInterval=$scheduledArrivalInterval, scheduledArrivalTime=$scheduledArrivalTime, scheduledDepartureInterval=$scheduledDepartureInterval, scheduledDepartureTime=$scheduledDepartureTime, scheduledTrack=$scheduledTrack, serviceDate=$serviceDate, situationIds=$situationIds, status=$status, stopId=$stopId, stopSequence=$stopSequence, totalStopsInTrip=$totalStopsInTrip, tripHeadsign=$tripHeadsign, tripId=$tripId, tripStatus=$tripStatus, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" + "ArrivalsAndDeparture{arrivalEnabled=$arrivalEnabled, blockTripSequence=$blockTripSequence, departureEnabled=$departureEnabled, numberOfStopsAway=$numberOfStopsAway, predictedArrivalTime=$predictedArrivalTime, predictedDepartureTime=$predictedDepartureTime, routeId=$routeId, scheduledArrivalTime=$scheduledArrivalTime, scheduledDepartureTime=$scheduledDepartureTime, serviceDate=$serviceDate, stopId=$stopId, stopSequence=$stopSequence, totalStopsInTrip=$totalStopsInTrip, tripHeadsign=$tripHeadsign, tripId=$tripId, vehicleId=$vehicleId, actualTrack=$actualTrack, distanceFromStop=$distanceFromStop, frequency=$frequency, historicalOccupancy=$historicalOccupancy, lastUpdateTime=$lastUpdateTime, occupancyStatus=$occupancyStatus, predicted=$predicted, predictedArrivalInterval=$predictedArrivalInterval, predictedDepartureInterval=$predictedDepartureInterval, predictedOccupancy=$predictedOccupancy, routeLongName=$routeLongName, routeShortName=$routeShortName, scheduledArrivalInterval=$scheduledArrivalInterval, scheduledDepartureInterval=$scheduledDepartureInterval, scheduledTrack=$scheduledTrack, situationIds=$situationIds, status=$status, tripStatus=$tripStatus, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -2386,17 +2539,14 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.arrivalsAndDepartures == other.arrivalsAndDepartures && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && arrivalsAndDepartures == other.arrivalsAndDepartures && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(arrivalsAndDepartures, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(arrivalsAndDepartures, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Entry{arrivalsAndDepartures=$arrivalsAndDepartures, additionalProperties=$additionalProperties}" @@ -2407,17 +2557,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, references=$references, additionalProperties=$additionalProperties}" @@ -2428,17 +2575,14 @@ private constructor( return true } - return /* spotless:off */ other is ArrivalAndDepartureListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is ArrivalAndDepartureListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "ArrivalAndDepartureListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureRetrieveParams.kt index a4890f6..2ce93d0 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureRetrieveParams.kt @@ -2,25 +2,26 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** arrival-and-departure-for-stop */ class ArrivalAndDepartureRetrieveParams -constructor( +private constructor( private val stopId: String, private val serviceDate: Long, private val tripId: String, private val stopSequence: Long?, private val time: Long?, private val vehicleId: String?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun stopId(): String = stopId @@ -34,18 +35,21 @@ constructor( fun vehicleId(): Optional = Optional.ofNullable(vehicleId) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.serviceDate.let { params.put("serviceDate", listOf(it.toString())) } - this.tripId.let { params.put("tripId", listOf(it.toString())) } - this.stopSequence?.let { params.put("stopSequence", listOf(it.toString())) } - this.time?.let { params.put("time", listOf(it.toString())) } - this.vehicleId?.let { params.put("vehicleId", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.serviceDate.let { queryParams.put("serviceDate", listOf(it.toString())) } + this.tripId.let { queryParams.put("tripId", listOf(it.toString())) } + this.stopSequence?.let { queryParams.put("stopSequence", listOf(it.toString())) } + this.time?.let { queryParams.put("time", listOf(it.toString())) } + this.vehicleId?.let { queryParams.put("vehicleId", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } fun getPathParam(index: Int): String { @@ -55,25 +59,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ArrivalAndDepartureRetrieveParams && this.stopId == other.stopId && this.serviceDate == other.serviceDate && this.tripId == other.tripId && this.stopSequence == other.stopSequence && this.time == other.time && this.vehicleId == other.vehicleId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(stopId, serviceDate, tripId, stopSequence, time, vehicleId, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "ArrivalAndDepartureRetrieveParams{stopId=$stopId, serviceDate=$serviceDate, tripId=$tripId, stopSequence=$stopSequence, time=$time, vehicleId=$vehicleId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -81,8 +66,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [ArrivalAndDepartureRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var stopId: String? = null private var serviceDate: Long? = null @@ -90,20 +76,21 @@ constructor( private var stopSequence: Long? = null private var time: Long? = null private var vehicleId: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(arrivalAndDepartureRetrieveParams: ArrivalAndDepartureRetrieveParams) = apply { - this.stopId = arrivalAndDepartureRetrieveParams.stopId - this.serviceDate = arrivalAndDepartureRetrieveParams.serviceDate - this.tripId = arrivalAndDepartureRetrieveParams.tripId - this.stopSequence = arrivalAndDepartureRetrieveParams.stopSequence - this.time = arrivalAndDepartureRetrieveParams.time - this.vehicleId = arrivalAndDepartureRetrieveParams.vehicleId - additionalHeaders(arrivalAndDepartureRetrieveParams.additionalHeaders) - additionalQueryParams(arrivalAndDepartureRetrieveParams.additionalQueryParams) + stopId = arrivalAndDepartureRetrieveParams.stopId + serviceDate = arrivalAndDepartureRetrieveParams.serviceDate + tripId = arrivalAndDepartureRetrieveParams.tripId + stopSequence = arrivalAndDepartureRetrieveParams.stopSequence + time = arrivalAndDepartureRetrieveParams.time + vehicleId = arrivalAndDepartureRetrieveParams.vehicleId + additionalHeaders = arrivalAndDepartureRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = + arrivalAndDepartureRetrieveParams.additionalQueryParams.toBuilder() } fun stopId(stopId: String) = apply { this.stopId = stopId } @@ -112,11 +99,29 @@ constructor( fun tripId(tripId: String) = apply { this.tripId = tripId } - fun stopSequence(stopSequence: Long) = apply { this.stopSequence = stopSequence } + fun stopSequence(stopSequence: Long?) = apply { this.stopSequence = stopSequence } + + fun stopSequence(stopSequence: Long) = stopSequence(stopSequence as Long?) + + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun stopSequence(stopSequence: Optional) = + stopSequence(stopSequence.orElse(null) as Long?) - fun time(time: Long) = apply { this.time = time } + fun time(time: Long?) = apply { this.time = time } - fun vehicleId(vehicleId: String) = apply { this.vehicleId = vehicleId } + fun time(time: Long) = time(time as Long?) + + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun time(time: Optional) = time(time.orElse(null) as Long?) + + fun vehicleId(vehicleId: String?) = apply { this.vehicleId = vehicleId } + + fun vehicleId(vehicleId: Optional) = vehicleId(vehicleId.orElse(null)) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -128,29 +133,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -163,51 +181,64 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): ArrivalAndDepartureRetrieveParams = ArrivalAndDepartureRetrieveParams( - checkNotNull(stopId) { "`stopId` is required but was not set" }, - checkNotNull(serviceDate) { "`serviceDate` is required but was not set" }, - checkNotNull(tripId) { "`tripId` is required but was not set" }, + checkRequired("stopId", stopId), + checkRequired("serviceDate", serviceDate), + checkRequired("tripId", tripId), stopSequence, time, vehicleId, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ArrivalAndDepartureRetrieveParams && stopId == other.stopId && serviceDate == other.serviceDate && tripId == other.tripId && stopSequence == other.stopSequence && time == other.time && vehicleId == other.vehicleId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(stopId, serviceDate, tripId, stopSequence, time, vehicleId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "ArrivalAndDepartureRetrieveParams{stopId=$stopId, serviceDate=$serviceDate, tripId=$tripId, stopSequence=$stopSequence, time=$time, vehicleId=$vehicleId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureRetrieveResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureRetrieveResponse.kt index eaa7107..cfc7751 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureRetrieveResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ArrivalAndDepartureRetrieveResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = ArrivalAndDepartureRetrieveResponse.Builder::class) @NoAutoDetect class ArrivalAndDepartureRetrieveResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): ArrivalAndDepartureRetrieveResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,111 +87,117 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [ArrivalAndDepartureRetrieveResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from( arrivalAndDepartureRetrieveResponse: ArrivalAndDepartureRetrieveResponse ) = apply { - this.code = arrivalAndDepartureRetrieveResponse.code - this.currentTime = arrivalAndDepartureRetrieveResponse.currentTime - this.text = arrivalAndDepartureRetrieveResponse.text - this.version = arrivalAndDepartureRetrieveResponse.version - this.data = arrivalAndDepartureRetrieveResponse.data - additionalProperties(arrivalAndDepartureRetrieveResponse.additionalProperties) + code = arrivalAndDepartureRetrieveResponse.code + currentTime = arrivalAndDepartureRetrieveResponse.currentTime + text = arrivalAndDepartureRetrieveResponse.text + version = arrivalAndDepartureRetrieveResponse.version + data = arrivalAndDepartureRetrieveResponse.data + additionalProperties = + arrivalAndDepartureRetrieveResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): ArrivalAndDepartureRetrieveResponse = ArrivalAndDepartureRetrieveResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") fun references(): References = references.getRequired("references") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -193,102 +207,167 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val actualTrack: JsonField, - private val arrivalEnabled: JsonField, - private val blockTripSequence: JsonField, - private val departureEnabled: JsonField, - private val distanceFromStop: JsonField, - private val frequency: JsonField, - private val historicalOccupancy: JsonField, - private val lastUpdateTime: JsonField, - private val numberOfStopsAway: JsonField, - private val occupancyStatus: JsonField, - private val predicted: JsonField, - private val predictedArrivalInterval: JsonField, - private val predictedArrivalTime: JsonField, - private val predictedDepartureInterval: JsonField, - private val predictedDepartureTime: JsonField, - private val predictedOccupancy: JsonField, - private val routeId: JsonField, - private val routeLongName: JsonField, - private val routeShortName: JsonField, - private val scheduledArrivalInterval: JsonField, - private val scheduledArrivalTime: JsonField, - private val scheduledDepartureInterval: JsonField, - private val scheduledDepartureTime: JsonField, - private val scheduledTrack: JsonField, - private val serviceDate: JsonField, - private val situationIds: JsonField>, - private val status: JsonField, - private val stopId: JsonField, - private val stopSequence: JsonField, - private val totalStopsInTrip: JsonField, - private val tripHeadsign: JsonField, - private val tripId: JsonField, - private val tripStatus: JsonField, - private val vehicleId: JsonField, - private val additionalProperties: Map, + @JsonProperty("arrivalEnabled") + @ExcludeMissing + private val arrivalEnabled: JsonField = JsonMissing.of(), + @JsonProperty("blockTripSequence") + @ExcludeMissing + private val blockTripSequence: JsonField = JsonMissing.of(), + @JsonProperty("departureEnabled") + @ExcludeMissing + private val departureEnabled: JsonField = JsonMissing.of(), + @JsonProperty("numberOfStopsAway") + @ExcludeMissing + private val numberOfStopsAway: JsonField = JsonMissing.of(), + @JsonProperty("predictedArrivalTime") + @ExcludeMissing + private val predictedArrivalTime: JsonField = JsonMissing.of(), + @JsonProperty("predictedDepartureTime") + @ExcludeMissing + private val predictedDepartureTime: JsonField = JsonMissing.of(), + @JsonProperty("routeId") + @ExcludeMissing + private val routeId: JsonField = JsonMissing.of(), + @JsonProperty("scheduledArrivalTime") + @ExcludeMissing + private val scheduledArrivalTime: JsonField = JsonMissing.of(), + @JsonProperty("scheduledDepartureTime") + @ExcludeMissing + private val scheduledDepartureTime: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonProperty("stopId") + @ExcludeMissing + private val stopId: JsonField = JsonMissing.of(), + @JsonProperty("stopSequence") + @ExcludeMissing + private val stopSequence: JsonField = JsonMissing.of(), + @JsonProperty("totalStopsInTrip") + @ExcludeMissing + private val totalStopsInTrip: JsonField = JsonMissing.of(), + @JsonProperty("tripHeadsign") + @ExcludeMissing + private val tripHeadsign: JsonField = JsonMissing.of(), + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), + @JsonProperty("vehicleId") + @ExcludeMissing + private val vehicleId: JsonField = JsonMissing.of(), + @JsonProperty("actualTrack") + @ExcludeMissing + private val actualTrack: JsonField = JsonMissing.of(), + @JsonProperty("distanceFromStop") + @ExcludeMissing + private val distanceFromStop: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonProperty("historicalOccupancy") + @ExcludeMissing + private val historicalOccupancy: JsonField = JsonMissing.of(), + @JsonProperty("lastUpdateTime") + @ExcludeMissing + private val lastUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("occupancyStatus") + @ExcludeMissing + private val occupancyStatus: JsonField = JsonMissing.of(), + @JsonProperty("predicted") + @ExcludeMissing + private val predicted: JsonField = JsonMissing.of(), + @JsonProperty("predictedArrivalInterval") + @ExcludeMissing + private val predictedArrivalInterval: JsonField = JsonMissing.of(), + @JsonProperty("predictedDepartureInterval") + @ExcludeMissing + private val predictedDepartureInterval: JsonField = JsonMissing.of(), + @JsonProperty("predictedOccupancy") + @ExcludeMissing + private val predictedOccupancy: JsonField = JsonMissing.of(), + @JsonProperty("routeLongName") + @ExcludeMissing + private val routeLongName: JsonField = JsonMissing.of(), + @JsonProperty("routeShortName") + @ExcludeMissing + private val routeShortName: JsonField = JsonMissing.of(), + @JsonProperty("scheduledArrivalInterval") + @ExcludeMissing + private val scheduledArrivalInterval: JsonField = JsonMissing.of(), + @JsonProperty("scheduledDepartureInterval") + @ExcludeMissing + private val scheduledDepartureInterval: JsonField = JsonMissing.of(), + @JsonProperty("scheduledTrack") + @ExcludeMissing + private val scheduledTrack: JsonField = JsonMissing.of(), + @JsonProperty("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonProperty("tripStatus") + @ExcludeMissing + private val tripStatus: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - /** The actual track information of the arriving transit vehicle. */ - fun actualTrack(): Optional = - Optional.ofNullable(actualTrack.getNullable("actualTrack")) - /** Indicates if riders can arrive on this transit vehicle. */ fun arrivalEnabled(): Boolean = arrivalEnabled.getRequired("arrivalEnabled") @@ -298,6 +377,70 @@ private constructor( /** Indicates if riders can depart from this transit vehicle. */ fun departureEnabled(): Boolean = departureEnabled.getRequired("departureEnabled") + /** + * Number of stops between the arriving transit vehicle and the current stop (excluding + * the current stop). + */ + fun numberOfStopsAway(): Long = numberOfStopsAway.getRequired("numberOfStopsAway") + + /** + * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time + * available). + */ + fun predictedArrivalTime(): Long = + predictedArrivalTime.getRequired("predictedArrivalTime") + + /** + * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time + * available). + */ + fun predictedDepartureTime(): Long = + predictedDepartureTime.getRequired("predictedDepartureTime") + + /** The ID of the route for the arriving vehicle. */ + fun routeId(): String = routeId.getRequired("routeId") + + /** Scheduled arrival time, in milliseconds since Unix epoch. */ + fun scheduledArrivalTime(): Long = + scheduledArrivalTime.getRequired("scheduledArrivalTime") + + /** Scheduled departure time, in milliseconds since Unix epoch. */ + fun scheduledDepartureTime(): Long = + scheduledDepartureTime.getRequired("scheduledDepartureTime") + + /** + * Time, in milliseconds since the Unix epoch, of midnight for the start of the service + * date for the trip. + */ + fun serviceDate(): Long = serviceDate.getRequired("serviceDate") + + /** The ID of the stop the vehicle is arriving at. */ + fun stopId(): String = stopId.getRequired("stopId") + + /** + * Index of the stop into the sequence of stops that make up the trip for this arrival. + */ + fun stopSequence(): Long = stopSequence.getRequired("stopSequence") + + /** Total number of stops visited on the trip for this arrival. */ + fun totalStopsInTrip(): Long = totalStopsInTrip.getRequired("totalStopsInTrip") + + /** + * Optional trip headsign that potentially overrides the trip headsign in the referenced + * trip element. + */ + fun tripHeadsign(): String = tripHeadsign.getRequired("tripHeadsign") + + /** The ID of the trip for the arriving vehicle. */ + fun tripId(): String = tripId.getRequired("tripId") + + /** ID of the transit vehicle serving this trip. */ + fun vehicleId(): String = vehicleId.getRequired("vehicleId") + + /** The actual track information of the arriving transit vehicle. */ + fun actualTrack(): Optional = + Optional.ofNullable(actualTrack.getNullable("actualTrack")) + /** Distance of the arriving transit vehicle from the stop, in meters. */ fun distanceFromStop(): Optional = Optional.ofNullable(distanceFromStop.getNullable("distanceFromStop")) @@ -314,12 +457,6 @@ private constructor( fun lastUpdateTime(): Optional = Optional.ofNullable(lastUpdateTime.getNullable("lastUpdateTime")) - /** - * Number of stops between the arriving transit vehicle and the current stop (excluding - * the current stop). - */ - fun numberOfStopsAway(): Long = numberOfStopsAway.getRequired("numberOfStopsAway") - /** Current occupancy status of the transit vehicle. */ fun occupancyStatus(): Optional = Optional.ofNullable(occupancyStatus.getNullable("occupancyStatus")) @@ -334,33 +471,16 @@ private constructor( predictedArrivalInterval.getNullable("predictedArrivalInterval") ) - /** - * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time - * available). - */ - fun predictedArrivalTime(): Long = - predictedArrivalTime.getRequired("predictedArrivalTime") - /** Interval for predicted departure time, if available. */ fun predictedDepartureInterval(): Optional = Optional.ofNullable( predictedDepartureInterval.getNullable("predictedDepartureInterval") ) - /** - * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time - * available). - */ - fun predictedDepartureTime(): Long = - predictedDepartureTime.getRequired("predictedDepartureTime") - /** Predicted occupancy status of the transit vehicle. */ fun predictedOccupancy(): Optional = Optional.ofNullable(predictedOccupancy.getNullable("predictedOccupancy")) - /** The ID of the route for the arriving vehicle. */ - fun routeId(): String = routeId.getRequired("routeId") - /** * Optional route long name that potentially overrides the route long name in the * referenced route element. @@ -381,30 +501,16 @@ private constructor( scheduledArrivalInterval.getNullable("scheduledArrivalInterval") ) - /** Scheduled arrival time, in milliseconds since Unix epoch. */ - fun scheduledArrivalTime(): Long = - scheduledArrivalTime.getRequired("scheduledArrivalTime") - /** Interval for scheduled departure time. */ fun scheduledDepartureInterval(): Optional = Optional.ofNullable( scheduledDepartureInterval.getNullable("scheduledDepartureInterval") ) - /** Scheduled departure time, in milliseconds since Unix epoch. */ - fun scheduledDepartureTime(): Long = - scheduledDepartureTime.getRequired("scheduledDepartureTime") - /** Scheduled track information of the arriving transit vehicle. */ fun scheduledTrack(): Optional = Optional.ofNullable(scheduledTrack.getNullable("scheduledTrack")) - /** - * Time, in milliseconds since the Unix epoch, of midnight for the start of the service - * date for the trip. - */ - fun serviceDate(): Long = serviceDate.getRequired("serviceDate") - /** References to situation elements (if any) applicable to this arrival. */ fun situationIds(): Optional> = Optional.ofNullable(situationIds.getNullable("situationIds")) @@ -412,64 +518,24 @@ private constructor( /** Current status of the arrival. */ fun status(): Optional = Optional.ofNullable(status.getNullable("status")) - /** The ID of the stop the vehicle is arriving at. */ - fun stopId(): String = stopId.getRequired("stopId") - - /** - * Index of the stop into the sequence of stops that make up the trip for this arrival. - */ - fun stopSequence(): Long = stopSequence.getRequired("stopSequence") - - /** Total number of stops visited on the trip for this arrival. */ - fun totalStopsInTrip(): Long = totalStopsInTrip.getRequired("totalStopsInTrip") - - /** - * Optional trip headsign that potentially overrides the trip headsign in the referenced - * trip element. - */ - fun tripHeadsign(): String = tripHeadsign.getRequired("tripHeadsign") - - /** The ID of the trip for the arriving vehicle. */ - fun tripId(): String = tripId.getRequired("tripId") - /** Trip-specific status for the arriving transit vehicle. */ fun tripStatus(): Optional = Optional.ofNullable(tripStatus.getNullable("tripStatus")) - /** ID of the transit vehicle serving this trip. */ - fun vehicleId(): String = vehicleId.getRequired("vehicleId") - - /** The actual track information of the arriving transit vehicle. */ - @JsonProperty("actualTrack") @ExcludeMissing fun _actualTrack() = actualTrack - /** Indicates if riders can arrive on this transit vehicle. */ - @JsonProperty("arrivalEnabled") @ExcludeMissing fun _arrivalEnabled() = arrivalEnabled + @JsonProperty("arrivalEnabled") + @ExcludeMissing + fun _arrivalEnabled(): JsonField = arrivalEnabled /** Index of this arrival’s trip into the sequence of trips for the active block. */ @JsonProperty("blockTripSequence") @ExcludeMissing - fun _blockTripSequence() = blockTripSequence + fun _blockTripSequence(): JsonField = blockTripSequence /** Indicates if riders can depart from this transit vehicle. */ @JsonProperty("departureEnabled") @ExcludeMissing - fun _departureEnabled() = departureEnabled - - /** Distance of the arriving transit vehicle from the stop, in meters. */ - @JsonProperty("distanceFromStop") - @ExcludeMissing - fun _distanceFromStop() = distanceFromStop - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency - - /** Historical occupancy information of the transit vehicle. */ - @JsonProperty("historicalOccupancy") - @ExcludeMissing - fun _historicalOccupancy() = historicalOccupancy - - /** Timestamp of the last update time for this arrival. */ - @JsonProperty("lastUpdateTime") @ExcludeMissing fun _lastUpdateTime() = lastUpdateTime + fun _departureEnabled(): JsonField = departureEnabled /** * Number of stops between the arriving transit vehicle and the current stop (excluding @@ -477,167 +543,216 @@ private constructor( */ @JsonProperty("numberOfStopsAway") @ExcludeMissing - fun _numberOfStopsAway() = numberOfStopsAway + fun _numberOfStopsAway(): JsonField = numberOfStopsAway - /** Current occupancy status of the transit vehicle. */ - @JsonProperty("occupancyStatus") + /** + * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time + * available). + */ + @JsonProperty("predictedArrivalTime") @ExcludeMissing - fun _occupancyStatus() = occupancyStatus + fun _predictedArrivalTime(): JsonField = predictedArrivalTime - /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") @ExcludeMissing fun _predicted() = predicted + /** + * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time + * available). + */ + @JsonProperty("predictedDepartureTime") + @ExcludeMissing + fun _predictedDepartureTime(): JsonField = predictedDepartureTime - /** Interval for predicted arrival time, if available. */ - @JsonProperty("predictedArrivalInterval") + /** The ID of the route for the arriving vehicle. */ + @JsonProperty("routeId") @ExcludeMissing fun _routeId(): JsonField = routeId + + /** Scheduled arrival time, in milliseconds since Unix epoch. */ + @JsonProperty("scheduledArrivalTime") + @ExcludeMissing + fun _scheduledArrivalTime(): JsonField = scheduledArrivalTime + + /** Scheduled departure time, in milliseconds since Unix epoch. */ + @JsonProperty("scheduledDepartureTime") @ExcludeMissing - fun _predictedArrivalInterval() = predictedArrivalInterval + fun _scheduledDepartureTime(): JsonField = scheduledDepartureTime /** - * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time - * available). + * Time, in milliseconds since the Unix epoch, of midnight for the start of the service + * date for the trip. */ - @JsonProperty("predictedArrivalTime") + @JsonProperty("serviceDate") @ExcludeMissing - fun _predictedArrivalTime() = predictedArrivalTime + fun _serviceDate(): JsonField = serviceDate - /** Interval for predicted departure time, if available. */ - @JsonProperty("predictedDepartureInterval") + /** The ID of the stop the vehicle is arriving at. */ + @JsonProperty("stopId") @ExcludeMissing fun _stopId(): JsonField = stopId + + /** + * Index of the stop into the sequence of stops that make up the trip for this arrival. + */ + @JsonProperty("stopSequence") + @ExcludeMissing + fun _stopSequence(): JsonField = stopSequence + + /** Total number of stops visited on the trip for this arrival. */ + @JsonProperty("totalStopsInTrip") @ExcludeMissing - fun _predictedDepartureInterval() = predictedDepartureInterval + fun _totalStopsInTrip(): JsonField = totalStopsInTrip /** - * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time - * available). + * Optional trip headsign that potentially overrides the trip headsign in the referenced + * trip element. */ - @JsonProperty("predictedDepartureTime") + @JsonProperty("tripHeadsign") + @ExcludeMissing + fun _tripHeadsign(): JsonField = tripHeadsign + + /** The ID of the trip for the arriving vehicle. */ + @JsonProperty("tripId") @ExcludeMissing fun _tripId(): JsonField = tripId + + /** ID of the transit vehicle serving this trip. */ + @JsonProperty("vehicleId") + @ExcludeMissing + fun _vehicleId(): JsonField = vehicleId + + /** The actual track information of the arriving transit vehicle. */ + @JsonProperty("actualTrack") + @ExcludeMissing + fun _actualTrack(): JsonField = actualTrack + + /** Distance of the arriving transit vehicle from the stop, in meters. */ + @JsonProperty("distanceFromStop") + @ExcludeMissing + fun _distanceFromStop(): JsonField = distanceFromStop + + /** Information about frequency-based scheduling, if applicable to the trip. */ + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency + + /** Historical occupancy information of the transit vehicle. */ + @JsonProperty("historicalOccupancy") @ExcludeMissing - fun _predictedDepartureTime() = predictedDepartureTime + fun _historicalOccupancy(): JsonField = historicalOccupancy + + /** Timestamp of the last update time for this arrival. */ + @JsonProperty("lastUpdateTime") + @ExcludeMissing + fun _lastUpdateTime(): JsonField = lastUpdateTime + + /** Current occupancy status of the transit vehicle. */ + @JsonProperty("occupancyStatus") + @ExcludeMissing + fun _occupancyStatus(): JsonField = occupancyStatus + + /** Indicates if real-time arrival info is available for this trip. */ + @JsonProperty("predicted") + @ExcludeMissing + fun _predicted(): JsonField = predicted + + /** Interval for predicted arrival time, if available. */ + @JsonProperty("predictedArrivalInterval") + @ExcludeMissing + fun _predictedArrivalInterval(): JsonField = predictedArrivalInterval + + /** Interval for predicted departure time, if available. */ + @JsonProperty("predictedDepartureInterval") + @ExcludeMissing + fun _predictedDepartureInterval(): JsonField = predictedDepartureInterval /** Predicted occupancy status of the transit vehicle. */ @JsonProperty("predictedOccupancy") @ExcludeMissing - fun _predictedOccupancy() = predictedOccupancy - - /** The ID of the route for the arriving vehicle. */ - @JsonProperty("routeId") @ExcludeMissing fun _routeId() = routeId + fun _predictedOccupancy(): JsonField = predictedOccupancy /** * Optional route long name that potentially overrides the route long name in the * referenced route element. */ - @JsonProperty("routeLongName") @ExcludeMissing fun _routeLongName() = routeLongName + @JsonProperty("routeLongName") + @ExcludeMissing + fun _routeLongName(): JsonField = routeLongName /** * Optional route short name that potentially overrides the route short name in the * referenced route element. */ - @JsonProperty("routeShortName") @ExcludeMissing fun _routeShortName() = routeShortName + @JsonProperty("routeShortName") + @ExcludeMissing + fun _routeShortName(): JsonField = routeShortName /** Interval for scheduled arrival time. */ @JsonProperty("scheduledArrivalInterval") @ExcludeMissing - fun _scheduledArrivalInterval() = scheduledArrivalInterval - - /** Scheduled arrival time, in milliseconds since Unix epoch. */ - @JsonProperty("scheduledArrivalTime") - @ExcludeMissing - fun _scheduledArrivalTime() = scheduledArrivalTime + fun _scheduledArrivalInterval(): JsonField = scheduledArrivalInterval /** Interval for scheduled departure time. */ @JsonProperty("scheduledDepartureInterval") @ExcludeMissing - fun _scheduledDepartureInterval() = scheduledDepartureInterval - - /** Scheduled departure time, in milliseconds since Unix epoch. */ - @JsonProperty("scheduledDepartureTime") - @ExcludeMissing - fun _scheduledDepartureTime() = scheduledDepartureTime + fun _scheduledDepartureInterval(): JsonField = scheduledDepartureInterval /** Scheduled track information of the arriving transit vehicle. */ - @JsonProperty("scheduledTrack") @ExcludeMissing fun _scheduledTrack() = scheduledTrack - - /** - * Time, in milliseconds since the Unix epoch, of midnight for the start of the service - * date for the trip. - */ - @JsonProperty("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate + @JsonProperty("scheduledTrack") + @ExcludeMissing + fun _scheduledTrack(): JsonField = scheduledTrack /** References to situation elements (if any) applicable to this arrival. */ - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds - - /** Current status of the arrival. */ - @JsonProperty("status") @ExcludeMissing fun _status() = status - - /** The ID of the stop the vehicle is arriving at. */ - @JsonProperty("stopId") @ExcludeMissing fun _stopId() = stopId - - /** - * Index of the stop into the sequence of stops that make up the trip for this arrival. - */ - @JsonProperty("stopSequence") @ExcludeMissing fun _stopSequence() = stopSequence - - /** Total number of stops visited on the trip for this arrival. */ - @JsonProperty("totalStopsInTrip") + @JsonProperty("situationIds") @ExcludeMissing - fun _totalStopsInTrip() = totalStopsInTrip - - /** - * Optional trip headsign that potentially overrides the trip headsign in the referenced - * trip element. - */ - @JsonProperty("tripHeadsign") @ExcludeMissing fun _tripHeadsign() = tripHeadsign + fun _situationIds(): JsonField> = situationIds - /** The ID of the trip for the arriving vehicle. */ - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + /** Current status of the arrival. */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status /** Trip-specific status for the arriving transit vehicle. */ - @JsonProperty("tripStatus") @ExcludeMissing fun _tripStatus() = tripStatus - - /** ID of the transit vehicle serving this trip. */ - @JsonProperty("vehicleId") @ExcludeMissing fun _vehicleId() = vehicleId + @JsonProperty("tripStatus") + @ExcludeMissing + fun _tripStatus(): JsonField = tripStatus @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - actualTrack() - arrivalEnabled() - blockTripSequence() - departureEnabled() - distanceFromStop() - frequency() - historicalOccupancy() - lastUpdateTime() - numberOfStopsAway() - occupancyStatus() - predicted() - predictedArrivalInterval() - predictedArrivalTime() - predictedDepartureInterval() - predictedDepartureTime() - predictedOccupancy() - routeId() - routeLongName() - routeShortName() - scheduledArrivalInterval() - scheduledArrivalTime() - scheduledDepartureInterval() - scheduledDepartureTime() - scheduledTrack() - serviceDate() - situationIds() - status() - stopId() - stopSequence() - totalStopsInTrip() - tripHeadsign() - tripId() - tripStatus().map { it.validate() } - vehicleId() - validated = true + if (validated) { + return@apply } + + arrivalEnabled() + blockTripSequence() + departureEnabled() + numberOfStopsAway() + predictedArrivalTime() + predictedDepartureTime() + routeId() + scheduledArrivalTime() + scheduledDepartureTime() + serviceDate() + stopId() + stopSequence() + totalStopsInTrip() + tripHeadsign() + tripId() + vehicleId() + actualTrack() + distanceFromStop() + frequency() + historicalOccupancy() + lastUpdateTime() + occupancyStatus() + predicted() + predictedArrivalInterval() + predictedDepartureInterval() + predictedOccupancy() + routeLongName() + routeShortName() + scheduledArrivalInterval() + scheduledDepartureInterval() + scheduledTrack() + situationIds() + status() + tripStatus().ifPresent { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -647,91 +762,82 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - + /** A builder for [Entry]. */ + class Builder internal constructor() { + + private var arrivalEnabled: JsonField? = null + private var blockTripSequence: JsonField? = null + private var departureEnabled: JsonField? = null + private var numberOfStopsAway: JsonField? = null + private var predictedArrivalTime: JsonField? = null + private var predictedDepartureTime: JsonField? = null + private var routeId: JsonField? = null + private var scheduledArrivalTime: JsonField? = null + private var scheduledDepartureTime: JsonField? = null + private var serviceDate: JsonField? = null + private var stopId: JsonField? = null + private var stopSequence: JsonField? = null + private var totalStopsInTrip: JsonField? = null + private var tripHeadsign: JsonField? = null + private var tripId: JsonField? = null + private var vehicleId: JsonField? = null private var actualTrack: JsonField = JsonMissing.of() - private var arrivalEnabled: JsonField = JsonMissing.of() - private var blockTripSequence: JsonField = JsonMissing.of() - private var departureEnabled: JsonField = JsonMissing.of() private var distanceFromStop: JsonField = JsonMissing.of() private var frequency: JsonField = JsonMissing.of() private var historicalOccupancy: JsonField = JsonMissing.of() private var lastUpdateTime: JsonField = JsonMissing.of() - private var numberOfStopsAway: JsonField = JsonMissing.of() private var occupancyStatus: JsonField = JsonMissing.of() private var predicted: JsonField = JsonMissing.of() private var predictedArrivalInterval: JsonField = JsonMissing.of() - private var predictedArrivalTime: JsonField = JsonMissing.of() private var predictedDepartureInterval: JsonField = JsonMissing.of() - private var predictedDepartureTime: JsonField = JsonMissing.of() private var predictedOccupancy: JsonField = JsonMissing.of() - private var routeId: JsonField = JsonMissing.of() private var routeLongName: JsonField = JsonMissing.of() private var routeShortName: JsonField = JsonMissing.of() private var scheduledArrivalInterval: JsonField = JsonMissing.of() - private var scheduledArrivalTime: JsonField = JsonMissing.of() private var scheduledDepartureInterval: JsonField = JsonMissing.of() - private var scheduledDepartureTime: JsonField = JsonMissing.of() private var scheduledTrack: JsonField = JsonMissing.of() - private var serviceDate: JsonField = JsonMissing.of() - private var situationIds: JsonField> = JsonMissing.of() + private var situationIds: JsonField>? = null private var status: JsonField = JsonMissing.of() - private var stopId: JsonField = JsonMissing.of() - private var stopSequence: JsonField = JsonMissing.of() - private var totalStopsInTrip: JsonField = JsonMissing.of() - private var tripHeadsign: JsonField = JsonMissing.of() - private var tripId: JsonField = JsonMissing.of() private var tripStatus: JsonField = JsonMissing.of() - private var vehicleId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(entry: Entry) = apply { - this.actualTrack = entry.actualTrack - this.arrivalEnabled = entry.arrivalEnabled - this.blockTripSequence = entry.blockTripSequence - this.departureEnabled = entry.departureEnabled - this.distanceFromStop = entry.distanceFromStop - this.frequency = entry.frequency - this.historicalOccupancy = entry.historicalOccupancy - this.lastUpdateTime = entry.lastUpdateTime - this.numberOfStopsAway = entry.numberOfStopsAway - this.occupancyStatus = entry.occupancyStatus - this.predicted = entry.predicted - this.predictedArrivalInterval = entry.predictedArrivalInterval - this.predictedArrivalTime = entry.predictedArrivalTime - this.predictedDepartureInterval = entry.predictedDepartureInterval - this.predictedDepartureTime = entry.predictedDepartureTime - this.predictedOccupancy = entry.predictedOccupancy - this.routeId = entry.routeId - this.routeLongName = entry.routeLongName - this.routeShortName = entry.routeShortName - this.scheduledArrivalInterval = entry.scheduledArrivalInterval - this.scheduledArrivalTime = entry.scheduledArrivalTime - this.scheduledDepartureInterval = entry.scheduledDepartureInterval - this.scheduledDepartureTime = entry.scheduledDepartureTime - this.scheduledTrack = entry.scheduledTrack - this.serviceDate = entry.serviceDate - this.situationIds = entry.situationIds - this.status = entry.status - this.stopId = entry.stopId - this.stopSequence = entry.stopSequence - this.totalStopsInTrip = entry.totalStopsInTrip - this.tripHeadsign = entry.tripHeadsign - this.tripId = entry.tripId - this.tripStatus = entry.tripStatus - this.vehicleId = entry.vehicleId - additionalProperties(entry.additionalProperties) - } - - /** The actual track information of the arriving transit vehicle. */ - fun actualTrack(actualTrack: String) = actualTrack(JsonField.of(actualTrack)) - - /** The actual track information of the arriving transit vehicle. */ - @JsonProperty("actualTrack") - @ExcludeMissing - fun actualTrack(actualTrack: JsonField) = apply { - this.actualTrack = actualTrack + arrivalEnabled = entry.arrivalEnabled + blockTripSequence = entry.blockTripSequence + departureEnabled = entry.departureEnabled + numberOfStopsAway = entry.numberOfStopsAway + predictedArrivalTime = entry.predictedArrivalTime + predictedDepartureTime = entry.predictedDepartureTime + routeId = entry.routeId + scheduledArrivalTime = entry.scheduledArrivalTime + scheduledDepartureTime = entry.scheduledDepartureTime + serviceDate = entry.serviceDate + stopId = entry.stopId + stopSequence = entry.stopSequence + totalStopsInTrip = entry.totalStopsInTrip + tripHeadsign = entry.tripHeadsign + tripId = entry.tripId + vehicleId = entry.vehicleId + actualTrack = entry.actualTrack + distanceFromStop = entry.distanceFromStop + frequency = entry.frequency + historicalOccupancy = entry.historicalOccupancy + lastUpdateTime = entry.lastUpdateTime + occupancyStatus = entry.occupancyStatus + predicted = entry.predicted + predictedArrivalInterval = entry.predictedArrivalInterval + predictedDepartureInterval = entry.predictedDepartureInterval + predictedOccupancy = entry.predictedOccupancy + routeLongName = entry.routeLongName + routeShortName = entry.routeShortName + scheduledArrivalInterval = entry.scheduledArrivalInterval + scheduledDepartureInterval = entry.scheduledDepartureInterval + scheduledTrack = entry.scheduledTrack + situationIds = entry.situationIds.map { it.toMutableList() } + status = entry.status + tripStatus = entry.tripStatus + additionalProperties = entry.additionalProperties.toMutableMap() } /** Indicates if riders can arrive on this transit vehicle. */ @@ -739,8 +845,6 @@ private constructor( arrivalEnabled(JsonField.of(arrivalEnabled)) /** Indicates if riders can arrive on this transit vehicle. */ - @JsonProperty("arrivalEnabled") - @ExcludeMissing fun arrivalEnabled(arrivalEnabled: JsonField) = apply { this.arrivalEnabled = arrivalEnabled } @@ -750,8 +854,6 @@ private constructor( blockTripSequence(JsonField.of(blockTripSequence)) /** Index of this arrival’s trip into the sequence of trips for the active block. */ - @JsonProperty("blockTripSequence") - @ExcludeMissing fun blockTripSequence(blockTripSequence: JsonField) = apply { this.blockTripSequence = blockTripSequence } @@ -761,19 +863,161 @@ private constructor( departureEnabled(JsonField.of(departureEnabled)) /** Indicates if riders can depart from this transit vehicle. */ - @JsonProperty("departureEnabled") - @ExcludeMissing fun departureEnabled(departureEnabled: JsonField) = apply { this.departureEnabled = departureEnabled } + /** + * Number of stops between the arriving transit vehicle and the current stop + * (excluding the current stop). + */ + fun numberOfStopsAway(numberOfStopsAway: Long) = + numberOfStopsAway(JsonField.of(numberOfStopsAway)) + + /** + * Number of stops between the arriving transit vehicle and the current stop + * (excluding the current stop). + */ + fun numberOfStopsAway(numberOfStopsAway: JsonField) = apply { + this.numberOfStopsAway = numberOfStopsAway + } + + /** + * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time + * available). + */ + fun predictedArrivalTime(predictedArrivalTime: Long) = + predictedArrivalTime(JsonField.of(predictedArrivalTime)) + + /** + * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time + * available). + */ + fun predictedArrivalTime(predictedArrivalTime: JsonField) = apply { + this.predictedArrivalTime = predictedArrivalTime + } + + /** + * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time + * available). + */ + fun predictedDepartureTime(predictedDepartureTime: Long) = + predictedDepartureTime(JsonField.of(predictedDepartureTime)) + + /** + * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time + * available). + */ + fun predictedDepartureTime(predictedDepartureTime: JsonField) = apply { + this.predictedDepartureTime = predictedDepartureTime + } + + /** The ID of the route for the arriving vehicle. */ + fun routeId(routeId: String) = routeId(JsonField.of(routeId)) + + /** The ID of the route for the arriving vehicle. */ + fun routeId(routeId: JsonField) = apply { this.routeId = routeId } + + /** Scheduled arrival time, in milliseconds since Unix epoch. */ + fun scheduledArrivalTime(scheduledArrivalTime: Long) = + scheduledArrivalTime(JsonField.of(scheduledArrivalTime)) + + /** Scheduled arrival time, in milliseconds since Unix epoch. */ + fun scheduledArrivalTime(scheduledArrivalTime: JsonField) = apply { + this.scheduledArrivalTime = scheduledArrivalTime + } + + /** Scheduled departure time, in milliseconds since Unix epoch. */ + fun scheduledDepartureTime(scheduledDepartureTime: Long) = + scheduledDepartureTime(JsonField.of(scheduledDepartureTime)) + + /** Scheduled departure time, in milliseconds since Unix epoch. */ + fun scheduledDepartureTime(scheduledDepartureTime: JsonField) = apply { + this.scheduledDepartureTime = scheduledDepartureTime + } + + /** + * Time, in milliseconds since the Unix epoch, of midnight for the start of the + * service date for the trip. + */ + fun serviceDate(serviceDate: Long) = serviceDate(JsonField.of(serviceDate)) + + /** + * Time, in milliseconds since the Unix epoch, of midnight for the start of the + * service date for the trip. + */ + fun serviceDate(serviceDate: JsonField) = apply { + this.serviceDate = serviceDate + } + + /** The ID of the stop the vehicle is arriving at. */ + fun stopId(stopId: String) = stopId(JsonField.of(stopId)) + + /** The ID of the stop the vehicle is arriving at. */ + fun stopId(stopId: JsonField) = apply { this.stopId = stopId } + + /** + * Index of the stop into the sequence of stops that make up the trip for this + * arrival. + */ + fun stopSequence(stopSequence: Long) = stopSequence(JsonField.of(stopSequence)) + + /** + * Index of the stop into the sequence of stops that make up the trip for this + * arrival. + */ + fun stopSequence(stopSequence: JsonField) = apply { + this.stopSequence = stopSequence + } + + /** Total number of stops visited on the trip for this arrival. */ + fun totalStopsInTrip(totalStopsInTrip: Long) = + totalStopsInTrip(JsonField.of(totalStopsInTrip)) + + /** Total number of stops visited on the trip for this arrival. */ + fun totalStopsInTrip(totalStopsInTrip: JsonField) = apply { + this.totalStopsInTrip = totalStopsInTrip + } + + /** + * Optional trip headsign that potentially overrides the trip headsign in the + * referenced trip element. + */ + fun tripHeadsign(tripHeadsign: String) = tripHeadsign(JsonField.of(tripHeadsign)) + + /** + * Optional trip headsign that potentially overrides the trip headsign in the + * referenced trip element. + */ + fun tripHeadsign(tripHeadsign: JsonField) = apply { + this.tripHeadsign = tripHeadsign + } + + /** The ID of the trip for the arriving vehicle. */ + fun tripId(tripId: String) = tripId(JsonField.of(tripId)) + + /** The ID of the trip for the arriving vehicle. */ + fun tripId(tripId: JsonField) = apply { this.tripId = tripId } + + /** ID of the transit vehicle serving this trip. */ + fun vehicleId(vehicleId: String) = vehicleId(JsonField.of(vehicleId)) + + /** ID of the transit vehicle serving this trip. */ + fun vehicleId(vehicleId: JsonField) = apply { this.vehicleId = vehicleId } + + /** The actual track information of the arriving transit vehicle. */ + fun actualTrack(actualTrack: String) = actualTrack(JsonField.of(actualTrack)) + + /** The actual track information of the arriving transit vehicle. */ + fun actualTrack(actualTrack: JsonField) = apply { + this.actualTrack = actualTrack + } + /** Distance of the arriving transit vehicle from the stop, in meters. */ fun distanceFromStop(distanceFromStop: Double) = distanceFromStop(JsonField.of(distanceFromStop)) /** Distance of the arriving transit vehicle from the stop, in meters. */ - @JsonProperty("distanceFromStop") - @ExcludeMissing fun distanceFromStop(distanceFromStop: JsonField) = apply { this.distanceFromStop = distanceFromStop } @@ -782,8 +1026,6 @@ private constructor( fun frequency(frequency: String) = frequency(JsonField.of(frequency)) /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") - @ExcludeMissing fun frequency(frequency: JsonField) = apply { this.frequency = frequency } /** Historical occupancy information of the transit vehicle. */ @@ -791,8 +1033,6 @@ private constructor( historicalOccupancy(JsonField.of(historicalOccupancy)) /** Historical occupancy information of the transit vehicle. */ - @JsonProperty("historicalOccupancy") - @ExcludeMissing fun historicalOccupancy(historicalOccupancy: JsonField) = apply { this.historicalOccupancy = historicalOccupancy } @@ -802,36 +1042,15 @@ private constructor( lastUpdateTime(JsonField.of(lastUpdateTime)) /** Timestamp of the last update time for this arrival. */ - @JsonProperty("lastUpdateTime") - @ExcludeMissing fun lastUpdateTime(lastUpdateTime: JsonField) = apply { this.lastUpdateTime = lastUpdateTime } - /** - * Number of stops between the arriving transit vehicle and the current stop - * (excluding the current stop). - */ - fun numberOfStopsAway(numberOfStopsAway: Long) = - numberOfStopsAway(JsonField.of(numberOfStopsAway)) - - /** - * Number of stops between the arriving transit vehicle and the current stop - * (excluding the current stop). - */ - @JsonProperty("numberOfStopsAway") - @ExcludeMissing - fun numberOfStopsAway(numberOfStopsAway: JsonField) = apply { - this.numberOfStopsAway = numberOfStopsAway - } - /** Current occupancy status of the transit vehicle. */ fun occupancyStatus(occupancyStatus: String) = occupancyStatus(JsonField.of(occupancyStatus)) /** Current occupancy status of the transit vehicle. */ - @JsonProperty("occupancyStatus") - @ExcludeMissing fun occupancyStatus(occupancyStatus: JsonField) = apply { this.occupancyStatus = occupancyStatus } @@ -840,8 +1059,6 @@ private constructor( fun predicted(predicted: Boolean) = predicted(JsonField.of(predicted)) /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") - @ExcludeMissing fun predicted(predicted: JsonField) = apply { this.predicted = predicted } /** Interval for predicted arrival time, if available. */ @@ -849,77 +1066,29 @@ private constructor( predictedArrivalInterval(JsonField.of(predictedArrivalInterval)) /** Interval for predicted arrival time, if available. */ - @JsonProperty("predictedArrivalInterval") - @ExcludeMissing fun predictedArrivalInterval(predictedArrivalInterval: JsonField) = apply { this.predictedArrivalInterval = predictedArrivalInterval } - /** - * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time - * available). - */ - fun predictedArrivalTime(predictedArrivalTime: Long) = - predictedArrivalTime(JsonField.of(predictedArrivalTime)) - - /** - * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time - * available). - */ - @JsonProperty("predictedArrivalTime") - @ExcludeMissing - fun predictedArrivalTime(predictedArrivalTime: JsonField) = apply { - this.predictedArrivalTime = predictedArrivalTime - } - /** Interval for predicted departure time, if available. */ fun predictedDepartureInterval(predictedDepartureInterval: String) = predictedDepartureInterval(JsonField.of(predictedDepartureInterval)) /** Interval for predicted departure time, if available. */ - @JsonProperty("predictedDepartureInterval") - @ExcludeMissing fun predictedDepartureInterval(predictedDepartureInterval: JsonField) = apply { this.predictedDepartureInterval = predictedDepartureInterval } - /** - * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time - * available). - */ - fun predictedDepartureTime(predictedDepartureTime: Long) = - predictedDepartureTime(JsonField.of(predictedDepartureTime)) - - /** - * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time - * available). - */ - @JsonProperty("predictedDepartureTime") - @ExcludeMissing - fun predictedDepartureTime(predictedDepartureTime: JsonField) = apply { - this.predictedDepartureTime = predictedDepartureTime - } - /** Predicted occupancy status of the transit vehicle. */ fun predictedOccupancy(predictedOccupancy: String) = predictedOccupancy(JsonField.of(predictedOccupancy)) /** Predicted occupancy status of the transit vehicle. */ - @JsonProperty("predictedOccupancy") - @ExcludeMissing fun predictedOccupancy(predictedOccupancy: JsonField) = apply { this.predictedOccupancy = predictedOccupancy } - /** The ID of the route for the arriving vehicle. */ - fun routeId(routeId: String) = routeId(JsonField.of(routeId)) - - /** The ID of the route for the arriving vehicle. */ - @JsonProperty("routeId") - @ExcludeMissing - fun routeId(routeId: JsonField) = apply { this.routeId = routeId } - /** * Optional route long name that potentially overrides the route long name in the * referenced route element. @@ -931,8 +1100,6 @@ private constructor( * Optional route long name that potentially overrides the route long name in the * referenced route element. */ - @JsonProperty("routeLongName") - @ExcludeMissing fun routeLongName(routeLongName: JsonField) = apply { this.routeLongName = routeLongName } @@ -948,8 +1115,6 @@ private constructor( * Optional route short name that potentially overrides the route short name in the * referenced route element. */ - @JsonProperty("routeShortName") - @ExcludeMissing fun routeShortName(routeShortName: JsonField) = apply { this.routeShortName = routeShortName } @@ -959,177 +1124,73 @@ private constructor( scheduledArrivalInterval(JsonField.of(scheduledArrivalInterval)) /** Interval for scheduled arrival time. */ - @JsonProperty("scheduledArrivalInterval") - @ExcludeMissing fun scheduledArrivalInterval(scheduledArrivalInterval: JsonField) = apply { this.scheduledArrivalInterval = scheduledArrivalInterval } - /** Scheduled arrival time, in milliseconds since Unix epoch. */ - fun scheduledArrivalTime(scheduledArrivalTime: Long) = - scheduledArrivalTime(JsonField.of(scheduledArrivalTime)) - - /** Scheduled arrival time, in milliseconds since Unix epoch. */ - @JsonProperty("scheduledArrivalTime") - @ExcludeMissing - fun scheduledArrivalTime(scheduledArrivalTime: JsonField) = apply { - this.scheduledArrivalTime = scheduledArrivalTime - } - /** Interval for scheduled departure time. */ fun scheduledDepartureInterval(scheduledDepartureInterval: String) = scheduledDepartureInterval(JsonField.of(scheduledDepartureInterval)) /** Interval for scheduled departure time. */ - @JsonProperty("scheduledDepartureInterval") - @ExcludeMissing fun scheduledDepartureInterval(scheduledDepartureInterval: JsonField) = apply { this.scheduledDepartureInterval = scheduledDepartureInterval } - /** Scheduled departure time, in milliseconds since Unix epoch. */ - fun scheduledDepartureTime(scheduledDepartureTime: Long) = - scheduledDepartureTime(JsonField.of(scheduledDepartureTime)) - - /** Scheduled departure time, in milliseconds since Unix epoch. */ - @JsonProperty("scheduledDepartureTime") - @ExcludeMissing - fun scheduledDepartureTime(scheduledDepartureTime: JsonField) = apply { - this.scheduledDepartureTime = scheduledDepartureTime - } - /** Scheduled track information of the arriving transit vehicle. */ fun scheduledTrack(scheduledTrack: String) = scheduledTrack(JsonField.of(scheduledTrack)) /** Scheduled track information of the arriving transit vehicle. */ - @JsonProperty("scheduledTrack") - @ExcludeMissing fun scheduledTrack(scheduledTrack: JsonField) = apply { this.scheduledTrack = scheduledTrack } - /** - * Time, in milliseconds since the Unix epoch, of midnight for the start of the - * service date for the trip. - */ - fun serviceDate(serviceDate: Long) = serviceDate(JsonField.of(serviceDate)) - - /** - * Time, in milliseconds since the Unix epoch, of midnight for the start of the - * service date for the trip. - */ - @JsonProperty("serviceDate") - @ExcludeMissing - fun serviceDate(serviceDate: JsonField) = apply { - this.serviceDate = serviceDate - } - /** References to situation elements (if any) applicable to this arrival. */ fun situationIds(situationIds: List) = situationIds(JsonField.of(situationIds)) /** References to situation elements (if any) applicable to this arrival. */ - @JsonProperty("situationIds") - @ExcludeMissing fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds + this.situationIds = situationIds.map { it.toMutableList() } + } + + /** References to situation elements (if any) applicable to this arrival. */ + fun addSituationId(situationId: String) = apply { + situationIds = + (situationIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situationId) + } } /** Current status of the arrival. */ fun status(status: String) = status(JsonField.of(status)) /** Current status of the arrival. */ - @JsonProperty("status") - @ExcludeMissing fun status(status: JsonField) = apply { this.status = status } - /** The ID of the stop the vehicle is arriving at. */ - fun stopId(stopId: String) = stopId(JsonField.of(stopId)) - - /** The ID of the stop the vehicle is arriving at. */ - @JsonProperty("stopId") - @ExcludeMissing - fun stopId(stopId: JsonField) = apply { this.stopId = stopId } - - /** - * Index of the stop into the sequence of stops that make up the trip for this - * arrival. - */ - fun stopSequence(stopSequence: Long) = stopSequence(JsonField.of(stopSequence)) - - /** - * Index of the stop into the sequence of stops that make up the trip for this - * arrival. - */ - @JsonProperty("stopSequence") - @ExcludeMissing - fun stopSequence(stopSequence: JsonField) = apply { - this.stopSequence = stopSequence - } - - /** Total number of stops visited on the trip for this arrival. */ - fun totalStopsInTrip(totalStopsInTrip: Long) = - totalStopsInTrip(JsonField.of(totalStopsInTrip)) - - /** Total number of stops visited on the trip for this arrival. */ - @JsonProperty("totalStopsInTrip") - @ExcludeMissing - fun totalStopsInTrip(totalStopsInTrip: JsonField) = apply { - this.totalStopsInTrip = totalStopsInTrip - } - - /** - * Optional trip headsign that potentially overrides the trip headsign in the - * referenced trip element. - */ - fun tripHeadsign(tripHeadsign: String) = tripHeadsign(JsonField.of(tripHeadsign)) - - /** - * Optional trip headsign that potentially overrides the trip headsign in the - * referenced trip element. - */ - @JsonProperty("tripHeadsign") - @ExcludeMissing - fun tripHeadsign(tripHeadsign: JsonField) = apply { - this.tripHeadsign = tripHeadsign - } - - /** The ID of the trip for the arriving vehicle. */ - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - /** The ID of the trip for the arriving vehicle. */ - @JsonProperty("tripId") - @ExcludeMissing - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - /** Trip-specific status for the arriving transit vehicle. */ fun tripStatus(tripStatus: TripStatus) = tripStatus(JsonField.of(tripStatus)) /** Trip-specific status for the arriving transit vehicle. */ - @JsonProperty("tripStatus") - @ExcludeMissing fun tripStatus(tripStatus: JsonField) = apply { this.tripStatus = tripStatus } - /** ID of the transit vehicle serving this trip. */ - fun vehicleId(vehicleId: String) = vehicleId(JsonField.of(vehicleId)) - - /** ID of the transit vehicle serving this trip. */ - @JsonProperty("vehicleId") - @ExcludeMissing - fun vehicleId(vehicleId: JsonField) = apply { this.vehicleId = vehicleId } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1137,83 +1198,144 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( + checkRequired("arrivalEnabled", arrivalEnabled), + checkRequired("blockTripSequence", blockTripSequence), + checkRequired("departureEnabled", departureEnabled), + checkRequired("numberOfStopsAway", numberOfStopsAway), + checkRequired("predictedArrivalTime", predictedArrivalTime), + checkRequired("predictedDepartureTime", predictedDepartureTime), + checkRequired("routeId", routeId), + checkRequired("scheduledArrivalTime", scheduledArrivalTime), + checkRequired("scheduledDepartureTime", scheduledDepartureTime), + checkRequired("serviceDate", serviceDate), + checkRequired("stopId", stopId), + checkRequired("stopSequence", stopSequence), + checkRequired("totalStopsInTrip", totalStopsInTrip), + checkRequired("tripHeadsign", tripHeadsign), + checkRequired("tripId", tripId), + checkRequired("vehicleId", vehicleId), actualTrack, - arrivalEnabled, - blockTripSequence, - departureEnabled, distanceFromStop, frequency, historicalOccupancy, lastUpdateTime, - numberOfStopsAway, occupancyStatus, predicted, predictedArrivalInterval, - predictedArrivalTime, predictedDepartureInterval, - predictedDepartureTime, predictedOccupancy, - routeId, routeLongName, routeShortName, scheduledArrivalInterval, - scheduledArrivalTime, scheduledDepartureInterval, - scheduledDepartureTime, scheduledTrack, - serviceDate, - situationIds.map { it.toImmutable() }, + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, status, - stopId, - stopSequence, - totalStopsInTrip, - tripHeadsign, - tripId, tripStatus, - vehicleId, additionalProperties.toImmutable(), ) } /** Trip-specific status for the arriving transit vehicle. */ - @JsonDeserialize(builder = TripStatus.Builder::class) @NoAutoDetect class TripStatus + @JsonCreator private constructor( - private val activeTripId: JsonField, - private val blockTripSequence: JsonField, - private val closestStop: JsonField, - private val closestStopTimeOffset: JsonField, - private val distanceAlongTrip: JsonField, - private val frequency: JsonField, - private val lastKnownDistanceAlongTrip: JsonField, - private val lastKnownLocation: JsonField, - private val lastKnownOrientation: JsonField, - private val lastLocationUpdateTime: JsonField, - private val lastUpdateTime: JsonField, - private val nextStop: JsonField, - private val nextStopTimeOffset: JsonField, - private val occupancyCapacity: JsonField, - private val occupancyCount: JsonField, - private val occupancyStatus: JsonField, - private val orientation: JsonField, - private val phase: JsonField, - private val position: JsonField, - private val predicted: JsonField, - private val scheduleDeviation: JsonField, - private val scheduledDistanceAlongTrip: JsonField, - private val serviceDate: JsonField, - private val situationIds: JsonField>, - private val status: JsonField, - private val totalDistanceAlongTrip: JsonField, - private val vehicleId: JsonField, - private val additionalProperties: Map, + @JsonProperty("activeTripId") + @ExcludeMissing + private val activeTripId: JsonField = JsonMissing.of(), + @JsonProperty("blockTripSequence") + @ExcludeMissing + private val blockTripSequence: JsonField = JsonMissing.of(), + @JsonProperty("closestStop") + @ExcludeMissing + private val closestStop: JsonField = JsonMissing.of(), + @JsonProperty("distanceAlongTrip") + @ExcludeMissing + private val distanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownDistanceAlongTrip") + @ExcludeMissing + private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastLocationUpdateTime") + @ExcludeMissing + private val lastLocationUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("lastUpdateTime") + @ExcludeMissing + private val lastUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCapacity") + @ExcludeMissing + private val occupancyCapacity: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCount") + @ExcludeMissing + private val occupancyCount: JsonField = JsonMissing.of(), + @JsonProperty("occupancyStatus") + @ExcludeMissing + private val occupancyStatus: JsonField = JsonMissing.of(), + @JsonProperty("phase") + @ExcludeMissing + private val phase: JsonField = JsonMissing.of(), + @JsonProperty("predicted") + @ExcludeMissing + private val predicted: JsonField = JsonMissing.of(), + @JsonProperty("scheduleDeviation") + @ExcludeMissing + private val scheduleDeviation: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonProperty("totalDistanceAlongTrip") + @ExcludeMissing + private val totalDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + private val closestStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownLocation") + @ExcludeMissing + private val lastKnownLocation: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + private val lastKnownOrientation: JsonField = JsonMissing.of(), + @JsonProperty("nextStop") + @ExcludeMissing + private val nextStop: JsonField = JsonMissing.of(), + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + private val nextStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("orientation") + @ExcludeMissing + private val orientation: JsonField = JsonMissing.of(), + @JsonProperty("position") + @ExcludeMissing + private val position: JsonField = JsonMissing.of(), + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + private val scheduledDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), + @JsonProperty("vehicleId") + @ExcludeMissing + private val vehicleId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Trip ID of the trip the vehicle is actively serving. */ fun activeTripId(): String = activeTripId.getRequired("activeTripId") @@ -1223,22 +1345,11 @@ private constructor( /** ID of the closest stop to the current location of the transit vehicle. */ fun closestStop(): String = closestStop.getRequired("closestStop") - /** - * Time offset from the closest stop to the current position of the transit vehicle - * (in seconds). - */ - fun closestStopTimeOffset(): Optional = - Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) - /** * Distance, in meters, the transit vehicle has progressed along the active trip. */ fun distanceAlongTrip(): Double = distanceAlongTrip.getRequired("distanceAlongTrip") - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1246,14 +1357,6 @@ private constructor( fun lastKnownDistanceAlongTrip(): Double = lastKnownDistanceAlongTrip.getRequired("lastKnownDistanceAlongTrip") - /** Last known location of the transit vehicle. */ - fun lastKnownLocation(): Optional = - Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) - - /** Last known orientation value received in real-time from the transit vehicle. */ - fun lastKnownOrientation(): Optional = - Optional.ofNullable(lastKnownOrientation.getNullable("lastKnownOrientation")) - /** * Timestamp of the last known real-time location update from the transit vehicle. */ @@ -1263,17 +1366,6 @@ private constructor( /** Timestamp of the last known real-time update from the transit vehicle. */ fun lastUpdateTime(): Long = lastUpdateTime.getRequired("lastUpdateTime") - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - fun nextStop(): Optional = - Optional.ofNullable(nextStop.getNullable("nextStop")) - - /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). - */ - fun nextStopTimeOffset(): Optional = - Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(): Long = occupancyCapacity.getRequired("occupancyCapacity") @@ -1283,17 +1375,9 @@ private constructor( /** Current occupancy status of the transit vehicle. */ fun occupancyStatus(): String = occupancyStatus.getRequired("occupancyStatus") - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - fun orientation(): Optional = - Optional.ofNullable(orientation.getNullable("orientation")) - /** Current journey phase of the trip. */ fun phase(): String = phase.getRequired("phase") - /** Current position of the transit vehicle. */ - fun position(): Optional = - Optional.ofNullable(position.getNullable("position")) - /** Indicates if real-time arrival info is available for this trip. */ fun predicted(): Boolean = predicted.getRequired("predicted") @@ -1302,25 +1386,12 @@ private constructor( */ fun scheduleDeviation(): Long = scheduleDeviation.getRequired("scheduleDeviation") - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed along - * the active trip. - */ - fun scheduledDistanceAlongTrip(): Optional = - Optional.ofNullable( - scheduledDistanceAlongTrip.getNullable("scheduledDistanceAlongTrip") - ) - /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ fun serviceDate(): Long = serviceDate.getRequired("serviceDate") - /** References to situation elements (if any) applicable to this trip. */ - fun situationIds(): Optional> = - Optional.ofNullable(situationIds.getNullable("situationIds")) - /** Current status modifiers for the trip. */ fun status(): String = status.getRequired("status") @@ -1328,38 +1399,82 @@ private constructor( fun totalDistanceAlongTrip(): Double = totalDistanceAlongTrip.getRequired("totalDistanceAlongTrip") + /** + * Time offset from the closest stop to the current position of the transit vehicle + * (in seconds). + */ + fun closestStopTimeOffset(): Optional = + Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(): Optional = + Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) + + /** Last known orientation value received in real-time from the transit vehicle. */ + fun lastKnownOrientation(): Optional = + Optional.ofNullable(lastKnownOrientation.getNullable("lastKnownOrientation")) + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(): Optional = + Optional.ofNullable(nextStop.getNullable("nextStop")) + + /** + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). + */ + fun nextStopTimeOffset(): Optional = + Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(): Optional = + Optional.ofNullable(orientation.getNullable("orientation")) + + /** Current position of the transit vehicle. */ + fun position(): Optional = + Optional.ofNullable(position.getNullable("position")) + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed along + * the active trip. + */ + fun scheduledDistanceAlongTrip(): Optional = + Optional.ofNullable( + scheduledDistanceAlongTrip.getNullable("scheduledDistanceAlongTrip") + ) + + /** References to situation elements (if any) applicable to this trip. */ + fun situationIds(): Optional> = + Optional.ofNullable(situationIds.getNullable("situationIds")) + /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(): Optional = Optional.ofNullable(vehicleId.getNullable("vehicleId")) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") @ExcludeMissing fun _activeTripId() = activeTripId + @JsonProperty("activeTripId") + @ExcludeMissing + fun _activeTripId(): JsonField = activeTripId /** Index of the active trip into the sequence of trips for the active block. */ @JsonProperty("blockTripSequence") @ExcludeMissing - fun _blockTripSequence() = blockTripSequence + fun _blockTripSequence(): JsonField = blockTripSequence /** ID of the closest stop to the current location of the transit vehicle. */ - @JsonProperty("closestStop") @ExcludeMissing fun _closestStop() = closestStop - - /** - * Time offset from the closest stop to the current position of the transit vehicle - * (in seconds). - */ - @JsonProperty("closestStopTimeOffset") + @JsonProperty("closestStop") @ExcludeMissing - fun _closestStopTimeOffset() = closestStopTimeOffset + fun _closestStop(): JsonField = closestStop /** * Distance, in meters, the transit vehicle has progressed along the active trip. */ @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + fun _distanceAlongTrip(): JsonField = distanceAlongTrip /** * Last known distance along the trip received in real-time from the transit @@ -1367,138 +1482,169 @@ private constructor( */ @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing - fun _lastKnownDistanceAlongTrip() = lastKnownDistanceAlongTrip - - /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun _lastKnownLocation() = lastKnownLocation - - /** Last known orientation value received in real-time from the transit vehicle. */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun _lastKnownOrientation() = lastKnownOrientation + fun _lastKnownDistanceAlongTrip(): JsonField = lastKnownDistanceAlongTrip /** * Timestamp of the last known real-time location update from the transit vehicle. */ @JsonProperty("lastLocationUpdateTime") @ExcludeMissing - fun _lastLocationUpdateTime() = lastLocationUpdateTime + fun _lastLocationUpdateTime(): JsonField = lastLocationUpdateTime /** Timestamp of the last known real-time update from the transit vehicle. */ @JsonProperty("lastUpdateTime") @ExcludeMissing - fun _lastUpdateTime() = lastUpdateTime - - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") @ExcludeMissing fun _nextStop() = nextStop - - /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). - */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - fun _nextStopTimeOffset() = nextStopTimeOffset + fun _lastUpdateTime(): JsonField = lastUpdateTime /** Capacity of the transit vehicle in terms of occupancy. */ @JsonProperty("occupancyCapacity") @ExcludeMissing - fun _occupancyCapacity() = occupancyCapacity + fun _occupancyCapacity(): JsonField = occupancyCapacity /** Current count of occupants in the transit vehicle. */ @JsonProperty("occupancyCount") @ExcludeMissing - fun _occupancyCount() = occupancyCount + fun _occupancyCount(): JsonField = occupancyCount /** Current occupancy status of the transit vehicle. */ @JsonProperty("occupancyStatus") @ExcludeMissing - fun _occupancyStatus() = occupancyStatus - - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") @ExcludeMissing fun _orientation() = orientation + fun _occupancyStatus(): JsonField = occupancyStatus /** Current journey phase of the trip. */ - @JsonProperty("phase") @ExcludeMissing fun _phase() = phase - - /** Current position of the transit vehicle. */ - @JsonProperty("position") @ExcludeMissing fun _position() = position + @JsonProperty("phase") @ExcludeMissing fun _phase(): JsonField = phase /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") @ExcludeMissing fun _predicted() = predicted + @JsonProperty("predicted") + @ExcludeMissing + fun _predicted(): JsonField = predicted /** * Deviation from the schedule in seconds (positive for late, negative for early). */ @JsonProperty("scheduleDeviation") @ExcludeMissing - fun _scheduleDeviation() = scheduleDeviation - - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed along - * the active trip. - */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - fun _scheduledDistanceAlongTrip() = scheduledDistanceAlongTrip + fun _scheduleDeviation(): JsonField = scheduleDeviation /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate - - /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate /** Current status modifiers for the trip. */ - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status /** Total length of the trip, in meters. */ @JsonProperty("totalDistanceAlongTrip") @ExcludeMissing - fun _totalDistanceAlongTrip() = totalDistanceAlongTrip + fun _totalDistanceAlongTrip(): JsonField = totalDistanceAlongTrip + + /** + * Time offset from the closest stop to the current position of the transit vehicle + * (in seconds). + */ + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + fun _closestStopTimeOffset(): JsonField = closestStopTimeOffset + + /** Information about frequency-based scheduling, if applicable to the trip. */ + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency + + /** Last known location of the transit vehicle. */ + @JsonProperty("lastKnownLocation") + @ExcludeMissing + fun _lastKnownLocation(): JsonField = lastKnownLocation + + /** Last known orientation value received in real-time from the transit vehicle. */ + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + fun _lastKnownOrientation(): JsonField = lastKnownOrientation + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + @JsonProperty("nextStop") + @ExcludeMissing + fun _nextStop(): JsonField = nextStop + + /** + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). + */ + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + fun _nextStopTimeOffset(): JsonField = nextStopTimeOffset + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + @JsonProperty("orientation") + @ExcludeMissing + fun _orientation(): JsonField = orientation + + /** Current position of the transit vehicle. */ + @JsonProperty("position") + @ExcludeMissing + fun _position(): JsonField = position + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed along + * the active trip. + */ + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + fun _scheduledDistanceAlongTrip(): JsonField = scheduledDistanceAlongTrip + + /** References to situation elements (if any) applicable to this trip. */ + @JsonProperty("situationIds") + @ExcludeMissing + fun _situationIds(): JsonField> = situationIds /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") @ExcludeMissing fun _vehicleId() = vehicleId + @JsonProperty("vehicleId") + @ExcludeMissing + fun _vehicleId(): JsonField = vehicleId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): TripStatus = apply { - if (!validated) { - activeTripId() - blockTripSequence() - closestStop() - closestStopTimeOffset() - distanceAlongTrip() - frequency() - lastKnownDistanceAlongTrip() - lastKnownLocation().map { it.validate() } - lastKnownOrientation() - lastLocationUpdateTime() - lastUpdateTime() - nextStop() - nextStopTimeOffset() - occupancyCapacity() - occupancyCount() - occupancyStatus() - orientation() - phase() - position().map { it.validate() } - predicted() - scheduleDeviation() - scheduledDistanceAlongTrip() - serviceDate() - situationIds() - status() - totalDistanceAlongTrip() - vehicleId() - validated = true + if (validated) { + return@apply } + + activeTripId() + blockTripSequence() + closestStop() + distanceAlongTrip() + lastKnownDistanceAlongTrip() + lastLocationUpdateTime() + lastUpdateTime() + occupancyCapacity() + occupancyCount() + occupancyStatus() + phase() + predicted() + scheduleDeviation() + serviceDate() + status() + totalDistanceAlongTrip() + closestStopTimeOffset() + frequency() + lastKnownLocation().ifPresent { it.validate() } + lastKnownOrientation() + nextStop() + nextStopTimeOffset() + orientation() + position().ifPresent { it.validate() } + scheduledDistanceAlongTrip() + situationIds() + vehicleId() + validated = true } fun toBuilder() = Builder().from(this) @@ -1508,67 +1654,68 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - - private var activeTripId: JsonField = JsonMissing.of() - private var blockTripSequence: JsonField = JsonMissing.of() - private var closestStop: JsonField = JsonMissing.of() + /** A builder for [TripStatus]. */ + class Builder internal constructor() { + + private var activeTripId: JsonField? = null + private var blockTripSequence: JsonField? = null + private var closestStop: JsonField? = null + private var distanceAlongTrip: JsonField? = null + private var lastKnownDistanceAlongTrip: JsonField? = null + private var lastLocationUpdateTime: JsonField? = null + private var lastUpdateTime: JsonField? = null + private var occupancyCapacity: JsonField? = null + private var occupancyCount: JsonField? = null + private var occupancyStatus: JsonField? = null + private var phase: JsonField? = null + private var predicted: JsonField? = null + private var scheduleDeviation: JsonField? = null + private var serviceDate: JsonField? = null + private var status: JsonField? = null + private var totalDistanceAlongTrip: JsonField? = null private var closestStopTimeOffset: JsonField = JsonMissing.of() - private var distanceAlongTrip: JsonField = JsonMissing.of() private var frequency: JsonField = JsonMissing.of() - private var lastKnownDistanceAlongTrip: JsonField = JsonMissing.of() private var lastKnownLocation: JsonField = JsonMissing.of() private var lastKnownOrientation: JsonField = JsonMissing.of() - private var lastLocationUpdateTime: JsonField = JsonMissing.of() - private var lastUpdateTime: JsonField = JsonMissing.of() private var nextStop: JsonField = JsonMissing.of() private var nextStopTimeOffset: JsonField = JsonMissing.of() - private var occupancyCapacity: JsonField = JsonMissing.of() - private var occupancyCount: JsonField = JsonMissing.of() - private var occupancyStatus: JsonField = JsonMissing.of() private var orientation: JsonField = JsonMissing.of() - private var phase: JsonField = JsonMissing.of() private var position: JsonField = JsonMissing.of() - private var predicted: JsonField = JsonMissing.of() - private var scheduleDeviation: JsonField = JsonMissing.of() private var scheduledDistanceAlongTrip: JsonField = JsonMissing.of() - private var serviceDate: JsonField = JsonMissing.of() - private var situationIds: JsonField> = JsonMissing.of() - private var status: JsonField = JsonMissing.of() - private var totalDistanceAlongTrip: JsonField = JsonMissing.of() + private var situationIds: JsonField>? = null private var vehicleId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(tripStatus: TripStatus) = apply { - this.activeTripId = tripStatus.activeTripId - this.blockTripSequence = tripStatus.blockTripSequence - this.closestStop = tripStatus.closestStop - this.closestStopTimeOffset = tripStatus.closestStopTimeOffset - this.distanceAlongTrip = tripStatus.distanceAlongTrip - this.frequency = tripStatus.frequency - this.lastKnownDistanceAlongTrip = tripStatus.lastKnownDistanceAlongTrip - this.lastKnownLocation = tripStatus.lastKnownLocation - this.lastKnownOrientation = tripStatus.lastKnownOrientation - this.lastLocationUpdateTime = tripStatus.lastLocationUpdateTime - this.lastUpdateTime = tripStatus.lastUpdateTime - this.nextStop = tripStatus.nextStop - this.nextStopTimeOffset = tripStatus.nextStopTimeOffset - this.occupancyCapacity = tripStatus.occupancyCapacity - this.occupancyCount = tripStatus.occupancyCount - this.occupancyStatus = tripStatus.occupancyStatus - this.orientation = tripStatus.orientation - this.phase = tripStatus.phase - this.position = tripStatus.position - this.predicted = tripStatus.predicted - this.scheduleDeviation = tripStatus.scheduleDeviation - this.scheduledDistanceAlongTrip = tripStatus.scheduledDistanceAlongTrip - this.serviceDate = tripStatus.serviceDate - this.situationIds = tripStatus.situationIds - this.status = tripStatus.status - this.totalDistanceAlongTrip = tripStatus.totalDistanceAlongTrip - this.vehicleId = tripStatus.vehicleId - additionalProperties(tripStatus.additionalProperties) + activeTripId = tripStatus.activeTripId + blockTripSequence = tripStatus.blockTripSequence + closestStop = tripStatus.closestStop + distanceAlongTrip = tripStatus.distanceAlongTrip + lastKnownDistanceAlongTrip = tripStatus.lastKnownDistanceAlongTrip + lastLocationUpdateTime = tripStatus.lastLocationUpdateTime + lastUpdateTime = tripStatus.lastUpdateTime + occupancyCapacity = tripStatus.occupancyCapacity + occupancyCount = tripStatus.occupancyCount + occupancyStatus = tripStatus.occupancyStatus + phase = tripStatus.phase + predicted = tripStatus.predicted + scheduleDeviation = tripStatus.scheduleDeviation + serviceDate = tripStatus.serviceDate + status = tripStatus.status + totalDistanceAlongTrip = tripStatus.totalDistanceAlongTrip + closestStopTimeOffset = tripStatus.closestStopTimeOffset + frequency = tripStatus.frequency + lastKnownLocation = tripStatus.lastKnownLocation + lastKnownOrientation = tripStatus.lastKnownOrientation + nextStop = tripStatus.nextStop + nextStopTimeOffset = tripStatus.nextStopTimeOffset + orientation = tripStatus.orientation + position = tripStatus.position + scheduledDistanceAlongTrip = tripStatus.scheduledDistanceAlongTrip + situationIds = tripStatus.situationIds.map { it.toMutableList() } + vehicleId = tripStatus.vehicleId + additionalProperties = tripStatus.additionalProperties.toMutableMap() } /** Trip ID of the trip the vehicle is actively serving. */ @@ -1576,8 +1723,6 @@ private constructor( activeTripId(JsonField.of(activeTripId)) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") - @ExcludeMissing fun activeTripId(activeTripId: JsonField) = apply { this.activeTripId = activeTripId } @@ -1587,8 +1732,6 @@ private constructor( blockTripSequence(JsonField.of(blockTripSequence)) /** Index of the active trip into the sequence of trips for the active block. */ - @JsonProperty("blockTripSequence") - @ExcludeMissing fun blockTripSequence(blockTripSequence: JsonField) = apply { this.blockTripSequence = blockTripSequence } @@ -1597,29 +1740,10 @@ private constructor( fun closestStop(closestStop: String) = closestStop(JsonField.of(closestStop)) /** ID of the closest stop to the current location of the transit vehicle. */ - @JsonProperty("closestStop") - @ExcludeMissing fun closestStop(closestStop: JsonField) = apply { this.closestStop = closestStop } - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - fun closestStopTimeOffset(closestStopTimeOffset: Long) = - closestStopTimeOffset(JsonField.of(closestStopTimeOffset)) - - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing - fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { - this.closestStopTimeOffset = closestStopTimeOffset - } - /** * Distance, in meters, the transit vehicle has progressed along the active * trip. @@ -1631,20 +1755,8 @@ private constructor( * Distance, in meters, the transit vehicle has progressed along the active * trip. */ - @JsonProperty("distanceAlongTrip") - @ExcludeMissing - fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { - this.distanceAlongTrip = distanceAlongTrip - } - - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") - @ExcludeMissing - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency + fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { + this.distanceAlongTrip = distanceAlongTrip } /** @@ -1658,39 +1770,11 @@ private constructor( * Last known distance along the trip received in real-time from the transit * vehicle. */ - @JsonProperty("lastKnownDistanceAlongTrip") - @ExcludeMissing fun lastKnownDistanceAlongTrip(lastKnownDistanceAlongTrip: JsonField) = apply { this.lastKnownDistanceAlongTrip = lastKnownDistanceAlongTrip } - /** Last known location of the transit vehicle. */ - fun lastKnownLocation(lastKnownLocation: LastKnownLocation) = - lastKnownLocation(JsonField.of(lastKnownLocation)) - - /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun lastKnownLocation(lastKnownLocation: JsonField) = apply { - this.lastKnownLocation = lastKnownLocation - } - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - fun lastKnownOrientation(lastKnownOrientation: Double) = - lastKnownOrientation(JsonField.of(lastKnownOrientation)) - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun lastKnownOrientation(lastKnownOrientation: JsonField) = apply { - this.lastKnownOrientation = lastKnownOrientation - } - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1702,8 +1786,6 @@ private constructor( * Timestamp of the last known real-time location update from the transit * vehicle. */ - @JsonProperty("lastLocationUpdateTime") - @ExcludeMissing fun lastLocationUpdateTime(lastLocationUpdateTime: JsonField) = apply { this.lastLocationUpdateTime = lastLocationUpdateTime } @@ -1713,44 +1795,15 @@ private constructor( lastUpdateTime(JsonField.of(lastUpdateTime)) /** Timestamp of the last known real-time update from the transit vehicle. */ - @JsonProperty("lastUpdateTime") - @ExcludeMissing fun lastUpdateTime(lastUpdateTime: JsonField) = apply { this.lastUpdateTime = lastUpdateTime } - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - fun nextStop(nextStop: String) = nextStop(JsonField.of(nextStop)) - - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") - @ExcludeMissing - fun nextStop(nextStop: JsonField) = apply { this.nextStop = nextStop } - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - fun nextStopTimeOffset(nextStopTimeOffset: Long) = - nextStopTimeOffset(JsonField.of(nextStopTimeOffset)) - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - fun nextStopTimeOffset(nextStopTimeOffset: JsonField) = apply { - this.nextStopTimeOffset = nextStopTimeOffset - } - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) /** Capacity of the transit vehicle in terms of occupancy. */ - @JsonProperty("occupancyCapacity") - @ExcludeMissing fun occupancyCapacity(occupancyCapacity: JsonField) = apply { this.occupancyCapacity = occupancyCapacity } @@ -1760,8 +1813,6 @@ private constructor( occupancyCount(JsonField.of(occupancyCount)) /** Current count of occupants in the transit vehicle. */ - @JsonProperty("occupancyCount") - @ExcludeMissing fun occupancyCount(occupancyCount: JsonField) = apply { this.occupancyCount = occupancyCount } @@ -1771,44 +1822,20 @@ private constructor( occupancyStatus(JsonField.of(occupancyStatus)) /** Current occupancy status of the transit vehicle. */ - @JsonProperty("occupancyStatus") - @ExcludeMissing fun occupancyStatus(occupancyStatus: JsonField) = apply { this.occupancyStatus = occupancyStatus } - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - fun orientation(orientation: Double) = orientation(JsonField.of(orientation)) - - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") - @ExcludeMissing - fun orientation(orientation: JsonField) = apply { - this.orientation = orientation - } - /** Current journey phase of the trip. */ fun phase(phase: String) = phase(JsonField.of(phase)) /** Current journey phase of the trip. */ - @JsonProperty("phase") - @ExcludeMissing fun phase(phase: JsonField) = apply { this.phase = phase } - /** Current position of the transit vehicle. */ - fun position(position: Position) = position(JsonField.of(position)) - - /** Current position of the transit vehicle. */ - @JsonProperty("position") - @ExcludeMissing - fun position(position: JsonField) = apply { this.position = position } - /** Indicates if real-time arrival info is available for this trip. */ fun predicted(predicted: Boolean) = predicted(JsonField.of(predicted)) /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") - @ExcludeMissing fun predicted(predicted: JsonField) = apply { this.predicted = predicted } @@ -1824,30 +1851,10 @@ private constructor( * Deviation from the schedule in seconds (positive for late, negative for * early). */ - @JsonProperty("scheduleDeviation") - @ExcludeMissing fun scheduleDeviation(scheduleDeviation: JsonField) = apply { this.scheduleDeviation = scheduleDeviation } - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed - * along the active trip. - */ - fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: Double) = - scheduledDistanceAlongTrip(JsonField.of(scheduledDistanceAlongTrip)) - - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed - * along the active trip. - */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: JsonField) = - apply { - this.scheduledDistanceAlongTrip = scheduledDistanceAlongTrip - } - /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. @@ -1858,29 +1865,14 @@ private constructor( * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") - @ExcludeMissing fun serviceDate(serviceDate: JsonField) = apply { this.serviceDate = serviceDate } - /** References to situation elements (if any) applicable to this trip. */ - fun situationIds(situationIds: List) = - situationIds(JsonField.of(situationIds)) - - /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") - @ExcludeMissing - fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds - } - /** Current status modifiers for the trip. */ fun status(status: String) = status(JsonField.of(status)) /** Current status modifiers for the trip. */ - @JsonProperty("status") - @ExcludeMissing fun status(status: JsonField) = apply { this.status = status } /** Total length of the trip, in meters. */ @@ -1888,30 +1880,144 @@ private constructor( totalDistanceAlongTrip(JsonField.of(totalDistanceAlongTrip)) /** Total length of the trip, in meters. */ - @JsonProperty("totalDistanceAlongTrip") - @ExcludeMissing fun totalDistanceAlongTrip(totalDistanceAlongTrip: JsonField) = apply { this.totalDistanceAlongTrip = totalDistanceAlongTrip } + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + fun closestStopTimeOffset(closestStopTimeOffset: Long) = + closestStopTimeOffset(JsonField.of(closestStopTimeOffset)) + + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { + this.closestStopTimeOffset = closestStopTimeOffset + } + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: String) = frequency(JsonField.of(frequency)) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: JsonField) = apply { + this.frequency = frequency + } + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(lastKnownLocation: LastKnownLocation) = + lastKnownLocation(JsonField.of(lastKnownLocation)) + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(lastKnownLocation: JsonField) = apply { + this.lastKnownLocation = lastKnownLocation + } + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + fun lastKnownOrientation(lastKnownOrientation: Double) = + lastKnownOrientation(JsonField.of(lastKnownOrientation)) + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + fun lastKnownOrientation(lastKnownOrientation: JsonField) = apply { + this.lastKnownOrientation = lastKnownOrientation + } + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(nextStop: String) = nextStop(JsonField.of(nextStop)) + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(nextStop: JsonField) = apply { this.nextStop = nextStop } + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + fun nextStopTimeOffset(nextStopTimeOffset: Long) = + nextStopTimeOffset(JsonField.of(nextStopTimeOffset)) + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + fun nextStopTimeOffset(nextStopTimeOffset: JsonField) = apply { + this.nextStopTimeOffset = nextStopTimeOffset + } + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(orientation: Double) = orientation(JsonField.of(orientation)) + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(orientation: JsonField) = apply { + this.orientation = orientation + } + + /** Current position of the transit vehicle. */ + fun position(position: Position) = position(JsonField.of(position)) + + /** Current position of the transit vehicle. */ + fun position(position: JsonField) = apply { this.position = position } + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed + * along the active trip. + */ + fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: Double) = + scheduledDistanceAlongTrip(JsonField.of(scheduledDistanceAlongTrip)) + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed + * along the active trip. + */ + fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: JsonField) = + apply { + this.scheduledDistanceAlongTrip = scheduledDistanceAlongTrip + } + + /** References to situation elements (if any) applicable to this trip. */ + fun situationIds(situationIds: List) = + situationIds(JsonField.of(situationIds)) + + /** References to situation elements (if any) applicable to this trip. */ + fun situationIds(situationIds: JsonField>) = apply { + this.situationIds = situationIds.map { it.toMutableList() } + } + + /** References to situation elements (if any) applicable to this trip. */ + fun addSituationId(situationId: String) = apply { + situationIds = + (situationIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situationId) + } + } + /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(vehicleId: String) = vehicleId(JsonField.of(vehicleId)) /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") - @ExcludeMissing fun vehicleId(vehicleId: JsonField) = apply { this.vehicleId = vehicleId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1919,51 +2025,62 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): TripStatus = TripStatus( - activeTripId, - blockTripSequence, - closestStop, + checkRequired("activeTripId", activeTripId), + checkRequired("blockTripSequence", blockTripSequence), + checkRequired("closestStop", closestStop), + checkRequired("distanceAlongTrip", distanceAlongTrip), + checkRequired("lastKnownDistanceAlongTrip", lastKnownDistanceAlongTrip), + checkRequired("lastLocationUpdateTime", lastLocationUpdateTime), + checkRequired("lastUpdateTime", lastUpdateTime), + checkRequired("occupancyCapacity", occupancyCapacity), + checkRequired("occupancyCount", occupancyCount), + checkRequired("occupancyStatus", occupancyStatus), + checkRequired("phase", phase), + checkRequired("predicted", predicted), + checkRequired("scheduleDeviation", scheduleDeviation), + checkRequired("serviceDate", serviceDate), + checkRequired("status", status), + checkRequired("totalDistanceAlongTrip", totalDistanceAlongTrip), closestStopTimeOffset, - distanceAlongTrip, frequency, - lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, - lastLocationUpdateTime, - lastUpdateTime, nextStop, nextStopTimeOffset, - occupancyCapacity, - occupancyCount, - occupancyStatus, orientation, - phase, position, - predicted, - scheduleDeviation, scheduledDistanceAlongTrip, - serviceDate, - situationIds.map { it.toImmutable() }, - status, - totalDistanceAlongTrip, + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, vehicleId, additionalProperties.toImmutable(), ) } /** Last known location of the transit vehicle. */ - @JsonDeserialize(builder = LastKnownLocation.Builder::class) @NoAutoDetect class LastKnownLocation + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the last known location of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -1971,21 +2088,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): LastKnownLocation = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -1995,7 +2116,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [LastKnownLocation]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -2004,42 +2126,46 @@ private constructor( @JvmSynthetic internal fun from(lastKnownLocation: LastKnownLocation) = apply { - this.lat = lastKnownLocation.lat - this.lon = lastKnownLocation.lon - additionalProperties(lastKnownLocation.additionalProperties) + lat = lastKnownLocation.lat + lon = lastKnownLocation.lon + additionalProperties = + lastKnownLocation.additionalProperties.toMutableMap() } /** Latitude of the last known location of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the last known location of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): LastKnownLocation = LastKnownLocation( lat, @@ -2053,34 +2179,34 @@ private constructor( return true } - return /* spotless:off */ other is LastKnownLocation && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is LastKnownLocation && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "LastKnownLocation{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" } /** Current position of the transit vehicle. */ - @JsonDeserialize(builder = Position.Builder::class) @NoAutoDetect class Position + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the current position of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -2088,21 +2214,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Position = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -2112,7 +2242,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Position]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -2121,42 +2252,45 @@ private constructor( @JvmSynthetic internal fun from(position: Position) = apply { - this.lat = position.lat - this.lon = position.lon - additionalProperties(position.additionalProperties) + lat = position.lat + lon = position.lon + additionalProperties = position.additionalProperties.toMutableMap() } /** Latitude of the current position of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the current position of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Position = Position( lat, @@ -2170,17 +2304,14 @@ private constructor( return true } - return /* spotless:off */ other is Position && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Position && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Position{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" @@ -2191,20 +2322,17 @@ private constructor( return true } - return /* spotless:off */ other is TripStatus && this.activeTripId == other.activeTripId && this.blockTripSequence == other.blockTripSequence && this.closestStop == other.closestStop && this.closestStopTimeOffset == other.closestStopTimeOffset && this.distanceAlongTrip == other.distanceAlongTrip && this.frequency == other.frequency && this.lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && this.lastKnownLocation == other.lastKnownLocation && this.lastKnownOrientation == other.lastKnownOrientation && this.lastLocationUpdateTime == other.lastLocationUpdateTime && this.lastUpdateTime == other.lastUpdateTime && this.nextStop == other.nextStop && this.nextStopTimeOffset == other.nextStopTimeOffset && this.occupancyCapacity == other.occupancyCapacity && this.occupancyCount == other.occupancyCount && this.occupancyStatus == other.occupancyStatus && this.orientation == other.orientation && this.phase == other.phase && this.position == other.position && this.predicted == other.predicted && this.scheduleDeviation == other.scheduleDeviation && this.scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && this.serviceDate == other.serviceDate && this.situationIds == other.situationIds && this.status == other.status && this.totalDistanceAlongTrip == other.totalDistanceAlongTrip && this.vehicleId == other.vehicleId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is TripStatus && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && distanceAlongTrip == other.distanceAlongTrip && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && phase == other.phase && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && serviceDate == other.serviceDate && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && closestStopTimeOffset == other.closestStopTimeOffset && frequency == other.frequency && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && orientation == other.orientation && position == other.position && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && situationIds == other.situationIds && vehicleId == other.vehicleId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(activeTripId, blockTripSequence, closestStop, distanceAlongTrip, lastKnownDistanceAlongTrip, lastLocationUpdateTime, lastUpdateTime, occupancyCapacity, occupancyCount, occupancyStatus, phase, predicted, scheduleDeviation, serviceDate, status, totalDistanceAlongTrip, closestStopTimeOffset, frequency, lastKnownLocation, lastKnownOrientation, nextStop, nextStopTimeOffset, orientation, position, scheduledDistanceAlongTrip, situationIds, vehicleId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(activeTripId, blockTripSequence, closestStop, closestStopTimeOffset, distanceAlongTrip, frequency, lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, lastLocationUpdateTime, lastUpdateTime, nextStop, nextStopTimeOffset, occupancyCapacity, occupancyCount, occupancyStatus, orientation, phase, position, predicted, scheduleDeviation, scheduledDistanceAlongTrip, serviceDate, situationIds, status, totalDistanceAlongTrip, vehicleId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "TripStatus{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, closestStopTimeOffset=$closestStopTimeOffset, distanceAlongTrip=$distanceAlongTrip, frequency=$frequency, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, orientation=$orientation, phase=$phase, position=$position, predicted=$predicted, scheduleDeviation=$scheduleDeviation, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, serviceDate=$serviceDate, situationIds=$situationIds, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" + "TripStatus{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, distanceAlongTrip=$distanceAlongTrip, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, phase=$phase, predicted=$predicted, scheduleDeviation=$scheduleDeviation, serviceDate=$serviceDate, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, closestStopTimeOffset=$closestStopTimeOffset, frequency=$frequency, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, orientation=$orientation, position=$position, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, situationIds=$situationIds, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -2212,20 +2340,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.actualTrack == other.actualTrack && this.arrivalEnabled == other.arrivalEnabled && this.blockTripSequence == other.blockTripSequence && this.departureEnabled == other.departureEnabled && this.distanceFromStop == other.distanceFromStop && this.frequency == other.frequency && this.historicalOccupancy == other.historicalOccupancy && this.lastUpdateTime == other.lastUpdateTime && this.numberOfStopsAway == other.numberOfStopsAway && this.occupancyStatus == other.occupancyStatus && this.predicted == other.predicted && this.predictedArrivalInterval == other.predictedArrivalInterval && this.predictedArrivalTime == other.predictedArrivalTime && this.predictedDepartureInterval == other.predictedDepartureInterval && this.predictedDepartureTime == other.predictedDepartureTime && this.predictedOccupancy == other.predictedOccupancy && this.routeId == other.routeId && this.routeLongName == other.routeLongName && this.routeShortName == other.routeShortName && this.scheduledArrivalInterval == other.scheduledArrivalInterval && this.scheduledArrivalTime == other.scheduledArrivalTime && this.scheduledDepartureInterval == other.scheduledDepartureInterval && this.scheduledDepartureTime == other.scheduledDepartureTime && this.scheduledTrack == other.scheduledTrack && this.serviceDate == other.serviceDate && this.situationIds == other.situationIds && this.status == other.status && this.stopId == other.stopId && this.stopSequence == other.stopSequence && this.totalStopsInTrip == other.totalStopsInTrip && this.tripHeadsign == other.tripHeadsign && this.tripId == other.tripId && this.tripStatus == other.tripStatus && this.vehicleId == other.vehicleId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && arrivalEnabled == other.arrivalEnabled && blockTripSequence == other.blockTripSequence && departureEnabled == other.departureEnabled && numberOfStopsAway == other.numberOfStopsAway && predictedArrivalTime == other.predictedArrivalTime && predictedDepartureTime == other.predictedDepartureTime && routeId == other.routeId && scheduledArrivalTime == other.scheduledArrivalTime && scheduledDepartureTime == other.scheduledDepartureTime && serviceDate == other.serviceDate && stopId == other.stopId && stopSequence == other.stopSequence && totalStopsInTrip == other.totalStopsInTrip && tripHeadsign == other.tripHeadsign && tripId == other.tripId && vehicleId == other.vehicleId && actualTrack == other.actualTrack && distanceFromStop == other.distanceFromStop && frequency == other.frequency && historicalOccupancy == other.historicalOccupancy && lastUpdateTime == other.lastUpdateTime && occupancyStatus == other.occupancyStatus && predicted == other.predicted && predictedArrivalInterval == other.predictedArrivalInterval && predictedDepartureInterval == other.predictedDepartureInterval && predictedOccupancy == other.predictedOccupancy && routeLongName == other.routeLongName && routeShortName == other.routeShortName && scheduledArrivalInterval == other.scheduledArrivalInterval && scheduledDepartureInterval == other.scheduledDepartureInterval && scheduledTrack == other.scheduledTrack && situationIds == other.situationIds && status == other.status && tripStatus == other.tripStatus && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(arrivalEnabled, blockTripSequence, departureEnabled, numberOfStopsAway, predictedArrivalTime, predictedDepartureTime, routeId, scheduledArrivalTime, scheduledDepartureTime, serviceDate, stopId, stopSequence, totalStopsInTrip, tripHeadsign, tripId, vehicleId, actualTrack, distanceFromStop, frequency, historicalOccupancy, lastUpdateTime, occupancyStatus, predicted, predictedArrivalInterval, predictedDepartureInterval, predictedOccupancy, routeLongName, routeShortName, scheduledArrivalInterval, scheduledDepartureInterval, scheduledTrack, situationIds, status, tripStatus, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(actualTrack, arrivalEnabled, blockTripSequence, departureEnabled, distanceFromStop, frequency, historicalOccupancy, lastUpdateTime, numberOfStopsAway, occupancyStatus, predicted, predictedArrivalInterval, predictedArrivalTime, predictedDepartureInterval, predictedDepartureTime, predictedOccupancy, routeId, routeLongName, routeShortName, scheduledArrivalInterval, scheduledArrivalTime, scheduledDepartureInterval, scheduledDepartureTime, scheduledTrack, serviceDate, situationIds, status, stopId, stopSequence, totalStopsInTrip, tripHeadsign, tripId, tripStatus, vehicleId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Entry{actualTrack=$actualTrack, arrivalEnabled=$arrivalEnabled, blockTripSequence=$blockTripSequence, departureEnabled=$departureEnabled, distanceFromStop=$distanceFromStop, frequency=$frequency, historicalOccupancy=$historicalOccupancy, lastUpdateTime=$lastUpdateTime, numberOfStopsAway=$numberOfStopsAway, occupancyStatus=$occupancyStatus, predicted=$predicted, predictedArrivalInterval=$predictedArrivalInterval, predictedArrivalTime=$predictedArrivalTime, predictedDepartureInterval=$predictedDepartureInterval, predictedDepartureTime=$predictedDepartureTime, predictedOccupancy=$predictedOccupancy, routeId=$routeId, routeLongName=$routeLongName, routeShortName=$routeShortName, scheduledArrivalInterval=$scheduledArrivalInterval, scheduledArrivalTime=$scheduledArrivalTime, scheduledDepartureInterval=$scheduledDepartureInterval, scheduledDepartureTime=$scheduledDepartureTime, scheduledTrack=$scheduledTrack, serviceDate=$serviceDate, situationIds=$situationIds, status=$status, stopId=$stopId, stopSequence=$stopSequence, totalStopsInTrip=$totalStopsInTrip, tripHeadsign=$tripHeadsign, tripId=$tripId, tripStatus=$tripStatus, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" + "Entry{arrivalEnabled=$arrivalEnabled, blockTripSequence=$blockTripSequence, departureEnabled=$departureEnabled, numberOfStopsAway=$numberOfStopsAway, predictedArrivalTime=$predictedArrivalTime, predictedDepartureTime=$predictedDepartureTime, routeId=$routeId, scheduledArrivalTime=$scheduledArrivalTime, scheduledDepartureTime=$scheduledDepartureTime, serviceDate=$serviceDate, stopId=$stopId, stopSequence=$stopSequence, totalStopsInTrip=$totalStopsInTrip, tripHeadsign=$tripHeadsign, tripId=$tripId, vehicleId=$vehicleId, actualTrack=$actualTrack, distanceFromStop=$distanceFromStop, frequency=$frequency, historicalOccupancy=$historicalOccupancy, lastUpdateTime=$lastUpdateTime, occupancyStatus=$occupancyStatus, predicted=$predicted, predictedArrivalInterval=$predictedArrivalInterval, predictedDepartureInterval=$predictedDepartureInterval, predictedOccupancy=$predictedOccupancy, routeLongName=$routeLongName, routeShortName=$routeShortName, scheduledArrivalInterval=$scheduledArrivalInterval, scheduledDepartureInterval=$scheduledDepartureInterval, scheduledTrack=$scheduledTrack, situationIds=$situationIds, status=$status, tripStatus=$tripStatus, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -2233,17 +2358,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, references=$references, additionalProperties=$additionalProperties}" @@ -2254,17 +2376,14 @@ private constructor( return true } - return /* spotless:off */ other is ArrivalAndDepartureRetrieveResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is ArrivalAndDepartureRetrieveResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "ArrivalAndDepartureRetrieveResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/BlockRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/BlockRetrieveParams.kt index 58536ee..3acfe8b 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/BlockRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/BlockRetrieveParams.kt @@ -2,25 +2,30 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Get details of a specific block by ID */ class BlockRetrieveParams -constructor( +private constructor( private val blockId: String, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun blockId(): String = blockId - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -29,25 +34,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is BlockRetrieveParams && this.blockId == other.blockId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(blockId, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "BlockRetrieveParams{blockId=$blockId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -55,22 +41,28 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [BlockRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var blockId: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(blockRetrieveParams: BlockRetrieveParams) = apply { - this.blockId = blockRetrieveParams.blockId - additionalHeaders(blockRetrieveParams.additionalHeaders) - additionalQueryParams(blockRetrieveParams.additionalQueryParams) + blockId = blockRetrieveParams.blockId + additionalHeaders = blockRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = blockRetrieveParams.additionalQueryParams.toBuilder() } fun blockId(blockId: String) = apply { this.blockId = blockId } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -81,29 +73,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -116,46 +121,59 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): BlockRetrieveParams = BlockRetrieveParams( - checkNotNull(blockId) { "`blockId` is required but was not set" }, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + checkRequired("blockId", blockId), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is BlockRetrieveParams && blockId == other.blockId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(blockId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "BlockRetrieveParams{blockId=$blockId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/BlockRetrieveResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/BlockRetrieveResponse.kt index fc59f55..1f04291 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/BlockRetrieveResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/BlockRetrieveResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = BlockRetrieveResponse.Builder::class) @NoAutoDetect class BlockRetrieveResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): BlockRetrieveResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,109 +87,114 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [BlockRetrieveResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(blockRetrieveResponse: BlockRetrieveResponse) = apply { - this.code = blockRetrieveResponse.code - this.currentTime = blockRetrieveResponse.currentTime - this.text = blockRetrieveResponse.text - this.version = blockRetrieveResponse.version - this.data = blockRetrieveResponse.data - additionalProperties(blockRetrieveResponse.additionalProperties) + code = blockRetrieveResponse.code + currentTime = blockRetrieveResponse.currentTime + text = blockRetrieveResponse.text + version = blockRetrieveResponse.version + data = blockRetrieveResponse.data + additionalProperties = blockRetrieveResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): BlockRetrieveResponse = BlockRetrieveResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") fun references(): References = references.getRequired("references") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -191,84 +204,95 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val id: JsonField, - private val configurations: JsonField>, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("configurations") + @ExcludeMissing + private val configurations: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun id(): String = id.getRequired("id") fun configurations(): List = configurations.getRequired("configurations") - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("configurations") @ExcludeMissing fun _configurations() = configurations + @JsonProperty("configurations") + @ExcludeMissing + fun _configurations(): JsonField> = configurations @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - id() - configurations().forEach { it.validate() } - validated = true + if (validated) { + return@apply } + + id() + configurations().forEach { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -278,42 +302,51 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Entry]. */ + class Builder internal constructor() { - private var id: JsonField = JsonMissing.of() - private var configurations: JsonField> = JsonMissing.of() + private var id: JsonField? = null + private var configurations: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(entry: Entry) = apply { - this.id = entry.id - this.configurations = entry.configurations - additionalProperties(entry.additionalProperties) + id = entry.id + configurations = entry.configurations.map { it.toMutableList() } + additionalProperties = entry.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) - @JsonProperty("id") - @ExcludeMissing fun id(id: JsonField) = apply { this.id = id } fun configurations(configurations: List) = configurations(JsonField.of(configurations)) - @JsonProperty("configurations") - @ExcludeMissing fun configurations(configurations: JsonField>) = apply { - this.configurations = configurations + this.configurations = configurations.map { it.toMutableList() } + } + + fun addConfiguration(configuration: Configuration) = apply { + configurations = + (configurations ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(configuration) + } } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -321,55 +354,72 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( - id, - configurations.map { it.toImmutable() }, + checkRequired("id", id), + checkRequired("configurations", configurations).map { it.toImmutable() }, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Configuration.Builder::class) @NoAutoDetect class Configuration + @JsonCreator private constructor( - private val activeServiceIds: JsonField>, - private val inactiveServiceIds: JsonField>, - private val trips: JsonField>, - private val additionalProperties: Map, + @JsonProperty("activeServiceIds") + @ExcludeMissing + private val activeServiceIds: JsonField> = JsonMissing.of(), + @JsonProperty("trips") + @ExcludeMissing + private val trips: JsonField> = JsonMissing.of(), + @JsonProperty("inactiveServiceIds") + @ExcludeMissing + private val inactiveServiceIds: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun activeServiceIds(): List = activeServiceIds.getRequired("activeServiceIds") + fun trips(): List = trips.getRequired("trips") + fun inactiveServiceIds(): Optional> = Optional.ofNullable(inactiveServiceIds.getNullable("inactiveServiceIds")) - fun trips(): List = trips.getRequired("trips") - @JsonProperty("activeServiceIds") @ExcludeMissing - fun _activeServiceIds() = activeServiceIds + fun _activeServiceIds(): JsonField> = activeServiceIds + + @JsonProperty("trips") @ExcludeMissing fun _trips(): JsonField> = trips @JsonProperty("inactiveServiceIds") @ExcludeMissing - fun _inactiveServiceIds() = inactiveServiceIds - - @JsonProperty("trips") @ExcludeMissing fun _trips() = trips + fun _inactiveServiceIds(): JsonField> = inactiveServiceIds @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Configuration = apply { - if (!validated) { - activeServiceIds() - inactiveServiceIds() - trips().forEach { it.validate() } - validated = true + if (validated) { + return@apply } + + activeServiceIds() + trips().forEach { it.validate() } + inactiveServiceIds() + validated = true } fun toBuilder() = Builder().from(this) @@ -379,53 +429,89 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Configuration]. */ + class Builder internal constructor() { - private var activeServiceIds: JsonField> = JsonMissing.of() - private var inactiveServiceIds: JsonField> = JsonMissing.of() - private var trips: JsonField> = JsonMissing.of() + private var activeServiceIds: JsonField>? = null + private var trips: JsonField>? = null + private var inactiveServiceIds: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(configuration: Configuration) = apply { - this.activeServiceIds = configuration.activeServiceIds - this.inactiveServiceIds = configuration.inactiveServiceIds - this.trips = configuration.trips - additionalProperties(configuration.additionalProperties) + activeServiceIds = configuration.activeServiceIds.map { it.toMutableList() } + trips = configuration.trips.map { it.toMutableList() } + inactiveServiceIds = + configuration.inactiveServiceIds.map { it.toMutableList() } + additionalProperties = configuration.additionalProperties.toMutableMap() } fun activeServiceIds(activeServiceIds: List) = activeServiceIds(JsonField.of(activeServiceIds)) - @JsonProperty("activeServiceIds") - @ExcludeMissing fun activeServiceIds(activeServiceIds: JsonField>) = apply { - this.activeServiceIds = activeServiceIds + this.activeServiceIds = activeServiceIds.map { it.toMutableList() } + } + + fun addActiveServiceId(activeServiceId: String) = apply { + activeServiceIds = + (activeServiceIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(activeServiceId) + } + } + + fun trips(trips: List) = trips(JsonField.of(trips)) + + fun trips(trips: JsonField>) = apply { + this.trips = trips.map { it.toMutableList() } + } + + fun addTrip(trip: Trip) = apply { + trips = + (trips ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(trip) + } } fun inactiveServiceIds(inactiveServiceIds: List) = inactiveServiceIds(JsonField.of(inactiveServiceIds)) - @JsonProperty("inactiveServiceIds") - @ExcludeMissing fun inactiveServiceIds(inactiveServiceIds: JsonField>) = apply { - this.inactiveServiceIds = inactiveServiceIds + this.inactiveServiceIds = inactiveServiceIds.map { it.toMutableList() } } - fun trips(trips: List) = trips(JsonField.of(trips)) - - @JsonProperty("trips") - @ExcludeMissing - fun trips(trips: JsonField>) = apply { this.trips = trips } + fun addInactiveServiceId(inactiveServiceId: String) = apply { + inactiveServiceIds = + (inactiveServiceIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(inactiveServiceId) + } + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -433,65 +519,88 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Configuration = Configuration( - activeServiceIds.map { it.toImmutable() }, - inactiveServiceIds.map { it.toImmutable() }, - trips.map { it.toImmutable() }, + checkRequired("activeServiceIds", activeServiceIds).map { + it.toImmutable() + }, + checkRequired("trips", trips).map { it.toImmutable() }, + (inactiveServiceIds ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Trip.Builder::class) @NoAutoDetect class Trip + @JsonCreator private constructor( - private val tripId: JsonField, - private val distanceAlongBlock: JsonField, - private val accumulatedSlackTime: JsonField, - private val blockStopTimes: JsonField>, - private val additionalProperties: Map, + @JsonProperty("accumulatedSlackTime") + @ExcludeMissing + private val accumulatedSlackTime: JsonField = JsonMissing.of(), + @JsonProperty("blockStopTimes") + @ExcludeMissing + private val blockStopTimes: JsonField> = JsonMissing.of(), + @JsonProperty("distanceAlongBlock") + @ExcludeMissing + private val distanceAlongBlock: JsonField = JsonMissing.of(), + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun tripId(): String = tripId.getRequired("tripId") - - fun distanceAlongBlock(): Double = - distanceAlongBlock.getRequired("distanceAlongBlock") - fun accumulatedSlackTime(): Double = accumulatedSlackTime.getRequired("accumulatedSlackTime") fun blockStopTimes(): List = blockStopTimes.getRequired("blockStopTimes") - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + fun distanceAlongBlock(): Double = + distanceAlongBlock.getRequired("distanceAlongBlock") - @JsonProperty("distanceAlongBlock") - @ExcludeMissing - fun _distanceAlongBlock() = distanceAlongBlock + fun tripId(): String = tripId.getRequired("tripId") @JsonProperty("accumulatedSlackTime") @ExcludeMissing - fun _accumulatedSlackTime() = accumulatedSlackTime + fun _accumulatedSlackTime(): JsonField = accumulatedSlackTime @JsonProperty("blockStopTimes") @ExcludeMissing - fun _blockStopTimes() = blockStopTimes + fun _blockStopTimes(): JsonField> = blockStopTimes + + @JsonProperty("distanceAlongBlock") + @ExcludeMissing + fun _distanceAlongBlock(): JsonField = distanceAlongBlock + + @JsonProperty("tripId") + @ExcludeMissing + fun _tripId(): JsonField = tripId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Trip = apply { - if (!validated) { - tripId() - distanceAlongBlock() - accumulatedSlackTime() - blockStopTimes().forEach { it.validate() } - validated = true + if (validated) { + return@apply } + + accumulatedSlackTime() + blockStopTimes().forEach { it.validate() } + distanceAlongBlock() + tripId() + validated = true } fun toBuilder() = Builder().from(this) @@ -501,45 +610,28 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Trip]. */ + class Builder internal constructor() { - private var tripId: JsonField = JsonMissing.of() - private var distanceAlongBlock: JsonField = JsonMissing.of() - private var accumulatedSlackTime: JsonField = JsonMissing.of() - private var blockStopTimes: JsonField> = - JsonMissing.of() + private var accumulatedSlackTime: JsonField? = null + private var blockStopTimes: JsonField>? = null + private var distanceAlongBlock: JsonField? = null + private var tripId: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(trip: Trip) = apply { - this.tripId = trip.tripId - this.distanceAlongBlock = trip.distanceAlongBlock - this.accumulatedSlackTime = trip.accumulatedSlackTime - this.blockStopTimes = trip.blockStopTimes - additionalProperties(trip.additionalProperties) - } - - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - @JsonProperty("tripId") - @ExcludeMissing - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - - fun distanceAlongBlock(distanceAlongBlock: Double) = - distanceAlongBlock(JsonField.of(distanceAlongBlock)) - - @JsonProperty("distanceAlongBlock") - @ExcludeMissing - fun distanceAlongBlock(distanceAlongBlock: JsonField) = apply { - this.distanceAlongBlock = distanceAlongBlock + accumulatedSlackTime = trip.accumulatedSlackTime + blockStopTimes = trip.blockStopTimes.map { it.toMutableList() } + distanceAlongBlock = trip.distanceAlongBlock + tripId = trip.tripId + additionalProperties = trip.additionalProperties.toMutableMap() } fun accumulatedSlackTime(accumulatedSlackTime: Double) = accumulatedSlackTime(JsonField.of(accumulatedSlackTime)) - @JsonProperty("accumulatedSlackTime") - @ExcludeMissing fun accumulatedSlackTime(accumulatedSlackTime: JsonField) = apply { this.accumulatedSlackTime = accumulatedSlackTime } @@ -547,86 +639,131 @@ private constructor( fun blockStopTimes(blockStopTimes: List) = blockStopTimes(JsonField.of(blockStopTimes)) - @JsonProperty("blockStopTimes") - @ExcludeMissing fun blockStopTimes(blockStopTimes: JsonField>) = apply { - this.blockStopTimes = blockStopTimes + this.blockStopTimes = blockStopTimes.map { it.toMutableList() } + } + + fun addBlockStopTime(blockStopTime: BlockStopTime) = apply { + blockStopTimes = + (blockStopTimes ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(blockStopTime) + } + } + + fun distanceAlongBlock(distanceAlongBlock: Double) = + distanceAlongBlock(JsonField.of(distanceAlongBlock)) + + fun distanceAlongBlock(distanceAlongBlock: JsonField) = apply { + this.distanceAlongBlock = distanceAlongBlock } + fun tripId(tripId: String) = tripId(JsonField.of(tripId)) + + fun tripId(tripId: JsonField) = apply { this.tripId = tripId } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Trip = Trip( - tripId, - distanceAlongBlock, - accumulatedSlackTime, - blockStopTimes.map { it.toImmutable() }, + checkRequired("accumulatedSlackTime", accumulatedSlackTime), + checkRequired("blockStopTimes", blockStopTimes).map { + it.toImmutable() + }, + checkRequired("distanceAlongBlock", distanceAlongBlock), + checkRequired("tripId", tripId), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = BlockStopTime.Builder::class) @NoAutoDetect class BlockStopTime + @JsonCreator private constructor( - private val blockSequence: JsonField, - private val distanceAlongBlock: JsonField, - private val accumulatedSlackTime: JsonField, - private val stopTime: JsonField, - private val additionalProperties: Map, + @JsonProperty("accumulatedSlackTime") + @ExcludeMissing + private val accumulatedSlackTime: JsonField = JsonMissing.of(), + @JsonProperty("blockSequence") + @ExcludeMissing + private val blockSequence: JsonField = JsonMissing.of(), + @JsonProperty("distanceAlongBlock") + @ExcludeMissing + private val distanceAlongBlock: JsonField = JsonMissing.of(), + @JsonProperty("stopTime") + @ExcludeMissing + private val stopTime: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = + immutableEmptyMap(), ) { - private var validated: Boolean = false + fun accumulatedSlackTime(): Double = + accumulatedSlackTime.getRequired("accumulatedSlackTime") fun blockSequence(): Long = blockSequence.getRequired("blockSequence") fun distanceAlongBlock(): Double = distanceAlongBlock.getRequired("distanceAlongBlock") - fun accumulatedSlackTime(): Double = - accumulatedSlackTime.getRequired("accumulatedSlackTime") - fun stopTime(): StopTime = stopTime.getRequired("stopTime") + @JsonProperty("accumulatedSlackTime") + @ExcludeMissing + fun _accumulatedSlackTime(): JsonField = accumulatedSlackTime + @JsonProperty("blockSequence") @ExcludeMissing - fun _blockSequence() = blockSequence + fun _blockSequence(): JsonField = blockSequence @JsonProperty("distanceAlongBlock") @ExcludeMissing - fun _distanceAlongBlock() = distanceAlongBlock + fun _distanceAlongBlock(): JsonField = distanceAlongBlock - @JsonProperty("accumulatedSlackTime") + @JsonProperty("stopTime") @ExcludeMissing - fun _accumulatedSlackTime() = accumulatedSlackTime - - @JsonProperty("stopTime") @ExcludeMissing fun _stopTime() = stopTime + fun _stopTime(): JsonField = stopTime @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): BlockStopTime = apply { - if (!validated) { - blockSequence() - distanceAlongBlock() - accumulatedSlackTime() - stopTime().validate() - validated = true + if (validated) { + return@apply } + + accumulatedSlackTime() + blockSequence() + distanceAlongBlock() + stopTime().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -636,29 +773,37 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [BlockStopTime]. */ + class Builder internal constructor() { - private var blockSequence: JsonField = JsonMissing.of() - private var distanceAlongBlock: JsonField = JsonMissing.of() - private var accumulatedSlackTime: JsonField = JsonMissing.of() - private var stopTime: JsonField = JsonMissing.of() + private var accumulatedSlackTime: JsonField? = null + private var blockSequence: JsonField? = null + private var distanceAlongBlock: JsonField? = null + private var stopTime: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(blockStopTime: BlockStopTime) = apply { - this.blockSequence = blockStopTime.blockSequence - this.distanceAlongBlock = blockStopTime.distanceAlongBlock - this.accumulatedSlackTime = blockStopTime.accumulatedSlackTime - this.stopTime = blockStopTime.stopTime - additionalProperties(blockStopTime.additionalProperties) + accumulatedSlackTime = blockStopTime.accumulatedSlackTime + blockSequence = blockStopTime.blockSequence + distanceAlongBlock = blockStopTime.distanceAlongBlock + stopTime = blockStopTime.stopTime + additionalProperties = + blockStopTime.additionalProperties.toMutableMap() } + fun accumulatedSlackTime(accumulatedSlackTime: Double) = + accumulatedSlackTime(JsonField.of(accumulatedSlackTime)) + + fun accumulatedSlackTime(accumulatedSlackTime: JsonField) = + apply { + this.accumulatedSlackTime = accumulatedSlackTime + } + fun blockSequence(blockSequence: Long) = blockSequence(JsonField.of(blockSequence)) - @JsonProperty("blockSequence") - @ExcludeMissing fun blockSequence(blockSequence: JsonField) = apply { this.blockSequence = blockSequence } @@ -666,26 +811,12 @@ private constructor( fun distanceAlongBlock(distanceAlongBlock: Double) = distanceAlongBlock(JsonField.of(distanceAlongBlock)) - @JsonProperty("distanceAlongBlock") - @ExcludeMissing fun distanceAlongBlock(distanceAlongBlock: JsonField) = apply { this.distanceAlongBlock = distanceAlongBlock } - fun accumulatedSlackTime(accumulatedSlackTime: Double) = - accumulatedSlackTime(JsonField.of(accumulatedSlackTime)) - - @JsonProperty("accumulatedSlackTime") - @ExcludeMissing - fun accumulatedSlackTime(accumulatedSlackTime: JsonField) = - apply { - this.accumulatedSlackTime = accumulatedSlackTime - } - fun stopTime(stopTime: StopTime) = stopTime(JsonField.of(stopTime)) - @JsonProperty("stopTime") - @ExcludeMissing fun stopTime(stopTime: JsonField) = apply { this.stopTime = stopTime } @@ -693,86 +824,109 @@ private constructor( fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): BlockStopTime = BlockStopTime( - blockSequence, - distanceAlongBlock, - accumulatedSlackTime, - stopTime, + checkRequired("accumulatedSlackTime", accumulatedSlackTime), + checkRequired("blockSequence", blockSequence), + checkRequired("distanceAlongBlock", distanceAlongBlock), + checkRequired("stopTime", stopTime), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = StopTime.Builder::class) @NoAutoDetect class StopTime + @JsonCreator private constructor( - private val stopId: JsonField, - private val arrivalTime: JsonField, - private val departureTime: JsonField, - private val pickupType: JsonField, - private val dropOffType: JsonField, - private val additionalProperties: Map, + @JsonProperty("arrivalTime") + @ExcludeMissing + private val arrivalTime: JsonField = JsonMissing.of(), + @JsonProperty("departureTime") + @ExcludeMissing + private val departureTime: JsonField = JsonMissing.of(), + @JsonProperty("stopId") + @ExcludeMissing + private val stopId: JsonField = JsonMissing.of(), + @JsonProperty("dropOffType") + @ExcludeMissing + private val dropOffType: JsonField = JsonMissing.of(), + @JsonProperty("pickupType") + @ExcludeMissing + private val pickupType: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = + immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun stopId(): String = stopId.getRequired("stopId") - fun arrivalTime(): Long = arrivalTime.getRequired("arrivalTime") fun departureTime(): Long = departureTime.getRequired("departureTime") - fun pickupType(): Optional = - Optional.ofNullable(pickupType.getNullable("pickupType")) + fun stopId(): String = stopId.getRequired("stopId") fun dropOffType(): Optional = Optional.ofNullable(dropOffType.getNullable("dropOffType")) - @JsonProperty("stopId") @ExcludeMissing fun _stopId() = stopId + fun pickupType(): Optional = + Optional.ofNullable(pickupType.getNullable("pickupType")) @JsonProperty("arrivalTime") @ExcludeMissing - fun _arrivalTime() = arrivalTime + fun _arrivalTime(): JsonField = arrivalTime @JsonProperty("departureTime") @ExcludeMissing - fun _departureTime() = departureTime + fun _departureTime(): JsonField = departureTime - @JsonProperty("pickupType") + @JsonProperty("stopId") @ExcludeMissing - fun _pickupType() = pickupType + fun _stopId(): JsonField = stopId @JsonProperty("dropOffType") @ExcludeMissing - fun _dropOffType() = dropOffType + fun _dropOffType(): JsonField = dropOffType + + @JsonProperty("pickupType") + @ExcludeMissing + fun _pickupType(): JsonField = pickupType @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): StopTime = apply { - if (!validated) { - stopId() - arrivalTime() - departureTime() - pickupType() - dropOffType() - validated = true + if (validated) { + return@apply } + + arrivalTime() + departureTime() + stopId() + dropOffType() + pickupType() + validated = true } fun toBuilder() = Builder().from(this) @@ -782,39 +936,31 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopTime]. */ + class Builder internal constructor() { - private var stopId: JsonField = JsonMissing.of() - private var arrivalTime: JsonField = JsonMissing.of() - private var departureTime: JsonField = JsonMissing.of() - private var pickupType: JsonField = JsonMissing.of() + private var arrivalTime: JsonField? = null + private var departureTime: JsonField? = null + private var stopId: JsonField? = null private var dropOffType: JsonField = JsonMissing.of() + private var pickupType: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(stopTime: StopTime) = apply { - this.stopId = stopTime.stopId - this.arrivalTime = stopTime.arrivalTime - this.departureTime = stopTime.departureTime - this.pickupType = stopTime.pickupType - this.dropOffType = stopTime.dropOffType - additionalProperties(stopTime.additionalProperties) - } - - fun stopId(stopId: String) = stopId(JsonField.of(stopId)) - - @JsonProperty("stopId") - @ExcludeMissing - fun stopId(stopId: JsonField) = apply { - this.stopId = stopId + arrivalTime = stopTime.arrivalTime + departureTime = stopTime.departureTime + stopId = stopTime.stopId + dropOffType = stopTime.dropOffType + pickupType = stopTime.pickupType + additionalProperties = + stopTime.additionalProperties.toMutableMap() } fun arrivalTime(arrivalTime: Long) = arrivalTime(JsonField.of(arrivalTime)) - @JsonProperty("arrivalTime") - @ExcludeMissing fun arrivalTime(arrivalTime: JsonField) = apply { this.arrivalTime = arrivalTime } @@ -822,53 +968,60 @@ private constructor( fun departureTime(departureTime: Long) = departureTime(JsonField.of(departureTime)) - @JsonProperty("departureTime") - @ExcludeMissing fun departureTime(departureTime: JsonField) = apply { this.departureTime = departureTime } - fun pickupType(pickupType: Long) = - pickupType(JsonField.of(pickupType)) + fun stopId(stopId: String) = stopId(JsonField.of(stopId)) - @JsonProperty("pickupType") - @ExcludeMissing - fun pickupType(pickupType: JsonField) = apply { - this.pickupType = pickupType + fun stopId(stopId: JsonField) = apply { + this.stopId = stopId } fun dropOffType(dropOffType: Long) = dropOffType(JsonField.of(dropOffType)) - @JsonProperty("dropOffType") - @ExcludeMissing fun dropOffType(dropOffType: JsonField) = apply { this.dropOffType = dropOffType } + fun pickupType(pickupType: Long) = + pickupType(JsonField.of(pickupType)) + + fun pickupType(pickupType: JsonField) = apply { + this.pickupType = pickupType + } + fun additionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopTime = StopTime( - stopId, - arrivalTime, - departureTime, - pickupType, + checkRequired("arrivalTime", arrivalTime), + checkRequired("departureTime", departureTime), + checkRequired("stopId", stopId), dropOffType, + pickupType, additionalProperties.toImmutable(), ) } @@ -878,20 +1031,17 @@ private constructor( return true } - return /* spotless:off */ other is StopTime && this.stopId == other.stopId && this.arrivalTime == other.arrivalTime && this.departureTime == other.departureTime && this.pickupType == other.pickupType && this.dropOffType == other.dropOffType && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopTime && arrivalTime == other.arrivalTime && departureTime == other.departureTime && stopId == other.stopId && dropOffType == other.dropOffType && pickupType == other.pickupType && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(arrivalTime, departureTime, stopId, dropOffType, pickupType, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(stopId, arrivalTime, departureTime, pickupType, dropOffType, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "StopTime{stopId=$stopId, arrivalTime=$arrivalTime, departureTime=$departureTime, pickupType=$pickupType, dropOffType=$dropOffType, additionalProperties=$additionalProperties}" + "StopTime{arrivalTime=$arrivalTime, departureTime=$departureTime, stopId=$stopId, dropOffType=$dropOffType, pickupType=$pickupType, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -899,20 +1049,17 @@ private constructor( return true } - return /* spotless:off */ other is BlockStopTime && this.blockSequence == other.blockSequence && this.distanceAlongBlock == other.distanceAlongBlock && this.accumulatedSlackTime == other.accumulatedSlackTime && this.stopTime == other.stopTime && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is BlockStopTime && accumulatedSlackTime == other.accumulatedSlackTime && blockSequence == other.blockSequence && distanceAlongBlock == other.distanceAlongBlock && stopTime == other.stopTime && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(accumulatedSlackTime, blockSequence, distanceAlongBlock, stopTime, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(blockSequence, distanceAlongBlock, accumulatedSlackTime, stopTime, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "BlockStopTime{blockSequence=$blockSequence, distanceAlongBlock=$distanceAlongBlock, accumulatedSlackTime=$accumulatedSlackTime, stopTime=$stopTime, additionalProperties=$additionalProperties}" + "BlockStopTime{accumulatedSlackTime=$accumulatedSlackTime, blockSequence=$blockSequence, distanceAlongBlock=$distanceAlongBlock, stopTime=$stopTime, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -920,20 +1067,17 @@ private constructor( return true } - return /* spotless:off */ other is Trip && this.tripId == other.tripId && this.distanceAlongBlock == other.distanceAlongBlock && this.accumulatedSlackTime == other.accumulatedSlackTime && this.blockStopTimes == other.blockStopTimes && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Trip && accumulatedSlackTime == other.accumulatedSlackTime && blockStopTimes == other.blockStopTimes && distanceAlongBlock == other.distanceAlongBlock && tripId == other.tripId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(accumulatedSlackTime, blockStopTimes, distanceAlongBlock, tripId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(tripId, distanceAlongBlock, accumulatedSlackTime, blockStopTimes, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Trip{tripId=$tripId, distanceAlongBlock=$distanceAlongBlock, accumulatedSlackTime=$accumulatedSlackTime, blockStopTimes=$blockStopTimes, additionalProperties=$additionalProperties}" + "Trip{accumulatedSlackTime=$accumulatedSlackTime, blockStopTimes=$blockStopTimes, distanceAlongBlock=$distanceAlongBlock, tripId=$tripId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -941,20 +1085,17 @@ private constructor( return true } - return /* spotless:off */ other is Configuration && this.activeServiceIds == other.activeServiceIds && this.inactiveServiceIds == other.inactiveServiceIds && this.trips == other.trips && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Configuration && activeServiceIds == other.activeServiceIds && trips == other.trips && inactiveServiceIds == other.inactiveServiceIds && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(activeServiceIds, trips, inactiveServiceIds, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(activeServiceIds, inactiveServiceIds, trips, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Configuration{activeServiceIds=$activeServiceIds, inactiveServiceIds=$inactiveServiceIds, trips=$trips, additionalProperties=$additionalProperties}" + "Configuration{activeServiceIds=$activeServiceIds, trips=$trips, inactiveServiceIds=$inactiveServiceIds, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -962,17 +1103,14 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.id == other.id && this.configurations == other.configurations && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && id == other.id && configurations == other.configurations && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, configurations, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(id, configurations, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Entry{id=$id, configurations=$configurations, additionalProperties=$additionalProperties}" @@ -983,17 +1121,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, references=$references, additionalProperties=$additionalProperties}" @@ -1004,17 +1139,14 @@ private constructor( return true } - return /* spotless:off */ other is BlockRetrieveResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is BlockRetrieveResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "BlockRetrieveResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ConfigRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ConfigRetrieveParams.kt index 411d31f..45d12c5 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ConfigRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ConfigRetrieveParams.kt @@ -2,41 +2,26 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** config */ class ConfigRetrieveParams -constructor( - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { +private constructor( + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalHeaders(): Map> = additionalHeaders + override fun _headers(): Headers = additionalHeaders - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ConfigRetrieveParams && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "ConfigRetrieveParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -45,16 +30,22 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [ConfigRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(configRetrieveParams: ConfigRetrieveParams) = apply { - additionalHeaders(configRetrieveParams.additionalHeaders) - additionalQueryParams(configRetrieveParams.additionalQueryParams) + additionalHeaders = configRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = configRetrieveParams.additionalQueryParams.toBuilder() + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } fun additionalHeaders(additionalHeaders: Map>) = apply { @@ -67,29 +58,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -102,45 +106,55 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): ConfigRetrieveParams = - ConfigRetrieveParams( - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable() - ) + ConfigRetrieveParams(additionalHeaders.build(), additionalQueryParams.build()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ConfigRetrieveParams && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "ConfigRetrieveParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ConfigRetrieveResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ConfigRetrieveResponse.kt index 22b23c2..36c0a69 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ConfigRetrieveResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ConfigRetrieveResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = ConfigRetrieveResponse.Builder::class) @NoAutoDetect class ConfigRetrieveResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): ConfigRetrieveResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,109 +87,114 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [ConfigRetrieveResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(configRetrieveResponse: ConfigRetrieveResponse) = apply { - this.code = configRetrieveResponse.code - this.currentTime = configRetrieveResponse.currentTime - this.text = configRetrieveResponse.text - this.version = configRetrieveResponse.version - this.data = configRetrieveResponse.data - additionalProperties(configRetrieveResponse.additionalProperties) + code = configRetrieveResponse.code + currentTime = configRetrieveResponse.currentTime + text = configRetrieveResponse.text + version = configRetrieveResponse.version + data = configRetrieveResponse.data + additionalProperties = configRetrieveResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): ConfigRetrieveResponse = ConfigRetrieveResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") fun references(): References = references.getRequired("references") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -191,74 +204,85 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val gitProperties: JsonField, - private val id: JsonField, - private val name: JsonField, - private val serviceDateFrom: JsonField, - private val serviceDateTo: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("gitProperties") + @ExcludeMissing + private val gitProperties: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + private val name: JsonField = JsonMissing.of(), + @JsonProperty("serviceDateFrom") + @ExcludeMissing + private val serviceDateFrom: JsonField = JsonMissing.of(), + @JsonProperty("serviceDateTo") + @ExcludeMissing + private val serviceDateTo: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun id(): Optional = Optional.ofNullable(id.getNullable("id")) fun gitProperties(): Optional = Optional.ofNullable(gitProperties.getNullable("gitProperties")) - fun id(): Optional = Optional.ofNullable(id.getNullable("id")) - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) fun serviceDateFrom(): Optional = @@ -267,31 +291,39 @@ private constructor( fun serviceDateTo(): Optional = Optional.ofNullable(serviceDateTo.getNullable("serviceDateTo")) - @JsonProperty("gitProperties") @ExcludeMissing fun _gitProperties() = gitProperties + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("gitProperties") + @ExcludeMissing + fun _gitProperties(): JsonField = gitProperties - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name @JsonProperty("serviceDateFrom") @ExcludeMissing - fun _serviceDateFrom() = serviceDateFrom + fun _serviceDateFrom(): JsonField = serviceDateFrom - @JsonProperty("serviceDateTo") @ExcludeMissing fun _serviceDateTo() = serviceDateTo + @JsonProperty("serviceDateTo") + @ExcludeMissing + fun _serviceDateTo(): JsonField = serviceDateTo @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - gitProperties().map { it.validate() } - id() - name() - serviceDateFrom() - serviceDateTo() - validated = true + if (validated) { + return@apply } + + id() + gitProperties().ifPresent { it.validate() } + name() + serviceDateFrom() + serviceDateTo() + validated = true } fun toBuilder() = Builder().from(this) @@ -301,10 +333,11 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Entry]. */ + class Builder internal constructor() { - private var gitProperties: JsonField = JsonMissing.of() private var id: JsonField = JsonMissing.of() + private var gitProperties: JsonField = JsonMissing.of() private var name: JsonField = JsonMissing.of() private var serviceDateFrom: JsonField = JsonMissing.of() private var serviceDateTo: JsonField = JsonMissing.of() @@ -312,40 +345,32 @@ private constructor( @JvmSynthetic internal fun from(entry: Entry) = apply { - this.gitProperties = entry.gitProperties - this.id = entry.id - this.name = entry.name - this.serviceDateFrom = entry.serviceDateFrom - this.serviceDateTo = entry.serviceDateTo - additionalProperties(entry.additionalProperties) + id = entry.id + gitProperties = entry.gitProperties + name = entry.name + serviceDateFrom = entry.serviceDateFrom + serviceDateTo = entry.serviceDateTo + additionalProperties = entry.additionalProperties.toMutableMap() } + fun id(id: String) = id(JsonField.of(id)) + + fun id(id: JsonField) = apply { this.id = id } + fun gitProperties(gitProperties: GitProperties) = gitProperties(JsonField.of(gitProperties)) - @JsonProperty("gitProperties") - @ExcludeMissing fun gitProperties(gitProperties: JsonField) = apply { this.gitProperties = gitProperties } - fun id(id: String) = id(JsonField.of(id)) - - @JsonProperty("id") - @ExcludeMissing - fun id(id: JsonField) = apply { this.id = id } - fun name(name: String) = name(JsonField.of(name)) - @JsonProperty("name") - @ExcludeMissing fun name(name: JsonField) = apply { this.name = name } fun serviceDateFrom(serviceDateFrom: String) = serviceDateFrom(JsonField.of(serviceDateFrom)) - @JsonProperty("serviceDateFrom") - @ExcludeMissing fun serviceDateFrom(serviceDateFrom: JsonField) = apply { this.serviceDateFrom = serviceDateFrom } @@ -353,20 +378,17 @@ private constructor( fun serviceDateTo(serviceDateTo: String) = serviceDateTo(JsonField.of(serviceDateTo)) - @JsonProperty("serviceDateTo") - @ExcludeMissing fun serviceDateTo(serviceDateTo: JsonField) = apply { this.serviceDateTo = serviceDateTo } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -374,10 +396,18 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( - gitProperties, id, + gitProperties, name, serviceDateFrom, serviceDateTo, @@ -385,35 +415,74 @@ private constructor( ) } - @JsonDeserialize(builder = GitProperties.Builder::class) @NoAutoDetect class GitProperties + @JsonCreator private constructor( - private val gitBranch: JsonField, - private val gitBuildHost: JsonField, - private val gitBuildTime: JsonField, - private val gitBuildUserEmail: JsonField, - private val gitBuildUserName: JsonField, - private val gitBuildVersion: JsonField, - private val gitClosestTagCommitCount: JsonField, - private val gitClosestTagName: JsonField, - private val gitCommitId: JsonField, - private val gitCommitIdAbbrev: JsonField, - private val gitCommitIdDescribe: JsonField, - private val gitCommitIdDescribeShort: JsonField, - private val gitCommitMessageFull: JsonField, - private val gitCommitMessageShort: JsonField, - private val gitCommitTime: JsonField, - private val gitCommitUserEmail: JsonField, - private val gitCommitUserName: JsonField, - private val gitDirty: JsonField, - private val gitRemoteOriginUrl: JsonField, - private val gitTags: JsonField, - private val additionalProperties: Map, + @JsonProperty("git.branch") + @ExcludeMissing + private val gitBranch: JsonField = JsonMissing.of(), + @JsonProperty("git.build.host") + @ExcludeMissing + private val gitBuildHost: JsonField = JsonMissing.of(), + @JsonProperty("git.build.time") + @ExcludeMissing + private val gitBuildTime: JsonField = JsonMissing.of(), + @JsonProperty("git.build.user.email") + @ExcludeMissing + private val gitBuildUserEmail: JsonField = JsonMissing.of(), + @JsonProperty("git.build.user.name") + @ExcludeMissing + private val gitBuildUserName: JsonField = JsonMissing.of(), + @JsonProperty("git.build.version") + @ExcludeMissing + private val gitBuildVersion: JsonField = JsonMissing.of(), + @JsonProperty("git.closest.tag.commit.count") + @ExcludeMissing + private val gitClosestTagCommitCount: JsonField = JsonMissing.of(), + @JsonProperty("git.closest.tag.name") + @ExcludeMissing + private val gitClosestTagName: JsonField = JsonMissing.of(), + @JsonProperty("git.commit.id") + @ExcludeMissing + private val gitCommitId: JsonField = JsonMissing.of(), + @JsonProperty("git.commit.id.abbrev") + @ExcludeMissing + private val gitCommitIdAbbrev: JsonField = JsonMissing.of(), + @JsonProperty("git.commit.id.describe") + @ExcludeMissing + private val gitCommitIdDescribe: JsonField = JsonMissing.of(), + @JsonProperty("git.commit.id.describe-short") + @ExcludeMissing + private val gitCommitIdDescribeShort: JsonField = JsonMissing.of(), + @JsonProperty("git.commit.message.full") + @ExcludeMissing + private val gitCommitMessageFull: JsonField = JsonMissing.of(), + @JsonProperty("git.commit.message.short") + @ExcludeMissing + private val gitCommitMessageShort: JsonField = JsonMissing.of(), + @JsonProperty("git.commit.time") + @ExcludeMissing + private val gitCommitTime: JsonField = JsonMissing.of(), + @JsonProperty("git.commit.user.email") + @ExcludeMissing + private val gitCommitUserEmail: JsonField = JsonMissing.of(), + @JsonProperty("git.commit.user.name") + @ExcludeMissing + private val gitCommitUserName: JsonField = JsonMissing.of(), + @JsonProperty("git.dirty") + @ExcludeMissing + private val gitDirty: JsonField = JsonMissing.of(), + @JsonProperty("git.remote.origin.url") + @ExcludeMissing + private val gitRemoteOriginUrl: JsonField = JsonMissing.of(), + @JsonProperty("git.tags") + @ExcludeMissing + private val gitTags: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun gitBranch(): Optional = Optional.ofNullable(gitBranch.getNullable("git.branch")) @@ -480,102 +549,118 @@ private constructor( fun gitTags(): Optional = Optional.ofNullable(gitTags.getNullable("git.tags")) - @JsonProperty("git.branch") @ExcludeMissing fun _gitBranch() = gitBranch + @JsonProperty("git.branch") + @ExcludeMissing + fun _gitBranch(): JsonField = gitBranch - @JsonProperty("git.build.host") @ExcludeMissing fun _gitBuildHost() = gitBuildHost + @JsonProperty("git.build.host") + @ExcludeMissing + fun _gitBuildHost(): JsonField = gitBuildHost - @JsonProperty("git.build.time") @ExcludeMissing fun _gitBuildTime() = gitBuildTime + @JsonProperty("git.build.time") + @ExcludeMissing + fun _gitBuildTime(): JsonField = gitBuildTime @JsonProperty("git.build.user.email") @ExcludeMissing - fun _gitBuildUserEmail() = gitBuildUserEmail + fun _gitBuildUserEmail(): JsonField = gitBuildUserEmail @JsonProperty("git.build.user.name") @ExcludeMissing - fun _gitBuildUserName() = gitBuildUserName + fun _gitBuildUserName(): JsonField = gitBuildUserName @JsonProperty("git.build.version") @ExcludeMissing - fun _gitBuildVersion() = gitBuildVersion + fun _gitBuildVersion(): JsonField = gitBuildVersion @JsonProperty("git.closest.tag.commit.count") @ExcludeMissing - fun _gitClosestTagCommitCount() = gitClosestTagCommitCount + fun _gitClosestTagCommitCount(): JsonField = gitClosestTagCommitCount @JsonProperty("git.closest.tag.name") @ExcludeMissing - fun _gitClosestTagName() = gitClosestTagName + fun _gitClosestTagName(): JsonField = gitClosestTagName - @JsonProperty("git.commit.id") @ExcludeMissing fun _gitCommitId() = gitCommitId + @JsonProperty("git.commit.id") + @ExcludeMissing + fun _gitCommitId(): JsonField = gitCommitId @JsonProperty("git.commit.id.abbrev") @ExcludeMissing - fun _gitCommitIdAbbrev() = gitCommitIdAbbrev + fun _gitCommitIdAbbrev(): JsonField = gitCommitIdAbbrev @JsonProperty("git.commit.id.describe") @ExcludeMissing - fun _gitCommitIdDescribe() = gitCommitIdDescribe + fun _gitCommitIdDescribe(): JsonField = gitCommitIdDescribe @JsonProperty("git.commit.id.describe-short") @ExcludeMissing - fun _gitCommitIdDescribeShort() = gitCommitIdDescribeShort + fun _gitCommitIdDescribeShort(): JsonField = gitCommitIdDescribeShort @JsonProperty("git.commit.message.full") @ExcludeMissing - fun _gitCommitMessageFull() = gitCommitMessageFull + fun _gitCommitMessageFull(): JsonField = gitCommitMessageFull @JsonProperty("git.commit.message.short") @ExcludeMissing - fun _gitCommitMessageShort() = gitCommitMessageShort + fun _gitCommitMessageShort(): JsonField = gitCommitMessageShort @JsonProperty("git.commit.time") @ExcludeMissing - fun _gitCommitTime() = gitCommitTime + fun _gitCommitTime(): JsonField = gitCommitTime @JsonProperty("git.commit.user.email") @ExcludeMissing - fun _gitCommitUserEmail() = gitCommitUserEmail + fun _gitCommitUserEmail(): JsonField = gitCommitUserEmail @JsonProperty("git.commit.user.name") @ExcludeMissing - fun _gitCommitUserName() = gitCommitUserName + fun _gitCommitUserName(): JsonField = gitCommitUserName - @JsonProperty("git.dirty") @ExcludeMissing fun _gitDirty() = gitDirty + @JsonProperty("git.dirty") + @ExcludeMissing + fun _gitDirty(): JsonField = gitDirty @JsonProperty("git.remote.origin.url") @ExcludeMissing - fun _gitRemoteOriginUrl() = gitRemoteOriginUrl + fun _gitRemoteOriginUrl(): JsonField = gitRemoteOriginUrl - @JsonProperty("git.tags") @ExcludeMissing fun _gitTags() = gitTags + @JsonProperty("git.tags") + @ExcludeMissing + fun _gitTags(): JsonField = gitTags @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): GitProperties = apply { - if (!validated) { - gitBranch() - gitBuildHost() - gitBuildTime() - gitBuildUserEmail() - gitBuildUserName() - gitBuildVersion() - gitClosestTagCommitCount() - gitClosestTagName() - gitCommitId() - gitCommitIdAbbrev() - gitCommitIdDescribe() - gitCommitIdDescribeShort() - gitCommitMessageFull() - gitCommitMessageShort() - gitCommitTime() - gitCommitUserEmail() - gitCommitUserName() - gitDirty() - gitRemoteOriginUrl() - gitTags() - validated = true + if (validated) { + return@apply } + + gitBranch() + gitBuildHost() + gitBuildTime() + gitBuildUserEmail() + gitBuildUserName() + gitBuildVersion() + gitClosestTagCommitCount() + gitClosestTagName() + gitCommitId() + gitCommitIdAbbrev() + gitCommitIdDescribe() + gitCommitIdDescribeShort() + gitCommitMessageFull() + gitCommitMessageShort() + gitCommitTime() + gitCommitUserEmail() + gitCommitUserName() + gitDirty() + gitRemoteOriginUrl() + gitTags() + validated = true } fun toBuilder() = Builder().from(this) @@ -585,7 +670,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [GitProperties]. */ + class Builder internal constructor() { private var gitBranch: JsonField = JsonMissing.of() private var gitBuildHost: JsonField = JsonMissing.of() @@ -611,33 +697,31 @@ private constructor( @JvmSynthetic internal fun from(gitProperties: GitProperties) = apply { - this.gitBranch = gitProperties.gitBranch - this.gitBuildHost = gitProperties.gitBuildHost - this.gitBuildTime = gitProperties.gitBuildTime - this.gitBuildUserEmail = gitProperties.gitBuildUserEmail - this.gitBuildUserName = gitProperties.gitBuildUserName - this.gitBuildVersion = gitProperties.gitBuildVersion - this.gitClosestTagCommitCount = gitProperties.gitClosestTagCommitCount - this.gitClosestTagName = gitProperties.gitClosestTagName - this.gitCommitId = gitProperties.gitCommitId - this.gitCommitIdAbbrev = gitProperties.gitCommitIdAbbrev - this.gitCommitIdDescribe = gitProperties.gitCommitIdDescribe - this.gitCommitIdDescribeShort = gitProperties.gitCommitIdDescribeShort - this.gitCommitMessageFull = gitProperties.gitCommitMessageFull - this.gitCommitMessageShort = gitProperties.gitCommitMessageShort - this.gitCommitTime = gitProperties.gitCommitTime - this.gitCommitUserEmail = gitProperties.gitCommitUserEmail - this.gitCommitUserName = gitProperties.gitCommitUserName - this.gitDirty = gitProperties.gitDirty - this.gitRemoteOriginUrl = gitProperties.gitRemoteOriginUrl - this.gitTags = gitProperties.gitTags - additionalProperties(gitProperties.additionalProperties) + gitBranch = gitProperties.gitBranch + gitBuildHost = gitProperties.gitBuildHost + gitBuildTime = gitProperties.gitBuildTime + gitBuildUserEmail = gitProperties.gitBuildUserEmail + gitBuildUserName = gitProperties.gitBuildUserName + gitBuildVersion = gitProperties.gitBuildVersion + gitClosestTagCommitCount = gitProperties.gitClosestTagCommitCount + gitClosestTagName = gitProperties.gitClosestTagName + gitCommitId = gitProperties.gitCommitId + gitCommitIdAbbrev = gitProperties.gitCommitIdAbbrev + gitCommitIdDescribe = gitProperties.gitCommitIdDescribe + gitCommitIdDescribeShort = gitProperties.gitCommitIdDescribeShort + gitCommitMessageFull = gitProperties.gitCommitMessageFull + gitCommitMessageShort = gitProperties.gitCommitMessageShort + gitCommitTime = gitProperties.gitCommitTime + gitCommitUserEmail = gitProperties.gitCommitUserEmail + gitCommitUserName = gitProperties.gitCommitUserName + gitDirty = gitProperties.gitDirty + gitRemoteOriginUrl = gitProperties.gitRemoteOriginUrl + gitTags = gitProperties.gitTags + additionalProperties = gitProperties.additionalProperties.toMutableMap() } fun gitBranch(gitBranch: String) = gitBranch(JsonField.of(gitBranch)) - @JsonProperty("git.branch") - @ExcludeMissing fun gitBranch(gitBranch: JsonField) = apply { this.gitBranch = gitBranch } @@ -645,8 +729,6 @@ private constructor( fun gitBuildHost(gitBuildHost: String) = gitBuildHost(JsonField.of(gitBuildHost)) - @JsonProperty("git.build.host") - @ExcludeMissing fun gitBuildHost(gitBuildHost: JsonField) = apply { this.gitBuildHost = gitBuildHost } @@ -654,8 +736,6 @@ private constructor( fun gitBuildTime(gitBuildTime: String) = gitBuildTime(JsonField.of(gitBuildTime)) - @JsonProperty("git.build.time") - @ExcludeMissing fun gitBuildTime(gitBuildTime: JsonField) = apply { this.gitBuildTime = gitBuildTime } @@ -663,8 +743,6 @@ private constructor( fun gitBuildUserEmail(gitBuildUserEmail: String) = gitBuildUserEmail(JsonField.of(gitBuildUserEmail)) - @JsonProperty("git.build.user.email") - @ExcludeMissing fun gitBuildUserEmail(gitBuildUserEmail: JsonField) = apply { this.gitBuildUserEmail = gitBuildUserEmail } @@ -672,8 +750,6 @@ private constructor( fun gitBuildUserName(gitBuildUserName: String) = gitBuildUserName(JsonField.of(gitBuildUserName)) - @JsonProperty("git.build.user.name") - @ExcludeMissing fun gitBuildUserName(gitBuildUserName: JsonField) = apply { this.gitBuildUserName = gitBuildUserName } @@ -681,8 +757,6 @@ private constructor( fun gitBuildVersion(gitBuildVersion: String) = gitBuildVersion(JsonField.of(gitBuildVersion)) - @JsonProperty("git.build.version") - @ExcludeMissing fun gitBuildVersion(gitBuildVersion: JsonField) = apply { this.gitBuildVersion = gitBuildVersion } @@ -690,8 +764,6 @@ private constructor( fun gitClosestTagCommitCount(gitClosestTagCommitCount: String) = gitClosestTagCommitCount(JsonField.of(gitClosestTagCommitCount)) - @JsonProperty("git.closest.tag.commit.count") - @ExcludeMissing fun gitClosestTagCommitCount(gitClosestTagCommitCount: JsonField) = apply { this.gitClosestTagCommitCount = gitClosestTagCommitCount @@ -700,16 +772,12 @@ private constructor( fun gitClosestTagName(gitClosestTagName: String) = gitClosestTagName(JsonField.of(gitClosestTagName)) - @JsonProperty("git.closest.tag.name") - @ExcludeMissing fun gitClosestTagName(gitClosestTagName: JsonField) = apply { this.gitClosestTagName = gitClosestTagName } fun gitCommitId(gitCommitId: String) = gitCommitId(JsonField.of(gitCommitId)) - @JsonProperty("git.commit.id") - @ExcludeMissing fun gitCommitId(gitCommitId: JsonField) = apply { this.gitCommitId = gitCommitId } @@ -717,8 +785,6 @@ private constructor( fun gitCommitIdAbbrev(gitCommitIdAbbrev: String) = gitCommitIdAbbrev(JsonField.of(gitCommitIdAbbrev)) - @JsonProperty("git.commit.id.abbrev") - @ExcludeMissing fun gitCommitIdAbbrev(gitCommitIdAbbrev: JsonField) = apply { this.gitCommitIdAbbrev = gitCommitIdAbbrev } @@ -726,8 +792,6 @@ private constructor( fun gitCommitIdDescribe(gitCommitIdDescribe: String) = gitCommitIdDescribe(JsonField.of(gitCommitIdDescribe)) - @JsonProperty("git.commit.id.describe") - @ExcludeMissing fun gitCommitIdDescribe(gitCommitIdDescribe: JsonField) = apply { this.gitCommitIdDescribe = gitCommitIdDescribe } @@ -735,8 +799,6 @@ private constructor( fun gitCommitIdDescribeShort(gitCommitIdDescribeShort: String) = gitCommitIdDescribeShort(JsonField.of(gitCommitIdDescribeShort)) - @JsonProperty("git.commit.id.describe-short") - @ExcludeMissing fun gitCommitIdDescribeShort(gitCommitIdDescribeShort: JsonField) = apply { this.gitCommitIdDescribeShort = gitCommitIdDescribeShort @@ -745,8 +807,6 @@ private constructor( fun gitCommitMessageFull(gitCommitMessageFull: String) = gitCommitMessageFull(JsonField.of(gitCommitMessageFull)) - @JsonProperty("git.commit.message.full") - @ExcludeMissing fun gitCommitMessageFull(gitCommitMessageFull: JsonField) = apply { this.gitCommitMessageFull = gitCommitMessageFull } @@ -754,8 +814,6 @@ private constructor( fun gitCommitMessageShort(gitCommitMessageShort: String) = gitCommitMessageShort(JsonField.of(gitCommitMessageShort)) - @JsonProperty("git.commit.message.short") - @ExcludeMissing fun gitCommitMessageShort(gitCommitMessageShort: JsonField) = apply { this.gitCommitMessageShort = gitCommitMessageShort } @@ -763,8 +821,6 @@ private constructor( fun gitCommitTime(gitCommitTime: String) = gitCommitTime(JsonField.of(gitCommitTime)) - @JsonProperty("git.commit.time") - @ExcludeMissing fun gitCommitTime(gitCommitTime: JsonField) = apply { this.gitCommitTime = gitCommitTime } @@ -772,8 +828,6 @@ private constructor( fun gitCommitUserEmail(gitCommitUserEmail: String) = gitCommitUserEmail(JsonField.of(gitCommitUserEmail)) - @JsonProperty("git.commit.user.email") - @ExcludeMissing fun gitCommitUserEmail(gitCommitUserEmail: JsonField) = apply { this.gitCommitUserEmail = gitCommitUserEmail } @@ -781,41 +835,32 @@ private constructor( fun gitCommitUserName(gitCommitUserName: String) = gitCommitUserName(JsonField.of(gitCommitUserName)) - @JsonProperty("git.commit.user.name") - @ExcludeMissing fun gitCommitUserName(gitCommitUserName: JsonField) = apply { this.gitCommitUserName = gitCommitUserName } fun gitDirty(gitDirty: String) = gitDirty(JsonField.of(gitDirty)) - @JsonProperty("git.dirty") - @ExcludeMissing fun gitDirty(gitDirty: JsonField) = apply { this.gitDirty = gitDirty } fun gitRemoteOriginUrl(gitRemoteOriginUrl: String) = gitRemoteOriginUrl(JsonField.of(gitRemoteOriginUrl)) - @JsonProperty("git.remote.origin.url") - @ExcludeMissing fun gitRemoteOriginUrl(gitRemoteOriginUrl: JsonField) = apply { this.gitRemoteOriginUrl = gitRemoteOriginUrl } fun gitTags(gitTags: String) = gitTags(JsonField.of(gitTags)) - @JsonProperty("git.tags") - @ExcludeMissing fun gitTags(gitTags: JsonField) = apply { this.gitTags = gitTags } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -823,6 +868,14 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): GitProperties = GitProperties( gitBranch, @@ -854,17 +907,14 @@ private constructor( return true } - return /* spotless:off */ other is GitProperties && this.gitBranch == other.gitBranch && this.gitBuildHost == other.gitBuildHost && this.gitBuildTime == other.gitBuildTime && this.gitBuildUserEmail == other.gitBuildUserEmail && this.gitBuildUserName == other.gitBuildUserName && this.gitBuildVersion == other.gitBuildVersion && this.gitClosestTagCommitCount == other.gitClosestTagCommitCount && this.gitClosestTagName == other.gitClosestTagName && this.gitCommitId == other.gitCommitId && this.gitCommitIdAbbrev == other.gitCommitIdAbbrev && this.gitCommitIdDescribe == other.gitCommitIdDescribe && this.gitCommitIdDescribeShort == other.gitCommitIdDescribeShort && this.gitCommitMessageFull == other.gitCommitMessageFull && this.gitCommitMessageShort == other.gitCommitMessageShort && this.gitCommitTime == other.gitCommitTime && this.gitCommitUserEmail == other.gitCommitUserEmail && this.gitCommitUserName == other.gitCommitUserName && this.gitDirty == other.gitDirty && this.gitRemoteOriginUrl == other.gitRemoteOriginUrl && this.gitTags == other.gitTags && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is GitProperties && gitBranch == other.gitBranch && gitBuildHost == other.gitBuildHost && gitBuildTime == other.gitBuildTime && gitBuildUserEmail == other.gitBuildUserEmail && gitBuildUserName == other.gitBuildUserName && gitBuildVersion == other.gitBuildVersion && gitClosestTagCommitCount == other.gitClosestTagCommitCount && gitClosestTagName == other.gitClosestTagName && gitCommitId == other.gitCommitId && gitCommitIdAbbrev == other.gitCommitIdAbbrev && gitCommitIdDescribe == other.gitCommitIdDescribe && gitCommitIdDescribeShort == other.gitCommitIdDescribeShort && gitCommitMessageFull == other.gitCommitMessageFull && gitCommitMessageShort == other.gitCommitMessageShort && gitCommitTime == other.gitCommitTime && gitCommitUserEmail == other.gitCommitUserEmail && gitCommitUserName == other.gitCommitUserName && gitDirty == other.gitDirty && gitRemoteOriginUrl == other.gitRemoteOriginUrl && gitTags == other.gitTags && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(gitBranch, gitBuildHost, gitBuildTime, gitBuildUserEmail, gitBuildUserName, gitBuildVersion, gitClosestTagCommitCount, gitClosestTagName, gitCommitId, gitCommitIdAbbrev, gitCommitIdDescribe, gitCommitIdDescribeShort, gitCommitMessageFull, gitCommitMessageShort, gitCommitTime, gitCommitUserEmail, gitCommitUserName, gitDirty, gitRemoteOriginUrl, gitTags, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(gitBranch, gitBuildHost, gitBuildTime, gitBuildUserEmail, gitBuildUserName, gitBuildVersion, gitClosestTagCommitCount, gitClosestTagName, gitCommitId, gitCommitIdAbbrev, gitCommitIdDescribe, gitCommitIdDescribeShort, gitCommitMessageFull, gitCommitMessageShort, gitCommitTime, gitCommitUserEmail, gitCommitUserName, gitDirty, gitRemoteOriginUrl, gitTags, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "GitProperties{gitBranch=$gitBranch, gitBuildHost=$gitBuildHost, gitBuildTime=$gitBuildTime, gitBuildUserEmail=$gitBuildUserEmail, gitBuildUserName=$gitBuildUserName, gitBuildVersion=$gitBuildVersion, gitClosestTagCommitCount=$gitClosestTagCommitCount, gitClosestTagName=$gitClosestTagName, gitCommitId=$gitCommitId, gitCommitIdAbbrev=$gitCommitIdAbbrev, gitCommitIdDescribe=$gitCommitIdDescribe, gitCommitIdDescribeShort=$gitCommitIdDescribeShort, gitCommitMessageFull=$gitCommitMessageFull, gitCommitMessageShort=$gitCommitMessageShort, gitCommitTime=$gitCommitTime, gitCommitUserEmail=$gitCommitUserEmail, gitCommitUserName=$gitCommitUserName, gitDirty=$gitDirty, gitRemoteOriginUrl=$gitRemoteOriginUrl, gitTags=$gitTags, additionalProperties=$additionalProperties}" @@ -875,20 +925,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.gitProperties == other.gitProperties && this.id == other.id && this.name == other.name && this.serviceDateFrom == other.serviceDateFrom && this.serviceDateTo == other.serviceDateTo && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && id == other.id && gitProperties == other.gitProperties && name == other.name && serviceDateFrom == other.serviceDateFrom && serviceDateTo == other.serviceDateTo && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, gitProperties, name, serviceDateFrom, serviceDateTo, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(gitProperties, id, name, serviceDateFrom, serviceDateTo, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Entry{gitProperties=$gitProperties, id=$id, name=$name, serviceDateFrom=$serviceDateFrom, serviceDateTo=$serviceDateTo, additionalProperties=$additionalProperties}" + "Entry{id=$id, gitProperties=$gitProperties, name=$name, serviceDateFrom=$serviceDateFrom, serviceDateTo=$serviceDateTo, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -896,17 +943,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, references=$references, additionalProperties=$additionalProperties}" @@ -917,17 +961,14 @@ private constructor( return true } - return /* spotless:off */ other is ConfigRetrieveResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is ConfigRetrieveResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "ConfigRetrieveResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/CurrentTimeRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/CurrentTimeRetrieveParams.kt index 8cefdb2..dfc8416 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/CurrentTimeRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/CurrentTimeRetrieveParams.kt @@ -2,41 +2,26 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** current-time */ class CurrentTimeRetrieveParams -constructor( - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { +private constructor( + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalHeaders(): Map> = additionalHeaders + override fun _headers(): Headers = additionalHeaders - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is CurrentTimeRetrieveParams && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "CurrentTimeRetrieveParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -45,16 +30,22 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [CurrentTimeRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(currentTimeRetrieveParams: CurrentTimeRetrieveParams) = apply { - additionalHeaders(currentTimeRetrieveParams.additionalHeaders) - additionalQueryParams(currentTimeRetrieveParams.additionalQueryParams) + additionalHeaders = currentTimeRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = currentTimeRetrieveParams.additionalQueryParams.toBuilder() + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) } fun additionalHeaders(additionalHeaders: Map>) = apply { @@ -67,29 +58,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -102,45 +106,55 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): CurrentTimeRetrieveParams = - CurrentTimeRetrieveParams( - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable() - ) + CurrentTimeRetrieveParams(additionalHeaders.build(), additionalQueryParams.build()) + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is CurrentTimeRetrieveParams && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "CurrentTimeRetrieveParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/CurrentTimeRetrieveResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/CurrentTimeRetrieveResponse.kt index a1499d6..328b9a3 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/CurrentTimeRetrieveResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/CurrentTimeRetrieveResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = CurrentTimeRetrieveResponse.Builder::class) @NoAutoDetect class CurrentTimeRetrieveResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): CurrentTimeRetrieveResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,109 +87,114 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [CurrentTimeRetrieveResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(currentTimeRetrieveResponse: CurrentTimeRetrieveResponse) = apply { - this.code = currentTimeRetrieveResponse.code - this.currentTime = currentTimeRetrieveResponse.currentTime - this.text = currentTimeRetrieveResponse.text - this.version = currentTimeRetrieveResponse.version - this.data = currentTimeRetrieveResponse.data - additionalProperties(currentTimeRetrieveResponse.additionalProperties) + code = currentTimeRetrieveResponse.code + currentTime = currentTimeRetrieveResponse.currentTime + text = currentTimeRetrieveResponse.text + version = currentTimeRetrieveResponse.version + data = currentTimeRetrieveResponse.data + additionalProperties = currentTimeRetrieveResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): CurrentTimeRetrieveResponse = CurrentTimeRetrieveResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") fun references(): References = references.getRequired("references") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -191,85 +204,96 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val readableTime: JsonField, - private val time: JsonField, - private val additionalProperties: Map, + @JsonProperty("readableTime") + @ExcludeMissing + private val readableTime: JsonField = JsonMissing.of(), + @JsonProperty("time") + @ExcludeMissing + private val time: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun readableTime(): Optional = Optional.ofNullable(readableTime.getNullable("readableTime")) fun time(): Optional = Optional.ofNullable(time.getNullable("time")) - @JsonProperty("readableTime") @ExcludeMissing fun _readableTime() = readableTime + @JsonProperty("readableTime") + @ExcludeMissing + fun _readableTime(): JsonField = readableTime - @JsonProperty("time") @ExcludeMissing fun _time() = time + @JsonProperty("time") @ExcludeMissing fun _time(): JsonField = time @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - readableTime() - time() - validated = true + if (validated) { + return@apply } + + readableTime() + time() + validated = true } fun toBuilder() = Builder().from(this) @@ -279,7 +303,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Entry]. */ + class Builder internal constructor() { private var readableTime: JsonField = JsonMissing.of() private var time: JsonField = JsonMissing.of() @@ -287,33 +312,28 @@ private constructor( @JvmSynthetic internal fun from(entry: Entry) = apply { - this.readableTime = entry.readableTime - this.time = entry.time - additionalProperties(entry.additionalProperties) + readableTime = entry.readableTime + time = entry.time + additionalProperties = entry.additionalProperties.toMutableMap() } fun readableTime(readableTime: String) = readableTime(JsonField.of(readableTime)) - @JsonProperty("readableTime") - @ExcludeMissing fun readableTime(readableTime: JsonField) = apply { this.readableTime = readableTime } fun time(time: Long) = time(JsonField.of(time)) - @JsonProperty("time") - @ExcludeMissing fun time(time: JsonField) = apply { this.time = time } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -321,6 +341,14 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( readableTime, @@ -334,17 +362,14 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.readableTime == other.readableTime && this.time == other.time && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && readableTime == other.readableTime && time == other.time && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(readableTime, time, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(readableTime, time, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Entry{readableTime=$readableTime, time=$time, additionalProperties=$additionalProperties}" @@ -355,17 +380,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, references=$references, additionalProperties=$additionalProperties}" @@ -376,17 +398,14 @@ private constructor( return true } - return /* spotless:off */ other is CurrentTimeRetrieveResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is CurrentTimeRetrieveResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "CurrentTimeRetrieveResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/References.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/References.kt index 698d6d7..b855db0 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/References.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/References.kt @@ -6,7 +6,6 @@ import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.Enum @@ -15,62 +14,82 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable import org.onebusaway.errors.OnebusawaySdkInvalidDataException -@JsonDeserialize(builder = References.Builder::class) @NoAutoDetect class References +@JsonCreator private constructor( - private val agencies: JsonField>, - private val routes: JsonField>, - private val situations: JsonField>, - private val stopTimes: JsonField>, - private val stops: JsonField>, - private val trips: JsonField>, - private val additionalProperties: Map, + @JsonProperty("agencies") + @ExcludeMissing + private val agencies: JsonField> = JsonMissing.of(), + @JsonProperty("routes") + @ExcludeMissing + private val routes: JsonField> = JsonMissing.of(), + @JsonProperty("situations") + @ExcludeMissing + private val situations: JsonField> = JsonMissing.of(), + @JsonProperty("stops") + @ExcludeMissing + private val stops: JsonField> = JsonMissing.of(), + @JsonProperty("stopTimes") + @ExcludeMissing + private val stopTimes: JsonField> = JsonMissing.of(), + @JsonProperty("trips") + @ExcludeMissing + private val trips: JsonField> = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun agencies(): List = agencies.getRequired("agencies") fun routes(): List = routes.getRequired("routes") fun situations(): List = situations.getRequired("situations") - fun stopTimes(): List = stopTimes.getRequired("stopTimes") - fun stops(): List = stops.getRequired("stops") + fun stopTimes(): List = stopTimes.getRequired("stopTimes") + fun trips(): List = trips.getRequired("trips") - @JsonProperty("agencies") @ExcludeMissing fun _agencies() = agencies + @JsonProperty("agencies") @ExcludeMissing fun _agencies(): JsonField> = agencies - @JsonProperty("routes") @ExcludeMissing fun _routes() = routes + @JsonProperty("routes") @ExcludeMissing fun _routes(): JsonField> = routes - @JsonProperty("situations") @ExcludeMissing fun _situations() = situations + @JsonProperty("situations") + @ExcludeMissing + fun _situations(): JsonField> = situations - @JsonProperty("stopTimes") @ExcludeMissing fun _stopTimes() = stopTimes + @JsonProperty("stops") @ExcludeMissing fun _stops(): JsonField> = stops - @JsonProperty("stops") @ExcludeMissing fun _stops() = stops + @JsonProperty("stopTimes") + @ExcludeMissing + fun _stopTimes(): JsonField> = stopTimes - @JsonProperty("trips") @ExcludeMissing fun _trips() = trips + @JsonProperty("trips") @ExcludeMissing fun _trips(): JsonField> = trips @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): References = apply { - if (!validated) { - agencies().forEach { it.validate() } - routes().forEach { it.validate() } - situations().forEach { it.validate() } - stopTimes().forEach { it.validate() } - stops().forEach { it.validate() } - trips().forEach { it.validate() } - validated = true + if (validated) { + return@apply } + + agencies().forEach { it.validate() } + routes().forEach { it.validate() } + situations().forEach { it.validate() } + stops().forEach { it.validate() } + stopTimes().forEach { it.validate() } + trips().forEach { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -80,109 +99,214 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [References]. */ + class Builder internal constructor() { - private var agencies: JsonField> = JsonMissing.of() - private var routes: JsonField> = JsonMissing.of() - private var situations: JsonField> = JsonMissing.of() - private var stopTimes: JsonField> = JsonMissing.of() - private var stops: JsonField> = JsonMissing.of() - private var trips: JsonField> = JsonMissing.of() + private var agencies: JsonField>? = null + private var routes: JsonField>? = null + private var situations: JsonField>? = null + private var stops: JsonField>? = null + private var stopTimes: JsonField>? = null + private var trips: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(references: References) = apply { - this.agencies = references.agencies - this.routes = references.routes - this.situations = references.situations - this.stopTimes = references.stopTimes - this.stops = references.stops - this.trips = references.trips - additionalProperties(references.additionalProperties) + agencies = references.agencies.map { it.toMutableList() } + routes = references.routes.map { it.toMutableList() } + situations = references.situations.map { it.toMutableList() } + stops = references.stops.map { it.toMutableList() } + stopTimes = references.stopTimes.map { it.toMutableList() } + trips = references.trips.map { it.toMutableList() } + additionalProperties = references.additionalProperties.toMutableMap() } fun agencies(agencies: List) = agencies(JsonField.of(agencies)) - @JsonProperty("agencies") - @ExcludeMissing - fun agencies(agencies: JsonField>) = apply { this.agencies = agencies } + fun agencies(agencies: JsonField>) = apply { + this.agencies = agencies.map { it.toMutableList() } + } + + fun addAgency(agency: Agency) = apply { + agencies = + (agencies ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(agency) + } + } fun routes(routes: List) = routes(JsonField.of(routes)) - @JsonProperty("routes") - @ExcludeMissing - fun routes(routes: JsonField>) = apply { this.routes = routes } + fun routes(routes: JsonField>) = apply { + this.routes = routes.map { it.toMutableList() } + } + + fun addRoute(route: Route) = apply { + routes = + (routes ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(route) + } + } fun situations(situations: List) = situations(JsonField.of(situations)) - @JsonProperty("situations") - @ExcludeMissing fun situations(situations: JsonField>) = apply { - this.situations = situations + this.situations = situations.map { it.toMutableList() } } - fun stopTimes(stopTimes: List) = stopTimes(JsonField.of(stopTimes)) - - @JsonProperty("stopTimes") - @ExcludeMissing - fun stopTimes(stopTimes: JsonField>) = apply { this.stopTimes = stopTimes } + fun addSituation(situation: Situation) = apply { + situations = + (situations ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situation) + } + } fun stops(stops: List) = stops(JsonField.of(stops)) - @JsonProperty("stops") - @ExcludeMissing - fun stops(stops: JsonField>) = apply { this.stops = stops } + fun stops(stops: JsonField>) = apply { + this.stops = stops.map { it.toMutableList() } + } + + fun addStop(stop: Stop) = apply { + stops = + (stops ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stop) + } + } + + fun stopTimes(stopTimes: List) = stopTimes(JsonField.of(stopTimes)) + + fun stopTimes(stopTimes: JsonField>) = apply { + this.stopTimes = stopTimes.map { it.toMutableList() } + } + + fun addStopTime(stopTime: StopTime) = apply { + stopTimes = + (stopTimes ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stopTime) + } + } fun trips(trips: List) = trips(JsonField.of(trips)) - @JsonProperty("trips") - @ExcludeMissing - fun trips(trips: JsonField>) = apply { this.trips = trips } + fun trips(trips: JsonField>) = apply { + this.trips = trips.map { it.toMutableList() } + } + + fun addTrip(trip: Trip) = apply { + trips = + (trips ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(trip) + } + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): References = References( - agencies.map { it.toImmutable() }, - routes.map { it.toImmutable() }, - situations.map { it.toImmutable() }, - stopTimes.map { it.toImmutable() }, - stops.map { it.toImmutable() }, - trips.map { it.toImmutable() }, + checkRequired("agencies", agencies).map { it.toImmutable() }, + checkRequired("routes", routes).map { it.toImmutable() }, + checkRequired("situations", situations).map { it.toImmutable() }, + checkRequired("stops", stops).map { it.toImmutable() }, + checkRequired("stopTimes", stopTimes).map { it.toImmutable() }, + checkRequired("trips", trips).map { it.toImmutable() }, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Agency.Builder::class) @NoAutoDetect class Agency + @JsonCreator private constructor( - private val disclaimer: JsonField, - private val email: JsonField, - private val fareUrl: JsonField, - private val id: JsonField, - private val lang: JsonField, - private val name: JsonField, - private val phone: JsonField, - private val privateService: JsonField, - private val timezone: JsonField, - private val url: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + private val name: JsonField = JsonMissing.of(), + @JsonProperty("timezone") + @ExcludeMissing + private val timezone: JsonField = JsonMissing.of(), + @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), + @JsonProperty("disclaimer") + @ExcludeMissing + private val disclaimer: JsonField = JsonMissing.of(), + @JsonProperty("email") + @ExcludeMissing + private val email: JsonField = JsonMissing.of(), + @JsonProperty("fareUrl") + @ExcludeMissing + private val fareUrl: JsonField = JsonMissing.of(), + @JsonProperty("lang") + @ExcludeMissing + private val lang: JsonField = JsonMissing.of(), + @JsonProperty("phone") + @ExcludeMissing + private val phone: JsonField = JsonMissing.of(), + @JsonProperty("privateService") + @ExcludeMissing + private val privateService: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun id(): String = id.getRequired("id") + + fun name(): String = name.getRequired("name") + + fun timezone(): String = timezone.getRequired("timezone") + + fun url(): String = url.getRequired("url") fun disclaimer(): Optional = Optional.ofNullable(disclaimer.getNullable("disclaimer")) @@ -191,59 +315,59 @@ private constructor( fun fareUrl(): Optional = Optional.ofNullable(fareUrl.getNullable("fareUrl")) - fun id(): String = id.getRequired("id") - fun lang(): Optional = Optional.ofNullable(lang.getNullable("lang")) - fun name(): String = name.getRequired("name") - fun phone(): Optional = Optional.ofNullable(phone.getNullable("phone")) fun privateService(): Optional = Optional.ofNullable(privateService.getNullable("privateService")) - fun timezone(): String = timezone.getRequired("timezone") - - fun url(): String = url.getRequired("url") - - @JsonProperty("disclaimer") @ExcludeMissing fun _disclaimer() = disclaimer + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("email") @ExcludeMissing fun _email() = email + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("fareUrl") @ExcludeMissing fun _fareUrl() = fareUrl + @JsonProperty("timezone") @ExcludeMissing fun _timezone(): JsonField = timezone - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url - @JsonProperty("lang") @ExcludeMissing fun _lang() = lang + @JsonProperty("disclaimer") + @ExcludeMissing + fun _disclaimer(): JsonField = disclaimer - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("email") @ExcludeMissing fun _email(): JsonField = email - @JsonProperty("phone") @ExcludeMissing fun _phone() = phone + @JsonProperty("fareUrl") @ExcludeMissing fun _fareUrl(): JsonField = fareUrl - @JsonProperty("privateService") @ExcludeMissing fun _privateService() = privateService + @JsonProperty("lang") @ExcludeMissing fun _lang(): JsonField = lang - @JsonProperty("timezone") @ExcludeMissing fun _timezone() = timezone + @JsonProperty("phone") @ExcludeMissing fun _phone(): JsonField = phone - @JsonProperty("url") @ExcludeMissing fun _url() = url + @JsonProperty("privateService") + @ExcludeMissing + fun _privateService(): JsonField = privateService @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Agency = apply { - if (!validated) { - disclaimer() - email() - fareUrl() - id() - lang() - name() - phone() - privateService() - timezone() - url() - validated = true - } + if (validated) { + return@apply + } + + id() + name() + timezone() + url() + disclaimer() + email() + fareUrl() + lang() + phone() + privateService() + validated = true } fun toBuilder() = Builder().from(this) @@ -253,124 +377,110 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Agency]. */ + class Builder internal constructor() { + private var id: JsonField? = null + private var name: JsonField? = null + private var timezone: JsonField? = null + private var url: JsonField? = null private var disclaimer: JsonField = JsonMissing.of() private var email: JsonField = JsonMissing.of() private var fareUrl: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() private var lang: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() private var phone: JsonField = JsonMissing.of() private var privateService: JsonField = JsonMissing.of() - private var timezone: JsonField = JsonMissing.of() - private var url: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(agency: Agency) = apply { - this.disclaimer = agency.disclaimer - this.email = agency.email - this.fareUrl = agency.fareUrl - this.id = agency.id - this.lang = agency.lang - this.name = agency.name - this.phone = agency.phone - this.privateService = agency.privateService - this.timezone = agency.timezone - this.url = agency.url - additionalProperties(agency.additionalProperties) + id = agency.id + name = agency.name + timezone = agency.timezone + url = agency.url + disclaimer = agency.disclaimer + email = agency.email + fareUrl = agency.fareUrl + lang = agency.lang + phone = agency.phone + privateService = agency.privateService + additionalProperties = agency.additionalProperties.toMutableMap() } + fun id(id: String) = id(JsonField.of(id)) + + fun id(id: JsonField) = apply { this.id = id } + + fun name(name: String) = name(JsonField.of(name)) + + fun name(name: JsonField) = apply { this.name = name } + + fun timezone(timezone: String) = timezone(JsonField.of(timezone)) + + fun timezone(timezone: JsonField) = apply { this.timezone = timezone } + + fun url(url: String) = url(JsonField.of(url)) + + fun url(url: JsonField) = apply { this.url = url } + fun disclaimer(disclaimer: String) = disclaimer(JsonField.of(disclaimer)) - @JsonProperty("disclaimer") - @ExcludeMissing fun disclaimer(disclaimer: JsonField) = apply { this.disclaimer = disclaimer } fun email(email: String) = email(JsonField.of(email)) - @JsonProperty("email") - @ExcludeMissing fun email(email: JsonField) = apply { this.email = email } fun fareUrl(fareUrl: String) = fareUrl(JsonField.of(fareUrl)) - @JsonProperty("fareUrl") - @ExcludeMissing fun fareUrl(fareUrl: JsonField) = apply { this.fareUrl = fareUrl } - fun id(id: String) = id(JsonField.of(id)) - - @JsonProperty("id") - @ExcludeMissing - fun id(id: JsonField) = apply { this.id = id } - fun lang(lang: String) = lang(JsonField.of(lang)) - @JsonProperty("lang") - @ExcludeMissing fun lang(lang: JsonField) = apply { this.lang = lang } - fun name(name: String) = name(JsonField.of(name)) - - @JsonProperty("name") - @ExcludeMissing - fun name(name: JsonField) = apply { this.name = name } - fun phone(phone: String) = phone(JsonField.of(phone)) - @JsonProperty("phone") - @ExcludeMissing fun phone(phone: JsonField) = apply { this.phone = phone } fun privateService(privateService: Boolean) = privateService(JsonField.of(privateService)) - @JsonProperty("privateService") - @ExcludeMissing fun privateService(privateService: JsonField) = apply { this.privateService = privateService } - fun timezone(timezone: String) = timezone(JsonField.of(timezone)) - - @JsonProperty("timezone") - @ExcludeMissing - fun timezone(timezone: JsonField) = apply { this.timezone = timezone } - - fun url(url: String) = url(JsonField.of(url)) - - @JsonProperty("url") - @ExcludeMissing - fun url(url: JsonField) = apply { this.url = url } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Agency = Agency( + checkRequired("id", id), + checkRequired("name", name), + checkRequired("timezone", timezone), + checkRequired("url", url), disclaimer, email, fareUrl, - id, lang, - name, phone, privateService, - timezone, - url, additionalProperties.toImmutable(), ) } @@ -380,50 +490,62 @@ private constructor( return true } - return /* spotless:off */ other is Agency && this.disclaimer == other.disclaimer && this.email == other.email && this.fareUrl == other.fareUrl && this.id == other.id && this.lang == other.lang && this.name == other.name && this.phone == other.phone && this.privateService == other.privateService && this.timezone == other.timezone && this.url == other.url && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Agency && id == other.id && name == other.name && timezone == other.timezone && url == other.url && disclaimer == other.disclaimer && email == other.email && fareUrl == other.fareUrl && lang == other.lang && phone == other.phone && privateService == other.privateService && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, name, timezone, url, disclaimer, email, fareUrl, lang, phone, privateService, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(disclaimer, email, fareUrl, id, lang, name, phone, privateService, timezone, url, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Agency{disclaimer=$disclaimer, email=$email, fareUrl=$fareUrl, id=$id, lang=$lang, name=$name, phone=$phone, privateService=$privateService, timezone=$timezone, url=$url, additionalProperties=$additionalProperties}" + "Agency{id=$id, name=$name, timezone=$timezone, url=$url, disclaimer=$disclaimer, email=$email, fareUrl=$fareUrl, lang=$lang, phone=$phone, privateService=$privateService, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = Route.Builder::class) @NoAutoDetect class Route + @JsonCreator private constructor( - private val agencyId: JsonField, - private val color: JsonField, - private val description: JsonField, - private val id: JsonField, - private val longName: JsonField, - private val nullSafeShortName: JsonField, - private val shortName: JsonField, - private val textColor: JsonField, - private val type: JsonField, - private val url: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), + @JsonProperty("agencyId") + @ExcludeMissing + private val agencyId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing private val type: JsonField = JsonMissing.of(), + @JsonProperty("color") + @ExcludeMissing + private val color: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + private val description: JsonField = JsonMissing.of(), + @JsonProperty("longName") + @ExcludeMissing + private val longName: JsonField = JsonMissing.of(), + @JsonProperty("nullSafeShortName") + @ExcludeMissing + private val nullSafeShortName: JsonField = JsonMissing.of(), + @JsonProperty("shortName") + @ExcludeMissing + private val shortName: JsonField = JsonMissing.of(), + @JsonProperty("textColor") + @ExcludeMissing + private val textColor: JsonField = JsonMissing.of(), + @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun id(): String = id.getRequired("id") fun agencyId(): String = agencyId.getRequired("agencyId") + fun type(): Long = type.getRequired("type") + fun color(): Optional = Optional.ofNullable(color.getNullable("color")) fun description(): Optional = Optional.ofNullable(description.getNullable("description")) - fun id(): String = id.getRequired("id") - fun longName(): Optional = Optional.ofNullable(longName.getNullable("longName")) fun nullSafeShortName(): Optional = @@ -433,50 +555,54 @@ private constructor( fun textColor(): Optional = Optional.ofNullable(textColor.getNullable("textColor")) - fun type(): Long = type.getRequired("type") - fun url(): Optional = Optional.ofNullable(url.getNullable("url")) - @JsonProperty("agencyId") @ExcludeMissing fun _agencyId() = agencyId + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + @JsonProperty("agencyId") @ExcludeMissing fun _agencyId(): JsonField = agencyId - @JsonProperty("color") @ExcludeMissing fun _color() = color + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - @JsonProperty("description") @ExcludeMissing fun _description() = description + @JsonProperty("color") @ExcludeMissing fun _color(): JsonField = color - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description - @JsonProperty("longName") @ExcludeMissing fun _longName() = longName + @JsonProperty("longName") @ExcludeMissing fun _longName(): JsonField = longName @JsonProperty("nullSafeShortName") @ExcludeMissing - fun _nullSafeShortName() = nullSafeShortName - - @JsonProperty("shortName") @ExcludeMissing fun _shortName() = shortName + fun _nullSafeShortName(): JsonField = nullSafeShortName - @JsonProperty("textColor") @ExcludeMissing fun _textColor() = textColor + @JsonProperty("shortName") @ExcludeMissing fun _shortName(): JsonField = shortName - @JsonProperty("type") @ExcludeMissing fun _type() = type + @JsonProperty("textColor") @ExcludeMissing fun _textColor(): JsonField = textColor - @JsonProperty("url") @ExcludeMissing fun _url() = url + @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Route = apply { - if (!validated) { - agencyId() - color() - description() - id() - longName() - nullSafeShortName() - shortName() - textColor() - type() - url() - validated = true - } + if (validated) { + return@apply + } + + id() + agencyId() + type() + color() + description() + longName() + nullSafeShortName() + shortName() + textColor() + url() + validated = true } fun toBuilder() = Builder().from(this) @@ -486,125 +612,111 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Route]. */ + class Builder internal constructor() { - private var agencyId: JsonField = JsonMissing.of() + private var id: JsonField? = null + private var agencyId: JsonField? = null + private var type: JsonField? = null private var color: JsonField = JsonMissing.of() private var description: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() private var longName: JsonField = JsonMissing.of() private var nullSafeShortName: JsonField = JsonMissing.of() private var shortName: JsonField = JsonMissing.of() private var textColor: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var url: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(route: Route) = apply { - this.agencyId = route.agencyId - this.color = route.color - this.description = route.description - this.id = route.id - this.longName = route.longName - this.nullSafeShortName = route.nullSafeShortName - this.shortName = route.shortName - this.textColor = route.textColor - this.type = route.type - this.url = route.url - additionalProperties(route.additionalProperties) + id = route.id + agencyId = route.agencyId + type = route.type + color = route.color + description = route.description + longName = route.longName + nullSafeShortName = route.nullSafeShortName + shortName = route.shortName + textColor = route.textColor + url = route.url + additionalProperties = route.additionalProperties.toMutableMap() } + fun id(id: String) = id(JsonField.of(id)) + + fun id(id: JsonField) = apply { this.id = id } + fun agencyId(agencyId: String) = agencyId(JsonField.of(agencyId)) - @JsonProperty("agencyId") - @ExcludeMissing fun agencyId(agencyId: JsonField) = apply { this.agencyId = agencyId } + fun type(type: Long) = type(JsonField.of(type)) + + fun type(type: JsonField) = apply { this.type = type } + fun color(color: String) = color(JsonField.of(color)) - @JsonProperty("color") - @ExcludeMissing fun color(color: JsonField) = apply { this.color = color } fun description(description: String) = description(JsonField.of(description)) - @JsonProperty("description") - @ExcludeMissing fun description(description: JsonField) = apply { this.description = description } - fun id(id: String) = id(JsonField.of(id)) - - @JsonProperty("id") - @ExcludeMissing - fun id(id: JsonField) = apply { this.id = id } - fun longName(longName: String) = longName(JsonField.of(longName)) - @JsonProperty("longName") - @ExcludeMissing fun longName(longName: JsonField) = apply { this.longName = longName } fun nullSafeShortName(nullSafeShortName: String) = nullSafeShortName(JsonField.of(nullSafeShortName)) - @JsonProperty("nullSafeShortName") - @ExcludeMissing fun nullSafeShortName(nullSafeShortName: JsonField) = apply { this.nullSafeShortName = nullSafeShortName } fun shortName(shortName: String) = shortName(JsonField.of(shortName)) - @JsonProperty("shortName") - @ExcludeMissing fun shortName(shortName: JsonField) = apply { this.shortName = shortName } fun textColor(textColor: String) = textColor(JsonField.of(textColor)) - @JsonProperty("textColor") - @ExcludeMissing fun textColor(textColor: JsonField) = apply { this.textColor = textColor } - fun type(type: Long) = type(JsonField.of(type)) - - @JsonProperty("type") - @ExcludeMissing - fun type(type: JsonField) = apply { this.type = type } - fun url(url: String) = url(JsonField.of(url)) - @JsonProperty("url") - @ExcludeMissing fun url(url: JsonField) = apply { this.url = url } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Route = Route( - agencyId, + checkRequired("id", id), + checkRequired("agencyId", agencyId), + checkRequired("type", type), color, description, - id, longName, nullSafeShortName, shortName, textColor, - type, url, additionalProperties.toImmutable(), ) @@ -615,131 +727,161 @@ private constructor( return true } - return /* spotless:off */ other is Route && this.agencyId == other.agencyId && this.color == other.color && this.description == other.description && this.id == other.id && this.longName == other.longName && this.nullSafeShortName == other.nullSafeShortName && this.shortName == other.shortName && this.textColor == other.textColor && this.type == other.type && this.url == other.url && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Route && id == other.id && agencyId == other.agencyId && type == other.type && color == other.color && description == other.description && longName == other.longName && nullSafeShortName == other.nullSafeShortName && shortName == other.shortName && textColor == other.textColor && url == other.url && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, agencyId, type, color, description, longName, nullSafeShortName, shortName, textColor, url, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(agencyId, color, description, id, longName, nullSafeShortName, shortName, textColor, type, url, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Route{agencyId=$agencyId, color=$color, description=$description, id=$id, longName=$longName, nullSafeShortName=$nullSafeShortName, shortName=$shortName, textColor=$textColor, type=$type, url=$url, additionalProperties=$additionalProperties}" + "Route{id=$id, agencyId=$agencyId, type=$type, color=$color, description=$description, longName=$longName, nullSafeShortName=$nullSafeShortName, shortName=$shortName, textColor=$textColor, url=$url, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = Situation.Builder::class) @NoAutoDetect class Situation + @JsonCreator private constructor( - private val id: JsonField, - private val creationTime: JsonField, - private val reason: JsonField, - private val summary: JsonField, - private val description: JsonField, - private val url: JsonField, - private val activeWindows: JsonField>, - private val allAffects: JsonField>, - private val consequences: JsonField>, - private val publicationWindows: JsonField>, - private val severity: JsonField, - private val consequenceMessage: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), + @JsonProperty("creationTime") + @ExcludeMissing + private val creationTime: JsonField = JsonMissing.of(), + @JsonProperty("activeWindows") + @ExcludeMissing + private val activeWindows: JsonField> = JsonMissing.of(), + @JsonProperty("allAffects") + @ExcludeMissing + private val allAffects: JsonField> = JsonMissing.of(), + @JsonProperty("consequenceMessage") + @ExcludeMissing + private val consequenceMessage: JsonField = JsonMissing.of(), + @JsonProperty("consequences") + @ExcludeMissing + private val consequences: JsonField> = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + private val description: JsonField = JsonMissing.of(), + @JsonProperty("publicationWindows") + @ExcludeMissing + private val publicationWindows: JsonField> = JsonMissing.of(), + @JsonProperty("reason") + @ExcludeMissing + private val reason: JsonField = JsonMissing.of(), + @JsonProperty("severity") + @ExcludeMissing + private val severity: JsonField = JsonMissing.of(), + @JsonProperty("summary") + @ExcludeMissing + private val summary: JsonField = JsonMissing.of(), + @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Unique identifier for the situation. */ fun id(): String = id.getRequired("id") /** Unix timestamp of when this situation was created. */ fun creationTime(): Long = creationTime.getRequired("creationTime") - /** Reason for the service alert, taken from TPEG codes. */ - fun reason(): Optional = Optional.ofNullable(reason.getNullable("reason")) - - fun summary(): Optional = Optional.ofNullable(summary.getNullable("summary")) - - fun description(): Optional = - Optional.ofNullable(description.getNullable("description")) - - fun url(): Optional = Optional.ofNullable(url.getNullable("url")) - fun activeWindows(): Optional> = Optional.ofNullable(activeWindows.getNullable("activeWindows")) fun allAffects(): Optional> = Optional.ofNullable(allAffects.getNullable("allAffects")) + /** Message regarding the consequence of the situation. */ + fun consequenceMessage(): Optional = + Optional.ofNullable(consequenceMessage.getNullable("consequenceMessage")) + fun consequences(): Optional> = Optional.ofNullable(consequences.getNullable("consequences")) + fun description(): Optional = + Optional.ofNullable(description.getNullable("description")) + fun publicationWindows(): Optional> = Optional.ofNullable(publicationWindows.getNullable("publicationWindows")) + /** Reason for the service alert, taken from TPEG codes. */ + fun reason(): Optional = Optional.ofNullable(reason.getNullable("reason")) + /** Severity of the situation. */ fun severity(): Optional = Optional.ofNullable(severity.getNullable("severity")) - /** Message regarding the consequence of the situation. */ - fun consequenceMessage(): Optional = - Optional.ofNullable(consequenceMessage.getNullable("consequenceMessage")) + fun summary(): Optional = Optional.ofNullable(summary.getNullable("summary")) + + fun url(): Optional = Optional.ofNullable(url.getNullable("url")) /** Unique identifier for the situation. */ - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id /** Unix timestamp of when this situation was created. */ - @JsonProperty("creationTime") @ExcludeMissing fun _creationTime() = creationTime - - /** Reason for the service alert, taken from TPEG codes. */ - @JsonProperty("reason") @ExcludeMissing fun _reason() = reason - - @JsonProperty("summary") @ExcludeMissing fun _summary() = summary + @JsonProperty("creationTime") + @ExcludeMissing + fun _creationTime(): JsonField = creationTime - @JsonProperty("description") @ExcludeMissing fun _description() = description + @JsonProperty("activeWindows") + @ExcludeMissing + fun _activeWindows(): JsonField> = activeWindows - @JsonProperty("url") @ExcludeMissing fun _url() = url + @JsonProperty("allAffects") + @ExcludeMissing + fun _allAffects(): JsonField> = allAffects - @JsonProperty("activeWindows") @ExcludeMissing fun _activeWindows() = activeWindows + /** Message regarding the consequence of the situation. */ + @JsonProperty("consequenceMessage") + @ExcludeMissing + fun _consequenceMessage(): JsonField = consequenceMessage - @JsonProperty("allAffects") @ExcludeMissing fun _allAffects() = allAffects + @JsonProperty("consequences") + @ExcludeMissing + fun _consequences(): JsonField> = consequences - @JsonProperty("consequences") @ExcludeMissing fun _consequences() = consequences + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description @JsonProperty("publicationWindows") @ExcludeMissing - fun _publicationWindows() = publicationWindows + fun _publicationWindows(): JsonField> = publicationWindows + + /** Reason for the service alert, taken from TPEG codes. */ + @JsonProperty("reason") @ExcludeMissing fun _reason(): JsonField = reason /** Severity of the situation. */ - @JsonProperty("severity") @ExcludeMissing fun _severity() = severity + @JsonProperty("severity") @ExcludeMissing fun _severity(): JsonField = severity - /** Message regarding the consequence of the situation. */ - @JsonProperty("consequenceMessage") - @ExcludeMissing - fun _consequenceMessage() = consequenceMessage + @JsonProperty("summary") @ExcludeMissing fun _summary(): JsonField = summary + + @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Situation = apply { - if (!validated) { - id() - creationTime() - reason() - summary().map { it.validate() } - description().map { it.validate() } - url().map { it.validate() } - activeWindows().map { it.forEach { it.validate() } } - allAffects().map { it.forEach { it.validate() } } - consequences().map { it.forEach { it.validate() } } - publicationWindows().map { it.forEach { it.validate() } } - severity() - consequenceMessage() - validated = true - } + if (validated) { + return@apply + } + + id() + creationTime() + activeWindows().ifPresent { it.forEach { it.validate() } } + allAffects().ifPresent { it.forEach { it.validate() } } + consequenceMessage() + consequences().ifPresent { it.forEach { it.validate() } } + description().ifPresent { it.validate() } + publicationWindows().ifPresent { it.forEach { it.validate() } } + reason() + severity() + summary().ifPresent { it.validate() } + url().ifPresent { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -749,182 +891,217 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Situation]. */ + class Builder internal constructor() { - private var id: JsonField = JsonMissing.of() - private var creationTime: JsonField = JsonMissing.of() + private var id: JsonField? = null + private var creationTime: JsonField? = null + private var activeWindows: JsonField>? = null + private var allAffects: JsonField>? = null + private var consequenceMessage: JsonField = JsonMissing.of() + private var consequences: JsonField>? = null + private var description: JsonField = JsonMissing.of() + private var publicationWindows: JsonField>? = null private var reason: JsonField = JsonMissing.of() + private var severity: JsonField = JsonMissing.of() private var summary: JsonField = JsonMissing.of() - private var description: JsonField = JsonMissing.of() private var url: JsonField = JsonMissing.of() - private var activeWindows: JsonField> = JsonMissing.of() - private var allAffects: JsonField> = JsonMissing.of() - private var consequences: JsonField> = JsonMissing.of() - private var publicationWindows: JsonField> = JsonMissing.of() - private var severity: JsonField = JsonMissing.of() - private var consequenceMessage: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(situation: Situation) = apply { - this.id = situation.id - this.creationTime = situation.creationTime - this.reason = situation.reason - this.summary = situation.summary - this.description = situation.description - this.url = situation.url - this.activeWindows = situation.activeWindows - this.allAffects = situation.allAffects - this.consequences = situation.consequences - this.publicationWindows = situation.publicationWindows - this.severity = situation.severity - this.consequenceMessage = situation.consequenceMessage - additionalProperties(situation.additionalProperties) + id = situation.id + creationTime = situation.creationTime + activeWindows = situation.activeWindows.map { it.toMutableList() } + allAffects = situation.allAffects.map { it.toMutableList() } + consequenceMessage = situation.consequenceMessage + consequences = situation.consequences.map { it.toMutableList() } + description = situation.description + publicationWindows = situation.publicationWindows.map { it.toMutableList() } + reason = situation.reason + severity = situation.severity + summary = situation.summary + url = situation.url + additionalProperties = situation.additionalProperties.toMutableMap() } /** Unique identifier for the situation. */ fun id(id: String) = id(JsonField.of(id)) /** Unique identifier for the situation. */ - @JsonProperty("id") - @ExcludeMissing fun id(id: JsonField) = apply { this.id = id } /** Unix timestamp of when this situation was created. */ fun creationTime(creationTime: Long) = creationTime(JsonField.of(creationTime)) - /** Unix timestamp of when this situation was created. */ - @JsonProperty("creationTime") - @ExcludeMissing - fun creationTime(creationTime: JsonField) = apply { - this.creationTime = creationTime - } - - /** Reason for the service alert, taken from TPEG codes. */ - fun reason(reason: Reason) = reason(JsonField.of(reason)) - - /** Reason for the service alert, taken from TPEG codes. */ - @JsonProperty("reason") - @ExcludeMissing - fun reason(reason: JsonField) = apply { this.reason = reason } - - fun summary(summary: Summary) = summary(JsonField.of(summary)) - - @JsonProperty("summary") - @ExcludeMissing - fun summary(summary: JsonField) = apply { this.summary = summary } - - fun description(description: Description) = description(JsonField.of(description)) - - @JsonProperty("description") - @ExcludeMissing - fun description(description: JsonField) = apply { - this.description = description - } - - fun url(url: Url) = url(JsonField.of(url)) - - @JsonProperty("url") - @ExcludeMissing - fun url(url: JsonField) = apply { this.url = url } + /** Unix timestamp of when this situation was created. */ + fun creationTime(creationTime: JsonField) = apply { + this.creationTime = creationTime + } fun activeWindows(activeWindows: List) = activeWindows(JsonField.of(activeWindows)) - @JsonProperty("activeWindows") - @ExcludeMissing fun activeWindows(activeWindows: JsonField>) = apply { - this.activeWindows = activeWindows + this.activeWindows = activeWindows.map { it.toMutableList() } + } + + fun addActiveWindow(activeWindow: ActiveWindow) = apply { + activeWindows = + (activeWindows ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(activeWindow) + } } fun allAffects(allAffects: List) = allAffects(JsonField.of(allAffects)) - @JsonProperty("allAffects") - @ExcludeMissing fun allAffects(allAffects: JsonField>) = apply { - this.allAffects = allAffects + this.allAffects = allAffects.map { it.toMutableList() } + } + + fun addAllAffect(allAffect: AllAffect) = apply { + allAffects = + (allAffects ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(allAffect) + } + } + + /** Message regarding the consequence of the situation. */ + fun consequenceMessage(consequenceMessage: String) = + consequenceMessage(JsonField.of(consequenceMessage)) + + /** Message regarding the consequence of the situation. */ + fun consequenceMessage(consequenceMessage: JsonField) = apply { + this.consequenceMessage = consequenceMessage } fun consequences(consequences: List) = consequences(JsonField.of(consequences)) - @JsonProperty("consequences") - @ExcludeMissing fun consequences(consequences: JsonField>) = apply { - this.consequences = consequences + this.consequences = consequences.map { it.toMutableList() } + } + + fun addConsequence(consequence: Consequence) = apply { + consequences = + (consequences ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(consequence) + } + } + + fun description(description: Description) = description(JsonField.of(description)) + + fun description(description: JsonField) = apply { + this.description = description } fun publicationWindows(publicationWindows: List) = publicationWindows(JsonField.of(publicationWindows)) - @JsonProperty("publicationWindows") - @ExcludeMissing fun publicationWindows(publicationWindows: JsonField>) = apply { - this.publicationWindows = publicationWindows + this.publicationWindows = publicationWindows.map { it.toMutableList() } + } + + fun addPublicationWindow(publicationWindow: PublicationWindow) = apply { + publicationWindows = + (publicationWindows ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(publicationWindow) + } } + /** Reason for the service alert, taken from TPEG codes. */ + fun reason(reason: Reason) = reason(JsonField.of(reason)) + + /** Reason for the service alert, taken from TPEG codes. */ + fun reason(reason: JsonField) = apply { this.reason = reason } + /** Severity of the situation. */ fun severity(severity: String) = severity(JsonField.of(severity)) /** Severity of the situation. */ - @JsonProperty("severity") - @ExcludeMissing fun severity(severity: JsonField) = apply { this.severity = severity } - /** Message regarding the consequence of the situation. */ - fun consequenceMessage(consequenceMessage: String) = - consequenceMessage(JsonField.of(consequenceMessage)) + fun summary(summary: Summary) = summary(JsonField.of(summary)) - /** Message regarding the consequence of the situation. */ - @JsonProperty("consequenceMessage") - @ExcludeMissing - fun consequenceMessage(consequenceMessage: JsonField) = apply { - this.consequenceMessage = consequenceMessage - } + fun summary(summary: JsonField) = apply { this.summary = summary } + + fun url(url: Url) = url(JsonField.of(url)) + + fun url(url: JsonField) = apply { this.url = url } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Situation = Situation( - id, - creationTime, + checkRequired("id", id), + checkRequired("creationTime", creationTime), + (activeWindows ?: JsonMissing.of()).map { it.toImmutable() }, + (allAffects ?: JsonMissing.of()).map { it.toImmutable() }, + consequenceMessage, + (consequences ?: JsonMissing.of()).map { it.toImmutable() }, + description, + (publicationWindows ?: JsonMissing.of()).map { it.toImmutable() }, reason, + severity, summary, - description, url, - activeWindows.map { it.toImmutable() }, - allAffects.map { it.toImmutable() }, - consequences.map { it.toImmutable() }, - publicationWindows.map { it.toImmutable() }, - severity, - consequenceMessage, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = ActiveWindow.Builder::class) @NoAutoDetect class ActiveWindow + @JsonCreator private constructor( - private val from: JsonField, - private val to: JsonField, - private val additionalProperties: Map, + @JsonProperty("from") + @ExcludeMissing + private val from: JsonField = JsonMissing.of(), + @JsonProperty("to") @ExcludeMissing private val to: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Start time of the active window as a Unix timestamp. */ fun from(): Optional = Optional.ofNullable(from.getNullable("from")) @@ -932,21 +1109,25 @@ private constructor( fun to(): Optional = Optional.ofNullable(to.getNullable("to")) /** Start time of the active window as a Unix timestamp. */ - @JsonProperty("from") @ExcludeMissing fun _from() = from + @JsonProperty("from") @ExcludeMissing fun _from(): JsonField = from /** End time of the active window as a Unix timestamp. */ - @JsonProperty("to") @ExcludeMissing fun _to() = to + @JsonProperty("to") @ExcludeMissing fun _to(): JsonField = to @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ActiveWindow = apply { - if (!validated) { - from() - to() - validated = true + if (validated) { + return@apply } + + from() + to() + validated = true } fun toBuilder() = Builder().from(this) @@ -956,7 +1137,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [ActiveWindow]. */ + class Builder internal constructor() { private var from: JsonField = JsonMissing.of() private var to: JsonField = JsonMissing.of() @@ -964,35 +1146,30 @@ private constructor( @JvmSynthetic internal fun from(activeWindow: ActiveWindow) = apply { - this.from = activeWindow.from - this.to = activeWindow.to - additionalProperties(activeWindow.additionalProperties) + from = activeWindow.from + to = activeWindow.to + additionalProperties = activeWindow.additionalProperties.toMutableMap() } /** Start time of the active window as a Unix timestamp. */ fun from(from: Long) = from(JsonField.of(from)) /** Start time of the active window as a Unix timestamp. */ - @JsonProperty("from") - @ExcludeMissing fun from(from: JsonField) = apply { this.from = from } /** End time of the active window as a Unix timestamp. */ fun to(to: Long) = to(JsonField.of(to)) /** End time of the active window as a Unix timestamp. */ - @JsonProperty("to") - @ExcludeMissing fun to(to: JsonField) = apply { this.to = to } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1000,6 +1177,14 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): ActiveWindow = ActiveWindow( from, @@ -1013,37 +1198,45 @@ private constructor( return true } - return /* spotless:off */ other is ActiveWindow && this.from == other.from && this.to == other.to && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is ActiveWindow && from == other.from && to == other.to && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(from, to, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(from, to, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "ActiveWindow{from=$from, to=$to, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = AllAffect.Builder::class) @NoAutoDetect class AllAffect + @JsonCreator private constructor( - private val agencyId: JsonField, - private val applicationId: JsonField, - private val directionId: JsonField, - private val routeId: JsonField, - private val stopId: JsonField, - private val tripId: JsonField, - private val additionalProperties: Map, + @JsonProperty("agencyId") + @ExcludeMissing + private val agencyId: JsonField = JsonMissing.of(), + @JsonProperty("applicationId") + @ExcludeMissing + private val applicationId: JsonField = JsonMissing.of(), + @JsonProperty("directionId") + @ExcludeMissing + private val directionId: JsonField = JsonMissing.of(), + @JsonProperty("routeId") + @ExcludeMissing + private val routeId: JsonField = JsonMissing.of(), + @JsonProperty("stopId") + @ExcludeMissing + private val stopId: JsonField = JsonMissing.of(), + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Identifier for the agency. */ fun agencyId(): Optional = Optional.ofNullable(agencyId.getNullable("agencyId")) @@ -1065,37 +1258,45 @@ private constructor( fun tripId(): Optional = Optional.ofNullable(tripId.getNullable("tripId")) /** Identifier for the agency. */ - @JsonProperty("agencyId") @ExcludeMissing fun _agencyId() = agencyId + @JsonProperty("agencyId") @ExcludeMissing fun _agencyId(): JsonField = agencyId /** Identifier for the application. */ - @JsonProperty("applicationId") @ExcludeMissing fun _applicationId() = applicationId + @JsonProperty("applicationId") + @ExcludeMissing + fun _applicationId(): JsonField = applicationId /** Identifier for the direction. */ - @JsonProperty("directionId") @ExcludeMissing fun _directionId() = directionId + @JsonProperty("directionId") + @ExcludeMissing + fun _directionId(): JsonField = directionId /** Identifier for the route. */ - @JsonProperty("routeId") @ExcludeMissing fun _routeId() = routeId + @JsonProperty("routeId") @ExcludeMissing fun _routeId(): JsonField = routeId /** Identifier for the stop. */ - @JsonProperty("stopId") @ExcludeMissing fun _stopId() = stopId + @JsonProperty("stopId") @ExcludeMissing fun _stopId(): JsonField = stopId /** Identifier for the trip. */ - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + @JsonProperty("tripId") @ExcludeMissing fun _tripId(): JsonField = tripId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): AllAffect = apply { - if (!validated) { - agencyId() - applicationId() - directionId() - routeId() - stopId() - tripId() - validated = true + if (validated) { + return@apply } + + agencyId() + applicationId() + directionId() + routeId() + stopId() + tripId() + validated = true } fun toBuilder() = Builder().from(this) @@ -1105,7 +1306,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [AllAffect]. */ + class Builder internal constructor() { private var agencyId: JsonField = JsonMissing.of() private var applicationId: JsonField = JsonMissing.of() @@ -1117,21 +1319,19 @@ private constructor( @JvmSynthetic internal fun from(allAffect: AllAffect) = apply { - this.agencyId = allAffect.agencyId - this.applicationId = allAffect.applicationId - this.directionId = allAffect.directionId - this.routeId = allAffect.routeId - this.stopId = allAffect.stopId - this.tripId = allAffect.tripId - additionalProperties(allAffect.additionalProperties) + agencyId = allAffect.agencyId + applicationId = allAffect.applicationId + directionId = allAffect.directionId + routeId = allAffect.routeId + stopId = allAffect.stopId + tripId = allAffect.tripId + additionalProperties = allAffect.additionalProperties.toMutableMap() } /** Identifier for the agency. */ fun agencyId(agencyId: String) = agencyId(JsonField.of(agencyId)) /** Identifier for the agency. */ - @JsonProperty("agencyId") - @ExcludeMissing fun agencyId(agencyId: JsonField) = apply { this.agencyId = agencyId } /** Identifier for the application. */ @@ -1139,8 +1339,6 @@ private constructor( applicationId(JsonField.of(applicationId)) /** Identifier for the application. */ - @JsonProperty("applicationId") - @ExcludeMissing fun applicationId(applicationId: JsonField) = apply { this.applicationId = applicationId } @@ -1149,8 +1347,6 @@ private constructor( fun directionId(directionId: String) = directionId(JsonField.of(directionId)) /** Identifier for the direction. */ - @JsonProperty("directionId") - @ExcludeMissing fun directionId(directionId: JsonField) = apply { this.directionId = directionId } @@ -1159,34 +1355,27 @@ private constructor( fun routeId(routeId: String) = routeId(JsonField.of(routeId)) /** Identifier for the route. */ - @JsonProperty("routeId") - @ExcludeMissing fun routeId(routeId: JsonField) = apply { this.routeId = routeId } /** Identifier for the stop. */ fun stopId(stopId: String) = stopId(JsonField.of(stopId)) /** Identifier for the stop. */ - @JsonProperty("stopId") - @ExcludeMissing fun stopId(stopId: JsonField) = apply { this.stopId = stopId } /** Identifier for the trip. */ fun tripId(tripId: String) = tripId(JsonField.of(tripId)) /** Identifier for the trip. */ - @JsonProperty("tripId") - @ExcludeMissing fun tripId(tripId: JsonField) = apply { this.tripId = tripId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1194,6 +1383,14 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): AllAffect = AllAffect( agencyId, @@ -1211,33 +1408,33 @@ private constructor( return true } - return /* spotless:off */ other is AllAffect && this.agencyId == other.agencyId && this.applicationId == other.applicationId && this.directionId == other.directionId && this.routeId == other.routeId && this.stopId == other.stopId && this.tripId == other.tripId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is AllAffect && agencyId == other.agencyId && applicationId == other.applicationId && directionId == other.directionId && routeId == other.routeId && stopId == other.stopId && tripId == other.tripId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(agencyId, applicationId, directionId, routeId, stopId, tripId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(agencyId, applicationId, directionId, routeId, stopId, tripId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "AllAffect{agencyId=$agencyId, applicationId=$applicationId, directionId=$directionId, routeId=$routeId, stopId=$stopId, tripId=$tripId, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = Consequence.Builder::class) @NoAutoDetect class Consequence + @JsonCreator private constructor( - private val condition: JsonField, - private val conditionDetails: JsonField, - private val additionalProperties: Map, + @JsonProperty("condition") + @ExcludeMissing + private val condition: JsonField = JsonMissing.of(), + @JsonProperty("conditionDetails") + @ExcludeMissing + private val conditionDetails: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Condition of the consequence. */ fun condition(): Optional = Optional.ofNullable(condition.getNullable("condition")) @@ -1246,22 +1443,28 @@ private constructor( Optional.ofNullable(conditionDetails.getNullable("conditionDetails")) /** Condition of the consequence. */ - @JsonProperty("condition") @ExcludeMissing fun _condition() = condition + @JsonProperty("condition") + @ExcludeMissing + fun _condition(): JsonField = condition @JsonProperty("conditionDetails") @ExcludeMissing - fun _conditionDetails() = conditionDetails + fun _conditionDetails(): JsonField = conditionDetails @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Consequence = apply { - if (!validated) { - condition() - conditionDetails().map { it.validate() } - validated = true + if (validated) { + return@apply } + + condition() + conditionDetails().ifPresent { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -1271,7 +1474,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Consequence]. */ + class Builder internal constructor() { private var condition: JsonField = JsonMissing.of() private var conditionDetails: JsonField = JsonMissing.of() @@ -1279,36 +1483,31 @@ private constructor( @JvmSynthetic internal fun from(consequence: Consequence) = apply { - this.condition = consequence.condition - this.conditionDetails = consequence.conditionDetails - additionalProperties(consequence.additionalProperties) + condition = consequence.condition + conditionDetails = consequence.conditionDetails + additionalProperties = consequence.additionalProperties.toMutableMap() } /** Condition of the consequence. */ fun condition(condition: String) = condition(JsonField.of(condition)) /** Condition of the consequence. */ - @JsonProperty("condition") - @ExcludeMissing fun condition(condition: JsonField) = apply { this.condition = condition } fun conditionDetails(conditionDetails: ConditionDetails) = conditionDetails(JsonField.of(conditionDetails)) - @JsonProperty("conditionDetails") - @ExcludeMissing fun conditionDetails(conditionDetails: JsonField) = apply { this.conditionDetails = conditionDetails } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1316,6 +1515,14 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Consequence = Consequence( condition, @@ -1324,39 +1531,48 @@ private constructor( ) } - @JsonDeserialize(builder = ConditionDetails.Builder::class) @NoAutoDetect class ConditionDetails + @JsonCreator private constructor( - private val diversionPath: JsonField, - private val diversionStopIds: JsonField>, - private val additionalProperties: Map, + @JsonProperty("diversionPath") + @ExcludeMissing + private val diversionPath: JsonField = JsonMissing.of(), + @JsonProperty("diversionStopIds") + @ExcludeMissing + private val diversionStopIds: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun diversionPath(): Optional = Optional.ofNullable(diversionPath.getNullable("diversionPath")) fun diversionStopIds(): Optional> = Optional.ofNullable(diversionStopIds.getNullable("diversionStopIds")) - @JsonProperty("diversionPath") @ExcludeMissing fun _diversionPath() = diversionPath + @JsonProperty("diversionPath") + @ExcludeMissing + fun _diversionPath(): JsonField = diversionPath @JsonProperty("diversionStopIds") @ExcludeMissing - fun _diversionStopIds() = diversionStopIds + fun _diversionStopIds(): JsonField> = diversionStopIds @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ConditionDetails = apply { - if (!validated) { - diversionPath().map { it.validate() } - diversionStopIds() - validated = true + if (validated) { + return@apply } + + diversionPath().ifPresent { it.validate() } + diversionStopIds() + validated = true } fun toBuilder() = Builder().from(this) @@ -1366,24 +1582,24 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [ConditionDetails]. */ + class Builder internal constructor() { private var diversionPath: JsonField = JsonMissing.of() - private var diversionStopIds: JsonField> = JsonMissing.of() + private var diversionStopIds: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(conditionDetails: ConditionDetails) = apply { - this.diversionPath = conditionDetails.diversionPath - this.diversionStopIds = conditionDetails.diversionStopIds - additionalProperties(conditionDetails.additionalProperties) + diversionPath = conditionDetails.diversionPath + diversionStopIds = + conditionDetails.diversionStopIds.map { it.toMutableList() } + additionalProperties = conditionDetails.additionalProperties.toMutableMap() } fun diversionPath(diversionPath: DiversionPath) = diversionPath(JsonField.of(diversionPath)) - @JsonProperty("diversionPath") - @ExcludeMissing fun diversionPath(diversionPath: JsonField) = apply { this.diversionPath = diversionPath } @@ -1391,20 +1607,30 @@ private constructor( fun diversionStopIds(diversionStopIds: List) = diversionStopIds(JsonField.of(diversionStopIds)) - @JsonProperty("diversionStopIds") - @ExcludeMissing fun diversionStopIds(diversionStopIds: JsonField>) = apply { - this.diversionStopIds = diversionStopIds + this.diversionStopIds = diversionStopIds.map { it.toMutableList() } + } + + fun addDiversionStopId(diversionStopId: String) = apply { + diversionStopIds = + (diversionStopIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(diversionStopId) + } } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1412,26 +1638,39 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): ConditionDetails = ConditionDetails( diversionPath, - diversionStopIds.map { it.toImmutable() }, + (diversionStopIds ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = DiversionPath.Builder::class) @NoAutoDetect class DiversionPath + @JsonCreator private constructor( - private val length: JsonField, - private val levels: JsonField, - private val points: JsonField, - private val additionalProperties: Map, + @JsonProperty("length") + @ExcludeMissing + private val length: JsonField = JsonMissing.of(), + @JsonProperty("levels") + @ExcludeMissing + private val levels: JsonField = JsonMissing.of(), + @JsonProperty("points") + @ExcludeMissing + private val points: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Length of the diversion path. */ fun length(): Optional = Optional.ofNullable(length.getNullable("length")) @@ -1444,25 +1683,33 @@ private constructor( Optional.ofNullable(points.getNullable("points")) /** Length of the diversion path. */ - @JsonProperty("length") @ExcludeMissing fun _length() = length + @JsonProperty("length") @ExcludeMissing fun _length(): JsonField = length /** Levels of the diversion path. */ - @JsonProperty("levels") @ExcludeMissing fun _levels() = levels + @JsonProperty("levels") + @ExcludeMissing + fun _levels(): JsonField = levels /** Points of the diversion path. */ - @JsonProperty("points") @ExcludeMissing fun _points() = points + @JsonProperty("points") + @ExcludeMissing + fun _points(): JsonField = points @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): DiversionPath = apply { - if (!validated) { - length() - levels() - points() - validated = true + if (validated) { + return@apply } + + length() + levels() + points() + validated = true } fun toBuilder() = Builder().from(this) @@ -1472,7 +1719,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [DiversionPath]. */ + class Builder internal constructor() { private var length: JsonField = JsonMissing.of() private var levels: JsonField = JsonMissing.of() @@ -1482,51 +1730,52 @@ private constructor( @JvmSynthetic internal fun from(diversionPath: DiversionPath) = apply { - this.length = diversionPath.length - this.levels = diversionPath.levels - this.points = diversionPath.points - additionalProperties(diversionPath.additionalProperties) + length = diversionPath.length + levels = diversionPath.levels + points = diversionPath.points + additionalProperties = diversionPath.additionalProperties.toMutableMap() } /** Length of the diversion path. */ fun length(length: Long) = length(JsonField.of(length)) /** Length of the diversion path. */ - @JsonProperty("length") - @ExcludeMissing fun length(length: JsonField) = apply { this.length = length } /** Levels of the diversion path. */ fun levels(levels: String) = levels(JsonField.of(levels)) /** Levels of the diversion path. */ - @JsonProperty("levels") - @ExcludeMissing fun levels(levels: JsonField) = apply { this.levels = levels } /** Points of the diversion path. */ fun points(points: String) = points(JsonField.of(points)) /** Points of the diversion path. */ - @JsonProperty("points") - @ExcludeMissing fun points(points: JsonField) = apply { this.points = points } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): DiversionPath = DiversionPath( length, @@ -1541,17 +1790,14 @@ private constructor( return true } - return /* spotless:off */ other is DiversionPath && this.length == other.length && this.levels == other.levels && this.points == other.points && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is DiversionPath && length == other.length && levels == other.levels && points == other.points && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(length, levels, points, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(length, levels, points, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "DiversionPath{length=$length, levels=$levels, points=$points, additionalProperties=$additionalProperties}" @@ -1562,17 +1808,14 @@ private constructor( return true } - return /* spotless:off */ other is ConditionDetails && this.diversionPath == other.diversionPath && this.diversionStopIds == other.diversionStopIds && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is ConditionDetails && diversionPath == other.diversionPath && diversionStopIds == other.diversionStopIds && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(diversionPath, diversionStopIds, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(diversionPath, diversionStopIds, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "ConditionDetails{diversionPath=$diversionPath, diversionStopIds=$diversionStopIds, additionalProperties=$additionalProperties}" @@ -1583,33 +1826,33 @@ private constructor( return true } - return /* spotless:off */ other is Consequence && this.condition == other.condition && this.conditionDetails == other.conditionDetails && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Consequence && condition == other.condition && conditionDetails == other.conditionDetails && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(condition, conditionDetails, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(condition, conditionDetails, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Consequence{condition=$condition, conditionDetails=$conditionDetails, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = Description.Builder::class) @NoAutoDetect class Description + @JsonCreator private constructor( - private val lang: JsonField, - private val value: JsonField, - private val additionalProperties: Map, + @JsonProperty("lang") + @ExcludeMissing + private val lang: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + private val value: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Language of the description. */ fun lang(): Optional = Optional.ofNullable(lang.getNullable("lang")) @@ -1617,21 +1860,25 @@ private constructor( fun value(): Optional = Optional.ofNullable(value.getNullable("value")) /** Language of the description. */ - @JsonProperty("lang") @ExcludeMissing fun _lang() = lang + @JsonProperty("lang") @ExcludeMissing fun _lang(): JsonField = lang /** Longer description of the situation. */ - @JsonProperty("value") @ExcludeMissing fun _value() = value + @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Description = apply { - if (!validated) { - lang() - value() - validated = true + if (validated) { + return@apply } + + lang() + value() + validated = true } fun toBuilder() = Builder().from(this) @@ -1641,7 +1888,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Description]. */ + class Builder internal constructor() { private var lang: JsonField = JsonMissing.of() private var value: JsonField = JsonMissing.of() @@ -1649,35 +1897,30 @@ private constructor( @JvmSynthetic internal fun from(description: Description) = apply { - this.lang = description.lang - this.value = description.value - additionalProperties(description.additionalProperties) + lang = description.lang + value = description.value + additionalProperties = description.additionalProperties.toMutableMap() } /** Language of the description. */ fun lang(lang: String) = lang(JsonField.of(lang)) /** Language of the description. */ - @JsonProperty("lang") - @ExcludeMissing fun lang(lang: JsonField) = apply { this.lang = lang } /** Longer description of the situation. */ fun value(value: String) = value(JsonField.of(value)) /** Longer description of the situation. */ - @JsonProperty("value") - @ExcludeMissing fun value(value: JsonField) = apply { this.value = value } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1685,6 +1928,14 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Description = Description( lang, @@ -1698,33 +1949,31 @@ private constructor( return true } - return /* spotless:off */ other is Description && this.lang == other.lang && this.value == other.value && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Description && lang == other.lang && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lang, value, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lang, value, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Description{lang=$lang, value=$value, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = PublicationWindow.Builder::class) @NoAutoDetect class PublicationWindow + @JsonCreator private constructor( - private val from: JsonField, - private val to: JsonField, - private val additionalProperties: Map, + @JsonProperty("from") + @ExcludeMissing + private val from: JsonField = JsonMissing.of(), + @JsonProperty("to") @ExcludeMissing private val to: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Start time of the time window as a Unix timestamp. */ fun from(): Long = from.getRequired("from") @@ -1732,21 +1981,25 @@ private constructor( fun to(): Long = to.getRequired("to") /** Start time of the time window as a Unix timestamp. */ - @JsonProperty("from") @ExcludeMissing fun _from() = from + @JsonProperty("from") @ExcludeMissing fun _from(): JsonField = from /** End time of the time window as a Unix timestamp. */ - @JsonProperty("to") @ExcludeMissing fun _to() = to + @JsonProperty("to") @ExcludeMissing fun _to(): JsonField = to @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): PublicationWindow = apply { - if (!validated) { - from() - to() - validated = true + if (validated) { + return@apply } + + from() + to() + validated = true } fun toBuilder() = Builder().from(this) @@ -1756,43 +2009,39 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [PublicationWindow]. */ + class Builder internal constructor() { - private var from: JsonField = JsonMissing.of() - private var to: JsonField = JsonMissing.of() + private var from: JsonField? = null + private var to: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(publicationWindow: PublicationWindow) = apply { - this.from = publicationWindow.from - this.to = publicationWindow.to - additionalProperties(publicationWindow.additionalProperties) + from = publicationWindow.from + to = publicationWindow.to + additionalProperties = publicationWindow.additionalProperties.toMutableMap() } /** Start time of the time window as a Unix timestamp. */ fun from(from: Long) = from(JsonField.of(from)) /** Start time of the time window as a Unix timestamp. */ - @JsonProperty("from") - @ExcludeMissing fun from(from: JsonField) = apply { this.from = from } /** End time of the time window as a Unix timestamp. */ fun to(to: Long) = to(JsonField.of(to)) /** End time of the time window as a Unix timestamp. */ - @JsonProperty("to") - @ExcludeMissing fun to(to: JsonField) = apply { this.to = to } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1800,10 +2049,18 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): PublicationWindow = PublicationWindow( - from, - to, + checkRequired("from", from), + checkRequired("to", to), additionalProperties.toImmutable(), ) } @@ -1813,57 +2070,52 @@ private constructor( return true } - return /* spotless:off */ other is PublicationWindow && this.from == other.from && this.to == other.to && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is PublicationWindow && from == other.from && to == other.to && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(from, to, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(from, to, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "PublicationWindow{from=$from, to=$to, additionalProperties=$additionalProperties}" - } - - class Reason - @JsonCreator - private constructor( - private val value: JsonField, - ) : Enum { - - @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Reason && this.value == other.value /* spotless:on */ - } + } - override fun hashCode() = value.hashCode() + /** Reason for the service alert, taken from TPEG codes. */ + class Reason + @JsonCreator + private constructor( + private val value: JsonField, + ) : Enum { - override fun toString() = value.toString() + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is + * on an older version than the API, then the API may respond with new members that the + * SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value companion object { - @JvmField val EQUIPMENT_REASON = Reason(JsonField.of("equipmentReason")) + @JvmField val EQUIPMENT_REASON = of("equipmentReason") - @JvmField val ENVIRONMENT_REASON = Reason(JsonField.of("environmentReason")) + @JvmField val ENVIRONMENT_REASON = of("environmentReason") - @JvmField val PERSONNEL_REASON = Reason(JsonField.of("personnelReason")) + @JvmField val PERSONNEL_REASON = of("personnelReason") - @JvmField val MISCELLANEOUS_REASON = Reason(JsonField.of("miscellaneousReason")) + @JvmField val MISCELLANEOUS_REASON = of("miscellaneousReason") - @JvmField val SECURITY_ALERT = Reason(JsonField.of("securityAlert")) + @JvmField val SECURITY_ALERT = of("securityAlert") @JvmStatic fun of(value: String) = Reason(JsonField.of(value)) } + /** An enum containing [Reason]'s known values. */ enum class Known { EQUIPMENT_REASON, ENVIRONMENT_REASON, @@ -1872,15 +2124,34 @@ private constructor( SECURITY_ALERT, } + /** + * An enum containing [Reason]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Reason] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if + * the SDK is on an older version than the API, then the API may respond with new + * members that the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ enum class Value { EQUIPMENT_REASON, ENVIRONMENT_REASON, PERSONNEL_REASON, MISCELLANEOUS_REASON, SECURITY_ALERT, + /** + * An enum member indicating that [Reason] was instantiated with an unknown value. + */ _UNKNOWN, } + /** + * Returns an enum member corresponding to this class instance's value, or + * [Value._UNKNOWN] if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you + * want to throw for the unknown case. + */ fun value(): Value = when (this) { EQUIPMENT_REASON -> Value.EQUIPMENT_REASON @@ -1891,6 +2162,15 @@ private constructor( else -> Value._UNKNOWN } + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and + * don't want to throw for the unknown case. + * + * @throws OnebusawaySdkInvalidDataException if this class instance's value is a not a + * known member. + */ fun known(): Known = when (this) { EQUIPMENT_REASON -> Known.EQUIPMENT_REASON @@ -1902,19 +2182,34 @@ private constructor( } fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Reason && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() } - @JsonDeserialize(builder = Summary.Builder::class) @NoAutoDetect class Summary + @JsonCreator private constructor( - private val lang: JsonField, - private val value: JsonField, - private val additionalProperties: Map, + @JsonProperty("lang") + @ExcludeMissing + private val lang: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + private val value: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Language of the summary. */ fun lang(): Optional = Optional.ofNullable(lang.getNullable("lang")) @@ -1922,21 +2217,25 @@ private constructor( fun value(): Optional = Optional.ofNullable(value.getNullable("value")) /** Language of the summary. */ - @JsonProperty("lang") @ExcludeMissing fun _lang() = lang + @JsonProperty("lang") @ExcludeMissing fun _lang(): JsonField = lang /** Short summary of the situation. */ - @JsonProperty("value") @ExcludeMissing fun _value() = value + @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Summary = apply { - if (!validated) { - lang() - value() - validated = true + if (validated) { + return@apply } + + lang() + value() + validated = true } fun toBuilder() = Builder().from(this) @@ -1946,7 +2245,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Summary]. */ + class Builder internal constructor() { private var lang: JsonField = JsonMissing.of() private var value: JsonField = JsonMissing.of() @@ -1954,35 +2254,30 @@ private constructor( @JvmSynthetic internal fun from(summary: Summary) = apply { - this.lang = summary.lang - this.value = summary.value - additionalProperties(summary.additionalProperties) + lang = summary.lang + value = summary.value + additionalProperties = summary.additionalProperties.toMutableMap() } /** Language of the summary. */ fun lang(lang: String) = lang(JsonField.of(lang)) /** Language of the summary. */ - @JsonProperty("lang") - @ExcludeMissing fun lang(lang: JsonField) = apply { this.lang = lang } /** Short summary of the situation. */ fun value(value: String) = value(JsonField.of(value)) /** Short summary of the situation. */ - @JsonProperty("value") - @ExcludeMissing fun value(value: JsonField) = apply { this.value = value } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1990,6 +2285,14 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Summary = Summary( lang, @@ -2003,33 +2306,33 @@ private constructor( return true } - return /* spotless:off */ other is Summary && this.lang == other.lang && this.value == other.value && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Summary && lang == other.lang && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lang, value, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lang, value, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Summary{lang=$lang, value=$value, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = Url.Builder::class) @NoAutoDetect class Url + @JsonCreator private constructor( - private val lang: JsonField, - private val value: JsonField, - private val additionalProperties: Map, + @JsonProperty("lang") + @ExcludeMissing + private val lang: JsonField = JsonMissing.of(), + @JsonProperty("value") + @ExcludeMissing + private val value: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Language of the URL. */ fun lang(): Optional = Optional.ofNullable(lang.getNullable("lang")) @@ -2037,21 +2340,25 @@ private constructor( fun value(): Optional = Optional.ofNullable(value.getNullable("value")) /** Language of the URL. */ - @JsonProperty("lang") @ExcludeMissing fun _lang() = lang + @JsonProperty("lang") @ExcludeMissing fun _lang(): JsonField = lang /** URL for more information about the situation. */ - @JsonProperty("value") @ExcludeMissing fun _value() = value + @JsonProperty("value") @ExcludeMissing fun _value(): JsonField = value @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Url = apply { - if (!validated) { - lang() - value() - validated = true + if (validated) { + return@apply } + + lang() + value() + validated = true } fun toBuilder() = Builder().from(this) @@ -2061,7 +2368,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Url]. */ + class Builder internal constructor() { private var lang: JsonField = JsonMissing.of() private var value: JsonField = JsonMissing.of() @@ -2069,35 +2377,30 @@ private constructor( @JvmSynthetic internal fun from(url: Url) = apply { - this.lang = url.lang - this.value = url.value - additionalProperties(url.additionalProperties) + lang = url.lang + value = url.value + additionalProperties = url.additionalProperties.toMutableMap() } /** Language of the URL. */ fun lang(lang: String) = lang(JsonField.of(lang)) /** Language of the URL. */ - @JsonProperty("lang") - @ExcludeMissing fun lang(lang: JsonField) = apply { this.lang = lang } /** URL for more information about the situation. */ fun value(value: String) = value(JsonField.of(value)) /** URL for more information about the situation. */ - @JsonProperty("value") - @ExcludeMissing fun value(value: JsonField) = apply { this.value = value } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -2105,6 +2408,14 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Url = Url( lang, @@ -2118,17 +2429,14 @@ private constructor( return true } - return /* spotless:off */ other is Url && this.lang == other.lang && this.value == other.value && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Url && lang == other.lang && value == other.value && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lang, value, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lang, value, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Url{lang=$lang, value=$value, additionalProperties=$additionalProperties}" @@ -2139,52 +2447,59 @@ private constructor( return true } - return /* spotless:off */ other is Situation && this.id == other.id && this.creationTime == other.creationTime && this.reason == other.reason && this.summary == other.summary && this.description == other.description && this.url == other.url && this.activeWindows == other.activeWindows && this.allAffects == other.allAffects && this.consequences == other.consequences && this.publicationWindows == other.publicationWindows && this.severity == other.severity && this.consequenceMessage == other.consequenceMessage && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Situation && id == other.id && creationTime == other.creationTime && activeWindows == other.activeWindows && allAffects == other.allAffects && consequenceMessage == other.consequenceMessage && consequences == other.consequences && description == other.description && publicationWindows == other.publicationWindows && reason == other.reason && severity == other.severity && summary == other.summary && url == other.url && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, creationTime, activeWindows, allAffects, consequenceMessage, consequences, description, publicationWindows, reason, severity, summary, url, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(id, creationTime, reason, summary, description, url, activeWindows, allAffects, consequences, publicationWindows, severity, consequenceMessage, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Situation{id=$id, creationTime=$creationTime, reason=$reason, summary=$summary, description=$description, url=$url, activeWindows=$activeWindows, allAffects=$allAffects, consequences=$consequences, publicationWindows=$publicationWindows, severity=$severity, consequenceMessage=$consequenceMessage, additionalProperties=$additionalProperties}" + "Situation{id=$id, creationTime=$creationTime, activeWindows=$activeWindows, allAffects=$allAffects, consequenceMessage=$consequenceMessage, consequences=$consequences, description=$description, publicationWindows=$publicationWindows, reason=$reason, severity=$severity, summary=$summary, url=$url, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = Stop.Builder::class) @NoAutoDetect class Stop + @JsonCreator private constructor( - private val code: JsonField, - private val direction: JsonField, - private val id: JsonField, - private val lat: JsonField, - private val locationType: JsonField, - private val lon: JsonField, - private val name: JsonField, - private val parent: JsonField, - private val routeIds: JsonField>, - private val staticRouteIds: JsonField>, - private val wheelchairBoarding: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), + @JsonProperty("lat") @ExcludeMissing private val lat: JsonField = JsonMissing.of(), + @JsonProperty("locationType") + @ExcludeMissing + private val locationType: JsonField = JsonMissing.of(), + @JsonProperty("lon") @ExcludeMissing private val lon: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + private val name: JsonField = JsonMissing.of(), + @JsonProperty("parent") + @ExcludeMissing + private val parent: JsonField = JsonMissing.of(), + @JsonProperty("routeIds") + @ExcludeMissing + private val routeIds: JsonField> = JsonMissing.of(), + @JsonProperty("staticRouteIds") + @ExcludeMissing + private val staticRouteIds: JsonField> = JsonMissing.of(), + @JsonProperty("code") + @ExcludeMissing + private val code: JsonField = JsonMissing.of(), + @JsonProperty("direction") + @ExcludeMissing + private val direction: JsonField = JsonMissing.of(), + @JsonProperty("wheelchairBoarding") + @ExcludeMissing + private val wheelchairBoarding: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun code(): Optional = Optional.ofNullable(code.getNullable("code")) - - fun direction(): Optional = Optional.ofNullable(direction.getNullable("direction")) - fun id(): String = id.getRequired("id") fun lat(): Double = lat.getRequired("lat") - fun locationType(): Optional = - Optional.ofNullable(locationType.getNullable("locationType")) + fun locationType(): Long = locationType.getRequired("locationType") fun lon(): Double = lon.getRequired("lon") @@ -2196,52 +2511,66 @@ private constructor( fun staticRouteIds(): List = staticRouteIds.getRequired("staticRouteIds") + fun code(): Optional = Optional.ofNullable(code.getNullable("code")) + + fun direction(): Optional = Optional.ofNullable(direction.getNullable("direction")) + fun wheelchairBoarding(): Optional = Optional.ofNullable(wheelchairBoarding.getNullable("wheelchairBoarding")) - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("direction") @ExcludeMissing fun _direction() = direction + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("locationType") + @ExcludeMissing + fun _locationType(): JsonField = locationType - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon - @JsonProperty("locationType") @ExcludeMissing fun _locationType() = locationType + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("routeIds") + @ExcludeMissing + fun _routeIds(): JsonField> = routeIds - @JsonProperty("parent") @ExcludeMissing fun _parent() = parent + @JsonProperty("staticRouteIds") + @ExcludeMissing + fun _staticRouteIds(): JsonField> = staticRouteIds - @JsonProperty("routeIds") @ExcludeMissing fun _routeIds() = routeIds + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("staticRouteIds") @ExcludeMissing fun _staticRouteIds() = staticRouteIds + @JsonProperty("direction") @ExcludeMissing fun _direction(): JsonField = direction @JsonProperty("wheelchairBoarding") @ExcludeMissing - fun _wheelchairBoarding() = wheelchairBoarding + fun _wheelchairBoarding(): JsonField = wheelchairBoarding @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Stop = apply { - if (!validated) { - code() - direction() - id() - lat() - locationType() - lon() - name() - parent() - routeIds() - staticRouteIds() - wheelchairBoarding() - validated = true - } + if (validated) { + return@apply + } + + id() + lat() + locationType() + lon() + name() + parent() + routeIds() + staticRouteIds() + code() + direction() + wheelchairBoarding() + validated = true } fun toBuilder() = Builder().from(this) @@ -2251,137 +2580,149 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - + /** A builder for [Stop]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var lat: JsonField? = null + private var locationType: JsonField? = null + private var lon: JsonField? = null + private var name: JsonField? = null + private var parent: JsonField? = null + private var routeIds: JsonField>? = null + private var staticRouteIds: JsonField>? = null private var code: JsonField = JsonMissing.of() private var direction: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() - private var lat: JsonField = JsonMissing.of() - private var locationType: JsonField = JsonMissing.of() - private var lon: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var parent: JsonField = JsonMissing.of() - private var routeIds: JsonField> = JsonMissing.of() - private var staticRouteIds: JsonField> = JsonMissing.of() private var wheelchairBoarding: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(stop: Stop) = apply { - this.code = stop.code - this.direction = stop.direction - this.id = stop.id - this.lat = stop.lat - this.locationType = stop.locationType - this.lon = stop.lon - this.name = stop.name - this.parent = stop.parent - this.routeIds = stop.routeIds - this.staticRouteIds = stop.staticRouteIds - this.wheelchairBoarding = stop.wheelchairBoarding - additionalProperties(stop.additionalProperties) + id = stop.id + lat = stop.lat + locationType = stop.locationType + lon = stop.lon + name = stop.name + parent = stop.parent + routeIds = stop.routeIds.map { it.toMutableList() } + staticRouteIds = stop.staticRouteIds.map { it.toMutableList() } + code = stop.code + direction = stop.direction + wheelchairBoarding = stop.wheelchairBoarding + additionalProperties = stop.additionalProperties.toMutableMap() } - fun code(code: String) = code(JsonField.of(code)) - - @JsonProperty("code") - @ExcludeMissing - fun code(code: JsonField) = apply { this.code = code } - - fun direction(direction: String) = direction(JsonField.of(direction)) - - @JsonProperty("direction") - @ExcludeMissing - fun direction(direction: JsonField) = apply { this.direction = direction } - fun id(id: String) = id(JsonField.of(id)) - @JsonProperty("id") - @ExcludeMissing fun id(id: JsonField) = apply { this.id = id } fun lat(lat: Double) = lat(JsonField.of(lat)) - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } fun locationType(locationType: Long) = locationType(JsonField.of(locationType)) - @JsonProperty("locationType") - @ExcludeMissing fun locationType(locationType: JsonField) = apply { this.locationType = locationType } fun lon(lon: Double) = lon(JsonField.of(lon)) - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun name(name: String) = name(JsonField.of(name)) - @JsonProperty("name") - @ExcludeMissing fun name(name: JsonField) = apply { this.name = name } fun parent(parent: String) = parent(JsonField.of(parent)) - @JsonProperty("parent") - @ExcludeMissing fun parent(parent: JsonField) = apply { this.parent = parent } fun routeIds(routeIds: List) = routeIds(JsonField.of(routeIds)) - @JsonProperty("routeIds") - @ExcludeMissing - fun routeIds(routeIds: JsonField>) = apply { this.routeIds = routeIds } + fun routeIds(routeIds: JsonField>) = apply { + this.routeIds = routeIds.map { it.toMutableList() } + } + + fun addRouteId(routeId: String) = apply { + routeIds = + (routeIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(routeId) + } + } fun staticRouteIds(staticRouteIds: List) = staticRouteIds(JsonField.of(staticRouteIds)) - @JsonProperty("staticRouteIds") - @ExcludeMissing fun staticRouteIds(staticRouteIds: JsonField>) = apply { - this.staticRouteIds = staticRouteIds + this.staticRouteIds = staticRouteIds.map { it.toMutableList() } + } + + fun addStaticRouteId(staticRouteId: String) = apply { + staticRouteIds = + (staticRouteIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(staticRouteId) + } } + fun code(code: String) = code(JsonField.of(code)) + + fun code(code: JsonField) = apply { this.code = code } + + fun direction(direction: String) = direction(JsonField.of(direction)) + + fun direction(direction: JsonField) = apply { this.direction = direction } + fun wheelchairBoarding(wheelchairBoarding: String) = wheelchairBoarding(JsonField.of(wheelchairBoarding)) - @JsonProperty("wheelchairBoarding") - @ExcludeMissing fun wheelchairBoarding(wheelchairBoarding: JsonField) = apply { this.wheelchairBoarding = wheelchairBoarding } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Stop = Stop( + checkRequired("id", id), + checkRequired("lat", lat), + checkRequired("locationType", locationType), + checkRequired("lon", lon), + checkRequired("name", name), + checkRequired("parent", parent), + checkRequired("routeIds", routeIds).map { it.toImmutable() }, + checkRequired("staticRouteIds", staticRouteIds).map { it.toImmutable() }, code, direction, - id, - lat, - locationType, - lon, - name, - parent, - routeIds.map { it.toImmutable() }, - staticRouteIds.map { it.toImmutable() }, wheelchairBoarding, additionalProperties.toImmutable(), ) @@ -2392,37 +2733,45 @@ private constructor( return true } - return /* spotless:off */ other is Stop && this.code == other.code && this.direction == other.direction && this.id == other.id && this.lat == other.lat && this.locationType == other.locationType && this.lon == other.lon && this.name == other.name && this.parent == other.parent && this.routeIds == other.routeIds && this.staticRouteIds == other.staticRouteIds && this.wheelchairBoarding == other.wheelchairBoarding && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Stop && id == other.id && lat == other.lat && locationType == other.locationType && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && code == other.code && direction == other.direction && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, code, direction, wheelchairBoarding, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, direction, id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, wheelchairBoarding, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Stop{code=$code, direction=$direction, id=$id, lat=$lat, locationType=$locationType, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" + "Stop{id=$id, lat=$lat, locationType=$locationType, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, code=$code, direction=$direction, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = StopTime.Builder::class) @NoAutoDetect class StopTime + @JsonCreator private constructor( - private val arrivalTime: JsonField, - private val departureTime: JsonField, - private val distanceAlongTrip: JsonField, - private val historicalOccupancy: JsonField, - private val stopHeadsign: JsonField, - private val stopId: JsonField, - private val additionalProperties: Map, + @JsonProperty("arrivalTime") + @ExcludeMissing + private val arrivalTime: JsonField = JsonMissing.of(), + @JsonProperty("departureTime") + @ExcludeMissing + private val departureTime: JsonField = JsonMissing.of(), + @JsonProperty("distanceAlongTrip") + @ExcludeMissing + private val distanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("historicalOccupancy") + @ExcludeMissing + private val historicalOccupancy: JsonField = JsonMissing.of(), + @JsonProperty("stopHeadsign") + @ExcludeMissing + private val stopHeadsign: JsonField = JsonMissing.of(), + @JsonProperty("stopId") + @ExcludeMissing + private val stopId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun arrivalTime(): Optional = Optional.ofNullable(arrivalTime.getNullable("arrivalTime")) @@ -2440,36 +2789,46 @@ private constructor( fun stopId(): Optional = Optional.ofNullable(stopId.getNullable("stopId")) - @JsonProperty("arrivalTime") @ExcludeMissing fun _arrivalTime() = arrivalTime + @JsonProperty("arrivalTime") + @ExcludeMissing + fun _arrivalTime(): JsonField = arrivalTime - @JsonProperty("departureTime") @ExcludeMissing fun _departureTime() = departureTime + @JsonProperty("departureTime") + @ExcludeMissing + fun _departureTime(): JsonField = departureTime @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip + fun _distanceAlongTrip(): JsonField = distanceAlongTrip @JsonProperty("historicalOccupancy") @ExcludeMissing - fun _historicalOccupancy() = historicalOccupancy + fun _historicalOccupancy(): JsonField = historicalOccupancy - @JsonProperty("stopHeadsign") @ExcludeMissing fun _stopHeadsign() = stopHeadsign + @JsonProperty("stopHeadsign") + @ExcludeMissing + fun _stopHeadsign(): JsonField = stopHeadsign - @JsonProperty("stopId") @ExcludeMissing fun _stopId() = stopId + @JsonProperty("stopId") @ExcludeMissing fun _stopId(): JsonField = stopId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): StopTime = apply { - if (!validated) { - arrivalTime() - departureTime() - distanceAlongTrip() - historicalOccupancy() - stopHeadsign() - stopId() - validated = true + if (validated) { + return@apply } + + arrivalTime() + departureTime() + distanceAlongTrip() + historicalOccupancy() + stopHeadsign() + stopId() + validated = true } fun toBuilder() = Builder().from(this) @@ -2479,7 +2838,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopTime]. */ + class Builder internal constructor() { private var arrivalTime: JsonField = JsonMissing.of() private var departureTime: JsonField = JsonMissing.of() @@ -2491,25 +2851,21 @@ private constructor( @JvmSynthetic internal fun from(stopTime: StopTime) = apply { - this.arrivalTime = stopTime.arrivalTime - this.departureTime = stopTime.departureTime - this.distanceAlongTrip = stopTime.distanceAlongTrip - this.historicalOccupancy = stopTime.historicalOccupancy - this.stopHeadsign = stopTime.stopHeadsign - this.stopId = stopTime.stopId - additionalProperties(stopTime.additionalProperties) + arrivalTime = stopTime.arrivalTime + departureTime = stopTime.departureTime + distanceAlongTrip = stopTime.distanceAlongTrip + historicalOccupancy = stopTime.historicalOccupancy + stopHeadsign = stopTime.stopHeadsign + stopId = stopTime.stopId + additionalProperties = stopTime.additionalProperties.toMutableMap() } fun arrivalTime(arrivalTime: Long) = arrivalTime(JsonField.of(arrivalTime)) - @JsonProperty("arrivalTime") - @ExcludeMissing fun arrivalTime(arrivalTime: JsonField) = apply { this.arrivalTime = arrivalTime } fun departureTime(departureTime: Long) = departureTime(JsonField.of(departureTime)) - @JsonProperty("departureTime") - @ExcludeMissing fun departureTime(departureTime: JsonField) = apply { this.departureTime = departureTime } @@ -2517,8 +2873,6 @@ private constructor( fun distanceAlongTrip(distanceAlongTrip: Double) = distanceAlongTrip(JsonField.of(distanceAlongTrip)) - @JsonProperty("distanceAlongTrip") - @ExcludeMissing fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { this.distanceAlongTrip = distanceAlongTrip } @@ -2526,40 +2880,39 @@ private constructor( fun historicalOccupancy(historicalOccupancy: String) = historicalOccupancy(JsonField.of(historicalOccupancy)) - @JsonProperty("historicalOccupancy") - @ExcludeMissing fun historicalOccupancy(historicalOccupancy: JsonField) = apply { this.historicalOccupancy = historicalOccupancy } fun stopHeadsign(stopHeadsign: String) = stopHeadsign(JsonField.of(stopHeadsign)) - @JsonProperty("stopHeadsign") - @ExcludeMissing fun stopHeadsign(stopHeadsign: JsonField) = apply { this.stopHeadsign = stopHeadsign } fun stopId(stopId: String) = stopId(JsonField.of(stopId)) - @JsonProperty("stopId") - @ExcludeMissing fun stopId(stopId: JsonField) = apply { this.stopId = stopId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopTime = StopTime( arrivalTime, @@ -2577,59 +2930,75 @@ private constructor( return true } - return /* spotless:off */ other is StopTime && this.arrivalTime == other.arrivalTime && this.departureTime == other.departureTime && this.distanceAlongTrip == other.distanceAlongTrip && this.historicalOccupancy == other.historicalOccupancy && this.stopHeadsign == other.stopHeadsign && this.stopId == other.stopId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopTime && arrivalTime == other.arrivalTime && departureTime == other.departureTime && distanceAlongTrip == other.distanceAlongTrip && historicalOccupancy == other.historicalOccupancy && stopHeadsign == other.stopHeadsign && stopId == other.stopId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(arrivalTime, departureTime, distanceAlongTrip, historicalOccupancy, stopHeadsign, stopId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(arrivalTime, departureTime, distanceAlongTrip, historicalOccupancy, stopHeadsign, stopId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "StopTime{arrivalTime=$arrivalTime, departureTime=$departureTime, distanceAlongTrip=$distanceAlongTrip, historicalOccupancy=$historicalOccupancy, stopHeadsign=$stopHeadsign, stopId=$stopId, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = Trip.Builder::class) @NoAutoDetect class Trip + @JsonCreator private constructor( - private val blockId: JsonField, - private val directionId: JsonField, - private val id: JsonField, - private val peakOffpeak: JsonField, - private val routeId: JsonField, - private val routeShortName: JsonField, - private val serviceId: JsonField, - private val shapeId: JsonField, - private val timeZone: JsonField, - private val tripHeadsign: JsonField, - private val tripShortName: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), + @JsonProperty("routeId") + @ExcludeMissing + private val routeId: JsonField = JsonMissing.of(), + @JsonProperty("serviceId") + @ExcludeMissing + private val serviceId: JsonField = JsonMissing.of(), + @JsonProperty("blockId") + @ExcludeMissing + private val blockId: JsonField = JsonMissing.of(), + @JsonProperty("directionId") + @ExcludeMissing + private val directionId: JsonField = JsonMissing.of(), + @JsonProperty("peakOffpeak") + @ExcludeMissing + private val peakOffpeak: JsonField = JsonMissing.of(), + @JsonProperty("routeShortName") + @ExcludeMissing + private val routeShortName: JsonField = JsonMissing.of(), + @JsonProperty("shapeId") + @ExcludeMissing + private val shapeId: JsonField = JsonMissing.of(), + @JsonProperty("timeZone") + @ExcludeMissing + private val timeZone: JsonField = JsonMissing.of(), + @JsonProperty("tripHeadsign") + @ExcludeMissing + private val tripHeadsign: JsonField = JsonMissing.of(), + @JsonProperty("tripShortName") + @ExcludeMissing + private val tripShortName: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun id(): String = id.getRequired("id") + + fun routeId(): String = routeId.getRequired("routeId") + + fun serviceId(): String = serviceId.getRequired("serviceId") fun blockId(): Optional = Optional.ofNullable(blockId.getNullable("blockId")) fun directionId(): Optional = Optional.ofNullable(directionId.getNullable("directionId")) - fun id(): String = id.getRequired("id") - fun peakOffpeak(): Optional = Optional.ofNullable(peakOffpeak.getNullable("peakOffpeak")) - fun routeId(): String = routeId.getRequired("routeId") - fun routeShortName(): Optional = Optional.ofNullable(routeShortName.getNullable("routeShortName")) - fun serviceId(): String = serviceId.getRequired("serviceId") - fun shapeId(): Optional = Optional.ofNullable(shapeId.getNullable("shapeId")) fun timeZone(): Optional = Optional.ofNullable(timeZone.getNullable("timeZone")) @@ -2640,47 +3009,61 @@ private constructor( fun tripShortName(): Optional = Optional.ofNullable(tripShortName.getNullable("tripShortName")) - @JsonProperty("blockId") @ExcludeMissing fun _blockId() = blockId + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("directionId") @ExcludeMissing fun _directionId() = directionId + @JsonProperty("routeId") @ExcludeMissing fun _routeId(): JsonField = routeId - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("serviceId") @ExcludeMissing fun _serviceId(): JsonField = serviceId - @JsonProperty("peakOffpeak") @ExcludeMissing fun _peakOffpeak() = peakOffpeak + @JsonProperty("blockId") @ExcludeMissing fun _blockId(): JsonField = blockId - @JsonProperty("routeId") @ExcludeMissing fun _routeId() = routeId + @JsonProperty("directionId") + @ExcludeMissing + fun _directionId(): JsonField = directionId - @JsonProperty("routeShortName") @ExcludeMissing fun _routeShortName() = routeShortName + @JsonProperty("peakOffpeak") + @ExcludeMissing + fun _peakOffpeak(): JsonField = peakOffpeak - @JsonProperty("serviceId") @ExcludeMissing fun _serviceId() = serviceId + @JsonProperty("routeShortName") + @ExcludeMissing + fun _routeShortName(): JsonField = routeShortName - @JsonProperty("shapeId") @ExcludeMissing fun _shapeId() = shapeId + @JsonProperty("shapeId") @ExcludeMissing fun _shapeId(): JsonField = shapeId - @JsonProperty("timeZone") @ExcludeMissing fun _timeZone() = timeZone + @JsonProperty("timeZone") @ExcludeMissing fun _timeZone(): JsonField = timeZone - @JsonProperty("tripHeadsign") @ExcludeMissing fun _tripHeadsign() = tripHeadsign + @JsonProperty("tripHeadsign") + @ExcludeMissing + fun _tripHeadsign(): JsonField = tripHeadsign - @JsonProperty("tripShortName") @ExcludeMissing fun _tripShortName() = tripShortName + @JsonProperty("tripShortName") + @ExcludeMissing + fun _tripShortName(): JsonField = tripShortName @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Trip = apply { - if (!validated) { - blockId() - directionId() - id() - peakOffpeak() - routeId() - routeShortName() - serviceId() - shapeId() - timeZone() - tripHeadsign() - tripShortName() - validated = true - } + if (validated) { + return@apply + } + + id() + routeId() + serviceId() + blockId() + directionId() + peakOffpeak() + routeShortName() + shapeId() + timeZone() + tripHeadsign() + tripShortName() + validated = true } fun toBuilder() = Builder().from(this) @@ -2690,15 +3073,16 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Trip]. */ + class Builder internal constructor() { + private var id: JsonField? = null + private var routeId: JsonField? = null + private var serviceId: JsonField? = null private var blockId: JsonField = JsonMissing.of() private var directionId: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() private var peakOffpeak: JsonField = JsonMissing.of() - private var routeId: JsonField = JsonMissing.of() private var routeShortName: JsonField = JsonMissing.of() - private var serviceId: JsonField = JsonMissing.of() private var shapeId: JsonField = JsonMissing.of() private var timeZone: JsonField = JsonMissing.of() private var tripHeadsign: JsonField = JsonMissing.of() @@ -2707,118 +3091,101 @@ private constructor( @JvmSynthetic internal fun from(trip: Trip) = apply { - this.blockId = trip.blockId - this.directionId = trip.directionId - this.id = trip.id - this.peakOffpeak = trip.peakOffpeak - this.routeId = trip.routeId - this.routeShortName = trip.routeShortName - this.serviceId = trip.serviceId - this.shapeId = trip.shapeId - this.timeZone = trip.timeZone - this.tripHeadsign = trip.tripHeadsign - this.tripShortName = trip.tripShortName - additionalProperties(trip.additionalProperties) + id = trip.id + routeId = trip.routeId + serviceId = trip.serviceId + blockId = trip.blockId + directionId = trip.directionId + peakOffpeak = trip.peakOffpeak + routeShortName = trip.routeShortName + shapeId = trip.shapeId + timeZone = trip.timeZone + tripHeadsign = trip.tripHeadsign + tripShortName = trip.tripShortName + additionalProperties = trip.additionalProperties.toMutableMap() } + fun id(id: String) = id(JsonField.of(id)) + + fun id(id: JsonField) = apply { this.id = id } + + fun routeId(routeId: String) = routeId(JsonField.of(routeId)) + + fun routeId(routeId: JsonField) = apply { this.routeId = routeId } + + fun serviceId(serviceId: String) = serviceId(JsonField.of(serviceId)) + + fun serviceId(serviceId: JsonField) = apply { this.serviceId = serviceId } + fun blockId(blockId: String) = blockId(JsonField.of(blockId)) - @JsonProperty("blockId") - @ExcludeMissing fun blockId(blockId: JsonField) = apply { this.blockId = blockId } fun directionId(directionId: String) = directionId(JsonField.of(directionId)) - @JsonProperty("directionId") - @ExcludeMissing fun directionId(directionId: JsonField) = apply { this.directionId = directionId } - fun id(id: String) = id(JsonField.of(id)) - - @JsonProperty("id") - @ExcludeMissing - fun id(id: JsonField) = apply { this.id = id } - fun peakOffpeak(peakOffpeak: Long) = peakOffpeak(JsonField.of(peakOffpeak)) - @JsonProperty("peakOffpeak") - @ExcludeMissing fun peakOffpeak(peakOffpeak: JsonField) = apply { this.peakOffpeak = peakOffpeak } - fun routeId(routeId: String) = routeId(JsonField.of(routeId)) - - @JsonProperty("routeId") - @ExcludeMissing - fun routeId(routeId: JsonField) = apply { this.routeId = routeId } - fun routeShortName(routeShortName: String) = routeShortName(JsonField.of(routeShortName)) - @JsonProperty("routeShortName") - @ExcludeMissing fun routeShortName(routeShortName: JsonField) = apply { this.routeShortName = routeShortName } - fun serviceId(serviceId: String) = serviceId(JsonField.of(serviceId)) - - @JsonProperty("serviceId") - @ExcludeMissing - fun serviceId(serviceId: JsonField) = apply { this.serviceId = serviceId } - fun shapeId(shapeId: String) = shapeId(JsonField.of(shapeId)) - @JsonProperty("shapeId") - @ExcludeMissing fun shapeId(shapeId: JsonField) = apply { this.shapeId = shapeId } fun timeZone(timeZone: String) = timeZone(JsonField.of(timeZone)) - @JsonProperty("timeZone") - @ExcludeMissing fun timeZone(timeZone: JsonField) = apply { this.timeZone = timeZone } fun tripHeadsign(tripHeadsign: String) = tripHeadsign(JsonField.of(tripHeadsign)) - @JsonProperty("tripHeadsign") - @ExcludeMissing fun tripHeadsign(tripHeadsign: JsonField) = apply { this.tripHeadsign = tripHeadsign } fun tripShortName(tripShortName: String) = tripShortName(JsonField.of(tripShortName)) - @JsonProperty("tripShortName") - @ExcludeMissing fun tripShortName(tripShortName: JsonField) = apply { this.tripShortName = tripShortName } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Trip = Trip( + checkRequired("id", id), + checkRequired("routeId", routeId), + checkRequired("serviceId", serviceId), blockId, directionId, - id, peakOffpeak, - routeId, routeShortName, - serviceId, shapeId, timeZone, tripHeadsign, @@ -2832,20 +3199,17 @@ private constructor( return true } - return /* spotless:off */ other is Trip && this.blockId == other.blockId && this.directionId == other.directionId && this.id == other.id && this.peakOffpeak == other.peakOffpeak && this.routeId == other.routeId && this.routeShortName == other.routeShortName && this.serviceId == other.serviceId && this.shapeId == other.shapeId && this.timeZone == other.timeZone && this.tripHeadsign == other.tripHeadsign && this.tripShortName == other.tripShortName && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Trip && id == other.id && routeId == other.routeId && serviceId == other.serviceId && blockId == other.blockId && directionId == other.directionId && peakOffpeak == other.peakOffpeak && routeShortName == other.routeShortName && shapeId == other.shapeId && timeZone == other.timeZone && tripHeadsign == other.tripHeadsign && tripShortName == other.tripShortName && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, routeId, serviceId, blockId, directionId, peakOffpeak, routeShortName, shapeId, timeZone, tripHeadsign, tripShortName, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(blockId, directionId, id, peakOffpeak, routeId, routeShortName, serviceId, shapeId, timeZone, tripHeadsign, tripShortName, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Trip{blockId=$blockId, directionId=$directionId, id=$id, peakOffpeak=$peakOffpeak, routeId=$routeId, routeShortName=$routeShortName, serviceId=$serviceId, shapeId=$shapeId, timeZone=$timeZone, tripHeadsign=$tripHeadsign, tripShortName=$tripShortName, additionalProperties=$additionalProperties}" + "Trip{id=$id, routeId=$routeId, serviceId=$serviceId, blockId=$blockId, directionId=$directionId, peakOffpeak=$peakOffpeak, routeShortName=$routeShortName, shapeId=$shapeId, timeZone=$timeZone, tripHeadsign=$tripHeadsign, tripShortName=$tripShortName, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -2853,18 +3217,15 @@ private constructor( return true } - return /* spotless:off */ other is References && this.agencies == other.agencies && this.routes == other.routes && this.situations == other.situations && this.stopTimes == other.stopTimes && this.stops == other.stops && this.trips == other.trips && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is References && agencies == other.agencies && routes == other.routes && situations == other.situations && stops == other.stops && stopTimes == other.stopTimes && trips == other.trips && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(agencies, routes, situations, stops, stopTimes, trips, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(agencies, routes, situations, stopTimes, stops, trips, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "References{agencies=$agencies, routes=$routes, situations=$situations, stopTimes=$stopTimes, stops=$stops, trips=$trips, additionalProperties=$additionalProperties}" + "References{agencies=$agencies, routes=$routes, situations=$situations, stops=$stops, stopTimes=$stopTimes, trips=$trips, additionalProperties=$additionalProperties}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ReportProblemWithStopRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ReportProblemWithStopRetrieveParams.kt index 65aa1bc..9e9afca 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ReportProblemWithStopRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ReportProblemWithStopRetrieveParams.kt @@ -3,54 +3,64 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonCreator -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import java.util.Optional import org.onebusaway.core.Enum import org.onebusaway.core.JsonField -import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams import org.onebusaway.errors.OnebusawaySdkInvalidDataException -import org.onebusaway.models.* +/** Submit a user-generated problem report for a stop */ class ReportProblemWithStopRetrieveParams -constructor( +private constructor( private val stopId: String, private val code: Code?, private val userComment: String?, private val userLat: Double?, private val userLocationAccuracy: Double?, private val userLon: Double?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun stopId(): String = stopId + /** A string code identifying the nature of the problem */ fun code(): Optional = Optional.ofNullable(code) + /** Additional comment text supplied by the user describing the problem */ fun userComment(): Optional = Optional.ofNullable(userComment) + /** The reporting user’s current latitude */ fun userLat(): Optional = Optional.ofNullable(userLat) + /** The reporting user’s location accuracy, in meters */ fun userLocationAccuracy(): Optional = Optional.ofNullable(userLocationAccuracy) + /** The reporting user’s current longitude */ fun userLon(): Optional = Optional.ofNullable(userLon) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.code?.let { params.put("code", listOf(it.toString())) } - this.userComment?.let { params.put("userComment", listOf(it.toString())) } - this.userLat?.let { params.put("userLat", listOf(it.toString())) } - this.userLocationAccuracy?.let { params.put("userLocationAccuracy", listOf(it.toString())) } - this.userLon?.let { params.put("userLon", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.code?.let { queryParams.put("code", listOf(it.toString())) } + this.userComment?.let { queryParams.put("userComment", listOf(it.toString())) } + this.userLat?.let { queryParams.put("userLat", listOf(it.toString())) } + this.userLocationAccuracy?.let { + queryParams.put("userLocationAccuracy", listOf(it.toString())) + } + this.userLon?.let { queryParams.put("userLon", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } fun getPathParam(index: Int): String { @@ -60,25 +70,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ReportProblemWithStopRetrieveParams && this.stopId == other.stopId && this.code == other.code && this.userComment == other.userComment && this.userLat == other.userLat && this.userLocationAccuracy == other.userLocationAccuracy && this.userLon == other.userLon && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(stopId, code, userComment, userLat, userLocationAccuracy, userLon, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "ReportProblemWithStopRetrieveParams{stopId=$stopId, code=$code, userComment=$userComment, userLat=$userLat, userLocationAccuracy=$userLocationAccuracy, userLon=$userLon, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -86,8 +77,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [ReportProblemWithStopRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var stopId: String? = null private var code: Code? = null @@ -95,41 +87,76 @@ constructor( private var userLat: Double? = null private var userLocationAccuracy: Double? = null private var userLon: Double? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from( reportProblemWithStopRetrieveParams: ReportProblemWithStopRetrieveParams ) = apply { - this.stopId = reportProblemWithStopRetrieveParams.stopId - this.code = reportProblemWithStopRetrieveParams.code - this.userComment = reportProblemWithStopRetrieveParams.userComment - this.userLat = reportProblemWithStopRetrieveParams.userLat - this.userLocationAccuracy = reportProblemWithStopRetrieveParams.userLocationAccuracy - this.userLon = reportProblemWithStopRetrieveParams.userLon - additionalHeaders(reportProblemWithStopRetrieveParams.additionalHeaders) - additionalQueryParams(reportProblemWithStopRetrieveParams.additionalQueryParams) + stopId = reportProblemWithStopRetrieveParams.stopId + code = reportProblemWithStopRetrieveParams.code + userComment = reportProblemWithStopRetrieveParams.userComment + userLat = reportProblemWithStopRetrieveParams.userLat + userLocationAccuracy = reportProblemWithStopRetrieveParams.userLocationAccuracy + userLon = reportProblemWithStopRetrieveParams.userLon + additionalHeaders = reportProblemWithStopRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = + reportProblemWithStopRetrieveParams.additionalQueryParams.toBuilder() } fun stopId(stopId: String) = apply { this.stopId = stopId } /** A string code identifying the nature of the problem */ - fun code(code: Code) = apply { this.code = code } + fun code(code: Code?) = apply { this.code = code } + + /** A string code identifying the nature of the problem */ + fun code(code: Optional) = code(code.orElse(null)) + + /** Additional comment text supplied by the user describing the problem */ + fun userComment(userComment: String?) = apply { this.userComment = userComment } /** Additional comment text supplied by the user describing the problem */ - fun userComment(userComment: String) = apply { this.userComment = userComment } + fun userComment(userComment: Optional) = userComment(userComment.orElse(null)) + + /** The reporting user’s current latitude */ + fun userLat(userLat: Double?) = apply { this.userLat = userLat } /** The reporting user’s current latitude */ - fun userLat(userLat: Double) = apply { this.userLat = userLat } + fun userLat(userLat: Double) = userLat(userLat as Double?) + + /** The reporting user’s current latitude */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun userLat(userLat: Optional) = userLat(userLat.orElse(null) as Double?) /** The reporting user’s location accuracy, in meters */ - fun userLocationAccuracy(userLocationAccuracy: Double) = apply { + fun userLocationAccuracy(userLocationAccuracy: Double?) = apply { this.userLocationAccuracy = userLocationAccuracy } + /** The reporting user’s location accuracy, in meters */ + fun userLocationAccuracy(userLocationAccuracy: Double) = + userLocationAccuracy(userLocationAccuracy as Double?) + + /** The reporting user’s location accuracy, in meters */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun userLocationAccuracy(userLocationAccuracy: Optional) = + userLocationAccuracy(userLocationAccuracy.orElse(null) as Double?) + + /** The reporting user’s current longitude */ + fun userLon(userLon: Double?) = apply { this.userLon = userLon } + /** The reporting user’s current longitude */ - fun userLon(userLon: Double) = apply { this.userLon = userLon } + fun userLon(userLon: Double) = userLon(userLon as Double?) + + /** The reporting user’s current longitude */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun userLon(userLon: Optional) = userLon(userLon.orElse(null) as Double?) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -141,29 +168,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -176,89 +216,87 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): ReportProblemWithStopRetrieveParams = ReportProblemWithStopRetrieveParams( - checkNotNull(stopId) { "`stopId` is required but was not set" }, + checkRequired("stopId", stopId), code, userComment, userLat, userLocationAccuracy, userLon, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + /** A string code identifying the nature of the problem */ class Code @JsonCreator private constructor( private val value: JsonField, ) : Enum { + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Code && this.value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - companion object { - @JvmField val STOP_NAME_WRONG = Code(JsonField.of("stop_name_wrong")) + @JvmField val STOP_NAME_WRONG = of("stop_name_wrong") - @JvmField val STOP_NUMBER_WRONG = Code(JsonField.of("stop_number_wrong")) + @JvmField val STOP_NUMBER_WRONG = of("stop_number_wrong") - @JvmField val STOP_LOCATION_WRONG = Code(JsonField.of("stop_location_wrong")) + @JvmField val STOP_LOCATION_WRONG = of("stop_location_wrong") - @JvmField val ROUTE_OR_TRIP_MISSING = Code(JsonField.of("route_or_trip_missing")) + @JvmField val ROUTE_OR_TRIP_MISSING = of("route_or_trip_missing") - @JvmField val OTHER = Code(JsonField.of("other")) + @JvmField val OTHER = of("other") @JvmStatic fun of(value: String) = Code(JsonField.of(value)) } + /** An enum containing [Code]'s known values. */ enum class Known { STOP_NAME_WRONG, STOP_NUMBER_WRONG, @@ -267,15 +305,32 @@ constructor( OTHER, } + /** + * An enum containing [Code]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Code] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ enum class Value { STOP_NAME_WRONG, STOP_NUMBER_WRONG, STOP_LOCATION_WRONG, ROUTE_OR_TRIP_MISSING, OTHER, + /** An enum member indicating that [Code] was instantiated with an unknown value. */ _UNKNOWN, } + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ fun value(): Value = when (this) { STOP_NAME_WRONG -> Value.STOP_NAME_WRONG @@ -286,6 +341,15 @@ constructor( else -> Value._UNKNOWN } + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OnebusawaySdkInvalidDataException if this class instance's value is a not a known + * member. + */ fun known(): Known = when (this) { STOP_NAME_WRONG -> Known.STOP_NAME_WRONG @@ -297,5 +361,30 @@ constructor( } fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Code && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ReportProblemWithStopRetrieveParams && stopId == other.stopId && code == other.code && userComment == other.userComment && userLat == other.userLat && userLocationAccuracy == other.userLocationAccuracy && userLon == other.userLon && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(stopId, code, userComment, userLat, userLocationAccuracy, userLon, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "ReportProblemWithStopRetrieveParams{stopId=$stopId, code=$code, userComment=$userComment, userLat=$userLat, userLocationAccuracy=$userLocationAccuracy, userLon=$userLon, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ReportProblemWithTripRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ReportProblemWithTripRetrieveParams.kt index 8767e9b..213acd1 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ReportProblemWithTripRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ReportProblemWithTripRetrieveParams.kt @@ -3,20 +3,20 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonCreator -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import java.util.Optional import org.onebusaway.core.Enum import org.onebusaway.core.JsonField -import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams import org.onebusaway.errors.OnebusawaySdkInvalidDataException -import org.onebusaway.models.* +/** Submit a user-generated problem report for a particular trip. */ class ReportProblemWithTripRetrieveParams -constructor( +private constructor( private val tripId: String, private val code: Code?, private val serviceDate: Long?, @@ -28,49 +28,64 @@ constructor( private val userOnVehicle: Boolean?, private val userVehicleNumber: String?, private val vehicleId: String?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun tripId(): String = tripId + /** A string code identifying the nature of the problem */ fun code(): Optional = Optional.ofNullable(code) + /** The service date of the trip */ fun serviceDate(): Optional = Optional.ofNullable(serviceDate) + /** A stop ID indicating where the user is experiencing the problem */ fun stopId(): Optional = Optional.ofNullable(stopId) + /** Additional comment text supplied by the user describing the problem */ fun userComment(): Optional = Optional.ofNullable(userComment) + /** The reporting user’s current latitude */ fun userLat(): Optional = Optional.ofNullable(userLat) + /** The reporting user’s location accuracy, in meters */ fun userLocationAccuracy(): Optional = Optional.ofNullable(userLocationAccuracy) + /** The reporting user’s current longitude */ fun userLon(): Optional = Optional.ofNullable(userLon) + /** Indicator if the user is on the transit vehicle experiencing the problem */ fun userOnVehicle(): Optional = Optional.ofNullable(userOnVehicle) + /** The vehicle number, as reported by the user */ fun userVehicleNumber(): Optional = Optional.ofNullable(userVehicleNumber) + /** The vehicle actively serving the trip */ fun vehicleId(): Optional = Optional.ofNullable(vehicleId) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.code?.let { params.put("code", listOf(it.toString())) } - this.serviceDate?.let { params.put("serviceDate", listOf(it.toString())) } - this.stopId?.let { params.put("stopID", listOf(it.toString())) } - this.userComment?.let { params.put("userComment", listOf(it.toString())) } - this.userLat?.let { params.put("userLat", listOf(it.toString())) } - this.userLocationAccuracy?.let { params.put("userLocationAccuracy", listOf(it.toString())) } - this.userLon?.let { params.put("userLon", listOf(it.toString())) } - this.userOnVehicle?.let { params.put("userOnVehicle", listOf(it.toString())) } - this.userVehicleNumber?.let { params.put("userVehicleNumber", listOf(it.toString())) } - this.vehicleId?.let { params.put("vehicleID", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.code?.let { queryParams.put("code", listOf(it.toString())) } + this.serviceDate?.let { queryParams.put("serviceDate", listOf(it.toString())) } + this.stopId?.let { queryParams.put("stopID", listOf(it.toString())) } + this.userComment?.let { queryParams.put("userComment", listOf(it.toString())) } + this.userLat?.let { queryParams.put("userLat", listOf(it.toString())) } + this.userLocationAccuracy?.let { + queryParams.put("userLocationAccuracy", listOf(it.toString())) + } + this.userLon?.let { queryParams.put("userLon", listOf(it.toString())) } + this.userOnVehicle?.let { queryParams.put("userOnVehicle", listOf(it.toString())) } + this.userVehicleNumber?.let { queryParams.put("userVehicleNumber", listOf(it.toString())) } + this.vehicleId?.let { queryParams.put("vehicleID", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } fun getPathParam(index: Int): String { @@ -80,25 +95,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ReportProblemWithTripRetrieveParams && this.tripId == other.tripId && this.code == other.code && this.serviceDate == other.serviceDate && this.stopId == other.stopId && this.userComment == other.userComment && this.userLat == other.userLat && this.userLocationAccuracy == other.userLocationAccuracy && this.userLon == other.userLon && this.userOnVehicle == other.userOnVehicle && this.userVehicleNumber == other.userVehicleNumber && this.vehicleId == other.vehicleId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(tripId, code, serviceDate, stopId, userComment, userLat, userLocationAccuracy, userLon, userOnVehicle, userVehicleNumber, vehicleId, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "ReportProblemWithTripRetrieveParams{tripId=$tripId, code=$code, serviceDate=$serviceDate, stopId=$stopId, userComment=$userComment, userLat=$userLat, userLocationAccuracy=$userLocationAccuracy, userLon=$userLon, userOnVehicle=$userOnVehicle, userVehicleNumber=$userVehicleNumber, vehicleId=$vehicleId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -106,8 +102,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [ReportProblemWithTripRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var tripId: String? = null private var code: Code? = null @@ -120,63 +117,124 @@ constructor( private var userOnVehicle: Boolean? = null private var userVehicleNumber: String? = null private var vehicleId: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from( reportProblemWithTripRetrieveParams: ReportProblemWithTripRetrieveParams ) = apply { - this.tripId = reportProblemWithTripRetrieveParams.tripId - this.code = reportProblemWithTripRetrieveParams.code - this.serviceDate = reportProblemWithTripRetrieveParams.serviceDate - this.stopId = reportProblemWithTripRetrieveParams.stopId - this.userComment = reportProblemWithTripRetrieveParams.userComment - this.userLat = reportProblemWithTripRetrieveParams.userLat - this.userLocationAccuracy = reportProblemWithTripRetrieveParams.userLocationAccuracy - this.userLon = reportProblemWithTripRetrieveParams.userLon - this.userOnVehicle = reportProblemWithTripRetrieveParams.userOnVehicle - this.userVehicleNumber = reportProblemWithTripRetrieveParams.userVehicleNumber - this.vehicleId = reportProblemWithTripRetrieveParams.vehicleId - additionalHeaders(reportProblemWithTripRetrieveParams.additionalHeaders) - additionalQueryParams(reportProblemWithTripRetrieveParams.additionalQueryParams) + tripId = reportProblemWithTripRetrieveParams.tripId + code = reportProblemWithTripRetrieveParams.code + serviceDate = reportProblemWithTripRetrieveParams.serviceDate + stopId = reportProblemWithTripRetrieveParams.stopId + userComment = reportProblemWithTripRetrieveParams.userComment + userLat = reportProblemWithTripRetrieveParams.userLat + userLocationAccuracy = reportProblemWithTripRetrieveParams.userLocationAccuracy + userLon = reportProblemWithTripRetrieveParams.userLon + userOnVehicle = reportProblemWithTripRetrieveParams.userOnVehicle + userVehicleNumber = reportProblemWithTripRetrieveParams.userVehicleNumber + vehicleId = reportProblemWithTripRetrieveParams.vehicleId + additionalHeaders = reportProblemWithTripRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = + reportProblemWithTripRetrieveParams.additionalQueryParams.toBuilder() } fun tripId(tripId: String) = apply { this.tripId = tripId } /** A string code identifying the nature of the problem */ - fun code(code: Code) = apply { this.code = code } + fun code(code: Code?) = apply { this.code = code } + + /** A string code identifying the nature of the problem */ + fun code(code: Optional) = code(code.orElse(null)) + + /** The service date of the trip */ + fun serviceDate(serviceDate: Long?) = apply { this.serviceDate = serviceDate } /** The service date of the trip */ - fun serviceDate(serviceDate: Long) = apply { this.serviceDate = serviceDate } + fun serviceDate(serviceDate: Long) = serviceDate(serviceDate as Long?) + + /** The service date of the trip */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun serviceDate(serviceDate: Optional) = + serviceDate(serviceDate.orElse(null) as Long?) /** A stop ID indicating where the user is experiencing the problem */ - fun stopId(stopId: String) = apply { this.stopId = stopId } + fun stopId(stopId: String?) = apply { this.stopId = stopId } + + /** A stop ID indicating where the user is experiencing the problem */ + fun stopId(stopId: Optional) = stopId(stopId.orElse(null)) + + /** Additional comment text supplied by the user describing the problem */ + fun userComment(userComment: String?) = apply { this.userComment = userComment } /** Additional comment text supplied by the user describing the problem */ - fun userComment(userComment: String) = apply { this.userComment = userComment } + fun userComment(userComment: Optional) = userComment(userComment.orElse(null)) + + /** The reporting user’s current latitude */ + fun userLat(userLat: Double?) = apply { this.userLat = userLat } + + /** The reporting user’s current latitude */ + fun userLat(userLat: Double) = userLat(userLat as Double?) /** The reporting user’s current latitude */ - fun userLat(userLat: Double) = apply { this.userLat = userLat } + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun userLat(userLat: Optional) = userLat(userLat.orElse(null) as Double?) /** The reporting user’s location accuracy, in meters */ - fun userLocationAccuracy(userLocationAccuracy: Double) = apply { + fun userLocationAccuracy(userLocationAccuracy: Double?) = apply { this.userLocationAccuracy = userLocationAccuracy } + /** The reporting user’s location accuracy, in meters */ + fun userLocationAccuracy(userLocationAccuracy: Double) = + userLocationAccuracy(userLocationAccuracy as Double?) + + /** The reporting user’s location accuracy, in meters */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun userLocationAccuracy(userLocationAccuracy: Optional) = + userLocationAccuracy(userLocationAccuracy.orElse(null) as Double?) + + /** The reporting user’s current longitude */ + fun userLon(userLon: Double?) = apply { this.userLon = userLon } + + /** The reporting user’s current longitude */ + fun userLon(userLon: Double) = userLon(userLon as Double?) + /** The reporting user’s current longitude */ - fun userLon(userLon: Double) = apply { this.userLon = userLon } + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun userLon(userLon: Optional) = userLon(userLon.orElse(null) as Double?) + + /** Indicator if the user is on the transit vehicle experiencing the problem */ + fun userOnVehicle(userOnVehicle: Boolean?) = apply { this.userOnVehicle = userOnVehicle } + + /** Indicator if the user is on the transit vehicle experiencing the problem */ + fun userOnVehicle(userOnVehicle: Boolean) = userOnVehicle(userOnVehicle as Boolean?) /** Indicator if the user is on the transit vehicle experiencing the problem */ - fun userOnVehicle(userOnVehicle: Boolean) = apply { this.userOnVehicle = userOnVehicle } + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun userOnVehicle(userOnVehicle: Optional) = + userOnVehicle(userOnVehicle.orElse(null) as Boolean?) /** The vehicle number, as reported by the user */ - fun userVehicleNumber(userVehicleNumber: String) = apply { + fun userVehicleNumber(userVehicleNumber: String?) = apply { this.userVehicleNumber = userVehicleNumber } + /** The vehicle number, as reported by the user */ + fun userVehicleNumber(userVehicleNumber: Optional) = + userVehicleNumber(userVehicleNumber.orElse(null)) + /** The vehicle actively serving the trip */ - fun vehicleId(vehicleId: String) = apply { this.vehicleId = vehicleId } + fun vehicleId(vehicleId: String?) = apply { this.vehicleId = vehicleId } + + /** The vehicle actively serving the trip */ + fun vehicleId(vehicleId: Optional) = vehicleId(vehicleId.orElse(null)) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -188,29 +246,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -223,38 +294,44 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): ReportProblemWithTripRetrieveParams = ReportProblemWithTripRetrieveParams( - checkNotNull(tripId) { "`tripId` is required but was not set" }, + checkRequired("tripId", tripId), code, serviceDate, stopId, @@ -265,55 +342,46 @@ constructor( userOnVehicle, userVehicleNumber, vehicleId, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + /** A string code identifying the nature of the problem */ class Code @JsonCreator private constructor( private val value: JsonField, ) : Enum { + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is Code && this.value == other.value /* spotless:on */ - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - companion object { - @JvmField val VEHICLE_NEVER_CAME = Code(JsonField.of("vehicle_never_came")) + @JvmField val VEHICLE_NEVER_CAME = of("vehicle_never_came") - @JvmField val VEHICLE_CAME_EARLY = Code(JsonField.of("vehicle_came_early")) + @JvmField val VEHICLE_CAME_EARLY = of("vehicle_came_early") - @JvmField val VEHICLE_CAME_LATE = Code(JsonField.of("vehicle_came_late")) + @JvmField val VEHICLE_CAME_LATE = of("vehicle_came_late") - @JvmField val WRONG_HEADSIGN = Code(JsonField.of("wrong_headsign")) + @JvmField val WRONG_HEADSIGN = of("wrong_headsign") - @JvmField - val VEHICLE_DOES_NOT_STOP_HERE = Code(JsonField.of("vehicle_does_not_stop_here")) + @JvmField val VEHICLE_DOES_NOT_STOP_HERE = of("vehicle_does_not_stop_here") - @JvmField val OTHER = Code(JsonField.of("other")) + @JvmField val OTHER = of("other") @JvmStatic fun of(value: String) = Code(JsonField.of(value)) } + /** An enum containing [Code]'s known values. */ enum class Known { VEHICLE_NEVER_CAME, VEHICLE_CAME_EARLY, @@ -323,6 +391,15 @@ constructor( OTHER, } + /** + * An enum containing [Code]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Code] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ enum class Value { VEHICLE_NEVER_CAME, VEHICLE_CAME_EARLY, @@ -330,9 +407,17 @@ constructor( WRONG_HEADSIGN, VEHICLE_DOES_NOT_STOP_HERE, OTHER, + /** An enum member indicating that [Code] was instantiated with an unknown value. */ _UNKNOWN, } + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ fun value(): Value = when (this) { VEHICLE_NEVER_CAME -> Value.VEHICLE_NEVER_CAME @@ -344,6 +429,15 @@ constructor( else -> Value._UNKNOWN } + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws OnebusawaySdkInvalidDataException if this class instance's value is a not a known + * member. + */ fun known(): Known = when (this) { VEHICLE_NEVER_CAME -> Known.VEHICLE_NEVER_CAME @@ -356,5 +450,30 @@ constructor( } fun asString(): String = _value().asStringOrThrow() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is Code && value == other.value /* spotless:on */ + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ReportProblemWithTripRetrieveParams && tripId == other.tripId && code == other.code && serviceDate == other.serviceDate && stopId == other.stopId && userComment == other.userComment && userLat == other.userLat && userLocationAccuracy == other.userLocationAccuracy && userLon == other.userLon && userOnVehicle == other.userOnVehicle && userVehicleNumber == other.userVehicleNumber && vehicleId == other.vehicleId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(tripId, code, serviceDate, stopId, userComment, userLat, userLocationAccuracy, userLon, userOnVehicle, userVehicleNumber, vehicleId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "ReportProblemWithTripRetrieveParams{tripId=$tripId, code=$code, serviceDate=$serviceDate, stopId=$stopId, userComment=$userComment, userLat=$userLat, userLocationAccuracy=$userLocationAccuracy, userLon=$userLon, userOnVehicle=$userOnVehicle, userVehicleNumber=$userVehicleNumber, vehicleId=$vehicleId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ResponseWrapper.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ResponseWrapper.kt index dd7c5c0..2ca005b 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ResponseWrapper.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ResponseWrapper.kt @@ -4,29 +4,33 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import org.onebusaway.core.ExcludeMissing import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = ResponseWrapper.Builder::class) @NoAutoDetect class ResponseWrapper +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -35,26 +39,30 @@ private constructor( fun version(): Long = version.getRequired("version") - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ResponseWrapper = apply { - if (!validated) { - code() - currentTime() - text() - version() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + validated = true } fun toBuilder() = Builder().from(this) @@ -64,67 +72,65 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [ResponseWrapper]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(responseWrapper: ResponseWrapper) = apply { - this.code = responseWrapper.code - this.currentTime = responseWrapper.currentTime - this.text = responseWrapper.text - this.version = responseWrapper.version - additionalProperties(responseWrapper.additionalProperties) + code = responseWrapper.code + currentTime = responseWrapper.currentTime + text = responseWrapper.text + version = responseWrapper.version + additionalProperties = responseWrapper.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): ResponseWrapper = ResponseWrapper( - code, - currentTime, - text, - version, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), additionalProperties.toImmutable(), ) } @@ -134,17 +140,14 @@ private constructor( return true } - return /* spotless:off */ other is ResponseWrapper && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is ResponseWrapper && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "ResponseWrapper{code=$code, currentTime=$currentTime, text=$text, version=$version, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteIdsForAgencyListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteIdsForAgencyListParams.kt index c56d127..df3aead 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteIdsForAgencyListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteIdsForAgencyListParams.kt @@ -2,25 +2,30 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Get route IDs for a specific agency */ class RouteIdsForAgencyListParams -constructor( +private constructor( private val agencyId: String, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun agencyId(): String = agencyId - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -29,25 +34,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is RouteIdsForAgencyListParams && this.agencyId == other.agencyId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(agencyId, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "RouteIdsForAgencyListParams{agencyId=$agencyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -55,22 +41,28 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [RouteIdsForAgencyListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var agencyId: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(routeIdsForAgencyListParams: RouteIdsForAgencyListParams) = apply { - this.agencyId = routeIdsForAgencyListParams.agencyId - additionalHeaders(routeIdsForAgencyListParams.additionalHeaders) - additionalQueryParams(routeIdsForAgencyListParams.additionalQueryParams) + agencyId = routeIdsForAgencyListParams.agencyId + additionalHeaders = routeIdsForAgencyListParams.additionalHeaders.toBuilder() + additionalQueryParams = routeIdsForAgencyListParams.additionalQueryParams.toBuilder() } fun agencyId(agencyId: String) = apply { this.agencyId = agencyId } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -81,29 +73,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -116,46 +121,59 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): RouteIdsForAgencyListParams = RouteIdsForAgencyListParams( - checkNotNull(agencyId) { "`agencyId` is required but was not set" }, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + checkRequired("agencyId", agencyId), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is RouteIdsForAgencyListParams && agencyId == other.agencyId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(agencyId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "RouteIdsForAgencyListParams{agencyId=$agencyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteIdsForAgencyListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteIdsForAgencyListResponse.kt index ba35c08..dd63e25 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteIdsForAgencyListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteIdsForAgencyListResponse.kt @@ -4,30 +4,34 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import org.onebusaway.core.ExcludeMissing import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = RouteIdsForAgencyListResponse.Builder::class) @NoAutoDetect class RouteIdsForAgencyListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -38,37 +42,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): RouteIdsForAgencyListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -78,115 +86,124 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [RouteIdsForAgencyListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(routeIdsForAgencyListResponse: RouteIdsForAgencyListResponse) = apply { - this.code = routeIdsForAgencyListResponse.code - this.currentTime = routeIdsForAgencyListResponse.currentTime - this.text = routeIdsForAgencyListResponse.text - this.version = routeIdsForAgencyListResponse.version - this.data = routeIdsForAgencyListResponse.data - additionalProperties(routeIdsForAgencyListResponse.additionalProperties) + code = routeIdsForAgencyListResponse.code + currentTime = routeIdsForAgencyListResponse.currentTime + text = routeIdsForAgencyListResponse.text + version = routeIdsForAgencyListResponse.version + data = routeIdsForAgencyListResponse.data + additionalProperties = routeIdsForAgencyListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): RouteIdsForAgencyListResponse = RouteIdsForAgencyListResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val limitExceeded: JsonField, - private val list: JsonField>, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("limitExceeded") + @ExcludeMissing + private val limitExceeded: JsonField = JsonMissing.of(), + @JsonProperty("list") + @ExcludeMissing + private val list: JsonField> = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") fun list(): List = list.getRequired("list") fun references(): References = references.getRequired("references") - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + @JsonProperty("limitExceeded") + @ExcludeMissing + fun _limitExceeded(): JsonField = limitExceeded - @JsonProperty("list") @ExcludeMissing fun _list() = list + @JsonProperty("list") @ExcludeMissing fun _list(): JsonField> = list - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - limitExceeded() - list() - references().validate() - validated = true + if (validated) { + return@apply } + + limitExceeded() + list() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -196,62 +213,77 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var limitExceeded: JsonField = JsonMissing.of() - private var list: JsonField> = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var limitExceeded: JsonField? = null + private var list: JsonField>? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.limitExceeded = data.limitExceeded - this.list = data.list - this.references = data.references - additionalProperties(data.additionalProperties) + limitExceeded = data.limitExceeded + list = data.list.map { it.toMutableList() } + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) - @JsonProperty("limitExceeded") - @ExcludeMissing fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } fun list(list: List) = list(JsonField.of(list)) - @JsonProperty("list") - @ExcludeMissing - fun list(list: JsonField>) = apply { this.list = list } + fun list(list: JsonField>) = apply { + this.list = list.map { it.toMutableList() } + } + + fun addList(list: String) = apply { + this.list = + (this.list ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(list) + } + } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -261,17 +293,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.limitExceeded == other.limitExceeded && this.list == other.list && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && list == other.list && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(limitExceeded, list, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{limitExceeded=$limitExceeded, list=$list, references=$references, additionalProperties=$additionalProperties}" @@ -282,17 +311,14 @@ private constructor( return true } - return /* spotless:off */ other is RouteIdsForAgencyListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is RouteIdsForAgencyListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "RouteIdsForAgencyListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteRetrieveParams.kt index a37fb4d..3f67683 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteRetrieveParams.kt @@ -2,25 +2,30 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Retrieve information for a specific route identified by its unique ID. */ class RouteRetrieveParams -constructor( +private constructor( private val routeId: String, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun routeId(): String = routeId - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -29,25 +34,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is RouteRetrieveParams && this.routeId == other.routeId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(routeId, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "RouteRetrieveParams{routeId=$routeId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -55,22 +41,28 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [RouteRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var routeId: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(routeRetrieveParams: RouteRetrieveParams) = apply { - this.routeId = routeRetrieveParams.routeId - additionalHeaders(routeRetrieveParams.additionalHeaders) - additionalQueryParams(routeRetrieveParams.additionalQueryParams) + routeId = routeRetrieveParams.routeId + additionalHeaders = routeRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = routeRetrieveParams.additionalQueryParams.toBuilder() } fun routeId(routeId: String) = apply { this.routeId = routeId } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -81,29 +73,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -116,46 +121,59 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): RouteRetrieveParams = RouteRetrieveParams( - checkNotNull(routeId) { "`routeId` is required but was not set" }, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + checkRequired("routeId", routeId), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is RouteRetrieveParams && routeId == other.routeId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(routeId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "RouteRetrieveParams{routeId=$routeId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteRetrieveResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteRetrieveResponse.kt index 4b903c4..0f81450 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteRetrieveResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RouteRetrieveResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = RouteRetrieveResponse.Builder::class) @NoAutoDetect class RouteRetrieveResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): RouteRetrieveResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,109 +87,114 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [RouteRetrieveResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(routeRetrieveResponse: RouteRetrieveResponse) = apply { - this.code = routeRetrieveResponse.code - this.currentTime = routeRetrieveResponse.currentTime - this.text = routeRetrieveResponse.text - this.version = routeRetrieveResponse.version - this.data = routeRetrieveResponse.data - additionalProperties(routeRetrieveResponse.additionalProperties) + code = routeRetrieveResponse.code + currentTime = routeRetrieveResponse.currentTime + text = routeRetrieveResponse.text + version = routeRetrieveResponse.version + data = routeRetrieveResponse.data + additionalProperties = routeRetrieveResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): RouteRetrieveResponse = RouteRetrieveResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") fun references(): References = references.getRequired("references") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -191,83 +204,106 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val agencyId: JsonField, - private val color: JsonField, - private val description: JsonField, - private val id: JsonField, - private val longName: JsonField, - private val nullSafeShortName: JsonField, - private val shortName: JsonField, - private val textColor: JsonField, - private val type: JsonField, - private val url: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("agencyId") + @ExcludeMissing + private val agencyId: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + private val type: JsonField = JsonMissing.of(), + @JsonProperty("color") + @ExcludeMissing + private val color: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + private val description: JsonField = JsonMissing.of(), + @JsonProperty("longName") + @ExcludeMissing + private val longName: JsonField = JsonMissing.of(), + @JsonProperty("nullSafeShortName") + @ExcludeMissing + private val nullSafeShortName: JsonField = JsonMissing.of(), + @JsonProperty("shortName") + @ExcludeMissing + private val shortName: JsonField = JsonMissing.of(), + @JsonProperty("textColor") + @ExcludeMissing + private val textColor: JsonField = JsonMissing.of(), + @JsonProperty("url") + @ExcludeMissing + private val url: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun id(): String = id.getRequired("id") fun agencyId(): String = agencyId.getRequired("agencyId") + fun type(): Long = type.getRequired("type") + fun color(): Optional = Optional.ofNullable(color.getNullable("color")) fun description(): Optional = Optional.ofNullable(description.getNullable("description")) - fun id(): String = id.getRequired("id") - fun longName(): Optional = Optional.ofNullable(longName.getNullable("longName")) fun nullSafeShortName(): Optional = @@ -279,50 +315,58 @@ private constructor( fun textColor(): Optional = Optional.ofNullable(textColor.getNullable("textColor")) - fun type(): Long = type.getRequired("type") - fun url(): Optional = Optional.ofNullable(url.getNullable("url")) - @JsonProperty("agencyId") @ExcludeMissing fun _agencyId() = agencyId + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("color") @ExcludeMissing fun _color() = color + @JsonProperty("agencyId") @ExcludeMissing fun _agencyId(): JsonField = agencyId - @JsonProperty("description") @ExcludeMissing fun _description() = description + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("color") @ExcludeMissing fun _color(): JsonField = color - @JsonProperty("longName") @ExcludeMissing fun _longName() = longName + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + @JsonProperty("longName") @ExcludeMissing fun _longName(): JsonField = longName @JsonProperty("nullSafeShortName") @ExcludeMissing - fun _nullSafeShortName() = nullSafeShortName - - @JsonProperty("shortName") @ExcludeMissing fun _shortName() = shortName + fun _nullSafeShortName(): JsonField = nullSafeShortName - @JsonProperty("textColor") @ExcludeMissing fun _textColor() = textColor + @JsonProperty("shortName") + @ExcludeMissing + fun _shortName(): JsonField = shortName - @JsonProperty("type") @ExcludeMissing fun _type() = type + @JsonProperty("textColor") + @ExcludeMissing + fun _textColor(): JsonField = textColor - @JsonProperty("url") @ExcludeMissing fun _url() = url + @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - agencyId() - color() - description() - id() - longName() - nullSafeShortName() - shortName() - textColor() - type() - url() - validated = true + if (validated) { + return@apply } + + id() + agencyId() + type() + color() + description() + longName() + nullSafeShortName() + shortName() + textColor() + url() + validated = true } fun toBuilder() = Builder().from(this) @@ -332,108 +376,88 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Entry]. */ + class Builder internal constructor() { - private var agencyId: JsonField = JsonMissing.of() + private var id: JsonField? = null + private var agencyId: JsonField? = null + private var type: JsonField? = null private var color: JsonField = JsonMissing.of() private var description: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() private var longName: JsonField = JsonMissing.of() private var nullSafeShortName: JsonField = JsonMissing.of() private var shortName: JsonField = JsonMissing.of() private var textColor: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var url: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(entry: Entry) = apply { - this.agencyId = entry.agencyId - this.color = entry.color - this.description = entry.description - this.id = entry.id - this.longName = entry.longName - this.nullSafeShortName = entry.nullSafeShortName - this.shortName = entry.shortName - this.textColor = entry.textColor - this.type = entry.type - this.url = entry.url - additionalProperties(entry.additionalProperties) + id = entry.id + agencyId = entry.agencyId + type = entry.type + color = entry.color + description = entry.description + longName = entry.longName + nullSafeShortName = entry.nullSafeShortName + shortName = entry.shortName + textColor = entry.textColor + url = entry.url + additionalProperties = entry.additionalProperties.toMutableMap() } + fun id(id: String) = id(JsonField.of(id)) + + fun id(id: JsonField) = apply { this.id = id } + fun agencyId(agencyId: String) = agencyId(JsonField.of(agencyId)) - @JsonProperty("agencyId") - @ExcludeMissing fun agencyId(agencyId: JsonField) = apply { this.agencyId = agencyId } + fun type(type: Long) = type(JsonField.of(type)) + + fun type(type: JsonField) = apply { this.type = type } + fun color(color: String) = color(JsonField.of(color)) - @JsonProperty("color") - @ExcludeMissing fun color(color: JsonField) = apply { this.color = color } fun description(description: String) = description(JsonField.of(description)) - @JsonProperty("description") - @ExcludeMissing fun description(description: JsonField) = apply { this.description = description } - fun id(id: String) = id(JsonField.of(id)) - - @JsonProperty("id") - @ExcludeMissing - fun id(id: JsonField) = apply { this.id = id } - fun longName(longName: String) = longName(JsonField.of(longName)) - @JsonProperty("longName") - @ExcludeMissing fun longName(longName: JsonField) = apply { this.longName = longName } fun nullSafeShortName(nullSafeShortName: String) = nullSafeShortName(JsonField.of(nullSafeShortName)) - @JsonProperty("nullSafeShortName") - @ExcludeMissing fun nullSafeShortName(nullSafeShortName: JsonField) = apply { this.nullSafeShortName = nullSafeShortName } fun shortName(shortName: String) = shortName(JsonField.of(shortName)) - @JsonProperty("shortName") - @ExcludeMissing fun shortName(shortName: JsonField) = apply { this.shortName = shortName } fun textColor(textColor: String) = textColor(JsonField.of(textColor)) - @JsonProperty("textColor") - @ExcludeMissing fun textColor(textColor: JsonField) = apply { this.textColor = textColor } - fun type(type: Long) = type(JsonField.of(type)) - - @JsonProperty("type") - @ExcludeMissing - fun type(type: JsonField) = apply { this.type = type } - fun url(url: String) = url(JsonField.of(url)) - @JsonProperty("url") - @ExcludeMissing fun url(url: JsonField) = apply { this.url = url } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -441,17 +465,25 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( - agencyId, + checkRequired("id", id), + checkRequired("agencyId", agencyId), + checkRequired("type", type), color, description, - id, longName, nullSafeShortName, shortName, textColor, - type, url, additionalProperties.toImmutable(), ) @@ -462,20 +494,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.agencyId == other.agencyId && this.color == other.color && this.description == other.description && this.id == other.id && this.longName == other.longName && this.nullSafeShortName == other.nullSafeShortName && this.shortName == other.shortName && this.textColor == other.textColor && this.type == other.type && this.url == other.url && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && id == other.id && agencyId == other.agencyId && type == other.type && color == other.color && description == other.description && longName == other.longName && nullSafeShortName == other.nullSafeShortName && shortName == other.shortName && textColor == other.textColor && url == other.url && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, agencyId, type, color, description, longName, nullSafeShortName, shortName, textColor, url, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(agencyId, color, description, id, longName, nullSafeShortName, shortName, textColor, type, url, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Entry{agencyId=$agencyId, color=$color, description=$description, id=$id, longName=$longName, nullSafeShortName=$nullSafeShortName, shortName=$shortName, textColor=$textColor, type=$type, url=$url, additionalProperties=$additionalProperties}" + "Entry{id=$id, agencyId=$agencyId, type=$type, color=$color, description=$description, longName=$longName, nullSafeShortName=$nullSafeShortName, shortName=$shortName, textColor=$textColor, url=$url, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -483,17 +512,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, references=$references, additionalProperties=$additionalProperties}" @@ -504,17 +530,14 @@ private constructor( return true } - return /* spotless:off */ other is RouteRetrieveResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is RouteRetrieveResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "RouteRetrieveResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForAgencyListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForAgencyListParams.kt index 07bf4e9..1f6cb50 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForAgencyListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForAgencyListParams.kt @@ -2,25 +2,30 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Retrieve the list of all routes for a particular agency by id */ class RoutesForAgencyListParams -constructor( +private constructor( private val agencyId: String, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun agencyId(): String = agencyId - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -29,25 +34,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is RoutesForAgencyListParams && this.agencyId == other.agencyId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(agencyId, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "RoutesForAgencyListParams{agencyId=$agencyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -55,22 +41,28 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [RoutesForAgencyListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var agencyId: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(routesForAgencyListParams: RoutesForAgencyListParams) = apply { - this.agencyId = routesForAgencyListParams.agencyId - additionalHeaders(routesForAgencyListParams.additionalHeaders) - additionalQueryParams(routesForAgencyListParams.additionalQueryParams) + agencyId = routesForAgencyListParams.agencyId + additionalHeaders = routesForAgencyListParams.additionalHeaders.toBuilder() + additionalQueryParams = routesForAgencyListParams.additionalQueryParams.toBuilder() } fun agencyId(agencyId: String) = apply { this.agencyId = agencyId } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -81,29 +73,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -116,46 +121,59 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): RoutesForAgencyListParams = RoutesForAgencyListParams( - checkNotNull(agencyId) { "`agencyId` is required but was not set" }, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + checkRequired("agencyId", agencyId), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is RoutesForAgencyListParams && agencyId == other.agencyId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(agencyId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "RoutesForAgencyListParams{agencyId=$agencyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForAgencyListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForAgencyListResponse.kt index 7f3fa67..cf24f91 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForAgencyListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForAgencyListResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = RoutesForAgencyListResponse.Builder::class) @NoAutoDetect class RoutesForAgencyListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): RoutesForAgencyListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,115 +87,126 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [RoutesForAgencyListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(routesForAgencyListResponse: RoutesForAgencyListResponse) = apply { - this.code = routesForAgencyListResponse.code - this.currentTime = routesForAgencyListResponse.currentTime - this.text = routesForAgencyListResponse.text - this.version = routesForAgencyListResponse.version - this.data = routesForAgencyListResponse.data - additionalProperties(routesForAgencyListResponse.additionalProperties) + code = routesForAgencyListResponse.code + currentTime = routesForAgencyListResponse.currentTime + text = routesForAgencyListResponse.text + version = routesForAgencyListResponse.version + data = routesForAgencyListResponse.data + additionalProperties = routesForAgencyListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): RoutesForAgencyListResponse = RoutesForAgencyListResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val limitExceeded: JsonField, - private val list: JsonField>, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("limitExceeded") + @ExcludeMissing + private val limitExceeded: JsonField = JsonMissing.of(), + @JsonProperty("list") + @ExcludeMissing + private val list: JsonField> = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") fun list(): kotlin.collections.List = list.getRequired("list") fun references(): References = references.getRequired("references") - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + @JsonProperty("limitExceeded") + @ExcludeMissing + fun _limitExceeded(): JsonField = limitExceeded - @JsonProperty("list") @ExcludeMissing fun _list() = list + @JsonProperty("list") + @ExcludeMissing + fun _list(): JsonField> = list - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - limitExceeded() - list().forEach { it.validate() } - references().validate() - validated = true + if (validated) { + return@apply } + + limitExceeded() + list().forEach { it.validate() } + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -197,94 +216,130 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var limitExceeded: JsonField = JsonMissing.of() - private var list: JsonField> = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var limitExceeded: JsonField? = null + private var list: JsonField>? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.limitExceeded = data.limitExceeded - this.list = data.list - this.references = data.references - additionalProperties(data.additionalProperties) + limitExceeded = data.limitExceeded + list = data.list.map { it.toMutableList() } + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) - @JsonProperty("limitExceeded") - @ExcludeMissing fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } fun list(list: kotlin.collections.List) = list(JsonField.of(list)) - @JsonProperty("list") - @ExcludeMissing - fun list(list: JsonField>) = apply { this.list = list } + fun list(list: JsonField>) = apply { + this.list = list.map { it.toMutableList() } + } + + fun addList(list: List) = apply { + this.list = + (this.list ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(list) + } + } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = List.Builder::class) @NoAutoDetect class List + @JsonCreator private constructor( - private val agencyId: JsonField, - private val color: JsonField, - private val description: JsonField, - private val id: JsonField, - private val longName: JsonField, - private val nullSafeShortName: JsonField, - private val shortName: JsonField, - private val textColor: JsonField, - private val type: JsonField, - private val url: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("agencyId") + @ExcludeMissing + private val agencyId: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + private val type: JsonField = JsonMissing.of(), + @JsonProperty("color") + @ExcludeMissing + private val color: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + private val description: JsonField = JsonMissing.of(), + @JsonProperty("longName") + @ExcludeMissing + private val longName: JsonField = JsonMissing.of(), + @JsonProperty("nullSafeShortName") + @ExcludeMissing + private val nullSafeShortName: JsonField = JsonMissing.of(), + @JsonProperty("shortName") + @ExcludeMissing + private val shortName: JsonField = JsonMissing.of(), + @JsonProperty("textColor") + @ExcludeMissing + private val textColor: JsonField = JsonMissing.of(), + @JsonProperty("url") + @ExcludeMissing + private val url: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun id(): String = id.getRequired("id") fun agencyId(): String = agencyId.getRequired("agencyId") + fun type(): Long = type.getRequired("type") + fun color(): Optional = Optional.ofNullable(color.getNullable("color")) fun description(): Optional = Optional.ofNullable(description.getNullable("description")) - fun id(): String = id.getRequired("id") - fun longName(): Optional = Optional.ofNullable(longName.getNullable("longName")) fun nullSafeShortName(): Optional = @@ -296,50 +351,58 @@ private constructor( fun textColor(): Optional = Optional.ofNullable(textColor.getNullable("textColor")) - fun type(): Long = type.getRequired("type") - fun url(): Optional = Optional.ofNullable(url.getNullable("url")) - @JsonProperty("agencyId") @ExcludeMissing fun _agencyId() = agencyId + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("color") @ExcludeMissing fun _color() = color + @JsonProperty("agencyId") @ExcludeMissing fun _agencyId(): JsonField = agencyId - @JsonProperty("description") @ExcludeMissing fun _description() = description + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("color") @ExcludeMissing fun _color(): JsonField = color - @JsonProperty("longName") @ExcludeMissing fun _longName() = longName + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description + + @JsonProperty("longName") @ExcludeMissing fun _longName(): JsonField = longName @JsonProperty("nullSafeShortName") @ExcludeMissing - fun _nullSafeShortName() = nullSafeShortName + fun _nullSafeShortName(): JsonField = nullSafeShortName - @JsonProperty("shortName") @ExcludeMissing fun _shortName() = shortName - - @JsonProperty("textColor") @ExcludeMissing fun _textColor() = textColor + @JsonProperty("shortName") + @ExcludeMissing + fun _shortName(): JsonField = shortName - @JsonProperty("type") @ExcludeMissing fun _type() = type + @JsonProperty("textColor") + @ExcludeMissing + fun _textColor(): JsonField = textColor - @JsonProperty("url") @ExcludeMissing fun _url() = url + @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): List = apply { - if (!validated) { - agencyId() - color() - description() - id() - longName() - nullSafeShortName() - shortName() - textColor() - type() - url() - validated = true + if (validated) { + return@apply } + + id() + agencyId() + type() + color() + description() + longName() + nullSafeShortName() + shortName() + textColor() + url() + validated = true } fun toBuilder() = Builder().from(this) @@ -349,108 +412,88 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [List]. */ + class Builder internal constructor() { - private var agencyId: JsonField = JsonMissing.of() + private var id: JsonField? = null + private var agencyId: JsonField? = null + private var type: JsonField? = null private var color: JsonField = JsonMissing.of() private var description: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() private var longName: JsonField = JsonMissing.of() private var nullSafeShortName: JsonField = JsonMissing.of() private var shortName: JsonField = JsonMissing.of() private var textColor: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var url: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(list: List) = apply { - this.agencyId = list.agencyId - this.color = list.color - this.description = list.description - this.id = list.id - this.longName = list.longName - this.nullSafeShortName = list.nullSafeShortName - this.shortName = list.shortName - this.textColor = list.textColor - this.type = list.type - this.url = list.url - additionalProperties(list.additionalProperties) + id = list.id + agencyId = list.agencyId + type = list.type + color = list.color + description = list.description + longName = list.longName + nullSafeShortName = list.nullSafeShortName + shortName = list.shortName + textColor = list.textColor + url = list.url + additionalProperties = list.additionalProperties.toMutableMap() } + fun id(id: String) = id(JsonField.of(id)) + + fun id(id: JsonField) = apply { this.id = id } + fun agencyId(agencyId: String) = agencyId(JsonField.of(agencyId)) - @JsonProperty("agencyId") - @ExcludeMissing fun agencyId(agencyId: JsonField) = apply { this.agencyId = agencyId } + fun type(type: Long) = type(JsonField.of(type)) + + fun type(type: JsonField) = apply { this.type = type } + fun color(color: String) = color(JsonField.of(color)) - @JsonProperty("color") - @ExcludeMissing fun color(color: JsonField) = apply { this.color = color } fun description(description: String) = description(JsonField.of(description)) - @JsonProperty("description") - @ExcludeMissing fun description(description: JsonField) = apply { this.description = description } - fun id(id: String) = id(JsonField.of(id)) - - @JsonProperty("id") - @ExcludeMissing - fun id(id: JsonField) = apply { this.id = id } - fun longName(longName: String) = longName(JsonField.of(longName)) - @JsonProperty("longName") - @ExcludeMissing fun longName(longName: JsonField) = apply { this.longName = longName } fun nullSafeShortName(nullSafeShortName: String) = nullSafeShortName(JsonField.of(nullSafeShortName)) - @JsonProperty("nullSafeShortName") - @ExcludeMissing fun nullSafeShortName(nullSafeShortName: JsonField) = apply { this.nullSafeShortName = nullSafeShortName } fun shortName(shortName: String) = shortName(JsonField.of(shortName)) - @JsonProperty("shortName") - @ExcludeMissing fun shortName(shortName: JsonField) = apply { this.shortName = shortName } fun textColor(textColor: String) = textColor(JsonField.of(textColor)) - @JsonProperty("textColor") - @ExcludeMissing fun textColor(textColor: JsonField) = apply { this.textColor = textColor } - fun type(type: Long) = type(JsonField.of(type)) - - @JsonProperty("type") - @ExcludeMissing - fun type(type: JsonField) = apply { this.type = type } - fun url(url: String) = url(JsonField.of(url)) - @JsonProperty("url") - @ExcludeMissing fun url(url: JsonField) = apply { this.url = url } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -458,17 +501,25 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): List = List( - agencyId, + checkRequired("id", id), + checkRequired("agencyId", agencyId), + checkRequired("type", type), color, description, - id, longName, nullSafeShortName, shortName, textColor, - type, url, additionalProperties.toImmutable(), ) @@ -479,20 +530,17 @@ private constructor( return true } - return /* spotless:off */ other is List && this.agencyId == other.agencyId && this.color == other.color && this.description == other.description && this.id == other.id && this.longName == other.longName && this.nullSafeShortName == other.nullSafeShortName && this.shortName == other.shortName && this.textColor == other.textColor && this.type == other.type && this.url == other.url && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is List && id == other.id && agencyId == other.agencyId && type == other.type && color == other.color && description == other.description && longName == other.longName && nullSafeShortName == other.nullSafeShortName && shortName == other.shortName && textColor == other.textColor && url == other.url && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, agencyId, type, color, description, longName, nullSafeShortName, shortName, textColor, url, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(agencyId, color, description, id, longName, nullSafeShortName, shortName, textColor, type, url, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "List{agencyId=$agencyId, color=$color, description=$description, id=$id, longName=$longName, nullSafeShortName=$nullSafeShortName, shortName=$shortName, textColor=$textColor, type=$type, url=$url, additionalProperties=$additionalProperties}" + "List{id=$id, agencyId=$agencyId, type=$type, color=$color, description=$description, longName=$longName, nullSafeShortName=$nullSafeShortName, shortName=$shortName, textColor=$textColor, url=$url, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -500,17 +548,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.limitExceeded == other.limitExceeded && this.list == other.list && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && list == other.list && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(limitExceeded, list, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{limitExceeded=$limitExceeded, list=$list, references=$references, additionalProperties=$additionalProperties}" @@ -521,17 +566,14 @@ private constructor( return true } - return /* spotless:off */ other is RoutesForAgencyListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is RoutesForAgencyListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "RoutesForAgencyListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForLocationListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForLocationListParams.kt index fde116f..69461ad 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForLocationListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForLocationListParams.kt @@ -2,25 +2,26 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** routes-for-location */ class RoutesForLocationListParams -constructor( +private constructor( private val lat: Double, private val lon: Double, private val latSpan: Double?, private val lonSpan: Double?, private val query: String?, private val radius: Double?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun lat(): Double = lat @@ -34,40 +35,24 @@ constructor( fun radius(): Optional = Optional.ofNullable(radius) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.lat.let { params.put("lat", listOf(it.toString())) } - this.lon.let { params.put("lon", listOf(it.toString())) } - this.latSpan?.let { params.put("latSpan", listOf(it.toString())) } - this.lonSpan?.let { params.put("lonSpan", listOf(it.toString())) } - this.query?.let { params.put("query", listOf(it.toString())) } - this.radius?.let { params.put("radius", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() - } - - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams + fun _additionalHeaders(): Headers = additionalHeaders - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun _additionalQueryParams(): QueryParams = additionalQueryParams - return /* spotless:off */ other is RoutesForLocationListParams && this.lat == other.lat && this.lon == other.lon && this.latSpan == other.latSpan && this.lonSpan == other.lonSpan && this.query == other.query && this.radius == other.radius && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } + override fun _headers(): Headers = additionalHeaders - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(lat, lon, latSpan, lonSpan, query, radius, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.lat.let { queryParams.put("lat", listOf(it.toString())) } + this.lon.let { queryParams.put("lon", listOf(it.toString())) } + this.latSpan?.let { queryParams.put("latSpan", listOf(it.toString())) } + this.lonSpan?.let { queryParams.put("lonSpan", listOf(it.toString())) } + this.query?.let { queryParams.put("query", listOf(it.toString())) } + this.radius?.let { queryParams.put("radius", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } - override fun toString() = - "RoutesForLocationListParams{lat=$lat, lon=$lon, latSpan=$latSpan, lonSpan=$lonSpan, query=$query, radius=$radius, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -75,8 +60,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [RoutesForLocationListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var lat: Double? = null private var lon: Double? = null @@ -84,32 +70,54 @@ constructor( private var lonSpan: Double? = null private var query: String? = null private var radius: Double? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(routesForLocationListParams: RoutesForLocationListParams) = apply { - this.lat = routesForLocationListParams.lat - this.lon = routesForLocationListParams.lon - this.latSpan = routesForLocationListParams.latSpan - this.lonSpan = routesForLocationListParams.lonSpan - this.query = routesForLocationListParams.query - this.radius = routesForLocationListParams.radius - additionalHeaders(routesForLocationListParams.additionalHeaders) - additionalQueryParams(routesForLocationListParams.additionalQueryParams) + lat = routesForLocationListParams.lat + lon = routesForLocationListParams.lon + latSpan = routesForLocationListParams.latSpan + lonSpan = routesForLocationListParams.lonSpan + query = routesForLocationListParams.query + radius = routesForLocationListParams.radius + additionalHeaders = routesForLocationListParams.additionalHeaders.toBuilder() + additionalQueryParams = routesForLocationListParams.additionalQueryParams.toBuilder() } fun lat(lat: Double) = apply { this.lat = lat } fun lon(lon: Double) = apply { this.lon = lon } - fun latSpan(latSpan: Double) = apply { this.latSpan = latSpan } + fun latSpan(latSpan: Double?) = apply { this.latSpan = latSpan } + + fun latSpan(latSpan: Double) = latSpan(latSpan as Double?) - fun lonSpan(lonSpan: Double) = apply { this.lonSpan = lonSpan } + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun latSpan(latSpan: Optional) = latSpan(latSpan.orElse(null) as Double?) - fun query(query: String) = apply { this.query = query } + fun lonSpan(lonSpan: Double?) = apply { this.lonSpan = lonSpan } - fun radius(radius: Double) = apply { this.radius = radius } + fun lonSpan(lonSpan: Double) = lonSpan(lonSpan as Double?) + + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun lonSpan(lonSpan: Optional) = lonSpan(lonSpan.orElse(null) as Double?) + + fun query(query: String?) = apply { this.query = query } + + fun query(query: Optional) = query(query.orElse(null)) + + fun radius(radius: Double?) = apply { this.radius = radius } + + fun radius(radius: Double) = radius(radius as Double?) + + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun radius(radius: Optional) = radius(radius.orElse(null) as Double?) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -121,29 +129,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -156,51 +177,64 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): RoutesForLocationListParams = RoutesForLocationListParams( - checkNotNull(lat) { "`lat` is required but was not set" }, - checkNotNull(lon) { "`lon` is required but was not set" }, + checkRequired("lat", lat), + checkRequired("lon", lon), latSpan, lonSpan, query, radius, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is RoutesForLocationListParams && lat == other.lat && lon == other.lon && latSpan == other.latSpan && lonSpan == other.lonSpan && query == other.query && radius == other.radius && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(lat, lon, latSpan, lonSpan, query, radius, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "RoutesForLocationListParams{lat=$lat, lon=$lon, latSpan=$latSpan, lonSpan=$lonSpan, query=$query, radius=$radius, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForLocationListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForLocationListResponse.kt index af00a62..80b0395 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForLocationListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/RoutesForLocationListResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = RoutesForLocationListResponse.Builder::class) @NoAutoDetect class RoutesForLocationListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): RoutesForLocationListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,93 +87,96 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [RoutesForLocationListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(routesForLocationListResponse: RoutesForLocationListResponse) = apply { - this.code = routesForLocationListResponse.code - this.currentTime = routesForLocationListResponse.currentTime - this.text = routesForLocationListResponse.text - this.version = routesForLocationListResponse.version - this.data = routesForLocationListResponse.data - additionalProperties(routesForLocationListResponse.additionalProperties) + code = routesForLocationListResponse.code + currentTime = routesForLocationListResponse.currentTime + text = routesForLocationListResponse.text + version = routesForLocationListResponse.version + data = routesForLocationListResponse.data + additionalProperties = routesForLocationListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): RoutesForLocationListResponse = RoutesForLocationListResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val limitExceeded: JsonField, - private val list: JsonField>, - private val outOfRange: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("limitExceeded") + @ExcludeMissing + private val limitExceeded: JsonField = JsonMissing.of(), + @JsonProperty("list") + @ExcludeMissing + private val list: JsonField> = JsonMissing.of(), + @JsonProperty("outOfRange") + @ExcludeMissing + private val outOfRange: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") fun list(): kotlin.collections.List = list.getRequired("list") @@ -174,26 +185,38 @@ private constructor( fun references(): References = references.getRequired("references") - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + @JsonProperty("limitExceeded") + @ExcludeMissing + fun _limitExceeded(): JsonField = limitExceeded - @JsonProperty("list") @ExcludeMissing fun _list() = list + @JsonProperty("list") + @ExcludeMissing + fun _list(): JsonField> = list - @JsonProperty("outOfRange") @ExcludeMissing fun _outOfRange() = outOfRange + @JsonProperty("outOfRange") + @ExcludeMissing + fun _outOfRange(): JsonField = outOfRange - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - limitExceeded() - list().forEach { it.validate() } - outOfRange() - references().validate() - validated = true + if (validated) { + return@apply } + + limitExceeded() + list().forEach { it.validate() } + outOfRange() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -203,103 +226,137 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var limitExceeded: JsonField = JsonMissing.of() - private var list: JsonField> = JsonMissing.of() - private var outOfRange: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var limitExceeded: JsonField? = null + private var list: JsonField>? = null + private var outOfRange: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.limitExceeded = data.limitExceeded - this.list = data.list - this.outOfRange = data.outOfRange - this.references = data.references - additionalProperties(data.additionalProperties) + limitExceeded = data.limitExceeded + list = data.list.map { it.toMutableList() } + outOfRange = data.outOfRange + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) - @JsonProperty("limitExceeded") - @ExcludeMissing fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } fun list(list: kotlin.collections.List) = list(JsonField.of(list)) - @JsonProperty("list") - @ExcludeMissing - fun list(list: JsonField>) = apply { this.list = list } + fun list(list: JsonField>) = apply { + this.list = list.map { it.toMutableList() } + } + + fun addList(list: List) = apply { + this.list = + (this.list ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(list) + } + } fun outOfRange(outOfRange: Boolean) = outOfRange(JsonField.of(outOfRange)) - @JsonProperty("outOfRange") - @ExcludeMissing fun outOfRange(outOfRange: JsonField) = apply { this.outOfRange = outOfRange } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, - outOfRange, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("outOfRange", outOfRange), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = List.Builder::class) @NoAutoDetect class List + @JsonCreator private constructor( - private val agencyId: JsonField, - private val color: JsonField, - private val description: JsonField, - private val id: JsonField, - private val longName: JsonField, - private val nullSafeShortName: JsonField, - private val shortName: JsonField, - private val textColor: JsonField, - private val type: JsonField, - private val url: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("agencyId") + @ExcludeMissing + private val agencyId: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + private val type: JsonField = JsonMissing.of(), + @JsonProperty("color") + @ExcludeMissing + private val color: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + private val description: JsonField = JsonMissing.of(), + @JsonProperty("longName") + @ExcludeMissing + private val longName: JsonField = JsonMissing.of(), + @JsonProperty("nullSafeShortName") + @ExcludeMissing + private val nullSafeShortName: JsonField = JsonMissing.of(), + @JsonProperty("shortName") + @ExcludeMissing + private val shortName: JsonField = JsonMissing.of(), + @JsonProperty("textColor") + @ExcludeMissing + private val textColor: JsonField = JsonMissing.of(), + @JsonProperty("url") + @ExcludeMissing + private val url: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun id(): String = id.getRequired("id") fun agencyId(): String = agencyId.getRequired("agencyId") + fun type(): Long = type.getRequired("type") + fun color(): Optional = Optional.ofNullable(color.getNullable("color")) fun description(): Optional = Optional.ofNullable(description.getNullable("description")) - fun id(): String = id.getRequired("id") - fun longName(): Optional = Optional.ofNullable(longName.getNullable("longName")) fun nullSafeShortName(): Optional = @@ -311,50 +368,58 @@ private constructor( fun textColor(): Optional = Optional.ofNullable(textColor.getNullable("textColor")) - fun type(): Long = type.getRequired("type") - fun url(): Optional = Optional.ofNullable(url.getNullable("url")) - @JsonProperty("agencyId") @ExcludeMissing fun _agencyId() = agencyId + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + @JsonProperty("agencyId") @ExcludeMissing fun _agencyId(): JsonField = agencyId - @JsonProperty("color") @ExcludeMissing fun _color() = color + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - @JsonProperty("description") @ExcludeMissing fun _description() = description + @JsonProperty("color") @ExcludeMissing fun _color(): JsonField = color - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description - @JsonProperty("longName") @ExcludeMissing fun _longName() = longName + @JsonProperty("longName") @ExcludeMissing fun _longName(): JsonField = longName @JsonProperty("nullSafeShortName") @ExcludeMissing - fun _nullSafeShortName() = nullSafeShortName - - @JsonProperty("shortName") @ExcludeMissing fun _shortName() = shortName + fun _nullSafeShortName(): JsonField = nullSafeShortName - @JsonProperty("textColor") @ExcludeMissing fun _textColor() = textColor + @JsonProperty("shortName") + @ExcludeMissing + fun _shortName(): JsonField = shortName - @JsonProperty("type") @ExcludeMissing fun _type() = type + @JsonProperty("textColor") + @ExcludeMissing + fun _textColor(): JsonField = textColor - @JsonProperty("url") @ExcludeMissing fun _url() = url + @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): List = apply { - if (!validated) { - agencyId() - color() - description() - id() - longName() - nullSafeShortName() - shortName() - textColor() - type() - url() - validated = true + if (validated) { + return@apply } + + id() + agencyId() + type() + color() + description() + longName() + nullSafeShortName() + shortName() + textColor() + url() + validated = true } fun toBuilder() = Builder().from(this) @@ -364,108 +429,88 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [List]. */ + class Builder internal constructor() { - private var agencyId: JsonField = JsonMissing.of() + private var id: JsonField? = null + private var agencyId: JsonField? = null + private var type: JsonField? = null private var color: JsonField = JsonMissing.of() private var description: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() private var longName: JsonField = JsonMissing.of() private var nullSafeShortName: JsonField = JsonMissing.of() private var shortName: JsonField = JsonMissing.of() private var textColor: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var url: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(list: List) = apply { - this.agencyId = list.agencyId - this.color = list.color - this.description = list.description - this.id = list.id - this.longName = list.longName - this.nullSafeShortName = list.nullSafeShortName - this.shortName = list.shortName - this.textColor = list.textColor - this.type = list.type - this.url = list.url - additionalProperties(list.additionalProperties) + id = list.id + agencyId = list.agencyId + type = list.type + color = list.color + description = list.description + longName = list.longName + nullSafeShortName = list.nullSafeShortName + shortName = list.shortName + textColor = list.textColor + url = list.url + additionalProperties = list.additionalProperties.toMutableMap() } + fun id(id: String) = id(JsonField.of(id)) + + fun id(id: JsonField) = apply { this.id = id } + fun agencyId(agencyId: String) = agencyId(JsonField.of(agencyId)) - @JsonProperty("agencyId") - @ExcludeMissing fun agencyId(agencyId: JsonField) = apply { this.agencyId = agencyId } + fun type(type: Long) = type(JsonField.of(type)) + + fun type(type: JsonField) = apply { this.type = type } + fun color(color: String) = color(JsonField.of(color)) - @JsonProperty("color") - @ExcludeMissing fun color(color: JsonField) = apply { this.color = color } fun description(description: String) = description(JsonField.of(description)) - @JsonProperty("description") - @ExcludeMissing fun description(description: JsonField) = apply { this.description = description } - fun id(id: String) = id(JsonField.of(id)) - - @JsonProperty("id") - @ExcludeMissing - fun id(id: JsonField) = apply { this.id = id } - fun longName(longName: String) = longName(JsonField.of(longName)) - @JsonProperty("longName") - @ExcludeMissing fun longName(longName: JsonField) = apply { this.longName = longName } fun nullSafeShortName(nullSafeShortName: String) = nullSafeShortName(JsonField.of(nullSafeShortName)) - @JsonProperty("nullSafeShortName") - @ExcludeMissing fun nullSafeShortName(nullSafeShortName: JsonField) = apply { this.nullSafeShortName = nullSafeShortName } fun shortName(shortName: String) = shortName(JsonField.of(shortName)) - @JsonProperty("shortName") - @ExcludeMissing fun shortName(shortName: JsonField) = apply { this.shortName = shortName } fun textColor(textColor: String) = textColor(JsonField.of(textColor)) - @JsonProperty("textColor") - @ExcludeMissing fun textColor(textColor: JsonField) = apply { this.textColor = textColor } - fun type(type: Long) = type(JsonField.of(type)) - - @JsonProperty("type") - @ExcludeMissing - fun type(type: JsonField) = apply { this.type = type } - fun url(url: String) = url(JsonField.of(url)) - @JsonProperty("url") - @ExcludeMissing fun url(url: JsonField) = apply { this.url = url } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -473,17 +518,25 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): List = List( - agencyId, + checkRequired("id", id), + checkRequired("agencyId", agencyId), + checkRequired("type", type), color, description, - id, longName, nullSafeShortName, shortName, textColor, - type, url, additionalProperties.toImmutable(), ) @@ -494,20 +547,17 @@ private constructor( return true } - return /* spotless:off */ other is List && this.agencyId == other.agencyId && this.color == other.color && this.description == other.description && this.id == other.id && this.longName == other.longName && this.nullSafeShortName == other.nullSafeShortName && this.shortName == other.shortName && this.textColor == other.textColor && this.type == other.type && this.url == other.url && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is List && id == other.id && agencyId == other.agencyId && type == other.type && color == other.color && description == other.description && longName == other.longName && nullSafeShortName == other.nullSafeShortName && shortName == other.shortName && textColor == other.textColor && url == other.url && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, agencyId, type, color, description, longName, nullSafeShortName, shortName, textColor, url, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(agencyId, color, description, id, longName, nullSafeShortName, shortName, textColor, type, url, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "List{agencyId=$agencyId, color=$color, description=$description, id=$id, longName=$longName, nullSafeShortName=$nullSafeShortName, shortName=$shortName, textColor=$textColor, type=$type, url=$url, additionalProperties=$additionalProperties}" + "List{id=$id, agencyId=$agencyId, type=$type, color=$color, description=$description, longName=$longName, nullSafeShortName=$nullSafeShortName, shortName=$shortName, textColor=$textColor, url=$url, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -515,17 +565,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.limitExceeded == other.limitExceeded && this.list == other.list && this.outOfRange == other.outOfRange && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && list == other.list && outOfRange == other.outOfRange && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, outOfRange, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(limitExceeded, list, outOfRange, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{limitExceeded=$limitExceeded, list=$list, outOfRange=$outOfRange, references=$references, additionalProperties=$additionalProperties}" @@ -536,17 +583,14 @@ private constructor( return true } - return /* spotless:off */ other is RoutesForLocationListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is RoutesForLocationListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "RoutesForLocationListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForRouteRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForRouteRetrieveParams.kt index 8d835bc..288fae3 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForRouteRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForRouteRetrieveParams.kt @@ -2,35 +2,43 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.time.LocalDate import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Retrieve the full schedule for a route on a particular day */ class ScheduleForRouteRetrieveParams -constructor( +private constructor( private val routeId: String, private val date: LocalDate?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun routeId(): String = routeId + /** + * The date for which you want to request a schedule in the format YYYY-MM-DD (optional, + * defaults to current date) + */ fun date(): Optional = Optional.ofNullable(date) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.date?.let { params.put("date", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.date?.let { queryParams.put("date", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } fun getPathParam(index: Int): String { @@ -40,25 +48,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ScheduleForRouteRetrieveParams && this.routeId == other.routeId && this.date == other.date && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(routeId, date, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "ScheduleForRouteRetrieveParams{routeId=$routeId, date=$date, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -66,20 +55,21 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [ScheduleForRouteRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var routeId: String? = null private var date: LocalDate? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(scheduleForRouteRetrieveParams: ScheduleForRouteRetrieveParams) = apply { - this.routeId = scheduleForRouteRetrieveParams.routeId - this.date = scheduleForRouteRetrieveParams.date - additionalHeaders(scheduleForRouteRetrieveParams.additionalHeaders) - additionalQueryParams(scheduleForRouteRetrieveParams.additionalQueryParams) + routeId = scheduleForRouteRetrieveParams.routeId + date = scheduleForRouteRetrieveParams.date + additionalHeaders = scheduleForRouteRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = scheduleForRouteRetrieveParams.additionalQueryParams.toBuilder() } fun routeId(routeId: String) = apply { this.routeId = routeId } @@ -88,7 +78,18 @@ constructor( * The date for which you want to request a schedule in the format YYYY-MM-DD (optional, * defaults to current date) */ - fun date(date: LocalDate) = apply { this.date = date } + fun date(date: LocalDate?) = apply { this.date = date } + + /** + * The date for which you want to request a schedule in the format YYYY-MM-DD (optional, + * defaults to current date) + */ + fun date(date: Optional) = date(date.orElse(null)) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -100,29 +101,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -135,47 +149,60 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): ScheduleForRouteRetrieveParams = ScheduleForRouteRetrieveParams( - checkNotNull(routeId) { "`routeId` is required but was not set" }, + checkRequired("routeId", routeId), date, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ScheduleForRouteRetrieveParams && routeId == other.routeId && date == other.date && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(routeId, date, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "ScheduleForRouteRetrieveParams{routeId=$routeId, date=$date, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForRouteRetrieveResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForRouteRetrieveResponse.kt index 37a37a4..f686c9f 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForRouteRetrieveResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForRouteRetrieveResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = ScheduleForRouteRetrieveResponse.Builder::class) @NoAutoDetect class ScheduleForRouteRetrieveResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): ScheduleForRouteRetrieveResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,104 +87,106 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [ScheduleForRouteRetrieveResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(scheduleForRouteRetrieveResponse: ScheduleForRouteRetrieveResponse) = apply { - this.code = scheduleForRouteRetrieveResponse.code - this.currentTime = scheduleForRouteRetrieveResponse.currentTime - this.text = scheduleForRouteRetrieveResponse.text - this.version = scheduleForRouteRetrieveResponse.version - this.data = scheduleForRouteRetrieveResponse.data - additionalProperties(scheduleForRouteRetrieveResponse.additionalProperties) + code = scheduleForRouteRetrieveResponse.code + currentTime = scheduleForRouteRetrieveResponse.currentTime + text = scheduleForRouteRetrieveResponse.text + version = scheduleForRouteRetrieveResponse.version + data = scheduleForRouteRetrieveResponse.data + additionalProperties = + scheduleForRouteRetrieveResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): ScheduleForRouteRetrieveResponse = ScheduleForRouteRetrieveResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -186,96 +196,120 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() + private var entry: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - additionalProperties(data.additionalProperties) + entry = data.entry + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } - fun build(): Data = Data(entry, additionalProperties.toImmutable()) + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + fun build(): Data = + Data(checkRequired("entry", entry), additionalProperties.toImmutable()) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val routeId: JsonField, - private val scheduleDate: JsonField, - private val serviceIds: JsonField>, - private val stopTripGroupings: JsonField>, - private val stops: JsonField>, - private val trips: JsonField>, - private val additionalProperties: Map, + @JsonProperty("routeId") + @ExcludeMissing + private val routeId: JsonField = JsonMissing.of(), + @JsonProperty("scheduleDate") + @ExcludeMissing + private val scheduleDate: JsonField = JsonMissing.of(), + @JsonProperty("serviceIds") + @ExcludeMissing + private val serviceIds: JsonField> = JsonMissing.of(), + @JsonProperty("stops") + @ExcludeMissing + private val stops: JsonField> = JsonMissing.of(), + @JsonProperty("stopTripGroupings") + @ExcludeMissing + private val stopTripGroupings: JsonField> = JsonMissing.of(), + @JsonProperty("trips") + @ExcludeMissing + private val trips: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun routeId(): String = routeId.getRequired("routeId") fun scheduleDate(): Long = scheduleDate.getRequired("scheduleDate") fun serviceIds(): List = serviceIds.getRequired("serviceIds") + fun stops(): List = stops.getRequired("stops") + fun stopTripGroupings(): List = stopTripGroupings.getRequired("stopTripGroupings") - fun stops(): List = stops.getRequired("stops") - fun trips(): List = trips.getRequired("trips") - @JsonProperty("routeId") @ExcludeMissing fun _routeId() = routeId + @JsonProperty("routeId") @ExcludeMissing fun _routeId(): JsonField = routeId - @JsonProperty("scheduleDate") @ExcludeMissing fun _scheduleDate() = scheduleDate + @JsonProperty("scheduleDate") + @ExcludeMissing + fun _scheduleDate(): JsonField = scheduleDate - @JsonProperty("serviceIds") @ExcludeMissing fun _serviceIds() = serviceIds + @JsonProperty("serviceIds") + @ExcludeMissing + fun _serviceIds(): JsonField> = serviceIds + + @JsonProperty("stops") @ExcludeMissing fun _stops(): JsonField> = stops @JsonProperty("stopTripGroupings") @ExcludeMissing - fun _stopTripGroupings() = stopTripGroupings - - @JsonProperty("stops") @ExcludeMissing fun _stops() = stops + fun _stopTripGroupings(): JsonField> = stopTripGroupings - @JsonProperty("trips") @ExcludeMissing fun _trips() = trips + @JsonProperty("trips") @ExcludeMissing fun _trips(): JsonField> = trips @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - routeId() - scheduleDate() - serviceIds() - stopTripGroupings().forEach { it.validate() } - stops().forEach { it.validate() } - trips().forEach { it.validate() } - validated = true + if (validated) { + return@apply } + + routeId() + scheduleDate() + serviceIds() + stops().forEach { it.validate() } + stopTripGroupings().forEach { it.validate() } + trips().forEach { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -285,79 +319,123 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Entry]. */ + class Builder internal constructor() { - private var routeId: JsonField = JsonMissing.of() - private var scheduleDate: JsonField = JsonMissing.of() - private var serviceIds: JsonField> = JsonMissing.of() - private var stopTripGroupings: JsonField> = JsonMissing.of() - private var stops: JsonField> = JsonMissing.of() - private var trips: JsonField> = JsonMissing.of() + private var routeId: JsonField? = null + private var scheduleDate: JsonField? = null + private var serviceIds: JsonField>? = null + private var stops: JsonField>? = null + private var stopTripGroupings: JsonField>? = null + private var trips: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(entry: Entry) = apply { - this.routeId = entry.routeId - this.scheduleDate = entry.scheduleDate - this.serviceIds = entry.serviceIds - this.stopTripGroupings = entry.stopTripGroupings - this.stops = entry.stops - this.trips = entry.trips - additionalProperties(entry.additionalProperties) + routeId = entry.routeId + scheduleDate = entry.scheduleDate + serviceIds = entry.serviceIds.map { it.toMutableList() } + stops = entry.stops.map { it.toMutableList() } + stopTripGroupings = entry.stopTripGroupings.map { it.toMutableList() } + trips = entry.trips.map { it.toMutableList() } + additionalProperties = entry.additionalProperties.toMutableMap() } fun routeId(routeId: String) = routeId(JsonField.of(routeId)) - @JsonProperty("routeId") - @ExcludeMissing fun routeId(routeId: JsonField) = apply { this.routeId = routeId } fun scheduleDate(scheduleDate: Long) = scheduleDate(JsonField.of(scheduleDate)) - @JsonProperty("scheduleDate") - @ExcludeMissing fun scheduleDate(scheduleDate: JsonField) = apply { this.scheduleDate = scheduleDate } fun serviceIds(serviceIds: List) = serviceIds(JsonField.of(serviceIds)) - @JsonProperty("serviceIds") - @ExcludeMissing fun serviceIds(serviceIds: JsonField>) = apply { - this.serviceIds = serviceIds + this.serviceIds = serviceIds.map { it.toMutableList() } + } + + fun addServiceId(serviceId: String) = apply { + serviceIds = + (serviceIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(serviceId) + } + } + + fun stops(stops: List) = stops(JsonField.of(stops)) + + fun stops(stops: JsonField>) = apply { + this.stops = stops.map { it.toMutableList() } + } + + fun addStop(stop: Stop) = apply { + stops = + (stops ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stop) + } } fun stopTripGroupings(stopTripGroupings: List) = stopTripGroupings(JsonField.of(stopTripGroupings)) - @JsonProperty("stopTripGroupings") - @ExcludeMissing fun stopTripGroupings(stopTripGroupings: JsonField>) = apply { - this.stopTripGroupings = stopTripGroupings + this.stopTripGroupings = stopTripGroupings.map { it.toMutableList() } } - fun stops(stops: List) = stops(JsonField.of(stops)) - - @JsonProperty("stops") - @ExcludeMissing - fun stops(stops: JsonField>) = apply { this.stops = stops } + fun addStopTripGrouping(stopTripGrouping: StopTripGrouping) = apply { + stopTripGroupings = + (stopTripGroupings ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stopTripGrouping) + } + } fun trips(trips: List) = trips(JsonField.of(trips)) - @JsonProperty("trips") - @ExcludeMissing - fun trips(trips: JsonField>) = apply { this.trips = trips } + fun trips(trips: JsonField>) = apply { + this.trips = trips.map { it.toMutableList() } + } + + fun addTrip(trip: Trip) = apply { + trips = + (trips ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(trip) + } + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -365,49 +443,74 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( - routeId, - scheduleDate, - serviceIds.map { it.toImmutable() }, - stopTripGroupings.map { it.toImmutable() }, - stops.map { it.toImmutable() }, - trips.map { it.toImmutable() }, + checkRequired("routeId", routeId), + checkRequired("scheduleDate", scheduleDate), + checkRequired("serviceIds", serviceIds).map { it.toImmutable() }, + checkRequired("stops", stops).map { it.toImmutable() }, + checkRequired("stopTripGroupings", stopTripGroupings).map { + it.toImmutable() + }, + checkRequired("trips", trips).map { it.toImmutable() }, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Stop.Builder::class) @NoAutoDetect class Stop + @JsonCreator private constructor( - private val code: JsonField, - private val direction: JsonField, - private val id: JsonField, - private val lat: JsonField, - private val locationType: JsonField, - private val lon: JsonField, - private val name: JsonField, - private val parent: JsonField, - private val routeIds: JsonField>, - private val staticRouteIds: JsonField>, - private val wheelchairBoarding: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("locationType") + @ExcludeMissing + private val locationType: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + private val name: JsonField = JsonMissing.of(), + @JsonProperty("parent") + @ExcludeMissing + private val parent: JsonField = JsonMissing.of(), + @JsonProperty("routeIds") + @ExcludeMissing + private val routeIds: JsonField> = JsonMissing.of(), + @JsonProperty("staticRouteIds") + @ExcludeMissing + private val staticRouteIds: JsonField> = JsonMissing.of(), + @JsonProperty("code") + @ExcludeMissing + private val code: JsonField = JsonMissing.of(), + @JsonProperty("direction") + @ExcludeMissing + private val direction: JsonField = JsonMissing.of(), + @JsonProperty("wheelchairBoarding") + @ExcludeMissing + private val wheelchairBoarding: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun code(): Optional = Optional.ofNullable(code.getNullable("code")) - - fun direction(): Optional = - Optional.ofNullable(direction.getNullable("direction")) - fun id(): String = id.getRequired("id") fun lat(): Double = lat.getRequired("lat") - fun locationType(): Optional = - Optional.ofNullable(locationType.getNullable("locationType")) + fun locationType(): Long = locationType.getRequired("locationType") fun lon(): Double = lon.getRequired("lon") @@ -419,54 +522,69 @@ private constructor( fun staticRouteIds(): List = staticRouteIds.getRequired("staticRouteIds") + fun code(): Optional = Optional.ofNullable(code.getNullable("code")) + + fun direction(): Optional = + Optional.ofNullable(direction.getNullable("direction")) + fun wheelchairBoarding(): Optional = Optional.ofNullable(wheelchairBoarding.getNullable("wheelchairBoarding")) - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("direction") @ExcludeMissing fun _direction() = direction + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("locationType") + @ExcludeMissing + fun _locationType(): JsonField = locationType - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon - @JsonProperty("locationType") @ExcludeMissing fun _locationType() = locationType + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("routeIds") + @ExcludeMissing + fun _routeIds(): JsonField> = routeIds - @JsonProperty("parent") @ExcludeMissing fun _parent() = parent + @JsonProperty("staticRouteIds") + @ExcludeMissing + fun _staticRouteIds(): JsonField> = staticRouteIds - @JsonProperty("routeIds") @ExcludeMissing fun _routeIds() = routeIds + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("staticRouteIds") + @JsonProperty("direction") @ExcludeMissing - fun _staticRouteIds() = staticRouteIds + fun _direction(): JsonField = direction @JsonProperty("wheelchairBoarding") @ExcludeMissing - fun _wheelchairBoarding() = wheelchairBoarding + fun _wheelchairBoarding(): JsonField = wheelchairBoarding @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Stop = apply { - if (!validated) { - code() - direction() - id() - lat() - locationType() - lon() - name() - parent() - routeIds() - staticRouteIds() - wheelchairBoarding() - validated = true + if (validated) { + return@apply } + + id() + lat() + locationType() + lon() + name() + parent() + routeIds() + staticRouteIds() + code() + direction() + wheelchairBoarding() + validated = true } fun toBuilder() = Builder().from(this) @@ -476,123 +594,127 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - + /** A builder for [Stop]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var lat: JsonField? = null + private var locationType: JsonField? = null + private var lon: JsonField? = null + private var name: JsonField? = null + private var parent: JsonField? = null + private var routeIds: JsonField>? = null + private var staticRouteIds: JsonField>? = null private var code: JsonField = JsonMissing.of() private var direction: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() - private var lat: JsonField = JsonMissing.of() - private var locationType: JsonField = JsonMissing.of() - private var lon: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var parent: JsonField = JsonMissing.of() - private var routeIds: JsonField> = JsonMissing.of() - private var staticRouteIds: JsonField> = JsonMissing.of() private var wheelchairBoarding: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(stop: Stop) = apply { - this.code = stop.code - this.direction = stop.direction - this.id = stop.id - this.lat = stop.lat - this.locationType = stop.locationType - this.lon = stop.lon - this.name = stop.name - this.parent = stop.parent - this.routeIds = stop.routeIds - this.staticRouteIds = stop.staticRouteIds - this.wheelchairBoarding = stop.wheelchairBoarding - additionalProperties(stop.additionalProperties) - } - - fun code(code: String) = code(JsonField.of(code)) - - @JsonProperty("code") - @ExcludeMissing - fun code(code: JsonField) = apply { this.code = code } - - fun direction(direction: String) = direction(JsonField.of(direction)) - - @JsonProperty("direction") - @ExcludeMissing - fun direction(direction: JsonField) = apply { - this.direction = direction + id = stop.id + lat = stop.lat + locationType = stop.locationType + lon = stop.lon + name = stop.name + parent = stop.parent + routeIds = stop.routeIds.map { it.toMutableList() } + staticRouteIds = stop.staticRouteIds.map { it.toMutableList() } + code = stop.code + direction = stop.direction + wheelchairBoarding = stop.wheelchairBoarding + additionalProperties = stop.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) - @JsonProperty("id") - @ExcludeMissing fun id(id: JsonField) = apply { this.id = id } fun lat(lat: Double) = lat(JsonField.of(lat)) - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } fun locationType(locationType: Long) = locationType(JsonField.of(locationType)) - @JsonProperty("locationType") - @ExcludeMissing fun locationType(locationType: JsonField) = apply { this.locationType = locationType } fun lon(lon: Double) = lon(JsonField.of(lon)) - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun name(name: String) = name(JsonField.of(name)) - @JsonProperty("name") - @ExcludeMissing fun name(name: JsonField) = apply { this.name = name } fun parent(parent: String) = parent(JsonField.of(parent)) - @JsonProperty("parent") - @ExcludeMissing fun parent(parent: JsonField) = apply { this.parent = parent } fun routeIds(routeIds: List) = routeIds(JsonField.of(routeIds)) - @JsonProperty("routeIds") - @ExcludeMissing fun routeIds(routeIds: JsonField>) = apply { - this.routeIds = routeIds + this.routeIds = routeIds.map { it.toMutableList() } + } + + fun addRouteId(routeId: String) = apply { + routeIds = + (routeIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(routeId) + } } fun staticRouteIds(staticRouteIds: List) = staticRouteIds(JsonField.of(staticRouteIds)) - @JsonProperty("staticRouteIds") - @ExcludeMissing fun staticRouteIds(staticRouteIds: JsonField>) = apply { - this.staticRouteIds = staticRouteIds + this.staticRouteIds = staticRouteIds.map { it.toMutableList() } + } + + fun addStaticRouteId(staticRouteId: String) = apply { + staticRouteIds = + (staticRouteIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(staticRouteId) + } + } + + fun code(code: String) = code(JsonField.of(code)) + + fun code(code: JsonField) = apply { this.code = code } + + fun direction(direction: String) = direction(JsonField.of(direction)) + + fun direction(direction: JsonField) = apply { + this.direction = direction } fun wheelchairBoarding(wheelchairBoarding: String) = wheelchairBoarding(JsonField.of(wheelchairBoarding)) - @JsonProperty("wheelchairBoarding") - @ExcludeMissing fun wheelchairBoarding(wheelchairBoarding: JsonField) = apply { this.wheelchairBoarding = wheelchairBoarding } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -600,18 +722,28 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Stop = Stop( + checkRequired("id", id), + checkRequired("lat", lat), + checkRequired("locationType", locationType), + checkRequired("lon", lon), + checkRequired("name", name), + checkRequired("parent", parent), + checkRequired("routeIds", routeIds).map { it.toImmutable() }, + checkRequired("staticRouteIds", staticRouteIds).map { + it.toImmutable() + }, code, direction, - id, - lat, - locationType, - lon, - name, - parent, - routeIds.map { it.toImmutable() }, - staticRouteIds.map { it.toImmutable() }, wheelchairBoarding, additionalProperties.toImmutable(), ) @@ -622,36 +754,43 @@ private constructor( return true } - return /* spotless:off */ other is Stop && this.code == other.code && this.direction == other.direction && this.id == other.id && this.lat == other.lat && this.locationType == other.locationType && this.lon == other.lon && this.name == other.name && this.parent == other.parent && this.routeIds == other.routeIds && this.staticRouteIds == other.staticRouteIds && this.wheelchairBoarding == other.wheelchairBoarding && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Stop && id == other.id && lat == other.lat && locationType == other.locationType && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && code == other.code && direction == other.direction && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, code, direction, wheelchairBoarding, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, direction, id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, wheelchairBoarding, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Stop{code=$code, direction=$direction, id=$id, lat=$lat, locationType=$locationType, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" + "Stop{id=$id, lat=$lat, locationType=$locationType, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, code=$code, direction=$direction, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = StopTripGrouping.Builder::class) @NoAutoDetect class StopTripGrouping + @JsonCreator private constructor( - private val directionId: JsonField, - private val stopIds: JsonField>, - private val tripHeadsigns: JsonField>, - private val tripIds: JsonField>, - private val tripsWithStopTimes: JsonField>, - private val additionalProperties: Map, + @JsonProperty("directionId") + @ExcludeMissing + private val directionId: JsonField = JsonMissing.of(), + @JsonProperty("stopIds") + @ExcludeMissing + private val stopIds: JsonField> = JsonMissing.of(), + @JsonProperty("tripHeadsigns") + @ExcludeMissing + private val tripHeadsigns: JsonField> = JsonMissing.of(), + @JsonProperty("tripIds") + @ExcludeMissing + private val tripIds: JsonField> = JsonMissing.of(), + @JsonProperty("tripsWithStopTimes") + @ExcludeMissing + private val tripsWithStopTimes: JsonField> = + JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun directionId(): String = directionId.getRequired("directionId") fun stopIds(): List = stopIds.getRequired("stopIds") @@ -663,31 +802,43 @@ private constructor( fun tripsWithStopTimes(): Optional> = Optional.ofNullable(tripsWithStopTimes.getNullable("tripsWithStopTimes")) - @JsonProperty("directionId") @ExcludeMissing fun _directionId() = directionId + @JsonProperty("directionId") + @ExcludeMissing + fun _directionId(): JsonField = directionId - @JsonProperty("stopIds") @ExcludeMissing fun _stopIds() = stopIds + @JsonProperty("stopIds") + @ExcludeMissing + fun _stopIds(): JsonField> = stopIds - @JsonProperty("tripHeadsigns") @ExcludeMissing fun _tripHeadsigns() = tripHeadsigns + @JsonProperty("tripHeadsigns") + @ExcludeMissing + fun _tripHeadsigns(): JsonField> = tripHeadsigns - @JsonProperty("tripIds") @ExcludeMissing fun _tripIds() = tripIds + @JsonProperty("tripIds") + @ExcludeMissing + fun _tripIds(): JsonField> = tripIds @JsonProperty("tripsWithStopTimes") @ExcludeMissing - fun _tripsWithStopTimes() = tripsWithStopTimes + fun _tripsWithStopTimes(): JsonField> = tripsWithStopTimes @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): StopTripGrouping = apply { - if (!validated) { - directionId() - stopIds() - tripHeadsigns() - tripIds() - tripsWithStopTimes().map { it.forEach { it.validate() } } - validated = true + if (validated) { + return@apply } + + directionId() + stopIds() + tripHeadsigns() + tripIds() + tripsWithStopTimes().ifPresent { it.forEach { it.validate() } } + validated = true } fun toBuilder() = Builder().from(this) @@ -697,73 +848,120 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopTripGrouping]. */ + class Builder internal constructor() { - private var directionId: JsonField = JsonMissing.of() - private var stopIds: JsonField> = JsonMissing.of() - private var tripHeadsigns: JsonField> = JsonMissing.of() - private var tripIds: JsonField> = JsonMissing.of() - private var tripsWithStopTimes: JsonField> = - JsonMissing.of() + private var directionId: JsonField? = null + private var stopIds: JsonField>? = null + private var tripHeadsigns: JsonField>? = null + private var tripIds: JsonField>? = null + private var tripsWithStopTimes: JsonField>? = + null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(stopTripGrouping: StopTripGrouping) = apply { - this.directionId = stopTripGrouping.directionId - this.stopIds = stopTripGrouping.stopIds - this.tripHeadsigns = stopTripGrouping.tripHeadsigns - this.tripIds = stopTripGrouping.tripIds - this.tripsWithStopTimes = stopTripGrouping.tripsWithStopTimes - additionalProperties(stopTripGrouping.additionalProperties) + directionId = stopTripGrouping.directionId + stopIds = stopTripGrouping.stopIds.map { it.toMutableList() } + tripHeadsigns = stopTripGrouping.tripHeadsigns.map { it.toMutableList() } + tripIds = stopTripGrouping.tripIds.map { it.toMutableList() } + tripsWithStopTimes = + stopTripGrouping.tripsWithStopTimes.map { it.toMutableList() } + additionalProperties = stopTripGrouping.additionalProperties.toMutableMap() } fun directionId(directionId: String) = directionId(JsonField.of(directionId)) - @JsonProperty("directionId") - @ExcludeMissing fun directionId(directionId: JsonField) = apply { this.directionId = directionId } fun stopIds(stopIds: List) = stopIds(JsonField.of(stopIds)) - @JsonProperty("stopIds") - @ExcludeMissing - fun stopIds(stopIds: JsonField>) = apply { this.stopIds = stopIds } + fun stopIds(stopIds: JsonField>) = apply { + this.stopIds = stopIds.map { it.toMutableList() } + } + + fun addStopId(stopId: String) = apply { + stopIds = + (stopIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stopId) + } + } fun tripHeadsigns(tripHeadsigns: List) = tripHeadsigns(JsonField.of(tripHeadsigns)) - @JsonProperty("tripHeadsigns") - @ExcludeMissing fun tripHeadsigns(tripHeadsigns: JsonField>) = apply { - this.tripHeadsigns = tripHeadsigns + this.tripHeadsigns = tripHeadsigns.map { it.toMutableList() } + } + + fun addTripHeadsign(tripHeadsign: String) = apply { + tripHeadsigns = + (tripHeadsigns ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(tripHeadsign) + } } fun tripIds(tripIds: List) = tripIds(JsonField.of(tripIds)) - @JsonProperty("tripIds") - @ExcludeMissing - fun tripIds(tripIds: JsonField>) = apply { this.tripIds = tripIds } + fun tripIds(tripIds: JsonField>) = apply { + this.tripIds = tripIds.map { it.toMutableList() } + } + + fun addTripId(tripId: String) = apply { + tripIds = + (tripIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(tripId) + } + } fun tripsWithStopTimes(tripsWithStopTimes: List) = tripsWithStopTimes(JsonField.of(tripsWithStopTimes)) - @JsonProperty("tripsWithStopTimes") - @ExcludeMissing fun tripsWithStopTimes(tripsWithStopTimes: JsonField>) = apply { - this.tripsWithStopTimes = tripsWithStopTimes + this.tripsWithStopTimes = tripsWithStopTimes.map { it.toMutableList() } } + fun addTripsWithStopTime(tripsWithStopTime: TripsWithStopTime) = apply { + tripsWithStopTimes = + (tripsWithStopTimes ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(tripsWithStopTime) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -771,46 +969,65 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopTripGrouping = StopTripGrouping( - directionId, - stopIds.map { it.toImmutable() }, - tripHeadsigns.map { it.toImmutable() }, - tripIds.map { it.toImmutable() }, - tripsWithStopTimes.map { it.toImmutable() }, + checkRequired("directionId", directionId), + checkRequired("stopIds", stopIds).map { it.toImmutable() }, + checkRequired("tripHeadsigns", tripHeadsigns).map { it.toImmutable() }, + checkRequired("tripIds", tripIds).map { it.toImmutable() }, + (tripsWithStopTimes ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = TripsWithStopTime.Builder::class) @NoAutoDetect class TripsWithStopTime + @JsonCreator private constructor( - private val tripId: JsonField, - private val stopTimes: JsonField>, - private val additionalProperties: Map, + @JsonProperty("stopTimes") + @ExcludeMissing + private val stopTimes: JsonField> = JsonMissing.of(), + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun stopTimes(): List = stopTimes.getRequired("stopTimes") fun tripId(): String = tripId.getRequired("tripId") - fun stopTimes(): List = stopTimes.getRequired("stopTimes") - - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + @JsonProperty("stopTimes") + @ExcludeMissing + fun _stopTimes(): JsonField> = stopTimes - @JsonProperty("stopTimes") @ExcludeMissing fun _stopTimes() = stopTimes + @JsonProperty("tripId") + @ExcludeMissing + fun _tripId(): JsonField = tripId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): TripsWithStopTime = apply { - if (!validated) { - tripId() - stopTimes().forEach { it.validate() } - validated = true + if (validated) { + return@apply } + + stopTimes().forEach { it.validate() } + tripId() + validated = true } fun toBuilder() = Builder().from(this) @@ -820,75 +1037,109 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [TripsWithStopTime]. */ + class Builder internal constructor() { - private var tripId: JsonField = JsonMissing.of() - private var stopTimes: JsonField> = JsonMissing.of() + private var stopTimes: JsonField>? = null + private var tripId: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(tripsWithStopTime: TripsWithStopTime) = apply { - this.tripId = tripsWithStopTime.tripId - this.stopTimes = tripsWithStopTime.stopTimes - additionalProperties(tripsWithStopTime.additionalProperties) + stopTimes = tripsWithStopTime.stopTimes.map { it.toMutableList() } + tripId = tripsWithStopTime.tripId + additionalProperties = + tripsWithStopTime.additionalProperties.toMutableMap() } - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - @JsonProperty("tripId") - @ExcludeMissing - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - fun stopTimes(stopTimes: List) = stopTimes(JsonField.of(stopTimes)) - @JsonProperty("stopTimes") - @ExcludeMissing fun stopTimes(stopTimes: JsonField>) = apply { - this.stopTimes = stopTimes + this.stopTimes = stopTimes.map { it.toMutableList() } + } + + fun addStopTime(stopTime: StopTime) = apply { + stopTimes = + (stopTimes ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stopTime) + } } + fun tripId(tripId: String) = tripId(JsonField.of(tripId)) + + fun tripId(tripId: JsonField) = apply { this.tripId = tripId } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): TripsWithStopTime = TripsWithStopTime( - tripId, - stopTimes.map { it.toImmutable() }, + checkRequired("stopTimes", stopTimes).map { it.toImmutable() }, + checkRequired("tripId", tripId), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = StopTime.Builder::class) @NoAutoDetect class StopTime + @JsonCreator private constructor( - private val arrivalEnabled: JsonField, - private val arrivalTime: JsonField, - private val departureEnabled: JsonField, - private val departureTime: JsonField, - private val serviceId: JsonField, - private val stopHeadsign: JsonField, - private val stopId: JsonField, - private val tripId: JsonField, - private val additionalProperties: Map, + @JsonProperty("arrivalEnabled") + @ExcludeMissing + private val arrivalEnabled: JsonField = JsonMissing.of(), + @JsonProperty("arrivalTime") + @ExcludeMissing + private val arrivalTime: JsonField = JsonMissing.of(), + @JsonProperty("departureEnabled") + @ExcludeMissing + private val departureEnabled: JsonField = JsonMissing.of(), + @JsonProperty("departureTime") + @ExcludeMissing + private val departureTime: JsonField = JsonMissing.of(), + @JsonProperty("stopId") + @ExcludeMissing + private val stopId: JsonField = JsonMissing.of(), + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), + @JsonProperty("serviceId") + @ExcludeMissing + private val serviceId: JsonField = JsonMissing.of(), + @JsonProperty("stopHeadsign") + @ExcludeMissing + private val stopHeadsign: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = + immutableEmptyMap(), ) { - private var validated: Boolean = false - fun arrivalEnabled(): Boolean = arrivalEnabled.getRequired("arrivalEnabled") fun arrivalTime(): Long = arrivalTime.getRequired("arrivalTime") @@ -898,58 +1149,68 @@ private constructor( fun departureTime(): Long = departureTime.getRequired("departureTime") + fun stopId(): String = stopId.getRequired("stopId") + + fun tripId(): String = tripId.getRequired("tripId") + fun serviceId(): Optional = Optional.ofNullable(serviceId.getNullable("serviceId")) fun stopHeadsign(): Optional = Optional.ofNullable(stopHeadsign.getNullable("stopHeadsign")) - fun stopId(): String = stopId.getRequired("stopId") - - fun tripId(): String = tripId.getRequired("tripId") - @JsonProperty("arrivalEnabled") @ExcludeMissing - fun _arrivalEnabled() = arrivalEnabled + fun _arrivalEnabled(): JsonField = arrivalEnabled @JsonProperty("arrivalTime") @ExcludeMissing - fun _arrivalTime() = arrivalTime + fun _arrivalTime(): JsonField = arrivalTime @JsonProperty("departureEnabled") @ExcludeMissing - fun _departureEnabled() = departureEnabled + fun _departureEnabled(): JsonField = departureEnabled @JsonProperty("departureTime") @ExcludeMissing - fun _departureTime() = departureTime + fun _departureTime(): JsonField = departureTime - @JsonProperty("serviceId") @ExcludeMissing fun _serviceId() = serviceId + @JsonProperty("stopId") + @ExcludeMissing + fun _stopId(): JsonField = stopId - @JsonProperty("stopHeadsign") + @JsonProperty("tripId") @ExcludeMissing - fun _stopHeadsign() = stopHeadsign + fun _tripId(): JsonField = tripId - @JsonProperty("stopId") @ExcludeMissing fun _stopId() = stopId + @JsonProperty("serviceId") + @ExcludeMissing + fun _serviceId(): JsonField = serviceId - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + @JsonProperty("stopHeadsign") + @ExcludeMissing + fun _stopHeadsign(): JsonField = stopHeadsign @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): StopTime = apply { - if (!validated) { - arrivalEnabled() - arrivalTime() - departureEnabled() - departureTime() - serviceId() - stopHeadsign() - stopId() - tripId() - validated = true + if (validated) { + return@apply } + + arrivalEnabled() + arrivalTime() + departureEnabled() + departureTime() + stopId() + tripId() + serviceId() + stopHeadsign() + validated = true } fun toBuilder() = Builder().from(this) @@ -959,37 +1220,36 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopTime]. */ + class Builder internal constructor() { - private var arrivalEnabled: JsonField = JsonMissing.of() - private var arrivalTime: JsonField = JsonMissing.of() - private var departureEnabled: JsonField = JsonMissing.of() - private var departureTime: JsonField = JsonMissing.of() + private var arrivalEnabled: JsonField? = null + private var arrivalTime: JsonField? = null + private var departureEnabled: JsonField? = null + private var departureTime: JsonField? = null + private var stopId: JsonField? = null + private var tripId: JsonField? = null private var serviceId: JsonField = JsonMissing.of() private var stopHeadsign: JsonField = JsonMissing.of() - private var stopId: JsonField = JsonMissing.of() - private var tripId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(stopTime: StopTime) = apply { - this.arrivalEnabled = stopTime.arrivalEnabled - this.arrivalTime = stopTime.arrivalTime - this.departureEnabled = stopTime.departureEnabled - this.departureTime = stopTime.departureTime - this.serviceId = stopTime.serviceId - this.stopHeadsign = stopTime.stopHeadsign - this.stopId = stopTime.stopId - this.tripId = stopTime.tripId - additionalProperties(stopTime.additionalProperties) + arrivalEnabled = stopTime.arrivalEnabled + arrivalTime = stopTime.arrivalTime + departureEnabled = stopTime.departureEnabled + departureTime = stopTime.departureTime + stopId = stopTime.stopId + tripId = stopTime.tripId + serviceId = stopTime.serviceId + stopHeadsign = stopTime.stopHeadsign + additionalProperties = stopTime.additionalProperties.toMutableMap() } fun arrivalEnabled(arrivalEnabled: Boolean) = arrivalEnabled(JsonField.of(arrivalEnabled)) - @JsonProperty("arrivalEnabled") - @ExcludeMissing fun arrivalEnabled(arrivalEnabled: JsonField) = apply { this.arrivalEnabled = arrivalEnabled } @@ -997,8 +1257,6 @@ private constructor( fun arrivalTime(arrivalTime: Long) = arrivalTime(JsonField.of(arrivalTime)) - @JsonProperty("arrivalTime") - @ExcludeMissing fun arrivalTime(arrivalTime: JsonField) = apply { this.arrivalTime = arrivalTime } @@ -1006,8 +1264,6 @@ private constructor( fun departureEnabled(departureEnabled: Boolean) = departureEnabled(JsonField.of(departureEnabled)) - @JsonProperty("departureEnabled") - @ExcludeMissing fun departureEnabled(departureEnabled: JsonField) = apply { this.departureEnabled = departureEnabled } @@ -1015,16 +1271,20 @@ private constructor( fun departureTime(departureTime: Long) = departureTime(JsonField.of(departureTime)) - @JsonProperty("departureTime") - @ExcludeMissing fun departureTime(departureTime: JsonField) = apply { this.departureTime = departureTime } + fun stopId(stopId: String) = stopId(JsonField.of(stopId)) + + fun stopId(stopId: JsonField) = apply { this.stopId = stopId } + + fun tripId(tripId: String) = tripId(JsonField.of(tripId)) + + fun tripId(tripId: JsonField) = apply { this.tripId = tripId } + fun serviceId(serviceId: String) = serviceId(JsonField.of(serviceId)) - @JsonProperty("serviceId") - @ExcludeMissing fun serviceId(serviceId: JsonField) = apply { this.serviceId = serviceId } @@ -1032,49 +1292,42 @@ private constructor( fun stopHeadsign(stopHeadsign: String) = stopHeadsign(JsonField.of(stopHeadsign)) - @JsonProperty("stopHeadsign") - @ExcludeMissing fun stopHeadsign(stopHeadsign: JsonField) = apply { this.stopHeadsign = stopHeadsign } - fun stopId(stopId: String) = stopId(JsonField.of(stopId)) - - @JsonProperty("stopId") - @ExcludeMissing - fun stopId(stopId: JsonField) = apply { this.stopId = stopId } - - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - @JsonProperty("tripId") - @ExcludeMissing - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopTime = StopTime( - arrivalEnabled, - arrivalTime, - departureEnabled, - departureTime, + checkRequired("arrivalEnabled", arrivalEnabled), + checkRequired("arrivalTime", arrivalTime), + checkRequired("departureEnabled", departureEnabled), + checkRequired("departureTime", departureTime), + checkRequired("stopId", stopId), + checkRequired("tripId", tripId), serviceId, stopHeadsign, - stopId, - tripId, additionalProperties.toImmutable(), ) } @@ -1084,20 +1337,17 @@ private constructor( return true } - return /* spotless:off */ other is StopTime && this.arrivalEnabled == other.arrivalEnabled && this.arrivalTime == other.arrivalTime && this.departureEnabled == other.departureEnabled && this.departureTime == other.departureTime && this.serviceId == other.serviceId && this.stopHeadsign == other.stopHeadsign && this.stopId == other.stopId && this.tripId == other.tripId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopTime && arrivalEnabled == other.arrivalEnabled && arrivalTime == other.arrivalTime && departureEnabled == other.departureEnabled && departureTime == other.departureTime && stopId == other.stopId && tripId == other.tripId && serviceId == other.serviceId && stopHeadsign == other.stopHeadsign && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(arrivalEnabled, arrivalTime, departureEnabled, departureTime, stopId, tripId, serviceId, stopHeadsign, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(arrivalEnabled, arrivalTime, departureEnabled, departureTime, serviceId, stopHeadsign, stopId, tripId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "StopTime{arrivalEnabled=$arrivalEnabled, arrivalTime=$arrivalTime, departureEnabled=$departureEnabled, departureTime=$departureTime, serviceId=$serviceId, stopHeadsign=$stopHeadsign, stopId=$stopId, tripId=$tripId, additionalProperties=$additionalProperties}" + "StopTime{arrivalEnabled=$arrivalEnabled, arrivalTime=$arrivalTime, departureEnabled=$departureEnabled, departureTime=$departureTime, stopId=$stopId, tripId=$tripId, serviceId=$serviceId, stopHeadsign=$stopHeadsign, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1105,20 +1355,17 @@ private constructor( return true } - return /* spotless:off */ other is TripsWithStopTime && this.tripId == other.tripId && this.stopTimes == other.stopTimes && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is TripsWithStopTime && stopTimes == other.stopTimes && tripId == other.tripId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(stopTimes, tripId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(tripId, stopTimes, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "TripsWithStopTime{tripId=$tripId, stopTimes=$stopTimes, additionalProperties=$additionalProperties}" + "TripsWithStopTime{stopTimes=$stopTimes, tripId=$tripId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1126,41 +1373,65 @@ private constructor( return true } - return /* spotless:off */ other is StopTripGrouping && this.directionId == other.directionId && this.stopIds == other.stopIds && this.tripHeadsigns == other.tripHeadsigns && this.tripIds == other.tripIds && this.tripsWithStopTimes == other.tripsWithStopTimes && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopTripGrouping && directionId == other.directionId && stopIds == other.stopIds && tripHeadsigns == other.tripHeadsigns && tripIds == other.tripIds && tripsWithStopTimes == other.tripsWithStopTimes && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(directionId, stopIds, tripHeadsigns, tripIds, tripsWithStopTimes, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(directionId, stopIds, tripHeadsigns, tripIds, tripsWithStopTimes, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "StopTripGrouping{directionId=$directionId, stopIds=$stopIds, tripHeadsigns=$tripHeadsigns, tripIds=$tripIds, tripsWithStopTimes=$tripsWithStopTimes, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = Trip.Builder::class) @NoAutoDetect class Trip + @JsonCreator private constructor( - private val blockId: JsonField, - private val directionId: JsonField, - private val id: JsonField, - private val peakOffpeak: JsonField, - private val routeId: JsonField, - private val routeShortName: JsonField, - private val serviceId: JsonField, - private val shapeId: JsonField, - private val timeZone: JsonField, - private val tripHeadsign: JsonField, - private val tripShortName: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("routeId") + @ExcludeMissing + private val routeId: JsonField = JsonMissing.of(), + @JsonProperty("serviceId") + @ExcludeMissing + private val serviceId: JsonField = JsonMissing.of(), + @JsonProperty("blockId") + @ExcludeMissing + private val blockId: JsonField = JsonMissing.of(), + @JsonProperty("directionId") + @ExcludeMissing + private val directionId: JsonField = JsonMissing.of(), + @JsonProperty("peakOffpeak") + @ExcludeMissing + private val peakOffpeak: JsonField = JsonMissing.of(), + @JsonProperty("routeShortName") + @ExcludeMissing + private val routeShortName: JsonField = JsonMissing.of(), + @JsonProperty("shapeId") + @ExcludeMissing + private val shapeId: JsonField = JsonMissing.of(), + @JsonProperty("timeZone") + @ExcludeMissing + private val timeZone: JsonField = JsonMissing.of(), + @JsonProperty("tripHeadsign") + @ExcludeMissing + private val tripHeadsign: JsonField = JsonMissing.of(), + @JsonProperty("tripShortName") + @ExcludeMissing + private val tripShortName: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun id(): String = id.getRequired("id") + + fun routeId(): String = routeId.getRequired("routeId") + + fun serviceId(): String = serviceId.getRequired("serviceId") fun blockId(): Optional = Optional.ofNullable(blockId.getNullable("blockId")) @@ -1168,18 +1439,12 @@ private constructor( fun directionId(): Optional = Optional.ofNullable(directionId.getNullable("directionId")) - fun id(): String = id.getRequired("id") - fun peakOffpeak(): Optional = Optional.ofNullable(peakOffpeak.getNullable("peakOffpeak")) - fun routeId(): String = routeId.getRequired("routeId") - fun routeShortName(): Optional = Optional.ofNullable(routeShortName.getNullable("routeShortName")) - fun serviceId(): String = serviceId.getRequired("serviceId") - fun shapeId(): Optional = Optional.ofNullable(shapeId.getNullable("shapeId")) @@ -1192,49 +1457,65 @@ private constructor( fun tripShortName(): Optional = Optional.ofNullable(tripShortName.getNullable("tripShortName")) - @JsonProperty("blockId") @ExcludeMissing fun _blockId() = blockId + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + @JsonProperty("routeId") @ExcludeMissing fun _routeId(): JsonField = routeId - @JsonProperty("directionId") @ExcludeMissing fun _directionId() = directionId + @JsonProperty("serviceId") + @ExcludeMissing + fun _serviceId(): JsonField = serviceId - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("blockId") @ExcludeMissing fun _blockId(): JsonField = blockId - @JsonProperty("peakOffpeak") @ExcludeMissing fun _peakOffpeak() = peakOffpeak + @JsonProperty("directionId") + @ExcludeMissing + fun _directionId(): JsonField = directionId - @JsonProperty("routeId") @ExcludeMissing fun _routeId() = routeId + @JsonProperty("peakOffpeak") + @ExcludeMissing + fun _peakOffpeak(): JsonField = peakOffpeak @JsonProperty("routeShortName") @ExcludeMissing - fun _routeShortName() = routeShortName + fun _routeShortName(): JsonField = routeShortName - @JsonProperty("serviceId") @ExcludeMissing fun _serviceId() = serviceId + @JsonProperty("shapeId") @ExcludeMissing fun _shapeId(): JsonField = shapeId - @JsonProperty("shapeId") @ExcludeMissing fun _shapeId() = shapeId - - @JsonProperty("timeZone") @ExcludeMissing fun _timeZone() = timeZone + @JsonProperty("timeZone") + @ExcludeMissing + fun _timeZone(): JsonField = timeZone - @JsonProperty("tripHeadsign") @ExcludeMissing fun _tripHeadsign() = tripHeadsign + @JsonProperty("tripHeadsign") + @ExcludeMissing + fun _tripHeadsign(): JsonField = tripHeadsign - @JsonProperty("tripShortName") @ExcludeMissing fun _tripShortName() = tripShortName + @JsonProperty("tripShortName") + @ExcludeMissing + fun _tripShortName(): JsonField = tripShortName @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Trip = apply { - if (!validated) { - blockId() - directionId() - id() - peakOffpeak() - routeId() - routeShortName() - serviceId() - shapeId() - timeZone() - tripHeadsign() - tripShortName() - validated = true + if (validated) { + return@apply } + + id() + routeId() + serviceId() + blockId() + directionId() + peakOffpeak() + routeShortName() + shapeId() + timeZone() + tripHeadsign() + tripShortName() + validated = true } fun toBuilder() = Builder().from(this) @@ -1244,15 +1525,16 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Trip]. */ + class Builder internal constructor() { + private var id: JsonField? = null + private var routeId: JsonField? = null + private var serviceId: JsonField? = null private var blockId: JsonField = JsonMissing.of() private var directionId: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() private var peakOffpeak: JsonField = JsonMissing.of() - private var routeId: JsonField = JsonMissing.of() private var routeShortName: JsonField = JsonMissing.of() - private var serviceId: JsonField = JsonMissing.of() private var shapeId: JsonField = JsonMissing.of() private var timeZone: JsonField = JsonMissing.of() private var tripHeadsign: JsonField = JsonMissing.of() @@ -1261,88 +1543,68 @@ private constructor( @JvmSynthetic internal fun from(trip: Trip) = apply { - this.blockId = trip.blockId - this.directionId = trip.directionId - this.id = trip.id - this.peakOffpeak = trip.peakOffpeak - this.routeId = trip.routeId - this.routeShortName = trip.routeShortName - this.serviceId = trip.serviceId - this.shapeId = trip.shapeId - this.timeZone = trip.timeZone - this.tripHeadsign = trip.tripHeadsign - this.tripShortName = trip.tripShortName - additionalProperties(trip.additionalProperties) + id = trip.id + routeId = trip.routeId + serviceId = trip.serviceId + blockId = trip.blockId + directionId = trip.directionId + peakOffpeak = trip.peakOffpeak + routeShortName = trip.routeShortName + shapeId = trip.shapeId + timeZone = trip.timeZone + tripHeadsign = trip.tripHeadsign + tripShortName = trip.tripShortName + additionalProperties = trip.additionalProperties.toMutableMap() + } + + fun id(id: String) = id(JsonField.of(id)) + + fun id(id: JsonField) = apply { this.id = id } + + fun routeId(routeId: String) = routeId(JsonField.of(routeId)) + + fun routeId(routeId: JsonField) = apply { this.routeId = routeId } + + fun serviceId(serviceId: String) = serviceId(JsonField.of(serviceId)) + + fun serviceId(serviceId: JsonField) = apply { + this.serviceId = serviceId } fun blockId(blockId: String) = blockId(JsonField.of(blockId)) - @JsonProperty("blockId") - @ExcludeMissing fun blockId(blockId: JsonField) = apply { this.blockId = blockId } fun directionId(directionId: String) = directionId(JsonField.of(directionId)) - @JsonProperty("directionId") - @ExcludeMissing fun directionId(directionId: JsonField) = apply { this.directionId = directionId } - fun id(id: String) = id(JsonField.of(id)) - - @JsonProperty("id") - @ExcludeMissing - fun id(id: JsonField) = apply { this.id = id } - fun peakOffpeak(peakOffpeak: Long) = peakOffpeak(JsonField.of(peakOffpeak)) - @JsonProperty("peakOffpeak") - @ExcludeMissing fun peakOffpeak(peakOffpeak: JsonField) = apply { this.peakOffpeak = peakOffpeak } - fun routeId(routeId: String) = routeId(JsonField.of(routeId)) - - @JsonProperty("routeId") - @ExcludeMissing - fun routeId(routeId: JsonField) = apply { this.routeId = routeId } - fun routeShortName(routeShortName: String) = routeShortName(JsonField.of(routeShortName)) - @JsonProperty("routeShortName") - @ExcludeMissing fun routeShortName(routeShortName: JsonField) = apply { this.routeShortName = routeShortName } - fun serviceId(serviceId: String) = serviceId(JsonField.of(serviceId)) - - @JsonProperty("serviceId") - @ExcludeMissing - fun serviceId(serviceId: JsonField) = apply { - this.serviceId = serviceId - } - fun shapeId(shapeId: String) = shapeId(JsonField.of(shapeId)) - @JsonProperty("shapeId") - @ExcludeMissing fun shapeId(shapeId: JsonField) = apply { this.shapeId = shapeId } fun timeZone(timeZone: String) = timeZone(JsonField.of(timeZone)) - @JsonProperty("timeZone") - @ExcludeMissing fun timeZone(timeZone: JsonField) = apply { this.timeZone = timeZone } fun tripHeadsign(tripHeadsign: String) = tripHeadsign(JsonField.of(tripHeadsign)) - @JsonProperty("tripHeadsign") - @ExcludeMissing fun tripHeadsign(tripHeadsign: JsonField) = apply { this.tripHeadsign = tripHeadsign } @@ -1350,20 +1612,17 @@ private constructor( fun tripShortName(tripShortName: String) = tripShortName(JsonField.of(tripShortName)) - @JsonProperty("tripShortName") - @ExcludeMissing fun tripShortName(tripShortName: JsonField) = apply { this.tripShortName = tripShortName } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1371,15 +1630,23 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Trip = Trip( + checkRequired("id", id), + checkRequired("routeId", routeId), + checkRequired("serviceId", serviceId), blockId, directionId, - id, peakOffpeak, - routeId, routeShortName, - serviceId, shapeId, timeZone, tripHeadsign, @@ -1393,20 +1660,17 @@ private constructor( return true } - return /* spotless:off */ other is Trip && this.blockId == other.blockId && this.directionId == other.directionId && this.id == other.id && this.peakOffpeak == other.peakOffpeak && this.routeId == other.routeId && this.routeShortName == other.routeShortName && this.serviceId == other.serviceId && this.shapeId == other.shapeId && this.timeZone == other.timeZone && this.tripHeadsign == other.tripHeadsign && this.tripShortName == other.tripShortName && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Trip && id == other.id && routeId == other.routeId && serviceId == other.serviceId && blockId == other.blockId && directionId == other.directionId && peakOffpeak == other.peakOffpeak && routeShortName == other.routeShortName && shapeId == other.shapeId && timeZone == other.timeZone && tripHeadsign == other.tripHeadsign && tripShortName == other.tripShortName && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, routeId, serviceId, blockId, directionId, peakOffpeak, routeShortName, shapeId, timeZone, tripHeadsign, tripShortName, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(blockId, directionId, id, peakOffpeak, routeId, routeShortName, serviceId, shapeId, timeZone, tripHeadsign, tripShortName, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Trip{blockId=$blockId, directionId=$directionId, id=$id, peakOffpeak=$peakOffpeak, routeId=$routeId, routeShortName=$routeShortName, serviceId=$serviceId, shapeId=$shapeId, timeZone=$timeZone, tripHeadsign=$tripHeadsign, tripShortName=$tripShortName, additionalProperties=$additionalProperties}" + "Trip{id=$id, routeId=$routeId, serviceId=$serviceId, blockId=$blockId, directionId=$directionId, peakOffpeak=$peakOffpeak, routeShortName=$routeShortName, shapeId=$shapeId, timeZone=$timeZone, tripHeadsign=$tripHeadsign, tripShortName=$tripShortName, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1414,20 +1678,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.routeId == other.routeId && this.scheduleDate == other.scheduleDate && this.serviceIds == other.serviceIds && this.stopTripGroupings == other.stopTripGroupings && this.stops == other.stops && this.trips == other.trips && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && routeId == other.routeId && scheduleDate == other.scheduleDate && serviceIds == other.serviceIds && stops == other.stops && stopTripGroupings == other.stopTripGroupings && trips == other.trips && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(routeId, scheduleDate, serviceIds, stops, stopTripGroupings, trips, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(routeId, scheduleDate, serviceIds, stopTripGroupings, stops, trips, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Entry{routeId=$routeId, scheduleDate=$scheduleDate, serviceIds=$serviceIds, stopTripGroupings=$stopTripGroupings, stops=$stops, trips=$trips, additionalProperties=$additionalProperties}" + "Entry{routeId=$routeId, scheduleDate=$scheduleDate, serviceIds=$serviceIds, stops=$stops, stopTripGroupings=$stopTripGroupings, trips=$trips, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1435,17 +1696,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, additionalProperties=$additionalProperties}" } @@ -1455,17 +1713,14 @@ private constructor( return true } - return /* spotless:off */ other is ScheduleForRouteRetrieveResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is ScheduleForRouteRetrieveResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "ScheduleForRouteRetrieveResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForStopRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForStopRetrieveParams.kt index 6153cb7..5ec1ae9 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForStopRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForStopRetrieveParams.kt @@ -2,35 +2,43 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.time.LocalDate import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Get schedule for a specific stop */ class ScheduleForStopRetrieveParams -constructor( +private constructor( private val stopId: String, private val date: LocalDate?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun stopId(): String = stopId + /** + * The date for which you want to request a schedule in the format YYYY-MM-DD (optional, + * defaults to the current date) + */ fun date(): Optional = Optional.ofNullable(date) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.date?.let { params.put("date", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.date?.let { queryParams.put("date", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } fun getPathParam(index: Int): String { @@ -40,25 +48,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ScheduleForStopRetrieveParams && this.stopId == other.stopId && this.date == other.date && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(stopId, date, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "ScheduleForStopRetrieveParams{stopId=$stopId, date=$date, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -66,20 +55,21 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [ScheduleForStopRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var stopId: String? = null private var date: LocalDate? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(scheduleForStopRetrieveParams: ScheduleForStopRetrieveParams) = apply { - this.stopId = scheduleForStopRetrieveParams.stopId - this.date = scheduleForStopRetrieveParams.date - additionalHeaders(scheduleForStopRetrieveParams.additionalHeaders) - additionalQueryParams(scheduleForStopRetrieveParams.additionalQueryParams) + stopId = scheduleForStopRetrieveParams.stopId + date = scheduleForStopRetrieveParams.date + additionalHeaders = scheduleForStopRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = scheduleForStopRetrieveParams.additionalQueryParams.toBuilder() } fun stopId(stopId: String) = apply { this.stopId = stopId } @@ -88,7 +78,18 @@ constructor( * The date for which you want to request a schedule in the format YYYY-MM-DD (optional, * defaults to the current date) */ - fun date(date: LocalDate) = apply { this.date = date } + fun date(date: LocalDate?) = apply { this.date = date } + + /** + * The date for which you want to request a schedule in the format YYYY-MM-DD (optional, + * defaults to the current date) + */ + fun date(date: Optional) = date(date.orElse(null)) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -100,29 +101,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -135,47 +149,60 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): ScheduleForStopRetrieveParams = ScheduleForStopRetrieveParams( - checkNotNull(stopId) { "`stopId` is required but was not set" }, + checkRequired("stopId", stopId), date, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ScheduleForStopRetrieveParams && stopId == other.stopId && date == other.date && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(stopId, date, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "ScheduleForStopRetrieveParams{stopId=$stopId, date=$date, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForStopRetrieveResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForStopRetrieveResponse.kt index 3dab4f2..386941c 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForStopRetrieveResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ScheduleForStopRetrieveResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = ScheduleForStopRetrieveResponse.Builder::class) @NoAutoDetect class ScheduleForStopRetrieveResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("version") @ExcludeMissing fun _version() = version - - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): ScheduleForStopRetrieveResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,110 +87,116 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [ScheduleForStopRetrieveResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(scheduleForStopRetrieveResponse: ScheduleForStopRetrieveResponse) = apply { - this.code = scheduleForStopRetrieveResponse.code - this.currentTime = scheduleForStopRetrieveResponse.currentTime - this.text = scheduleForStopRetrieveResponse.text - this.version = scheduleForStopRetrieveResponse.version - this.data = scheduleForStopRetrieveResponse.data - additionalProperties(scheduleForStopRetrieveResponse.additionalProperties) + code = scheduleForStopRetrieveResponse.code + currentTime = scheduleForStopRetrieveResponse.currentTime + text = scheduleForStopRetrieveResponse.text + version = scheduleForStopRetrieveResponse.version + data = scheduleForStopRetrieveResponse.data + additionalProperties = + scheduleForStopRetrieveResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): ScheduleForStopRetrieveResponse = ScheduleForStopRetrieveResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") fun references(): References = references.getRequired("references") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -192,67 +206,74 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val date: JsonField, - private val stopId: JsonField, - private val stopRouteSchedules: JsonField>, - private val additionalProperties: Map, + @JsonProperty("date") + @ExcludeMissing + private val date: JsonField = JsonMissing.of(), + @JsonProperty("stopId") + @ExcludeMissing + private val stopId: JsonField = JsonMissing.of(), + @JsonProperty("stopRouteSchedules") + @ExcludeMissing + private val stopRouteSchedules: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun date(): Long = date.getRequired("date") fun stopId(): String = stopId.getRequired("stopId") @@ -260,25 +281,29 @@ private constructor( fun stopRouteSchedules(): List = stopRouteSchedules.getRequired("stopRouteSchedules") - @JsonProperty("date") @ExcludeMissing fun _date() = date + @JsonProperty("date") @ExcludeMissing fun _date(): JsonField = date - @JsonProperty("stopId") @ExcludeMissing fun _stopId() = stopId + @JsonProperty("stopId") @ExcludeMissing fun _stopId(): JsonField = stopId @JsonProperty("stopRouteSchedules") @ExcludeMissing - fun _stopRouteSchedules() = stopRouteSchedules + fun _stopRouteSchedules(): JsonField> = stopRouteSchedules @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - date() - stopId() - stopRouteSchedules().forEach { it.validate() } - validated = true + if (validated) { + return@apply } + + date() + stopId() + stopRouteSchedules().forEach { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -288,52 +313,58 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Entry]. */ + class Builder internal constructor() { - private var date: JsonField = JsonMissing.of() - private var stopId: JsonField = JsonMissing.of() - private var stopRouteSchedules: JsonField> = - JsonMissing.of() + private var date: JsonField? = null + private var stopId: JsonField? = null + private var stopRouteSchedules: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(entry: Entry) = apply { - this.date = entry.date - this.stopId = entry.stopId - this.stopRouteSchedules = entry.stopRouteSchedules - additionalProperties(entry.additionalProperties) + date = entry.date + stopId = entry.stopId + stopRouteSchedules = entry.stopRouteSchedules.map { it.toMutableList() } + additionalProperties = entry.additionalProperties.toMutableMap() } fun date(date: Long) = date(JsonField.of(date)) - @JsonProperty("date") - @ExcludeMissing fun date(date: JsonField) = apply { this.date = date } fun stopId(stopId: String) = stopId(JsonField.of(stopId)) - @JsonProperty("stopId") - @ExcludeMissing fun stopId(stopId: JsonField) = apply { this.stopId = stopId } fun stopRouteSchedules(stopRouteSchedules: List) = stopRouteSchedules(JsonField.of(stopRouteSchedules)) - @JsonProperty("stopRouteSchedules") - @ExcludeMissing fun stopRouteSchedules(stopRouteSchedules: JsonField>) = apply { - this.stopRouteSchedules = stopRouteSchedules + this.stopRouteSchedules = stopRouteSchedules.map { it.toMutableList() } } + fun addStopRouteSchedule(stopRouteSchedule: StopRouteSchedule) = apply { + stopRouteSchedules = + (stopRouteSchedules ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stopRouteSchedule) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -341,48 +372,67 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( - date, - stopId, - stopRouteSchedules.map { it.toImmutable() }, + checkRequired("date", date), + checkRequired("stopId", stopId), + checkRequired("stopRouteSchedules", stopRouteSchedules).map { + it.toImmutable() + }, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = StopRouteSchedule.Builder::class) @NoAutoDetect class StopRouteSchedule + @JsonCreator private constructor( - private val routeId: JsonField, + @JsonProperty("routeId") + @ExcludeMissing + private val routeId: JsonField = JsonMissing.of(), + @JsonProperty("stopRouteDirectionSchedules") + @ExcludeMissing private val stopRouteDirectionSchedules: - JsonField>, - private val additionalProperties: Map, + JsonField> = + JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun routeId(): String = routeId.getRequired("routeId") fun stopRouteDirectionSchedules(): List = stopRouteDirectionSchedules.getRequired("stopRouteDirectionSchedules") - @JsonProperty("routeId") @ExcludeMissing fun _routeId() = routeId + @JsonProperty("routeId") @ExcludeMissing fun _routeId(): JsonField = routeId @JsonProperty("stopRouteDirectionSchedules") @ExcludeMissing - fun _stopRouteDirectionSchedules() = stopRouteDirectionSchedules + fun _stopRouteDirectionSchedules(): JsonField> = + stopRouteDirectionSchedules @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): StopRouteSchedule = apply { - if (!validated) { - routeId() - stopRouteDirectionSchedules().forEach { it.validate() } - validated = true + if (validated) { + return@apply } + + routeId() + stopRouteDirectionSchedules().forEach { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -392,46 +442,60 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopRouteSchedule]. */ + class Builder internal constructor() { - private var routeId: JsonField = JsonMissing.of() + private var routeId: JsonField? = null private var stopRouteDirectionSchedules: - JsonField> = - JsonMissing.of() + JsonField>? = + null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(stopRouteSchedule: StopRouteSchedule) = apply { - this.routeId = stopRouteSchedule.routeId - this.stopRouteDirectionSchedules = - stopRouteSchedule.stopRouteDirectionSchedules - additionalProperties(stopRouteSchedule.additionalProperties) + routeId = stopRouteSchedule.routeId + stopRouteDirectionSchedules = + stopRouteSchedule.stopRouteDirectionSchedules.map { it.toMutableList() } + additionalProperties = stopRouteSchedule.additionalProperties.toMutableMap() } fun routeId(routeId: String) = routeId(JsonField.of(routeId)) - @JsonProperty("routeId") - @ExcludeMissing fun routeId(routeId: JsonField) = apply { this.routeId = routeId } fun stopRouteDirectionSchedules( stopRouteDirectionSchedules: List ) = stopRouteDirectionSchedules(JsonField.of(stopRouteDirectionSchedules)) - @JsonProperty("stopRouteDirectionSchedules") - @ExcludeMissing fun stopRouteDirectionSchedules( stopRouteDirectionSchedules: JsonField> - ) = apply { this.stopRouteDirectionSchedules = stopRouteDirectionSchedules } + ) = apply { + this.stopRouteDirectionSchedules = + stopRouteDirectionSchedules.map { it.toMutableList() } + } + + fun addStopRouteDirectionSchedule( + stopRouteDirectionSchedule: StopRouteDirectionSchedule + ) = apply { + stopRouteDirectionSchedules = + (stopRouteDirectionSchedules ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stopRouteDirectionSchedule) + } + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -439,55 +503,81 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopRouteSchedule = StopRouteSchedule( - routeId, - stopRouteDirectionSchedules.map { it.toImmutable() }, + checkRequired("routeId", routeId), + checkRequired( + "stopRouteDirectionSchedules", + stopRouteDirectionSchedules + ) + .map { it.toImmutable() }, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = StopRouteDirectionSchedule.Builder::class) @NoAutoDetect class StopRouteDirectionSchedule + @JsonCreator private constructor( - private val scheduleFrequencies: JsonField>, - private val scheduleStopTimes: JsonField>, - private val tripHeadsign: JsonField, - private val additionalProperties: Map, + @JsonProperty("scheduleStopTimes") + @ExcludeMissing + private val scheduleStopTimes: JsonField> = + JsonMissing.of(), + @JsonProperty("tripHeadsign") + @ExcludeMissing + private val tripHeadsign: JsonField = JsonMissing.of(), + @JsonProperty("scheduleFrequencies") + @ExcludeMissing + private val scheduleFrequencies: JsonField> = + JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun scheduleFrequencies(): Optional> = - Optional.ofNullable(scheduleFrequencies.getNullable("scheduleFrequencies")) - fun scheduleStopTimes(): List = scheduleStopTimes.getRequired("scheduleStopTimes") fun tripHeadsign(): String = tripHeadsign.getRequired("tripHeadsign") - @JsonProperty("scheduleFrequencies") - @ExcludeMissing - fun _scheduleFrequencies() = scheduleFrequencies + fun scheduleFrequencies(): Optional> = + Optional.ofNullable(scheduleFrequencies.getNullable("scheduleFrequencies")) @JsonProperty("scheduleStopTimes") @ExcludeMissing - fun _scheduleStopTimes() = scheduleStopTimes + fun _scheduleStopTimes(): JsonField> = scheduleStopTimes - @JsonProperty("tripHeadsign") @ExcludeMissing fun _tripHeadsign() = tripHeadsign + @JsonProperty("tripHeadsign") + @ExcludeMissing + fun _tripHeadsign(): JsonField = tripHeadsign + + @JsonProperty("scheduleFrequencies") + @ExcludeMissing + fun _scheduleFrequencies(): JsonField> = + scheduleFrequencies @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): StopRouteDirectionSchedule = apply { - if (!validated) { - scheduleFrequencies().map { it.forEach { it.validate() } } - scheduleStopTimes().forEach { it.validate() } - tripHeadsign() - validated = true + if (validated) { + return@apply } + + scheduleStopTimes().forEach { it.validate() } + tripHeadsign() + scheduleFrequencies().ifPresent { it.forEach { it.validate() } } + validated = true } fun toBuilder() = Builder().from(this) @@ -497,96 +587,149 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopRouteDirectionSchedule]. */ + class Builder internal constructor() { - private var scheduleFrequencies: JsonField> = - JsonMissing.of() - private var scheduleStopTimes: JsonField> = - JsonMissing.of() - private var tripHeadsign: JsonField = JsonMissing.of() + private var scheduleStopTimes: JsonField>? = + null + private var tripHeadsign: JsonField? = null + private var scheduleFrequencies: + JsonField>? = + null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(stopRouteDirectionSchedule: StopRouteDirectionSchedule) = apply { - this.scheduleFrequencies = - stopRouteDirectionSchedule.scheduleFrequencies - this.scheduleStopTimes = - stopRouteDirectionSchedule.scheduleStopTimes - this.tripHeadsign = stopRouteDirectionSchedule.tripHeadsign - additionalProperties( - stopRouteDirectionSchedule.additionalProperties - ) + scheduleStopTimes = + stopRouteDirectionSchedule.scheduleStopTimes.map { + it.toMutableList() + } + tripHeadsign = stopRouteDirectionSchedule.tripHeadsign + scheduleFrequencies = + stopRouteDirectionSchedule.scheduleFrequencies.map { + it.toMutableList() + } + additionalProperties = + stopRouteDirectionSchedule.additionalProperties.toMutableMap() } - fun scheduleFrequencies(scheduleFrequencies: List) = - scheduleFrequencies(JsonField.of(scheduleFrequencies)) - - @JsonProperty("scheduleFrequencies") - @ExcludeMissing - fun scheduleFrequencies( - scheduleFrequencies: JsonField> - ) = apply { this.scheduleFrequencies = scheduleFrequencies } - fun scheduleStopTimes(scheduleStopTimes: List) = scheduleStopTimes(JsonField.of(scheduleStopTimes)) - @JsonProperty("scheduleStopTimes") - @ExcludeMissing fun scheduleStopTimes( scheduleStopTimes: JsonField> - ) = apply { this.scheduleStopTimes = scheduleStopTimes } + ) = apply { + this.scheduleStopTimes = scheduleStopTimes.map { it.toMutableList() } + } + + fun addScheduleStopTime(scheduleStopTime: ScheduleStopTime) = apply { + scheduleStopTimes = + (scheduleStopTimes ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(scheduleStopTime) + } + } fun tripHeadsign(tripHeadsign: String) = tripHeadsign(JsonField.of(tripHeadsign)) - @JsonProperty("tripHeadsign") - @ExcludeMissing fun tripHeadsign(tripHeadsign: JsonField) = apply { this.tripHeadsign = tripHeadsign } + fun scheduleFrequencies(scheduleFrequencies: List) = + scheduleFrequencies(JsonField.of(scheduleFrequencies)) + + fun scheduleFrequencies( + scheduleFrequencies: JsonField> + ) = apply { + this.scheduleFrequencies = + scheduleFrequencies.map { it.toMutableList() } + } + + fun addScheduleFrequency(scheduleFrequency: ScheduleFrequency) = apply { + scheduleFrequencies = + (scheduleFrequencies ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(scheduleFrequency) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopRouteDirectionSchedule = StopRouteDirectionSchedule( - scheduleFrequencies.map { it.toImmutable() }, - scheduleStopTimes.map { it.toImmutable() }, - tripHeadsign, + checkRequired("scheduleStopTimes", scheduleStopTimes).map { + it.toImmutable() + }, + checkRequired("tripHeadsign", tripHeadsign), + (scheduleFrequencies ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = ScheduleStopTime.Builder::class) @NoAutoDetect class ScheduleStopTime + @JsonCreator private constructor( - private val arrivalEnabled: JsonField, - private val arrivalTime: JsonField, - private val departureEnabled: JsonField, - private val departureTime: JsonField, - private val serviceId: JsonField, - private val stopHeadsign: JsonField, - private val tripId: JsonField, - private val additionalProperties: Map, + @JsonProperty("arrivalEnabled") + @ExcludeMissing + private val arrivalEnabled: JsonField = JsonMissing.of(), + @JsonProperty("arrivalTime") + @ExcludeMissing + private val arrivalTime: JsonField = JsonMissing.of(), + @JsonProperty("departureEnabled") + @ExcludeMissing + private val departureEnabled: JsonField = JsonMissing.of(), + @JsonProperty("departureTime") + @ExcludeMissing + private val departureTime: JsonField = JsonMissing.of(), + @JsonProperty("serviceId") + @ExcludeMissing + private val serviceId: JsonField = JsonMissing.of(), + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), + @JsonProperty("stopHeadsign") + @ExcludeMissing + private val stopHeadsign: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = + immutableEmptyMap(), ) { - private var validated: Boolean = false - fun arrivalEnabled(): Boolean = arrivalEnabled.getRequired("arrivalEnabled") fun arrivalTime(): Long = arrivalTime.getRequired("arrivalTime") @@ -598,50 +741,58 @@ private constructor( fun serviceId(): String = serviceId.getRequired("serviceId") + fun tripId(): String = tripId.getRequired("tripId") + fun stopHeadsign(): Optional = Optional.ofNullable(stopHeadsign.getNullable("stopHeadsign")) - fun tripId(): String = tripId.getRequired("tripId") - @JsonProperty("arrivalEnabled") @ExcludeMissing - fun _arrivalEnabled() = arrivalEnabled + fun _arrivalEnabled(): JsonField = arrivalEnabled @JsonProperty("arrivalTime") @ExcludeMissing - fun _arrivalTime() = arrivalTime + fun _arrivalTime(): JsonField = arrivalTime @JsonProperty("departureEnabled") @ExcludeMissing - fun _departureEnabled() = departureEnabled + fun _departureEnabled(): JsonField = departureEnabled @JsonProperty("departureTime") @ExcludeMissing - fun _departureTime() = departureTime + fun _departureTime(): JsonField = departureTime - @JsonProperty("serviceId") @ExcludeMissing fun _serviceId() = serviceId + @JsonProperty("serviceId") + @ExcludeMissing + fun _serviceId(): JsonField = serviceId - @JsonProperty("stopHeadsign") + @JsonProperty("tripId") @ExcludeMissing - fun _stopHeadsign() = stopHeadsign + fun _tripId(): JsonField = tripId - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + @JsonProperty("stopHeadsign") + @ExcludeMissing + fun _stopHeadsign(): JsonField = stopHeadsign @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ScheduleStopTime = apply { - if (!validated) { - arrivalEnabled() - arrivalTime() - departureEnabled() - departureTime() - serviceId() - stopHeadsign() - tripId() - validated = true + if (validated) { + return@apply } + + arrivalEnabled() + arrivalTime() + departureEnabled() + departureTime() + serviceId() + tripId() + stopHeadsign() + validated = true } fun toBuilder() = Builder().from(this) @@ -651,35 +802,35 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [ScheduleStopTime]. */ + class Builder internal constructor() { - private var arrivalEnabled: JsonField = JsonMissing.of() - private var arrivalTime: JsonField = JsonMissing.of() - private var departureEnabled: JsonField = JsonMissing.of() - private var departureTime: JsonField = JsonMissing.of() - private var serviceId: JsonField = JsonMissing.of() + private var arrivalEnabled: JsonField? = null + private var arrivalTime: JsonField? = null + private var departureEnabled: JsonField? = null + private var departureTime: JsonField? = null + private var serviceId: JsonField? = null + private var tripId: JsonField? = null private var stopHeadsign: JsonField = JsonMissing.of() - private var tripId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(scheduleStopTime: ScheduleStopTime) = apply { - this.arrivalEnabled = scheduleStopTime.arrivalEnabled - this.arrivalTime = scheduleStopTime.arrivalTime - this.departureEnabled = scheduleStopTime.departureEnabled - this.departureTime = scheduleStopTime.departureTime - this.serviceId = scheduleStopTime.serviceId - this.stopHeadsign = scheduleStopTime.stopHeadsign - this.tripId = scheduleStopTime.tripId - additionalProperties(scheduleStopTime.additionalProperties) + arrivalEnabled = scheduleStopTime.arrivalEnabled + arrivalTime = scheduleStopTime.arrivalTime + departureEnabled = scheduleStopTime.departureEnabled + departureTime = scheduleStopTime.departureTime + serviceId = scheduleStopTime.serviceId + tripId = scheduleStopTime.tripId + stopHeadsign = scheduleStopTime.stopHeadsign + additionalProperties = + scheduleStopTime.additionalProperties.toMutableMap() } fun arrivalEnabled(arrivalEnabled: Boolean) = arrivalEnabled(JsonField.of(arrivalEnabled)) - @JsonProperty("arrivalEnabled") - @ExcludeMissing fun arrivalEnabled(arrivalEnabled: JsonField) = apply { this.arrivalEnabled = arrivalEnabled } @@ -687,8 +838,6 @@ private constructor( fun arrivalTime(arrivalTime: Long) = arrivalTime(JsonField.of(arrivalTime)) - @JsonProperty("arrivalTime") - @ExcludeMissing fun arrivalTime(arrivalTime: JsonField) = apply { this.arrivalTime = arrivalTime } @@ -696,8 +845,6 @@ private constructor( fun departureEnabled(departureEnabled: Boolean) = departureEnabled(JsonField.of(departureEnabled)) - @JsonProperty("departureEnabled") - @ExcludeMissing fun departureEnabled(departureEnabled: JsonField) = apply { this.departureEnabled = departureEnabled } @@ -705,59 +852,58 @@ private constructor( fun departureTime(departureTime: Long) = departureTime(JsonField.of(departureTime)) - @JsonProperty("departureTime") - @ExcludeMissing fun departureTime(departureTime: JsonField) = apply { this.departureTime = departureTime } fun serviceId(serviceId: String) = serviceId(JsonField.of(serviceId)) - @JsonProperty("serviceId") - @ExcludeMissing fun serviceId(serviceId: JsonField) = apply { this.serviceId = serviceId } + fun tripId(tripId: String) = tripId(JsonField.of(tripId)) + + fun tripId(tripId: JsonField) = apply { this.tripId = tripId } + fun stopHeadsign(stopHeadsign: String) = stopHeadsign(JsonField.of(stopHeadsign)) - @JsonProperty("stopHeadsign") - @ExcludeMissing fun stopHeadsign(stopHeadsign: JsonField) = apply { this.stopHeadsign = stopHeadsign } - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - @JsonProperty("tripId") - @ExcludeMissing - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): ScheduleStopTime = ScheduleStopTime( - arrivalEnabled, - arrivalTime, - departureEnabled, - departureTime, - serviceId, + checkRequired("arrivalEnabled", arrivalEnabled), + checkRequired("arrivalTime", arrivalTime), + checkRequired("departureEnabled", departureEnabled), + checkRequired("departureTime", departureTime), + checkRequired("serviceId", serviceId), + checkRequired("tripId", tripId), stopHeadsign, - tripId, additionalProperties.toImmutable(), ) } @@ -767,77 +913,100 @@ private constructor( return true } - return /* spotless:off */ other is ScheduleStopTime && this.arrivalEnabled == other.arrivalEnabled && this.arrivalTime == other.arrivalTime && this.departureEnabled == other.departureEnabled && this.departureTime == other.departureTime && this.serviceId == other.serviceId && this.stopHeadsign == other.stopHeadsign && this.tripId == other.tripId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is ScheduleStopTime && arrivalEnabled == other.arrivalEnabled && arrivalTime == other.arrivalTime && departureEnabled == other.departureEnabled && departureTime == other.departureTime && serviceId == other.serviceId && tripId == other.tripId && stopHeadsign == other.stopHeadsign && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(arrivalEnabled, arrivalTime, departureEnabled, departureTime, serviceId, tripId, stopHeadsign, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(arrivalEnabled, arrivalTime, departureEnabled, departureTime, serviceId, stopHeadsign, tripId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "ScheduleStopTime{arrivalEnabled=$arrivalEnabled, arrivalTime=$arrivalTime, departureEnabled=$departureEnabled, departureTime=$departureTime, serviceId=$serviceId, stopHeadsign=$stopHeadsign, tripId=$tripId, additionalProperties=$additionalProperties}" + "ScheduleStopTime{arrivalEnabled=$arrivalEnabled, arrivalTime=$arrivalTime, departureEnabled=$departureEnabled, departureTime=$departureTime, serviceId=$serviceId, tripId=$tripId, stopHeadsign=$stopHeadsign, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = ScheduleFrequency.Builder::class) @NoAutoDetect class ScheduleFrequency + @JsonCreator private constructor( - private val serviceDate: JsonField, - private val startTime: JsonField, - private val endTime: JsonField, - private val headway: JsonField, - private val serviceId: JsonField, - private val tripId: JsonField, - private val additionalProperties: Map, + @JsonProperty("endTime") + @ExcludeMissing + private val endTime: JsonField = JsonMissing.of(), + @JsonProperty("headway") + @ExcludeMissing + private val headway: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonProperty("serviceId") + @ExcludeMissing + private val serviceId: JsonField = JsonMissing.of(), + @JsonProperty("startTime") + @ExcludeMissing + private val startTime: JsonField = JsonMissing.of(), + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = + immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun serviceDate(): Long = serviceDate.getRequired("serviceDate") - - fun startTime(): Long = startTime.getRequired("startTime") - fun endTime(): Long = endTime.getRequired("endTime") fun headway(): Long = headway.getRequired("headway") + fun serviceDate(): Long = serviceDate.getRequired("serviceDate") + fun serviceId(): String = serviceId.getRequired("serviceId") + fun startTime(): Long = startTime.getRequired("startTime") + fun tripId(): String = tripId.getRequired("tripId") - @JsonProperty("serviceDate") + @JsonProperty("endTime") @ExcludeMissing - fun _serviceDate() = serviceDate + fun _endTime(): JsonField = endTime - @JsonProperty("startTime") @ExcludeMissing fun _startTime() = startTime + @JsonProperty("headway") + @ExcludeMissing + fun _headway(): JsonField = headway - @JsonProperty("endTime") @ExcludeMissing fun _endTime() = endTime + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate - @JsonProperty("headway") @ExcludeMissing fun _headway() = headway + @JsonProperty("serviceId") + @ExcludeMissing + fun _serviceId(): JsonField = serviceId - @JsonProperty("serviceId") @ExcludeMissing fun _serviceId() = serviceId + @JsonProperty("startTime") + @ExcludeMissing + fun _startTime(): JsonField = startTime - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + @JsonProperty("tripId") + @ExcludeMissing + fun _tripId(): JsonField = tripId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): ScheduleFrequency = apply { - if (!validated) { - serviceDate() - startTime() - endTime() - headway() - serviceId() - tripId() - validated = true + if (validated) { + return@apply } + + endTime() + headway() + serviceDate() + serviceId() + startTime() + tripId() + validated = true } fun toBuilder() = Builder().from(this) @@ -847,94 +1016,91 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [ScheduleFrequency]. */ + class Builder internal constructor() { - private var serviceDate: JsonField = JsonMissing.of() - private var startTime: JsonField = JsonMissing.of() - private var endTime: JsonField = JsonMissing.of() - private var headway: JsonField = JsonMissing.of() - private var serviceId: JsonField = JsonMissing.of() - private var tripId: JsonField = JsonMissing.of() + private var endTime: JsonField? = null + private var headway: JsonField? = null + private var serviceDate: JsonField? = null + private var serviceId: JsonField? = null + private var startTime: JsonField? = null + private var tripId: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(scheduleFrequency: ScheduleFrequency) = apply { - this.serviceDate = scheduleFrequency.serviceDate - this.startTime = scheduleFrequency.startTime - this.endTime = scheduleFrequency.endTime - this.headway = scheduleFrequency.headway - this.serviceId = scheduleFrequency.serviceId - this.tripId = scheduleFrequency.tripId - additionalProperties(scheduleFrequency.additionalProperties) - } - - fun serviceDate(serviceDate: Long) = - serviceDate(JsonField.of(serviceDate)) - - @JsonProperty("serviceDate") - @ExcludeMissing - fun serviceDate(serviceDate: JsonField) = apply { - this.serviceDate = serviceDate - } - - fun startTime(startTime: Long) = startTime(JsonField.of(startTime)) - - @JsonProperty("startTime") - @ExcludeMissing - fun startTime(startTime: JsonField) = apply { - this.startTime = startTime + endTime = scheduleFrequency.endTime + headway = scheduleFrequency.headway + serviceDate = scheduleFrequency.serviceDate + serviceId = scheduleFrequency.serviceId + startTime = scheduleFrequency.startTime + tripId = scheduleFrequency.tripId + additionalProperties = + scheduleFrequency.additionalProperties.toMutableMap() } fun endTime(endTime: Long) = endTime(JsonField.of(endTime)) - @JsonProperty("endTime") - @ExcludeMissing fun endTime(endTime: JsonField) = apply { this.endTime = endTime } fun headway(headway: Long) = headway(JsonField.of(headway)) - @JsonProperty("headway") - @ExcludeMissing fun headway(headway: JsonField) = apply { this.headway = headway } + fun serviceDate(serviceDate: Long) = + serviceDate(JsonField.of(serviceDate)) + + fun serviceDate(serviceDate: JsonField) = apply { + this.serviceDate = serviceDate + } + fun serviceId(serviceId: String) = serviceId(JsonField.of(serviceId)) - @JsonProperty("serviceId") - @ExcludeMissing fun serviceId(serviceId: JsonField) = apply { this.serviceId = serviceId } + fun startTime(startTime: Long) = startTime(JsonField.of(startTime)) + + fun startTime(startTime: JsonField) = apply { + this.startTime = startTime + } + fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - @JsonProperty("tripId") - @ExcludeMissing fun tripId(tripId: JsonField) = apply { this.tripId = tripId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): ScheduleFrequency = ScheduleFrequency( - serviceDate, - startTime, - endTime, - headway, - serviceId, - tripId, + checkRequired("endTime", endTime), + checkRequired("headway", headway), + checkRequired("serviceDate", serviceDate), + checkRequired("serviceId", serviceId), + checkRequired("startTime", startTime), + checkRequired("tripId", tripId), additionalProperties.toImmutable(), ) } @@ -944,20 +1110,17 @@ private constructor( return true } - return /* spotless:off */ other is ScheduleFrequency && this.serviceDate == other.serviceDate && this.startTime == other.startTime && this.endTime == other.endTime && this.headway == other.headway && this.serviceId == other.serviceId && this.tripId == other.tripId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is ScheduleFrequency && endTime == other.endTime && headway == other.headway && serviceDate == other.serviceDate && serviceId == other.serviceId && startTime == other.startTime && tripId == other.tripId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(endTime, headway, serviceDate, serviceId, startTime, tripId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(serviceDate, startTime, endTime, headway, serviceId, tripId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "ScheduleFrequency{serviceDate=$serviceDate, startTime=$startTime, endTime=$endTime, headway=$headway, serviceId=$serviceId, tripId=$tripId, additionalProperties=$additionalProperties}" + "ScheduleFrequency{endTime=$endTime, headway=$headway, serviceDate=$serviceDate, serviceId=$serviceId, startTime=$startTime, tripId=$tripId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -965,20 +1128,17 @@ private constructor( return true } - return /* spotless:off */ other is StopRouteDirectionSchedule && this.scheduleFrequencies == other.scheduleFrequencies && this.scheduleStopTimes == other.scheduleStopTimes && this.tripHeadsign == other.tripHeadsign && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopRouteDirectionSchedule && scheduleStopTimes == other.scheduleStopTimes && tripHeadsign == other.tripHeadsign && scheduleFrequencies == other.scheduleFrequencies && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(scheduleStopTimes, tripHeadsign, scheduleFrequencies, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(scheduleFrequencies, scheduleStopTimes, tripHeadsign, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "StopRouteDirectionSchedule{scheduleFrequencies=$scheduleFrequencies, scheduleStopTimes=$scheduleStopTimes, tripHeadsign=$tripHeadsign, additionalProperties=$additionalProperties}" + "StopRouteDirectionSchedule{scheduleStopTimes=$scheduleStopTimes, tripHeadsign=$tripHeadsign, scheduleFrequencies=$scheduleFrequencies, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -986,17 +1146,14 @@ private constructor( return true } - return /* spotless:off */ other is StopRouteSchedule && this.routeId == other.routeId && this.stopRouteDirectionSchedules == other.stopRouteDirectionSchedules && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopRouteSchedule && routeId == other.routeId && stopRouteDirectionSchedules == other.stopRouteDirectionSchedules && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(routeId, stopRouteDirectionSchedules, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(routeId, stopRouteDirectionSchedules, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "StopRouteSchedule{routeId=$routeId, stopRouteDirectionSchedules=$stopRouteDirectionSchedules, additionalProperties=$additionalProperties}" @@ -1007,17 +1164,14 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.date == other.date && this.stopId == other.stopId && this.stopRouteSchedules == other.stopRouteSchedules && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && date == other.date && stopId == other.stopId && stopRouteSchedules == other.stopRouteSchedules && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(date, stopId, stopRouteSchedules, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(date, stopId, stopRouteSchedules, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Entry{date=$date, stopId=$stopId, stopRouteSchedules=$stopRouteSchedules, additionalProperties=$additionalProperties}" @@ -1028,17 +1182,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, references=$references, additionalProperties=$additionalProperties}" @@ -1049,17 +1200,14 @@ private constructor( return true } - return /* spotless:off */ other is ScheduleForStopRetrieveResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is ScheduleForStopRetrieveResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "ScheduleForStopRetrieveResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForRouteListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForRouteListParams.kt index 821db49..2d08c20 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForRouteListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForRouteListParams.kt @@ -2,56 +2,43 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Search for a route based on its name. */ class SearchForRouteListParams -constructor( +private constructor( private val input: String, private val maxCount: Long?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + /** The string to search for. */ fun input(): String = input + /** The max number of results to return. Defaults to 20. */ fun maxCount(): Optional = Optional.ofNullable(maxCount) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.input.let { params.put("input", listOf(it.toString())) } - this.maxCount?.let { params.put("maxCount", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() - } - - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalQueryParams(): Map> = additionalQueryParams + override fun _headers(): Headers = additionalHeaders - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is SearchForRouteListParams && this.input == other.input && this.maxCount == other.maxCount && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(input, maxCount, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.input.let { queryParams.put("input", listOf(it.toString())) } + this.maxCount?.let { queryParams.put("maxCount", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } - override fun toString() = - "SearchForRouteListParams{input=$input, maxCount=$maxCount, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -59,27 +46,40 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [SearchForRouteListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var input: String? = null private var maxCount: Long? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(searchForRouteListParams: SearchForRouteListParams) = apply { - this.input = searchForRouteListParams.input - this.maxCount = searchForRouteListParams.maxCount - additionalHeaders(searchForRouteListParams.additionalHeaders) - additionalQueryParams(searchForRouteListParams.additionalQueryParams) + input = searchForRouteListParams.input + maxCount = searchForRouteListParams.maxCount + additionalHeaders = searchForRouteListParams.additionalHeaders.toBuilder() + additionalQueryParams = searchForRouteListParams.additionalQueryParams.toBuilder() } /** The string to search for. */ fun input(input: String) = apply { this.input = input } /** The max number of results to return. Defaults to 20. */ - fun maxCount(maxCount: Long) = apply { this.maxCount = maxCount } + fun maxCount(maxCount: Long?) = apply { this.maxCount = maxCount } + + /** The max number of results to return. Defaults to 20. */ + fun maxCount(maxCount: Long) = maxCount(maxCount as Long?) + + /** The max number of results to return. Defaults to 20. */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun maxCount(maxCount: Optional) = maxCount(maxCount.orElse(null) as Long?) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -91,29 +91,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -126,47 +139,60 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): SearchForRouteListParams = SearchForRouteListParams( - checkNotNull(input) { "`input` is required but was not set" }, + checkRequired("input", input), maxCount, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is SearchForRouteListParams && input == other.input && maxCount == other.maxCount && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(input, maxCount, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "SearchForRouteListParams{input=$input, maxCount=$maxCount, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForRouteListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForRouteListResponse.kt index d18d1be..0db7b57 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForRouteListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForRouteListResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = SearchForRouteListResponse.Builder::class) @NoAutoDetect class SearchForRouteListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Optional = Optional.ofNullable(data.getNullable("data")) - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): SearchForRouteListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().map { it.validate() } - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().ifPresent { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -79,93 +87,96 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [SearchForRouteListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null private var data: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(searchForRouteListResponse: SearchForRouteListResponse) = apply { - this.code = searchForRouteListResponse.code - this.currentTime = searchForRouteListResponse.currentTime - this.text = searchForRouteListResponse.text - this.version = searchForRouteListResponse.version - this.data = searchForRouteListResponse.data - additionalProperties(searchForRouteListResponse.additionalProperties) + code = searchForRouteListResponse.code + currentTime = searchForRouteListResponse.currentTime + text = searchForRouteListResponse.text + version = searchForRouteListResponse.version + data = searchForRouteListResponse.data + additionalProperties = searchForRouteListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): SearchForRouteListResponse = SearchForRouteListResponse( - code, - currentTime, - text, - version, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), data, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val limitExceeded: JsonField, - private val list: JsonField>, - private val outOfRange: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("limitExceeded") + @ExcludeMissing + private val limitExceeded: JsonField = JsonMissing.of(), + @JsonProperty("list") + @ExcludeMissing + private val list: JsonField> = JsonMissing.of(), + @JsonProperty("outOfRange") + @ExcludeMissing + private val outOfRange: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") fun list(): kotlin.collections.List = list.getRequired("list") @@ -174,26 +185,38 @@ private constructor( fun references(): References = references.getRequired("references") - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + @JsonProperty("limitExceeded") + @ExcludeMissing + fun _limitExceeded(): JsonField = limitExceeded - @JsonProperty("list") @ExcludeMissing fun _list() = list + @JsonProperty("list") + @ExcludeMissing + fun _list(): JsonField> = list - @JsonProperty("outOfRange") @ExcludeMissing fun _outOfRange() = outOfRange + @JsonProperty("outOfRange") + @ExcludeMissing + fun _outOfRange(): JsonField = outOfRange - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - limitExceeded() - list().forEach { it.validate() } - outOfRange() - references().validate() - validated = true + if (validated) { + return@apply } + + limitExceeded() + list().forEach { it.validate() } + outOfRange() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -203,103 +226,137 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var limitExceeded: JsonField = JsonMissing.of() - private var list: JsonField> = JsonMissing.of() - private var outOfRange: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var limitExceeded: JsonField? = null + private var list: JsonField>? = null + private var outOfRange: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.limitExceeded = data.limitExceeded - this.list = data.list - this.outOfRange = data.outOfRange - this.references = data.references - additionalProperties(data.additionalProperties) + limitExceeded = data.limitExceeded + list = data.list.map { it.toMutableList() } + outOfRange = data.outOfRange + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) - @JsonProperty("limitExceeded") - @ExcludeMissing fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } fun list(list: kotlin.collections.List) = list(JsonField.of(list)) - @JsonProperty("list") - @ExcludeMissing - fun list(list: JsonField>) = apply { this.list = list } + fun list(list: JsonField>) = apply { + this.list = list.map { it.toMutableList() } + } + + fun addList(list: List) = apply { + this.list = + (this.list ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(list) + } + } fun outOfRange(outOfRange: Boolean) = outOfRange(JsonField.of(outOfRange)) - @JsonProperty("outOfRange") - @ExcludeMissing fun outOfRange(outOfRange: JsonField) = apply { this.outOfRange = outOfRange } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, - outOfRange, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("outOfRange", outOfRange), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = List.Builder::class) @NoAutoDetect class List + @JsonCreator private constructor( - private val agencyId: JsonField, - private val color: JsonField, - private val description: JsonField, - private val id: JsonField, - private val longName: JsonField, - private val nullSafeShortName: JsonField, - private val shortName: JsonField, - private val textColor: JsonField, - private val type: JsonField, - private val url: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("agencyId") + @ExcludeMissing + private val agencyId: JsonField = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + private val type: JsonField = JsonMissing.of(), + @JsonProperty("color") + @ExcludeMissing + private val color: JsonField = JsonMissing.of(), + @JsonProperty("description") + @ExcludeMissing + private val description: JsonField = JsonMissing.of(), + @JsonProperty("longName") + @ExcludeMissing + private val longName: JsonField = JsonMissing.of(), + @JsonProperty("nullSafeShortName") + @ExcludeMissing + private val nullSafeShortName: JsonField = JsonMissing.of(), + @JsonProperty("shortName") + @ExcludeMissing + private val shortName: JsonField = JsonMissing.of(), + @JsonProperty("textColor") + @ExcludeMissing + private val textColor: JsonField = JsonMissing.of(), + @JsonProperty("url") + @ExcludeMissing + private val url: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun id(): String = id.getRequired("id") fun agencyId(): String = agencyId.getRequired("agencyId") + fun type(): Long = type.getRequired("type") + fun color(): Optional = Optional.ofNullable(color.getNullable("color")) fun description(): Optional = Optional.ofNullable(description.getNullable("description")) - fun id(): String = id.getRequired("id") - fun longName(): Optional = Optional.ofNullable(longName.getNullable("longName")) fun nullSafeShortName(): Optional = @@ -311,50 +368,58 @@ private constructor( fun textColor(): Optional = Optional.ofNullable(textColor.getNullable("textColor")) - fun type(): Long = type.getRequired("type") - fun url(): Optional = Optional.ofNullable(url.getNullable("url")) - @JsonProperty("agencyId") @ExcludeMissing fun _agencyId() = agencyId + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + @JsonProperty("agencyId") @ExcludeMissing fun _agencyId(): JsonField = agencyId - @JsonProperty("color") @ExcludeMissing fun _color() = color + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type - @JsonProperty("description") @ExcludeMissing fun _description() = description + @JsonProperty("color") @ExcludeMissing fun _color(): JsonField = color - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("description") + @ExcludeMissing + fun _description(): JsonField = description - @JsonProperty("longName") @ExcludeMissing fun _longName() = longName + @JsonProperty("longName") @ExcludeMissing fun _longName(): JsonField = longName @JsonProperty("nullSafeShortName") @ExcludeMissing - fun _nullSafeShortName() = nullSafeShortName - - @JsonProperty("shortName") @ExcludeMissing fun _shortName() = shortName + fun _nullSafeShortName(): JsonField = nullSafeShortName - @JsonProperty("textColor") @ExcludeMissing fun _textColor() = textColor + @JsonProperty("shortName") + @ExcludeMissing + fun _shortName(): JsonField = shortName - @JsonProperty("type") @ExcludeMissing fun _type() = type + @JsonProperty("textColor") + @ExcludeMissing + fun _textColor(): JsonField = textColor - @JsonProperty("url") @ExcludeMissing fun _url() = url + @JsonProperty("url") @ExcludeMissing fun _url(): JsonField = url @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): List = apply { - if (!validated) { - agencyId() - color() - description() - id() - longName() - nullSafeShortName() - shortName() - textColor() - type() - url() - validated = true + if (validated) { + return@apply } + + id() + agencyId() + type() + color() + description() + longName() + nullSafeShortName() + shortName() + textColor() + url() + validated = true } fun toBuilder() = Builder().from(this) @@ -364,108 +429,88 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [List]. */ + class Builder internal constructor() { - private var agencyId: JsonField = JsonMissing.of() + private var id: JsonField? = null + private var agencyId: JsonField? = null + private var type: JsonField? = null private var color: JsonField = JsonMissing.of() private var description: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() private var longName: JsonField = JsonMissing.of() private var nullSafeShortName: JsonField = JsonMissing.of() private var shortName: JsonField = JsonMissing.of() private var textColor: JsonField = JsonMissing.of() - private var type: JsonField = JsonMissing.of() private var url: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(list: List) = apply { - this.agencyId = list.agencyId - this.color = list.color - this.description = list.description - this.id = list.id - this.longName = list.longName - this.nullSafeShortName = list.nullSafeShortName - this.shortName = list.shortName - this.textColor = list.textColor - this.type = list.type - this.url = list.url - additionalProperties(list.additionalProperties) + id = list.id + agencyId = list.agencyId + type = list.type + color = list.color + description = list.description + longName = list.longName + nullSafeShortName = list.nullSafeShortName + shortName = list.shortName + textColor = list.textColor + url = list.url + additionalProperties = list.additionalProperties.toMutableMap() } + fun id(id: String) = id(JsonField.of(id)) + + fun id(id: JsonField) = apply { this.id = id } + fun agencyId(agencyId: String) = agencyId(JsonField.of(agencyId)) - @JsonProperty("agencyId") - @ExcludeMissing fun agencyId(agencyId: JsonField) = apply { this.agencyId = agencyId } + fun type(type: Long) = type(JsonField.of(type)) + + fun type(type: JsonField) = apply { this.type = type } + fun color(color: String) = color(JsonField.of(color)) - @JsonProperty("color") - @ExcludeMissing fun color(color: JsonField) = apply { this.color = color } fun description(description: String) = description(JsonField.of(description)) - @JsonProperty("description") - @ExcludeMissing fun description(description: JsonField) = apply { this.description = description } - fun id(id: String) = id(JsonField.of(id)) - - @JsonProperty("id") - @ExcludeMissing - fun id(id: JsonField) = apply { this.id = id } - fun longName(longName: String) = longName(JsonField.of(longName)) - @JsonProperty("longName") - @ExcludeMissing fun longName(longName: JsonField) = apply { this.longName = longName } fun nullSafeShortName(nullSafeShortName: String) = nullSafeShortName(JsonField.of(nullSafeShortName)) - @JsonProperty("nullSafeShortName") - @ExcludeMissing fun nullSafeShortName(nullSafeShortName: JsonField) = apply { this.nullSafeShortName = nullSafeShortName } fun shortName(shortName: String) = shortName(JsonField.of(shortName)) - @JsonProperty("shortName") - @ExcludeMissing fun shortName(shortName: JsonField) = apply { this.shortName = shortName } fun textColor(textColor: String) = textColor(JsonField.of(textColor)) - @JsonProperty("textColor") - @ExcludeMissing fun textColor(textColor: JsonField) = apply { this.textColor = textColor } - fun type(type: Long) = type(JsonField.of(type)) - - @JsonProperty("type") - @ExcludeMissing - fun type(type: JsonField) = apply { this.type = type } - fun url(url: String) = url(JsonField.of(url)) - @JsonProperty("url") - @ExcludeMissing fun url(url: JsonField) = apply { this.url = url } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -473,17 +518,25 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): List = List( - agencyId, + checkRequired("id", id), + checkRequired("agencyId", agencyId), + checkRequired("type", type), color, description, - id, longName, nullSafeShortName, shortName, textColor, - type, url, additionalProperties.toImmutable(), ) @@ -494,20 +547,17 @@ private constructor( return true } - return /* spotless:off */ other is List && this.agencyId == other.agencyId && this.color == other.color && this.description == other.description && this.id == other.id && this.longName == other.longName && this.nullSafeShortName == other.nullSafeShortName && this.shortName == other.shortName && this.textColor == other.textColor && this.type == other.type && this.url == other.url && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is List && id == other.id && agencyId == other.agencyId && type == other.type && color == other.color && description == other.description && longName == other.longName && nullSafeShortName == other.nullSafeShortName && shortName == other.shortName && textColor == other.textColor && url == other.url && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, agencyId, type, color, description, longName, nullSafeShortName, shortName, textColor, url, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(agencyId, color, description, id, longName, nullSafeShortName, shortName, textColor, type, url, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "List{agencyId=$agencyId, color=$color, description=$description, id=$id, longName=$longName, nullSafeShortName=$nullSafeShortName, shortName=$shortName, textColor=$textColor, type=$type, url=$url, additionalProperties=$additionalProperties}" + "List{id=$id, agencyId=$agencyId, type=$type, color=$color, description=$description, longName=$longName, nullSafeShortName=$nullSafeShortName, shortName=$shortName, textColor=$textColor, url=$url, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -515,17 +565,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.limitExceeded == other.limitExceeded && this.list == other.list && this.outOfRange == other.outOfRange && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && list == other.list && outOfRange == other.outOfRange && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, outOfRange, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(limitExceeded, list, outOfRange, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{limitExceeded=$limitExceeded, list=$list, outOfRange=$outOfRange, references=$references, additionalProperties=$additionalProperties}" @@ -536,17 +583,14 @@ private constructor( return true } - return /* spotless:off */ other is SearchForRouteListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is SearchForRouteListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "SearchForRouteListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForStopListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForStopListParams.kt index a4c84eb..0c20584 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForStopListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForStopListParams.kt @@ -2,56 +2,43 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Search for a stop based on its name. */ class SearchForStopListParams -constructor( +private constructor( private val input: String, private val maxCount: Long?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + /** The string to search for. */ fun input(): String = input + /** The max number of results to return. Defaults to 20. */ fun maxCount(): Optional = Optional.ofNullable(maxCount) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.input.let { params.put("input", listOf(it.toString())) } - this.maxCount?.let { params.put("maxCount", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() - } - - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalQueryParams(): QueryParams = additionalQueryParams - fun _additionalQueryParams(): Map> = additionalQueryParams + override fun _headers(): Headers = additionalHeaders - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is SearchForStopListParams && this.input == other.input && this.maxCount == other.maxCount && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(input, maxCount, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.input.let { queryParams.put("input", listOf(it.toString())) } + this.maxCount?.let { queryParams.put("maxCount", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } - override fun toString() = - "SearchForStopListParams{input=$input, maxCount=$maxCount, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -59,27 +46,40 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [SearchForStopListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var input: String? = null private var maxCount: Long? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(searchForStopListParams: SearchForStopListParams) = apply { - this.input = searchForStopListParams.input - this.maxCount = searchForStopListParams.maxCount - additionalHeaders(searchForStopListParams.additionalHeaders) - additionalQueryParams(searchForStopListParams.additionalQueryParams) + input = searchForStopListParams.input + maxCount = searchForStopListParams.maxCount + additionalHeaders = searchForStopListParams.additionalHeaders.toBuilder() + additionalQueryParams = searchForStopListParams.additionalQueryParams.toBuilder() } /** The string to search for. */ fun input(input: String) = apply { this.input = input } /** The max number of results to return. Defaults to 20. */ - fun maxCount(maxCount: Long) = apply { this.maxCount = maxCount } + fun maxCount(maxCount: Long?) = apply { this.maxCount = maxCount } + + /** The max number of results to return. Defaults to 20. */ + fun maxCount(maxCount: Long) = maxCount(maxCount as Long?) + + /** The max number of results to return. Defaults to 20. */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun maxCount(maxCount: Optional) = maxCount(maxCount.orElse(null) as Long?) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -91,29 +91,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -126,47 +139,60 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): SearchForStopListParams = SearchForStopListParams( - checkNotNull(input) { "`input` is required but was not set" }, + checkRequired("input", input), maxCount, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is SearchForStopListParams && input == other.input && maxCount == other.maxCount && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(input, maxCount, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "SearchForStopListParams{input=$input, maxCount=$maxCount, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForStopListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForStopListResponse.kt index e5437d0..ad7f970 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForStopListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/SearchForStopListResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = SearchForStopListResponse.Builder::class) @NoAutoDetect class SearchForStopListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Optional = Optional.ofNullable(data.getNullable("data")) - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): SearchForStopListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().map { it.validate() } - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().ifPresent { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -79,93 +87,96 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [SearchForStopListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null private var data: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(searchForStopListResponse: SearchForStopListResponse) = apply { - this.code = searchForStopListResponse.code - this.currentTime = searchForStopListResponse.currentTime - this.text = searchForStopListResponse.text - this.version = searchForStopListResponse.version - this.data = searchForStopListResponse.data - additionalProperties(searchForStopListResponse.additionalProperties) + code = searchForStopListResponse.code + currentTime = searchForStopListResponse.currentTime + text = searchForStopListResponse.text + version = searchForStopListResponse.version + data = searchForStopListResponse.data + additionalProperties = searchForStopListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): SearchForStopListResponse = SearchForStopListResponse( - code, - currentTime, - text, - version, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), data, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val limitExceeded: JsonField, - private val list: JsonField>, - private val outOfRange: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("limitExceeded") + @ExcludeMissing + private val limitExceeded: JsonField = JsonMissing.of(), + @JsonProperty("list") + @ExcludeMissing + private val list: JsonField> = JsonMissing.of(), + @JsonProperty("outOfRange") + @ExcludeMissing + private val outOfRange: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") fun list(): kotlin.collections.List = list.getRequired("list") @@ -174,26 +185,38 @@ private constructor( fun references(): References = references.getRequired("references") - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + @JsonProperty("limitExceeded") + @ExcludeMissing + fun _limitExceeded(): JsonField = limitExceeded - @JsonProperty("list") @ExcludeMissing fun _list() = list + @JsonProperty("list") + @ExcludeMissing + fun _list(): JsonField> = list - @JsonProperty("outOfRange") @ExcludeMissing fun _outOfRange() = outOfRange + @JsonProperty("outOfRange") + @ExcludeMissing + fun _outOfRange(): JsonField = outOfRange - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - limitExceeded() - list().forEach { it.validate() } - outOfRange() - references().validate() - validated = true + if (validated) { + return@apply } + + limitExceeded() + list().forEach { it.validate() } + outOfRange() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -203,106 +226,135 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var limitExceeded: JsonField = JsonMissing.of() - private var list: JsonField> = JsonMissing.of() - private var outOfRange: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var limitExceeded: JsonField? = null + private var list: JsonField>? = null + private var outOfRange: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.limitExceeded = data.limitExceeded - this.list = data.list - this.outOfRange = data.outOfRange - this.references = data.references - additionalProperties(data.additionalProperties) + limitExceeded = data.limitExceeded + list = data.list.map { it.toMutableList() } + outOfRange = data.outOfRange + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) - @JsonProperty("limitExceeded") - @ExcludeMissing fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } fun list(list: kotlin.collections.List) = list(JsonField.of(list)) - @JsonProperty("list") - @ExcludeMissing - fun list(list: JsonField>) = apply { this.list = list } + fun list(list: JsonField>) = apply { + this.list = list.map { it.toMutableList() } + } + + fun addList(list: List) = apply { + this.list = + (this.list ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(list) + } + } fun outOfRange(outOfRange: Boolean) = outOfRange(JsonField.of(outOfRange)) - @JsonProperty("outOfRange") - @ExcludeMissing fun outOfRange(outOfRange: JsonField) = apply { this.outOfRange = outOfRange } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, - outOfRange, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("outOfRange", outOfRange), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = List.Builder::class) @NoAutoDetect class List + @JsonCreator private constructor( - private val code: JsonField, - private val direction: JsonField, - private val id: JsonField, - private val lat: JsonField, - private val locationType: JsonField, - private val lon: JsonField, - private val name: JsonField, - private val parent: JsonField, - private val routeIds: JsonField>, - private val staticRouteIds: JsonField>, - private val wheelchairBoarding: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("locationType") + @ExcludeMissing + private val locationType: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + private val name: JsonField = JsonMissing.of(), + @JsonProperty("parent") + @ExcludeMissing + private val parent: JsonField = JsonMissing.of(), + @JsonProperty("routeIds") + @ExcludeMissing + private val routeIds: JsonField> = JsonMissing.of(), + @JsonProperty("staticRouteIds") + @ExcludeMissing + private val staticRouteIds: JsonField> = + JsonMissing.of(), + @JsonProperty("code") + @ExcludeMissing + private val code: JsonField = JsonMissing.of(), + @JsonProperty("direction") + @ExcludeMissing + private val direction: JsonField = JsonMissing.of(), + @JsonProperty("wheelchairBoarding") + @ExcludeMissing + private val wheelchairBoarding: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun code(): Optional = Optional.ofNullable(code.getNullable("code")) - - fun direction(): Optional = - Optional.ofNullable(direction.getNullable("direction")) - fun id(): String = id.getRequired("id") fun lat(): Double = lat.getRequired("lat") - fun locationType(): Optional = - Optional.ofNullable(locationType.getNullable("locationType")) + fun locationType(): Long = locationType.getRequired("locationType") fun lon(): Double = lon.getRequired("lon") @@ -315,52 +367,69 @@ private constructor( fun staticRouteIds(): kotlin.collections.List = staticRouteIds.getRequired("staticRouteIds") + fun code(): Optional = Optional.ofNullable(code.getNullable("code")) + + fun direction(): Optional = + Optional.ofNullable(direction.getNullable("direction")) + fun wheelchairBoarding(): Optional = Optional.ofNullable(wheelchairBoarding.getNullable("wheelchairBoarding")) - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("direction") @ExcludeMissing fun _direction() = direction + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("locationType") + @ExcludeMissing + fun _locationType(): JsonField = locationType - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon - @JsonProperty("locationType") @ExcludeMissing fun _locationType() = locationType + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("routeIds") + @ExcludeMissing + fun _routeIds(): JsonField> = routeIds - @JsonProperty("parent") @ExcludeMissing fun _parent() = parent + @JsonProperty("staticRouteIds") + @ExcludeMissing + fun _staticRouteIds(): JsonField> = staticRouteIds - @JsonProperty("routeIds") @ExcludeMissing fun _routeIds() = routeIds + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("staticRouteIds") @ExcludeMissing fun _staticRouteIds() = staticRouteIds + @JsonProperty("direction") + @ExcludeMissing + fun _direction(): JsonField = direction @JsonProperty("wheelchairBoarding") @ExcludeMissing - fun _wheelchairBoarding() = wheelchairBoarding + fun _wheelchairBoarding(): JsonField = wheelchairBoarding @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): List = apply { - if (!validated) { - code() - direction() - id() - lat() - locationType() - lon() - name() - parent() - routeIds() - staticRouteIds() - wheelchairBoarding() - validated = true + if (validated) { + return@apply } + + id() + lat() + locationType() + lon() + name() + parent() + routeIds() + staticRouteIds() + code() + direction() + wheelchairBoarding() + validated = true } fun toBuilder() = Builder().from(this) @@ -370,124 +439,127 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - + /** A builder for [List]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var lat: JsonField? = null + private var locationType: JsonField? = null + private var lon: JsonField? = null + private var name: JsonField? = null + private var parent: JsonField? = null + private var routeIds: JsonField>? = null + private var staticRouteIds: JsonField>? = null private var code: JsonField = JsonMissing.of() private var direction: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() - private var lat: JsonField = JsonMissing.of() - private var locationType: JsonField = JsonMissing.of() - private var lon: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var parent: JsonField = JsonMissing.of() - private var routeIds: JsonField> = JsonMissing.of() - private var staticRouteIds: JsonField> = - JsonMissing.of() private var wheelchairBoarding: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(list: List) = apply { - this.code = list.code - this.direction = list.direction - this.id = list.id - this.lat = list.lat - this.locationType = list.locationType - this.lon = list.lon - this.name = list.name - this.parent = list.parent - this.routeIds = list.routeIds - this.staticRouteIds = list.staticRouteIds - this.wheelchairBoarding = list.wheelchairBoarding - additionalProperties(list.additionalProperties) + id = list.id + lat = list.lat + locationType = list.locationType + lon = list.lon + name = list.name + parent = list.parent + routeIds = list.routeIds.map { it.toMutableList() } + staticRouteIds = list.staticRouteIds.map { it.toMutableList() } + code = list.code + direction = list.direction + wheelchairBoarding = list.wheelchairBoarding + additionalProperties = list.additionalProperties.toMutableMap() } - fun code(code: String) = code(JsonField.of(code)) - - @JsonProperty("code") - @ExcludeMissing - fun code(code: JsonField) = apply { this.code = code } - - fun direction(direction: String) = direction(JsonField.of(direction)) - - @JsonProperty("direction") - @ExcludeMissing - fun direction(direction: JsonField) = apply { this.direction = direction } - fun id(id: String) = id(JsonField.of(id)) - @JsonProperty("id") - @ExcludeMissing fun id(id: JsonField) = apply { this.id = id } fun lat(lat: Double) = lat(JsonField.of(lat)) - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } fun locationType(locationType: Long) = locationType(JsonField.of(locationType)) - @JsonProperty("locationType") - @ExcludeMissing fun locationType(locationType: JsonField) = apply { this.locationType = locationType } fun lon(lon: Double) = lon(JsonField.of(lon)) - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun name(name: String) = name(JsonField.of(name)) - @JsonProperty("name") - @ExcludeMissing fun name(name: JsonField) = apply { this.name = name } fun parent(parent: String) = parent(JsonField.of(parent)) - @JsonProperty("parent") - @ExcludeMissing fun parent(parent: JsonField) = apply { this.parent = parent } fun routeIds(routeIds: kotlin.collections.List) = routeIds(JsonField.of(routeIds)) - @JsonProperty("routeIds") - @ExcludeMissing fun routeIds(routeIds: JsonField>) = apply { - this.routeIds = routeIds + this.routeIds = routeIds.map { it.toMutableList() } + } + + fun addRouteId(routeId: String) = apply { + routeIds = + (routeIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(routeId) + } } fun staticRouteIds(staticRouteIds: kotlin.collections.List) = staticRouteIds(JsonField.of(staticRouteIds)) - @JsonProperty("staticRouteIds") - @ExcludeMissing fun staticRouteIds(staticRouteIds: JsonField>) = apply { - this.staticRouteIds = staticRouteIds + this.staticRouteIds = staticRouteIds.map { it.toMutableList() } } + fun addStaticRouteId(staticRouteId: String) = apply { + staticRouteIds = + (staticRouteIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(staticRouteId) + } + } + + fun code(code: String) = code(JsonField.of(code)) + + fun code(code: JsonField) = apply { this.code = code } + + fun direction(direction: String) = direction(JsonField.of(direction)) + + fun direction(direction: JsonField) = apply { this.direction = direction } + fun wheelchairBoarding(wheelchairBoarding: String) = wheelchairBoarding(JsonField.of(wheelchairBoarding)) - @JsonProperty("wheelchairBoarding") - @ExcludeMissing fun wheelchairBoarding(wheelchairBoarding: JsonField) = apply { this.wheelchairBoarding = wheelchairBoarding } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -495,18 +567,26 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): List = List( + checkRequired("id", id), + checkRequired("lat", lat), + checkRequired("locationType", locationType), + checkRequired("lon", lon), + checkRequired("name", name), + checkRequired("parent", parent), + checkRequired("routeIds", routeIds).map { it.toImmutable() }, + checkRequired("staticRouteIds", staticRouteIds).map { it.toImmutable() }, code, direction, - id, - lat, - locationType, - lon, - name, - parent, - routeIds.map { it.toImmutable() }, - staticRouteIds.map { it.toImmutable() }, wheelchairBoarding, additionalProperties.toImmutable(), ) @@ -517,20 +597,17 @@ private constructor( return true } - return /* spotless:off */ other is List && this.code == other.code && this.direction == other.direction && this.id == other.id && this.lat == other.lat && this.locationType == other.locationType && this.lon == other.lon && this.name == other.name && this.parent == other.parent && this.routeIds == other.routeIds && this.staticRouteIds == other.staticRouteIds && this.wheelchairBoarding == other.wheelchairBoarding && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is List && id == other.id && lat == other.lat && locationType == other.locationType && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && code == other.code && direction == other.direction && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, code, direction, wheelchairBoarding, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, direction, id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, wheelchairBoarding, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "List{code=$code, direction=$direction, id=$id, lat=$lat, locationType=$locationType, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" + "List{id=$id, lat=$lat, locationType=$locationType, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, code=$code, direction=$direction, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -538,17 +615,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.limitExceeded == other.limitExceeded && this.list == other.list && this.outOfRange == other.outOfRange && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && list == other.list && outOfRange == other.outOfRange && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, outOfRange, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(limitExceeded, list, outOfRange, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{limitExceeded=$limitExceeded, list=$list, outOfRange=$outOfRange, references=$references, additionalProperties=$additionalProperties}" @@ -559,17 +633,14 @@ private constructor( return true } - return /* spotless:off */ other is SearchForStopListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is SearchForStopListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "SearchForStopListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ShapeRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ShapeRetrieveParams.kt index 0688ca0..83b1125 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ShapeRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ShapeRetrieveParams.kt @@ -2,25 +2,30 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Retrieve a shape (the path traveled by a transit vehicle) by ID. */ class ShapeRetrieveParams -constructor( +private constructor( private val shapeId: String, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun shapeId(): String = shapeId - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -29,25 +34,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is ShapeRetrieveParams && this.shapeId == other.shapeId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(shapeId, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "ShapeRetrieveParams{shapeId=$shapeId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -55,22 +41,28 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [ShapeRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var shapeId: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(shapeRetrieveParams: ShapeRetrieveParams) = apply { - this.shapeId = shapeRetrieveParams.shapeId - additionalHeaders(shapeRetrieveParams.additionalHeaders) - additionalQueryParams(shapeRetrieveParams.additionalQueryParams) + shapeId = shapeRetrieveParams.shapeId + additionalHeaders = shapeRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = shapeRetrieveParams.additionalQueryParams.toBuilder() } fun shapeId(shapeId: String) = apply { this.shapeId = shapeId } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -81,29 +73,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -116,46 +121,59 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): ShapeRetrieveParams = ShapeRetrieveParams( - checkNotNull(shapeId) { "`shapeId` is required but was not set" }, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + checkRequired("shapeId", shapeId), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is ShapeRetrieveParams && shapeId == other.shapeId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(shapeId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "ShapeRetrieveParams{shapeId=$shapeId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ShapeRetrieveResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ShapeRetrieveResponse.kt index dc71798..3ab1dd0 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ShapeRetrieveResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/ShapeRetrieveResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = ShapeRetrieveResponse.Builder::class) @NoAutoDetect class ShapeRetrieveResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("version") @ExcludeMissing fun _version() = version - - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): ShapeRetrieveResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,109 +87,114 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [ShapeRetrieveResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(shapeRetrieveResponse: ShapeRetrieveResponse) = apply { - this.code = shapeRetrieveResponse.code - this.currentTime = shapeRetrieveResponse.currentTime - this.text = shapeRetrieveResponse.text - this.version = shapeRetrieveResponse.version - this.data = shapeRetrieveResponse.data - additionalProperties(shapeRetrieveResponse.additionalProperties) + code = shapeRetrieveResponse.code + currentTime = shapeRetrieveResponse.currentTime + text = shapeRetrieveResponse.text + version = shapeRetrieveResponse.version + data = shapeRetrieveResponse.data + additionalProperties = shapeRetrieveResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): ShapeRetrieveResponse = ShapeRetrieveResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") fun references(): References = references.getRequired("references") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -191,92 +204,103 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val length: JsonField, - private val levels: JsonField, - private val points: JsonField, - private val additionalProperties: Map, + @JsonProperty("length") + @ExcludeMissing + private val length: JsonField = JsonMissing.of(), + @JsonProperty("points") + @ExcludeMissing + private val points: JsonField = JsonMissing.of(), + @JsonProperty("levels") + @ExcludeMissing + private val levels: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun length(): Long = length.getRequired("length") - fun levels(): Optional = Optional.ofNullable(levels.getNullable("levels")) - /** Encoded polyline format representing the shape of the path */ fun points(): String = points.getRequired("points") - @JsonProperty("length") @ExcludeMissing fun _length() = length + fun levels(): Optional = Optional.ofNullable(levels.getNullable("levels")) - @JsonProperty("levels") @ExcludeMissing fun _levels() = levels + @JsonProperty("length") @ExcludeMissing fun _length(): JsonField = length /** Encoded polyline format representing the shape of the path */ - @JsonProperty("points") @ExcludeMissing fun _points() = points + @JsonProperty("points") @ExcludeMissing fun _points(): JsonField = points + + @JsonProperty("levels") @ExcludeMissing fun _levels(): JsonField = levels @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - length() - levels() - points() - validated = true + if (validated) { + return@apply } + + length() + points() + levels() + validated = true } fun toBuilder() = Builder().from(this) @@ -286,49 +310,43 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Entry]. */ + class Builder internal constructor() { - private var length: JsonField = JsonMissing.of() + private var length: JsonField? = null + private var points: JsonField? = null private var levels: JsonField = JsonMissing.of() - private var points: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(entry: Entry) = apply { - this.length = entry.length - this.levels = entry.levels - this.points = entry.points - additionalProperties(entry.additionalProperties) + length = entry.length + points = entry.points + levels = entry.levels + additionalProperties = entry.additionalProperties.toMutableMap() } fun length(length: Long) = length(JsonField.of(length)) - @JsonProperty("length") - @ExcludeMissing fun length(length: JsonField) = apply { this.length = length } - fun levels(levels: String) = levels(JsonField.of(levels)) - - @JsonProperty("levels") - @ExcludeMissing - fun levels(levels: JsonField) = apply { this.levels = levels } - /** Encoded polyline format representing the shape of the path */ fun points(points: String) = points(JsonField.of(points)) /** Encoded polyline format representing the shape of the path */ - @JsonProperty("points") - @ExcludeMissing fun points(points: JsonField) = apply { this.points = points } + fun levels(levels: String) = levels(JsonField.of(levels)) + + fun levels(levels: JsonField) = apply { this.levels = levels } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -336,11 +354,19 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( - length, + checkRequired("length", length), + checkRequired("points", points), levels, - points, additionalProperties.toImmutable(), ) } @@ -350,20 +376,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.length == other.length && this.levels == other.levels && this.points == other.points && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && length == other.length && points == other.points && levels == other.levels && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(length, points, levels, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(length, levels, points, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Entry{length=$length, levels=$levels, points=$points, additionalProperties=$additionalProperties}" + "Entry{length=$length, points=$points, levels=$levels, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -371,17 +394,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, references=$references, additionalProperties=$additionalProperties}" @@ -392,17 +412,14 @@ private constructor( return true } - return /* spotless:off */ other is ShapeRetrieveResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is ShapeRetrieveResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "ShapeRetrieveResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopIdsForAgencyListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopIdsForAgencyListParams.kt index 0db9961..62ecdf9 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopIdsForAgencyListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopIdsForAgencyListParams.kt @@ -2,25 +2,30 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Get stop IDs for a specific agency */ class StopIdsForAgencyListParams -constructor( +private constructor( private val agencyId: String, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun agencyId(): String = agencyId - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -29,25 +34,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is StopIdsForAgencyListParams && this.agencyId == other.agencyId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(agencyId, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "StopIdsForAgencyListParams{agencyId=$agencyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -55,22 +41,28 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [StopIdsForAgencyListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var agencyId: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(stopIdsForAgencyListParams: StopIdsForAgencyListParams) = apply { - this.agencyId = stopIdsForAgencyListParams.agencyId - additionalHeaders(stopIdsForAgencyListParams.additionalHeaders) - additionalQueryParams(stopIdsForAgencyListParams.additionalQueryParams) + agencyId = stopIdsForAgencyListParams.agencyId + additionalHeaders = stopIdsForAgencyListParams.additionalHeaders.toBuilder() + additionalQueryParams = stopIdsForAgencyListParams.additionalQueryParams.toBuilder() } fun agencyId(agencyId: String) = apply { this.agencyId = agencyId } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -81,29 +73,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -116,46 +121,59 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): StopIdsForAgencyListParams = StopIdsForAgencyListParams( - checkNotNull(agencyId) { "`agencyId` is required but was not set" }, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + checkRequired("agencyId", agencyId), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is StopIdsForAgencyListParams && agencyId == other.agencyId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(agencyId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "StopIdsForAgencyListParams{agencyId=$agencyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopIdsForAgencyListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopIdsForAgencyListResponse.kt index b8cebb1..f73bb4a 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopIdsForAgencyListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopIdsForAgencyListResponse.kt @@ -4,30 +4,34 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import org.onebusaway.core.ExcludeMissing import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = StopIdsForAgencyListResponse.Builder::class) @NoAutoDetect class StopIdsForAgencyListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -38,37 +42,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): StopIdsForAgencyListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -78,115 +86,124 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopIdsForAgencyListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(stopIdsForAgencyListResponse: StopIdsForAgencyListResponse) = apply { - this.code = stopIdsForAgencyListResponse.code - this.currentTime = stopIdsForAgencyListResponse.currentTime - this.text = stopIdsForAgencyListResponse.text - this.version = stopIdsForAgencyListResponse.version - this.data = stopIdsForAgencyListResponse.data - additionalProperties(stopIdsForAgencyListResponse.additionalProperties) + code = stopIdsForAgencyListResponse.code + currentTime = stopIdsForAgencyListResponse.currentTime + text = stopIdsForAgencyListResponse.text + version = stopIdsForAgencyListResponse.version + data = stopIdsForAgencyListResponse.data + additionalProperties = stopIdsForAgencyListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopIdsForAgencyListResponse = StopIdsForAgencyListResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val limitExceeded: JsonField, - private val list: JsonField>, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("limitExceeded") + @ExcludeMissing + private val limitExceeded: JsonField = JsonMissing.of(), + @JsonProperty("list") + @ExcludeMissing + private val list: JsonField> = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") fun list(): List = list.getRequired("list") fun references(): References = references.getRequired("references") - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + @JsonProperty("limitExceeded") + @ExcludeMissing + fun _limitExceeded(): JsonField = limitExceeded - @JsonProperty("list") @ExcludeMissing fun _list() = list + @JsonProperty("list") @ExcludeMissing fun _list(): JsonField> = list - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - limitExceeded() - list() - references().validate() - validated = true + if (validated) { + return@apply } + + limitExceeded() + list() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -196,62 +213,77 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var limitExceeded: JsonField = JsonMissing.of() - private var list: JsonField> = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var limitExceeded: JsonField? = null + private var list: JsonField>? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.limitExceeded = data.limitExceeded - this.list = data.list - this.references = data.references - additionalProperties(data.additionalProperties) + limitExceeded = data.limitExceeded + list = data.list.map { it.toMutableList() } + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) - @JsonProperty("limitExceeded") - @ExcludeMissing fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } fun list(list: List) = list(JsonField.of(list)) - @JsonProperty("list") - @ExcludeMissing - fun list(list: JsonField>) = apply { this.list = list } + fun list(list: JsonField>) = apply { + this.list = list.map { it.toMutableList() } + } + + fun addList(list: String) = apply { + this.list = + (this.list ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(list) + } + } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -261,17 +293,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.limitExceeded == other.limitExceeded && this.list == other.list && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && list == other.list && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(limitExceeded, list, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{limitExceeded=$limitExceeded, list=$list, references=$references, additionalProperties=$additionalProperties}" @@ -282,17 +311,14 @@ private constructor( return true } - return /* spotless:off */ other is StopIdsForAgencyListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopIdsForAgencyListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "StopIdsForAgencyListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopRetrieveParams.kt index f48cb58..2f25115 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopRetrieveParams.kt @@ -2,25 +2,30 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Get details of a specific stop */ class StopRetrieveParams -constructor( +private constructor( private val stopId: String, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun stopId(): String = stopId - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -29,25 +34,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is StopRetrieveParams && this.stopId == other.stopId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(stopId, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "StopRetrieveParams{stopId=$stopId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -55,22 +41,28 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [StopRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var stopId: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(stopRetrieveParams: StopRetrieveParams) = apply { - this.stopId = stopRetrieveParams.stopId - additionalHeaders(stopRetrieveParams.additionalHeaders) - additionalQueryParams(stopRetrieveParams.additionalQueryParams) + stopId = stopRetrieveParams.stopId + additionalHeaders = stopRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = stopRetrieveParams.additionalQueryParams.toBuilder() } fun stopId(stopId: String) = apply { this.stopId = stopId } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -81,29 +73,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -116,46 +121,59 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): StopRetrieveParams = StopRetrieveParams( - checkNotNull(stopId) { "`stopId` is required but was not set" }, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + checkRequired("stopId", stopId), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is StopRetrieveParams && stopId == other.stopId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(stopId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "StopRetrieveParams{stopId=$stopId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopRetrieveResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopRetrieveResponse.kt index c94ac1e..5de09a5 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopRetrieveResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopRetrieveResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = StopRetrieveResponse.Builder::class) @NoAutoDetect class StopRetrieveResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): StopRetrieveResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,109 +87,114 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopRetrieveResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(stopRetrieveResponse: StopRetrieveResponse) = apply { - this.code = stopRetrieveResponse.code - this.currentTime = stopRetrieveResponse.currentTime - this.text = stopRetrieveResponse.text - this.version = stopRetrieveResponse.version - this.data = stopRetrieveResponse.data - additionalProperties(stopRetrieveResponse.additionalProperties) + code = stopRetrieveResponse.code + currentTime = stopRetrieveResponse.currentTime + text = stopRetrieveResponse.text + version = stopRetrieveResponse.version + data = stopRetrieveResponse.data + additionalProperties = stopRetrieveResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopRetrieveResponse = StopRetrieveResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") fun references(): References = references.getRequired("references") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -191,86 +204,103 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val code: JsonField, - private val direction: JsonField, - private val id: JsonField, - private val lat: JsonField, - private val locationType: JsonField, - private val lon: JsonField, - private val name: JsonField, - private val parent: JsonField, - private val routeIds: JsonField>, - private val staticRouteIds: JsonField>, - private val wheelchairBoarding: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("locationType") + @ExcludeMissing + private val locationType: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + private val name: JsonField = JsonMissing.of(), + @JsonProperty("parent") + @ExcludeMissing + private val parent: JsonField = JsonMissing.of(), + @JsonProperty("routeIds") + @ExcludeMissing + private val routeIds: JsonField> = JsonMissing.of(), + @JsonProperty("staticRouteIds") + @ExcludeMissing + private val staticRouteIds: JsonField> = JsonMissing.of(), + @JsonProperty("code") + @ExcludeMissing + private val code: JsonField = JsonMissing.of(), + @JsonProperty("direction") + @ExcludeMissing + private val direction: JsonField = JsonMissing.of(), + @JsonProperty("wheelchairBoarding") + @ExcludeMissing + private val wheelchairBoarding: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun code(): Optional = Optional.ofNullable(code.getNullable("code")) - - fun direction(): Optional = - Optional.ofNullable(direction.getNullable("direction")) - fun id(): String = id.getRequired("id") fun lat(): Double = lat.getRequired("lat") - fun locationType(): Optional = - Optional.ofNullable(locationType.getNullable("locationType")) + fun locationType(): Long = locationType.getRequired("locationType") fun lon(): Double = lon.getRequired("lon") @@ -282,52 +312,69 @@ private constructor( fun staticRouteIds(): List = staticRouteIds.getRequired("staticRouteIds") + fun code(): Optional = Optional.ofNullable(code.getNullable("code")) + + fun direction(): Optional = + Optional.ofNullable(direction.getNullable("direction")) + fun wheelchairBoarding(): Optional = Optional.ofNullable(wheelchairBoarding.getNullable("wheelchairBoarding")) - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("direction") @ExcludeMissing fun _direction() = direction + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("locationType") + @ExcludeMissing + fun _locationType(): JsonField = locationType - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon - @JsonProperty("locationType") @ExcludeMissing fun _locationType() = locationType + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("routeIds") + @ExcludeMissing + fun _routeIds(): JsonField> = routeIds - @JsonProperty("parent") @ExcludeMissing fun _parent() = parent + @JsonProperty("staticRouteIds") + @ExcludeMissing + fun _staticRouteIds(): JsonField> = staticRouteIds - @JsonProperty("routeIds") @ExcludeMissing fun _routeIds() = routeIds + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("staticRouteIds") @ExcludeMissing fun _staticRouteIds() = staticRouteIds + @JsonProperty("direction") + @ExcludeMissing + fun _direction(): JsonField = direction @JsonProperty("wheelchairBoarding") @ExcludeMissing - fun _wheelchairBoarding() = wheelchairBoarding + fun _wheelchairBoarding(): JsonField = wheelchairBoarding @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - code() - direction() - id() - lat() - locationType() - lon() - name() - parent() - routeIds() - staticRouteIds() - wheelchairBoarding() - validated = true + if (validated) { + return@apply } + + id() + lat() + locationType() + lon() + name() + parent() + routeIds() + staticRouteIds() + code() + direction() + wheelchairBoarding() + validated = true } fun toBuilder() = Builder().from(this) @@ -337,119 +384,125 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - + /** A builder for [Entry]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var lat: JsonField? = null + private var locationType: JsonField? = null + private var lon: JsonField? = null + private var name: JsonField? = null + private var parent: JsonField? = null + private var routeIds: JsonField>? = null + private var staticRouteIds: JsonField>? = null private var code: JsonField = JsonMissing.of() private var direction: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() - private var lat: JsonField = JsonMissing.of() - private var locationType: JsonField = JsonMissing.of() - private var lon: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var parent: JsonField = JsonMissing.of() - private var routeIds: JsonField> = JsonMissing.of() - private var staticRouteIds: JsonField> = JsonMissing.of() private var wheelchairBoarding: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(entry: Entry) = apply { - this.code = entry.code - this.direction = entry.direction - this.id = entry.id - this.lat = entry.lat - this.locationType = entry.locationType - this.lon = entry.lon - this.name = entry.name - this.parent = entry.parent - this.routeIds = entry.routeIds - this.staticRouteIds = entry.staticRouteIds - this.wheelchairBoarding = entry.wheelchairBoarding - additionalProperties(entry.additionalProperties) + id = entry.id + lat = entry.lat + locationType = entry.locationType + lon = entry.lon + name = entry.name + parent = entry.parent + routeIds = entry.routeIds.map { it.toMutableList() } + staticRouteIds = entry.staticRouteIds.map { it.toMutableList() } + code = entry.code + direction = entry.direction + wheelchairBoarding = entry.wheelchairBoarding + additionalProperties = entry.additionalProperties.toMutableMap() } - fun code(code: String) = code(JsonField.of(code)) - - @JsonProperty("code") - @ExcludeMissing - fun code(code: JsonField) = apply { this.code = code } - - fun direction(direction: String) = direction(JsonField.of(direction)) - - @JsonProperty("direction") - @ExcludeMissing - fun direction(direction: JsonField) = apply { this.direction = direction } - fun id(id: String) = id(JsonField.of(id)) - @JsonProperty("id") - @ExcludeMissing fun id(id: JsonField) = apply { this.id = id } fun lat(lat: Double) = lat(JsonField.of(lat)) - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } fun locationType(locationType: Long) = locationType(JsonField.of(locationType)) - @JsonProperty("locationType") - @ExcludeMissing fun locationType(locationType: JsonField) = apply { this.locationType = locationType } fun lon(lon: Double) = lon(JsonField.of(lon)) - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun name(name: String) = name(JsonField.of(name)) - @JsonProperty("name") - @ExcludeMissing fun name(name: JsonField) = apply { this.name = name } fun parent(parent: String) = parent(JsonField.of(parent)) - @JsonProperty("parent") - @ExcludeMissing fun parent(parent: JsonField) = apply { this.parent = parent } fun routeIds(routeIds: List) = routeIds(JsonField.of(routeIds)) - @JsonProperty("routeIds") - @ExcludeMissing - fun routeIds(routeIds: JsonField>) = apply { this.routeIds = routeIds } + fun routeIds(routeIds: JsonField>) = apply { + this.routeIds = routeIds.map { it.toMutableList() } + } + + fun addRouteId(routeId: String) = apply { + routeIds = + (routeIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(routeId) + } + } fun staticRouteIds(staticRouteIds: List) = staticRouteIds(JsonField.of(staticRouteIds)) - @JsonProperty("staticRouteIds") - @ExcludeMissing fun staticRouteIds(staticRouteIds: JsonField>) = apply { - this.staticRouteIds = staticRouteIds + this.staticRouteIds = staticRouteIds.map { it.toMutableList() } + } + + fun addStaticRouteId(staticRouteId: String) = apply { + staticRouteIds = + (staticRouteIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(staticRouteId) + } } + fun code(code: String) = code(JsonField.of(code)) + + fun code(code: JsonField) = apply { this.code = code } + + fun direction(direction: String) = direction(JsonField.of(direction)) + + fun direction(direction: JsonField) = apply { this.direction = direction } + fun wheelchairBoarding(wheelchairBoarding: String) = wheelchairBoarding(JsonField.of(wheelchairBoarding)) - @JsonProperty("wheelchairBoarding") - @ExcludeMissing fun wheelchairBoarding(wheelchairBoarding: JsonField) = apply { this.wheelchairBoarding = wheelchairBoarding } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -457,18 +510,26 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( + checkRequired("id", id), + checkRequired("lat", lat), + checkRequired("locationType", locationType), + checkRequired("lon", lon), + checkRequired("name", name), + checkRequired("parent", parent), + checkRequired("routeIds", routeIds).map { it.toImmutable() }, + checkRequired("staticRouteIds", staticRouteIds).map { it.toImmutable() }, code, direction, - id, - lat, - locationType, - lon, - name, - parent, - routeIds.map { it.toImmutable() }, - staticRouteIds.map { it.toImmutable() }, wheelchairBoarding, additionalProperties.toImmutable(), ) @@ -479,20 +540,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.code == other.code && this.direction == other.direction && this.id == other.id && this.lat == other.lat && this.locationType == other.locationType && this.lon == other.lon && this.name == other.name && this.parent == other.parent && this.routeIds == other.routeIds && this.staticRouteIds == other.staticRouteIds && this.wheelchairBoarding == other.wheelchairBoarding && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && id == other.id && lat == other.lat && locationType == other.locationType && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && code == other.code && direction == other.direction && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, code, direction, wheelchairBoarding, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, direction, id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, wheelchairBoarding, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Entry{code=$code, direction=$direction, id=$id, lat=$lat, locationType=$locationType, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" + "Entry{id=$id, lat=$lat, locationType=$locationType, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, code=$code, direction=$direction, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -500,17 +558,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, references=$references, additionalProperties=$additionalProperties}" @@ -521,17 +576,14 @@ private constructor( return true } - return /* spotless:off */ other is StopRetrieveResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopRetrieveResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "StopRetrieveResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForAgencyListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForAgencyListParams.kt index 5c4c365..e58a7ed 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForAgencyListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForAgencyListParams.kt @@ -2,25 +2,30 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Get stops for a specific agency */ class StopsForAgencyListParams -constructor( +private constructor( private val agencyId: String, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun agencyId(): String = agencyId - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -29,25 +34,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is StopsForAgencyListParams && this.agencyId == other.agencyId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(agencyId, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "StopsForAgencyListParams{agencyId=$agencyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -55,22 +41,28 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [StopsForAgencyListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var agencyId: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(stopsForAgencyListParams: StopsForAgencyListParams) = apply { - this.agencyId = stopsForAgencyListParams.agencyId - additionalHeaders(stopsForAgencyListParams.additionalHeaders) - additionalQueryParams(stopsForAgencyListParams.additionalQueryParams) + agencyId = stopsForAgencyListParams.agencyId + additionalHeaders = stopsForAgencyListParams.additionalHeaders.toBuilder() + additionalQueryParams = stopsForAgencyListParams.additionalQueryParams.toBuilder() } fun agencyId(agencyId: String) = apply { this.agencyId = agencyId } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -81,29 +73,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -116,46 +121,59 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): StopsForAgencyListParams = StopsForAgencyListParams( - checkNotNull(agencyId) { "`agencyId` is required but was not set" }, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + checkRequired("agencyId", agencyId), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is StopsForAgencyListParams && agencyId == other.agencyId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(agencyId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "StopsForAgencyListParams{agencyId=$agencyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForAgencyListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForAgencyListResponse.kt index 56a8389..e78c5d8 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForAgencyListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForAgencyListResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,25 +13,37 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = StopsForAgencyListResponse.Builder::class) @NoAutoDetect class StopsForAgencyListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val limitExceeded: JsonField, - private val outOfRange: JsonField, - private val list: JsonField>, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("limitExceeded") + @ExcludeMissing + private val limitExceeded: JsonField = JsonMissing.of(), + @JsonProperty("list") + @ExcludeMissing + private val list: JsonField> = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonProperty("outOfRange") + @ExcludeMissing + private val outOfRange: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -42,52 +54,62 @@ private constructor( fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") - fun outOfRange(): Optional = Optional.ofNullable(outOfRange.getNullable("outOfRange")) - fun list(): kotlin.collections.List = list.getRequired("list") fun references(): References = references.getRequired("references") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() + fun outOfRange(): Optional = Optional.ofNullable(outOfRange.getNullable("outOfRange")) - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + @JsonProperty("limitExceeded") + @ExcludeMissing + fun _limitExceeded(): JsonField = limitExceeded - @JsonProperty("outOfRange") @ExcludeMissing fun _outOfRange() = outOfRange + @JsonProperty("list") + @ExcludeMissing + fun _list(): JsonField> = list - @JsonProperty("list") @ExcludeMissing fun _list() = list + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("outOfRange") @ExcludeMissing fun _outOfRange(): JsonField = outOfRange @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): StopsForAgencyListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - limitExceeded() - outOfRange() - list().forEach { it.validate() } - references().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + limitExceeded() + list().forEach { it.validate() } + references().validate() + outOfRange() + validated = true } fun toBuilder() = Builder().from(this) @@ -97,139 +119,154 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopsForAgencyListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var limitExceeded: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var limitExceeded: JsonField? = null + private var list: JsonField>? = null + private var references: JsonField? = null private var outOfRange: JsonField = JsonMissing.of() - private var list: JsonField> = JsonMissing.of() - private var references: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(stopsForAgencyListResponse: StopsForAgencyListResponse) = apply { - this.code = stopsForAgencyListResponse.code - this.currentTime = stopsForAgencyListResponse.currentTime - this.text = stopsForAgencyListResponse.text - this.version = stopsForAgencyListResponse.version - this.limitExceeded = stopsForAgencyListResponse.limitExceeded - this.outOfRange = stopsForAgencyListResponse.outOfRange - this.list = stopsForAgencyListResponse.list - this.references = stopsForAgencyListResponse.references - additionalProperties(stopsForAgencyListResponse.additionalProperties) + code = stopsForAgencyListResponse.code + currentTime = stopsForAgencyListResponse.currentTime + text = stopsForAgencyListResponse.text + version = stopsForAgencyListResponse.version + limitExceeded = stopsForAgencyListResponse.limitExceeded + list = stopsForAgencyListResponse.list.map { it.toMutableList() } + references = stopsForAgencyListResponse.references + outOfRange = stopsForAgencyListResponse.outOfRange + additionalProperties = stopsForAgencyListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) - @JsonProperty("limitExceeded") - @ExcludeMissing fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } - fun outOfRange(outOfRange: Boolean) = outOfRange(JsonField.of(outOfRange)) - - @JsonProperty("outOfRange") - @ExcludeMissing - fun outOfRange(outOfRange: JsonField) = apply { this.outOfRange = outOfRange } - fun list(list: kotlin.collections.List) = list(JsonField.of(list)) - @JsonProperty("list") - @ExcludeMissing - fun list(list: JsonField>) = apply { this.list = list } + fun list(list: JsonField>) = apply { + this.list = list.map { it.toMutableList() } + } + + fun addList(list: List) = apply { + this.list = + (this.list ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(list) + } + } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } + fun outOfRange(outOfRange: Boolean) = outOfRange(JsonField.of(outOfRange)) + + fun outOfRange(outOfRange: JsonField) = apply { this.outOfRange = outOfRange } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopsForAgencyListResponse = StopsForAgencyListResponse( - code, - currentTime, - text, - version, - limitExceeded, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), outOfRange, - list.map { it.toImmutable() }, - references, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = List.Builder::class) @NoAutoDetect class List + @JsonCreator private constructor( - private val code: JsonField, - private val direction: JsonField, - private val id: JsonField, - private val lat: JsonField, - private val locationType: JsonField, - private val lon: JsonField, - private val name: JsonField, - private val parent: JsonField, - private val routeIds: JsonField>, - private val staticRouteIds: JsonField>, - private val wheelchairBoarding: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), + @JsonProperty("lat") @ExcludeMissing private val lat: JsonField = JsonMissing.of(), + @JsonProperty("locationType") + @ExcludeMissing + private val locationType: JsonField = JsonMissing.of(), + @JsonProperty("lon") @ExcludeMissing private val lon: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + private val name: JsonField = JsonMissing.of(), + @JsonProperty("parent") + @ExcludeMissing + private val parent: JsonField = JsonMissing.of(), + @JsonProperty("routeIds") + @ExcludeMissing + private val routeIds: JsonField> = JsonMissing.of(), + @JsonProperty("staticRouteIds") + @ExcludeMissing + private val staticRouteIds: JsonField> = JsonMissing.of(), + @JsonProperty("code") + @ExcludeMissing + private val code: JsonField = JsonMissing.of(), + @JsonProperty("direction") + @ExcludeMissing + private val direction: JsonField = JsonMissing.of(), + @JsonProperty("wheelchairBoarding") + @ExcludeMissing + private val wheelchairBoarding: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun code(): Optional = Optional.ofNullable(code.getNullable("code")) - - fun direction(): Optional = Optional.ofNullable(direction.getNullable("direction")) - fun id(): String = id.getRequired("id") fun lat(): Double = lat.getRequired("lat") - fun locationType(): Optional = - Optional.ofNullable(locationType.getNullable("locationType")) + fun locationType(): Long = locationType.getRequired("locationType") fun lon(): Double = lon.getRequired("lon") @@ -242,52 +279,66 @@ private constructor( fun staticRouteIds(): kotlin.collections.List = staticRouteIds.getRequired("staticRouteIds") + fun code(): Optional = Optional.ofNullable(code.getNullable("code")) + + fun direction(): Optional = Optional.ofNullable(direction.getNullable("direction")) + fun wheelchairBoarding(): Optional = Optional.ofNullable(wheelchairBoarding.getNullable("wheelchairBoarding")) - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("direction") @ExcludeMissing fun _direction() = direction + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("locationType") + @ExcludeMissing + fun _locationType(): JsonField = locationType - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon - @JsonProperty("locationType") @ExcludeMissing fun _locationType() = locationType + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("routeIds") + @ExcludeMissing + fun _routeIds(): JsonField> = routeIds - @JsonProperty("parent") @ExcludeMissing fun _parent() = parent + @JsonProperty("staticRouteIds") + @ExcludeMissing + fun _staticRouteIds(): JsonField> = staticRouteIds - @JsonProperty("routeIds") @ExcludeMissing fun _routeIds() = routeIds + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("staticRouteIds") @ExcludeMissing fun _staticRouteIds() = staticRouteIds + @JsonProperty("direction") @ExcludeMissing fun _direction(): JsonField = direction @JsonProperty("wheelchairBoarding") @ExcludeMissing - fun _wheelchairBoarding() = wheelchairBoarding + fun _wheelchairBoarding(): JsonField = wheelchairBoarding @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): List = apply { - if (!validated) { - code() - direction() - id() - lat() - locationType() - lon() - name() - parent() - routeIds() - staticRouteIds() - wheelchairBoarding() - validated = true + if (validated) { + return@apply } + + id() + lat() + locationType() + lon() + name() + parent() + routeIds() + staticRouteIds() + code() + direction() + wheelchairBoarding() + validated = true } fun toBuilder() = Builder().from(this) @@ -297,141 +348,150 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - + /** A builder for [List]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var lat: JsonField? = null + private var locationType: JsonField? = null + private var lon: JsonField? = null + private var name: JsonField? = null + private var parent: JsonField? = null + private var routeIds: JsonField>? = null + private var staticRouteIds: JsonField>? = null private var code: JsonField = JsonMissing.of() private var direction: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() - private var lat: JsonField = JsonMissing.of() - private var locationType: JsonField = JsonMissing.of() - private var lon: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var parent: JsonField = JsonMissing.of() - private var routeIds: JsonField> = JsonMissing.of() - private var staticRouteIds: JsonField> = - JsonMissing.of() private var wheelchairBoarding: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(list: List) = apply { - this.code = list.code - this.direction = list.direction - this.id = list.id - this.lat = list.lat - this.locationType = list.locationType - this.lon = list.lon - this.name = list.name - this.parent = list.parent - this.routeIds = list.routeIds - this.staticRouteIds = list.staticRouteIds - this.wheelchairBoarding = list.wheelchairBoarding - additionalProperties(list.additionalProperties) + id = list.id + lat = list.lat + locationType = list.locationType + lon = list.lon + name = list.name + parent = list.parent + routeIds = list.routeIds.map { it.toMutableList() } + staticRouteIds = list.staticRouteIds.map { it.toMutableList() } + code = list.code + direction = list.direction + wheelchairBoarding = list.wheelchairBoarding + additionalProperties = list.additionalProperties.toMutableMap() } - fun code(code: String) = code(JsonField.of(code)) - - @JsonProperty("code") - @ExcludeMissing - fun code(code: JsonField) = apply { this.code = code } - - fun direction(direction: String) = direction(JsonField.of(direction)) - - @JsonProperty("direction") - @ExcludeMissing - fun direction(direction: JsonField) = apply { this.direction = direction } - fun id(id: String) = id(JsonField.of(id)) - @JsonProperty("id") - @ExcludeMissing fun id(id: JsonField) = apply { this.id = id } fun lat(lat: Double) = lat(JsonField.of(lat)) - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } fun locationType(locationType: Long) = locationType(JsonField.of(locationType)) - @JsonProperty("locationType") - @ExcludeMissing fun locationType(locationType: JsonField) = apply { this.locationType = locationType } fun lon(lon: Double) = lon(JsonField.of(lon)) - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun name(name: String) = name(JsonField.of(name)) - @JsonProperty("name") - @ExcludeMissing fun name(name: JsonField) = apply { this.name = name } fun parent(parent: String) = parent(JsonField.of(parent)) - @JsonProperty("parent") - @ExcludeMissing fun parent(parent: JsonField) = apply { this.parent = parent } fun routeIds(routeIds: kotlin.collections.List) = routeIds(JsonField.of(routeIds)) - @JsonProperty("routeIds") - @ExcludeMissing fun routeIds(routeIds: JsonField>) = apply { - this.routeIds = routeIds + this.routeIds = routeIds.map { it.toMutableList() } + } + + fun addRouteId(routeId: String) = apply { + routeIds = + (routeIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(routeId) + } } fun staticRouteIds(staticRouteIds: kotlin.collections.List) = staticRouteIds(JsonField.of(staticRouteIds)) - @JsonProperty("staticRouteIds") - @ExcludeMissing fun staticRouteIds(staticRouteIds: JsonField>) = apply { - this.staticRouteIds = staticRouteIds + this.staticRouteIds = staticRouteIds.map { it.toMutableList() } } + fun addStaticRouteId(staticRouteId: String) = apply { + staticRouteIds = + (staticRouteIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(staticRouteId) + } + } + + fun code(code: String) = code(JsonField.of(code)) + + fun code(code: JsonField) = apply { this.code = code } + + fun direction(direction: String) = direction(JsonField.of(direction)) + + fun direction(direction: JsonField) = apply { this.direction = direction } + fun wheelchairBoarding(wheelchairBoarding: String) = wheelchairBoarding(JsonField.of(wheelchairBoarding)) - @JsonProperty("wheelchairBoarding") - @ExcludeMissing fun wheelchairBoarding(wheelchairBoarding: JsonField) = apply { this.wheelchairBoarding = wheelchairBoarding } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): List = List( + checkRequired("id", id), + checkRequired("lat", lat), + checkRequired("locationType", locationType), + checkRequired("lon", lon), + checkRequired("name", name), + checkRequired("parent", parent), + checkRequired("routeIds", routeIds).map { it.toImmutable() }, + checkRequired("staticRouteIds", staticRouteIds).map { it.toImmutable() }, code, direction, - id, - lat, - locationType, - lon, - name, - parent, - routeIds.map { it.toImmutable() }, - staticRouteIds.map { it.toImmutable() }, wheelchairBoarding, additionalProperties.toImmutable(), ) @@ -442,20 +502,17 @@ private constructor( return true } - return /* spotless:off */ other is List && this.code == other.code && this.direction == other.direction && this.id == other.id && this.lat == other.lat && this.locationType == other.locationType && this.lon == other.lon && this.name == other.name && this.parent == other.parent && this.routeIds == other.routeIds && this.staticRouteIds == other.staticRouteIds && this.wheelchairBoarding == other.wheelchairBoarding && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is List && id == other.id && lat == other.lat && locationType == other.locationType && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && code == other.code && direction == other.direction && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, code, direction, wheelchairBoarding, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, direction, id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, wheelchairBoarding, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "List{code=$code, direction=$direction, id=$id, lat=$lat, locationType=$locationType, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" + "List{id=$id, lat=$lat, locationType=$locationType, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, code=$code, direction=$direction, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -463,18 +520,15 @@ private constructor( return true } - return /* spotless:off */ other is StopsForAgencyListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.limitExceeded == other.limitExceeded && this.outOfRange == other.outOfRange && this.list == other.list && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopsForAgencyListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && limitExceeded == other.limitExceeded && list == other.list && references == other.references && outOfRange == other.outOfRange && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, limitExceeded, list, references, outOfRange, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, limitExceeded, outOfRange, list, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "StopsForAgencyListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, limitExceeded=$limitExceeded, outOfRange=$outOfRange, list=$list, references=$references, additionalProperties=$additionalProperties}" + "StopsForAgencyListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, limitExceeded=$limitExceeded, list=$list, references=$references, outOfRange=$outOfRange, additionalProperties=$additionalProperties}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForLocationListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForLocationListParams.kt index 5a72da8..679c6c6 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForLocationListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForLocationListParams.kt @@ -2,72 +2,61 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** stops-for-location */ class StopsForLocationListParams -constructor( +private constructor( private val lat: Double, private val lon: Double, private val latSpan: Double?, private val lonSpan: Double?, private val query: String?, private val radius: Double?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun lat(): Double = lat fun lon(): Double = lon + /** An alternative to radius to set the search bounding box (optional) */ fun latSpan(): Optional = Optional.ofNullable(latSpan) + /** An alternative to radius to set the search bounding box (optional) */ fun lonSpan(): Optional = Optional.ofNullable(lonSpan) + /** A search query string to filter the results */ fun query(): Optional = Optional.ofNullable(query) + /** The radius in meters to search within */ fun radius(): Optional = Optional.ofNullable(radius) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.lat.let { params.put("lat", listOf(it.toString())) } - this.lon.let { params.put("lon", listOf(it.toString())) } - this.latSpan?.let { params.put("latSpan", listOf(it.toString())) } - this.lonSpan?.let { params.put("lonSpan", listOf(it.toString())) } - this.query?.let { params.put("query", listOf(it.toString())) } - this.radius?.let { params.put("radius", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() - } - - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun _additionalQueryParams(): QueryParams = additionalQueryParams - return /* spotless:off */ other is StopsForLocationListParams && this.lat == other.lat && this.lon == other.lon && this.latSpan == other.latSpan && this.lonSpan == other.lonSpan && this.query == other.query && this.radius == other.radius && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } + override fun _headers(): Headers = additionalHeaders - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(lat, lon, latSpan, lonSpan, query, radius, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.lat.let { queryParams.put("lat", listOf(it.toString())) } + this.lon.let { queryParams.put("lon", listOf(it.toString())) } + this.latSpan?.let { queryParams.put("latSpan", listOf(it.toString())) } + this.lonSpan?.let { queryParams.put("lonSpan", listOf(it.toString())) } + this.query?.let { queryParams.put("query", listOf(it.toString())) } + this.radius?.let { queryParams.put("radius", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } - override fun toString() = - "StopsForLocationListParams{lat=$lat, lon=$lon, latSpan=$latSpan, lonSpan=$lonSpan, query=$query, radius=$radius, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -75,8 +64,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [StopsForLocationListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var lat: Double? = null private var lon: Double? = null @@ -84,19 +74,19 @@ constructor( private var lonSpan: Double? = null private var query: String? = null private var radius: Double? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(stopsForLocationListParams: StopsForLocationListParams) = apply { - this.lat = stopsForLocationListParams.lat - this.lon = stopsForLocationListParams.lon - this.latSpan = stopsForLocationListParams.latSpan - this.lonSpan = stopsForLocationListParams.lonSpan - this.query = stopsForLocationListParams.query - this.radius = stopsForLocationListParams.radius - additionalHeaders(stopsForLocationListParams.additionalHeaders) - additionalQueryParams(stopsForLocationListParams.additionalQueryParams) + lat = stopsForLocationListParams.lat + lon = stopsForLocationListParams.lon + latSpan = stopsForLocationListParams.latSpan + lonSpan = stopsForLocationListParams.lonSpan + query = stopsForLocationListParams.query + radius = stopsForLocationListParams.radius + additionalHeaders = stopsForLocationListParams.additionalHeaders.toBuilder() + additionalQueryParams = stopsForLocationListParams.additionalQueryParams.toBuilder() } fun lat(lat: Double) = apply { this.lat = lat } @@ -104,16 +94,45 @@ constructor( fun lon(lon: Double) = apply { this.lon = lon } /** An alternative to radius to set the search bounding box (optional) */ - fun latSpan(latSpan: Double) = apply { this.latSpan = latSpan } + fun latSpan(latSpan: Double?) = apply { this.latSpan = latSpan } /** An alternative to radius to set the search bounding box (optional) */ - fun lonSpan(lonSpan: Double) = apply { this.lonSpan = lonSpan } + fun latSpan(latSpan: Double) = latSpan(latSpan as Double?) + + /** An alternative to radius to set the search bounding box (optional) */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun latSpan(latSpan: Optional) = latSpan(latSpan.orElse(null) as Double?) + + /** An alternative to radius to set the search bounding box (optional) */ + fun lonSpan(lonSpan: Double?) = apply { this.lonSpan = lonSpan } + + /** An alternative to radius to set the search bounding box (optional) */ + fun lonSpan(lonSpan: Double) = lonSpan(lonSpan as Double?) + + /** An alternative to radius to set the search bounding box (optional) */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun lonSpan(lonSpan: Optional) = lonSpan(lonSpan.orElse(null) as Double?) + + /** A search query string to filter the results */ + fun query(query: String?) = apply { this.query = query } /** A search query string to filter the results */ - fun query(query: String) = apply { this.query = query } + fun query(query: Optional) = query(query.orElse(null)) /** The radius in meters to search within */ - fun radius(radius: Double) = apply { this.radius = radius } + fun radius(radius: Double?) = apply { this.radius = radius } + + /** The radius in meters to search within */ + fun radius(radius: Double) = radius(radius as Double?) + + /** The radius in meters to search within */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun radius(radius: Optional) = radius(radius.orElse(null) as Double?) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -125,29 +144,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -160,51 +192,64 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): StopsForLocationListParams = StopsForLocationListParams( - checkNotNull(lat) { "`lat` is required but was not set" }, - checkNotNull(lon) { "`lon` is required but was not set" }, + checkRequired("lat", lat), + checkRequired("lon", lon), latSpan, lonSpan, query, radius, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is StopsForLocationListParams && lat == other.lat && lon == other.lon && latSpan == other.latSpan && lonSpan == other.lonSpan && query == other.query && radius == other.radius && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(lat, lon, latSpan, lonSpan, query, radius, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "StopsForLocationListParams{lat=$lat, lon=$lon, latSpan=$latSpan, lonSpan=$lonSpan, query=$query, radius=$radius, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForLocationListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForLocationListResponse.kt index 9a7970a..5fc7409 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForLocationListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForLocationListResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = StopsForLocationListResponse.Builder::class) @NoAutoDetect class StopsForLocationListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): StopsForLocationListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,122 +87,137 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopsForLocationListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(stopsForLocationListResponse: StopsForLocationListResponse) = apply { - this.code = stopsForLocationListResponse.code - this.currentTime = stopsForLocationListResponse.currentTime - this.text = stopsForLocationListResponse.text - this.version = stopsForLocationListResponse.version - this.data = stopsForLocationListResponse.data - additionalProperties(stopsForLocationListResponse.additionalProperties) + code = stopsForLocationListResponse.code + currentTime = stopsForLocationListResponse.currentTime + text = stopsForLocationListResponse.text + version = stopsForLocationListResponse.version + data = stopsForLocationListResponse.data + additionalProperties = stopsForLocationListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopsForLocationListResponse = StopsForLocationListResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val limitExceeded: JsonField, - private val outOfRange: JsonField, - private val list: JsonField>, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("limitExceeded") + @ExcludeMissing + private val limitExceeded: JsonField = JsonMissing.of(), + @JsonProperty("list") + @ExcludeMissing + private val list: JsonField> = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonProperty("outOfRange") + @ExcludeMissing + private val outOfRange: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") - fun outOfRange(): Optional = - Optional.ofNullable(outOfRange.getNullable("outOfRange")) - fun list(): kotlin.collections.List = list.getRequired("list") fun references(): References = references.getRequired("references") - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + fun outOfRange(): Optional = + Optional.ofNullable(outOfRange.getNullable("outOfRange")) + + @JsonProperty("limitExceeded") + @ExcludeMissing + fun _limitExceeded(): JsonField = limitExceeded - @JsonProperty("outOfRange") @ExcludeMissing fun _outOfRange() = outOfRange + @JsonProperty("list") + @ExcludeMissing + fun _list(): JsonField> = list - @JsonProperty("list") @ExcludeMissing fun _list() = list + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("outOfRange") + @ExcludeMissing + fun _outOfRange(): JsonField = outOfRange @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - limitExceeded() - outOfRange() - list().forEach { it.validate() } - references().validate() - validated = true + if (validated) { + return@apply } + + limitExceeded() + list().forEach { it.validate() } + references().validate() + outOfRange() + validated = true } fun toBuilder() = Builder().from(this) @@ -204,106 +227,135 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var limitExceeded: JsonField = JsonMissing.of() + private var limitExceeded: JsonField? = null + private var list: JsonField>? = null + private var references: JsonField? = null private var outOfRange: JsonField = JsonMissing.of() - private var list: JsonField> = JsonMissing.of() - private var references: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.limitExceeded = data.limitExceeded - this.outOfRange = data.outOfRange - this.list = data.list - this.references = data.references - additionalProperties(data.additionalProperties) + limitExceeded = data.limitExceeded + list = data.list.map { it.toMutableList() } + references = data.references + outOfRange = data.outOfRange + additionalProperties = data.additionalProperties.toMutableMap() } fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) - @JsonProperty("limitExceeded") - @ExcludeMissing fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } - fun outOfRange(outOfRange: Boolean) = outOfRange(JsonField.of(outOfRange)) - - @JsonProperty("outOfRange") - @ExcludeMissing - fun outOfRange(outOfRange: JsonField) = apply { this.outOfRange = outOfRange } - fun list(list: kotlin.collections.List) = list(JsonField.of(list)) - @JsonProperty("list") - @ExcludeMissing - fun list(list: JsonField>) = apply { this.list = list } + fun list(list: JsonField>) = apply { + this.list = list.map { it.toMutableList() } + } + + fun addList(list: List) = apply { + this.list = + (this.list ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(list) + } + } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } + fun outOfRange(outOfRange: Boolean) = outOfRange(JsonField.of(outOfRange)) + + fun outOfRange(outOfRange: JsonField) = apply { this.outOfRange = outOfRange } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - limitExceeded, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), outOfRange, - list.map { it.toImmutable() }, - references, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = List.Builder::class) @NoAutoDetect class List + @JsonCreator private constructor( - private val code: JsonField, - private val direction: JsonField, - private val id: JsonField, - private val lat: JsonField, - private val locationType: JsonField, - private val lon: JsonField, - private val name: JsonField, - private val parent: JsonField, - private val routeIds: JsonField>, - private val staticRouteIds: JsonField>, - private val wheelchairBoarding: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("locationType") + @ExcludeMissing + private val locationType: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + private val name: JsonField = JsonMissing.of(), + @JsonProperty("parent") + @ExcludeMissing + private val parent: JsonField = JsonMissing.of(), + @JsonProperty("routeIds") + @ExcludeMissing + private val routeIds: JsonField> = JsonMissing.of(), + @JsonProperty("staticRouteIds") + @ExcludeMissing + private val staticRouteIds: JsonField> = + JsonMissing.of(), + @JsonProperty("code") + @ExcludeMissing + private val code: JsonField = JsonMissing.of(), + @JsonProperty("direction") + @ExcludeMissing + private val direction: JsonField = JsonMissing.of(), + @JsonProperty("wheelchairBoarding") + @ExcludeMissing + private val wheelchairBoarding: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun code(): Optional = Optional.ofNullable(code.getNullable("code")) - - fun direction(): Optional = - Optional.ofNullable(direction.getNullable("direction")) - fun id(): String = id.getRequired("id") fun lat(): Double = lat.getRequired("lat") - fun locationType(): Optional = - Optional.ofNullable(locationType.getNullable("locationType")) + fun locationType(): Long = locationType.getRequired("locationType") fun lon(): Double = lon.getRequired("lon") @@ -316,52 +368,69 @@ private constructor( fun staticRouteIds(): kotlin.collections.List = staticRouteIds.getRequired("staticRouteIds") + fun code(): Optional = Optional.ofNullable(code.getNullable("code")) + + fun direction(): Optional = + Optional.ofNullable(direction.getNullable("direction")) + fun wheelchairBoarding(): Optional = Optional.ofNullable(wheelchairBoarding.getNullable("wheelchairBoarding")) - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("direction") @ExcludeMissing fun _direction() = direction + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("locationType") + @ExcludeMissing + fun _locationType(): JsonField = locationType - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon - @JsonProperty("locationType") @ExcludeMissing fun _locationType() = locationType + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("routeIds") + @ExcludeMissing + fun _routeIds(): JsonField> = routeIds - @JsonProperty("parent") @ExcludeMissing fun _parent() = parent + @JsonProperty("staticRouteIds") + @ExcludeMissing + fun _staticRouteIds(): JsonField> = staticRouteIds - @JsonProperty("routeIds") @ExcludeMissing fun _routeIds() = routeIds + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("staticRouteIds") @ExcludeMissing fun _staticRouteIds() = staticRouteIds + @JsonProperty("direction") + @ExcludeMissing + fun _direction(): JsonField = direction @JsonProperty("wheelchairBoarding") @ExcludeMissing - fun _wheelchairBoarding() = wheelchairBoarding + fun _wheelchairBoarding(): JsonField = wheelchairBoarding @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): List = apply { - if (!validated) { - code() - direction() - id() - lat() - locationType() - lon() - name() - parent() - routeIds() - staticRouteIds() - wheelchairBoarding() - validated = true + if (validated) { + return@apply } + + id() + lat() + locationType() + lon() + name() + parent() + routeIds() + staticRouteIds() + code() + direction() + wheelchairBoarding() + validated = true } fun toBuilder() = Builder().from(this) @@ -371,124 +440,127 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - + /** A builder for [List]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var lat: JsonField? = null + private var locationType: JsonField? = null + private var lon: JsonField? = null + private var name: JsonField? = null + private var parent: JsonField? = null + private var routeIds: JsonField>? = null + private var staticRouteIds: JsonField>? = null private var code: JsonField = JsonMissing.of() private var direction: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() - private var lat: JsonField = JsonMissing.of() - private var locationType: JsonField = JsonMissing.of() - private var lon: JsonField = JsonMissing.of() - private var name: JsonField = JsonMissing.of() - private var parent: JsonField = JsonMissing.of() - private var routeIds: JsonField> = JsonMissing.of() - private var staticRouteIds: JsonField> = - JsonMissing.of() private var wheelchairBoarding: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(list: List) = apply { - this.code = list.code - this.direction = list.direction - this.id = list.id - this.lat = list.lat - this.locationType = list.locationType - this.lon = list.lon - this.name = list.name - this.parent = list.parent - this.routeIds = list.routeIds - this.staticRouteIds = list.staticRouteIds - this.wheelchairBoarding = list.wheelchairBoarding - additionalProperties(list.additionalProperties) + id = list.id + lat = list.lat + locationType = list.locationType + lon = list.lon + name = list.name + parent = list.parent + routeIds = list.routeIds.map { it.toMutableList() } + staticRouteIds = list.staticRouteIds.map { it.toMutableList() } + code = list.code + direction = list.direction + wheelchairBoarding = list.wheelchairBoarding + additionalProperties = list.additionalProperties.toMutableMap() } - fun code(code: String) = code(JsonField.of(code)) - - @JsonProperty("code") - @ExcludeMissing - fun code(code: JsonField) = apply { this.code = code } - - fun direction(direction: String) = direction(JsonField.of(direction)) - - @JsonProperty("direction") - @ExcludeMissing - fun direction(direction: JsonField) = apply { this.direction = direction } - fun id(id: String) = id(JsonField.of(id)) - @JsonProperty("id") - @ExcludeMissing fun id(id: JsonField) = apply { this.id = id } fun lat(lat: Double) = lat(JsonField.of(lat)) - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } fun locationType(locationType: Long) = locationType(JsonField.of(locationType)) - @JsonProperty("locationType") - @ExcludeMissing fun locationType(locationType: JsonField) = apply { this.locationType = locationType } fun lon(lon: Double) = lon(JsonField.of(lon)) - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun name(name: String) = name(JsonField.of(name)) - @JsonProperty("name") - @ExcludeMissing fun name(name: JsonField) = apply { this.name = name } fun parent(parent: String) = parent(JsonField.of(parent)) - @JsonProperty("parent") - @ExcludeMissing fun parent(parent: JsonField) = apply { this.parent = parent } fun routeIds(routeIds: kotlin.collections.List) = routeIds(JsonField.of(routeIds)) - @JsonProperty("routeIds") - @ExcludeMissing fun routeIds(routeIds: JsonField>) = apply { - this.routeIds = routeIds + this.routeIds = routeIds.map { it.toMutableList() } + } + + fun addRouteId(routeId: String) = apply { + routeIds = + (routeIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(routeId) + } } fun staticRouteIds(staticRouteIds: kotlin.collections.List) = staticRouteIds(JsonField.of(staticRouteIds)) - @JsonProperty("staticRouteIds") - @ExcludeMissing fun staticRouteIds(staticRouteIds: JsonField>) = apply { - this.staticRouteIds = staticRouteIds + this.staticRouteIds = staticRouteIds.map { it.toMutableList() } } + fun addStaticRouteId(staticRouteId: String) = apply { + staticRouteIds = + (staticRouteIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(staticRouteId) + } + } + + fun code(code: String) = code(JsonField.of(code)) + + fun code(code: JsonField) = apply { this.code = code } + + fun direction(direction: String) = direction(JsonField.of(direction)) + + fun direction(direction: JsonField) = apply { this.direction = direction } + fun wheelchairBoarding(wheelchairBoarding: String) = wheelchairBoarding(JsonField.of(wheelchairBoarding)) - @JsonProperty("wheelchairBoarding") - @ExcludeMissing fun wheelchairBoarding(wheelchairBoarding: JsonField) = apply { this.wheelchairBoarding = wheelchairBoarding } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -496,18 +568,26 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): List = List( + checkRequired("id", id), + checkRequired("lat", lat), + checkRequired("locationType", locationType), + checkRequired("lon", lon), + checkRequired("name", name), + checkRequired("parent", parent), + checkRequired("routeIds", routeIds).map { it.toImmutable() }, + checkRequired("staticRouteIds", staticRouteIds).map { it.toImmutable() }, code, direction, - id, - lat, - locationType, - lon, - name, - parent, - routeIds.map { it.toImmutable() }, - staticRouteIds.map { it.toImmutable() }, wheelchairBoarding, additionalProperties.toImmutable(), ) @@ -518,20 +598,17 @@ private constructor( return true } - return /* spotless:off */ other is List && this.code == other.code && this.direction == other.direction && this.id == other.id && this.lat == other.lat && this.locationType == other.locationType && this.lon == other.lon && this.name == other.name && this.parent == other.parent && this.routeIds == other.routeIds && this.staticRouteIds == other.staticRouteIds && this.wheelchairBoarding == other.wheelchairBoarding && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is List && id == other.id && lat == other.lat && locationType == other.locationType && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && code == other.code && direction == other.direction && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, code, direction, wheelchairBoarding, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, direction, id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, wheelchairBoarding, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "List{code=$code, direction=$direction, id=$id, lat=$lat, locationType=$locationType, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" + "List{id=$id, lat=$lat, locationType=$locationType, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, code=$code, direction=$direction, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -539,20 +616,17 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.limitExceeded == other.limitExceeded && this.outOfRange == other.outOfRange && this.list == other.list && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && list == other.list && references == other.references && outOfRange == other.outOfRange && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, references, outOfRange, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(limitExceeded, outOfRange, list, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Data{limitExceeded=$limitExceeded, outOfRange=$outOfRange, list=$list, references=$references, additionalProperties=$additionalProperties}" + "Data{limitExceeded=$limitExceeded, list=$list, references=$references, outOfRange=$outOfRange, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -560,17 +634,14 @@ private constructor( return true } - return /* spotless:off */ other is StopsForLocationListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopsForLocationListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "StopsForLocationListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForRouteListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForRouteListParams.kt index 6a20455..3345bb5 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForRouteListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForRouteListParams.kt @@ -2,38 +2,44 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Get stops for a specific route */ class StopsForRouteListParams -constructor( +private constructor( private val routeId: String, private val includePolylines: Boolean?, private val time: String?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun routeId(): String = routeId + /** Include polyline elements in the response (default true) */ fun includePolylines(): Optional = Optional.ofNullable(includePolylines) + /** Specify service date (YYYY-MM-DD or epoch) (default today) */ fun time(): Optional = Optional.ofNullable(time) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.includePolylines?.let { params.put("includePolylines", listOf(it.toString())) } - this.time?.let { params.put("time", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.includePolylines?.let { queryParams.put("includePolylines", listOf(it.toString())) } + this.time?.let { queryParams.put("time", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } fun getPathParam(index: Int): String { @@ -43,25 +49,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is StopsForRouteListParams && this.routeId == other.routeId && this.includePolylines == other.includePolylines && this.time == other.time && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(routeId, includePolylines, time, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "StopsForRouteListParams{routeId=$routeId, includePolylines=$includePolylines, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -69,33 +56,51 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [StopsForRouteListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var routeId: String? = null private var includePolylines: Boolean? = null private var time: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(stopsForRouteListParams: StopsForRouteListParams) = apply { - this.routeId = stopsForRouteListParams.routeId - this.includePolylines = stopsForRouteListParams.includePolylines - this.time = stopsForRouteListParams.time - additionalHeaders(stopsForRouteListParams.additionalHeaders) - additionalQueryParams(stopsForRouteListParams.additionalQueryParams) + routeId = stopsForRouteListParams.routeId + includePolylines = stopsForRouteListParams.includePolylines + time = stopsForRouteListParams.time + additionalHeaders = stopsForRouteListParams.additionalHeaders.toBuilder() + additionalQueryParams = stopsForRouteListParams.additionalQueryParams.toBuilder() } fun routeId(routeId: String) = apply { this.routeId = routeId } /** Include polyline elements in the response (default true) */ - fun includePolylines(includePolylines: Boolean) = apply { + fun includePolylines(includePolylines: Boolean?) = apply { this.includePolylines = includePolylines } + /** Include polyline elements in the response (default true) */ + fun includePolylines(includePolylines: Boolean) = + includePolylines(includePolylines as Boolean?) + + /** Include polyline elements in the response (default true) */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun includePolylines(includePolylines: Optional) = + includePolylines(includePolylines.orElse(null) as Boolean?) + + /** Specify service date (YYYY-MM-DD or epoch) (default today) */ + fun time(time: String?) = apply { this.time = time } + /** Specify service date (YYYY-MM-DD or epoch) (default today) */ - fun time(time: String) = apply { this.time = time } + fun time(time: Optional) = time(time.orElse(null)) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -107,29 +112,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -142,48 +160,61 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): StopsForRouteListParams = StopsForRouteListParams( - checkNotNull(routeId) { "`routeId` is required but was not set" }, + checkRequired("routeId", routeId), includePolylines, time, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is StopsForRouteListParams && routeId == other.routeId && includePolylines == other.includePolylines && time == other.time && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(routeId, includePolylines, time, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "StopsForRouteListParams{routeId=$routeId, includePolylines=$includePolylines, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForRouteListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForRouteListResponse.kt index 70761aa..2676f66 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForRouteListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/StopsForRouteListResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = StopsForRouteListResponse.Builder::class) @NoAutoDetect class StopsForRouteListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): StopsForRouteListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,109 +87,114 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopsForRouteListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(stopsForRouteListResponse: StopsForRouteListResponse) = apply { - this.code = stopsForRouteListResponse.code - this.currentTime = stopsForRouteListResponse.currentTime - this.text = stopsForRouteListResponse.text - this.version = stopsForRouteListResponse.version - this.data = stopsForRouteListResponse.data - additionalProperties(stopsForRouteListResponse.additionalProperties) + code = stopsForRouteListResponse.code + currentTime = stopsForRouteListResponse.currentTime + text = stopsForRouteListResponse.text + version = stopsForRouteListResponse.version + data = stopsForRouteListResponse.data + additionalProperties = stopsForRouteListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopsForRouteListResponse = StopsForRouteListResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") fun references(): References = references.getRequired("references") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -191,68 +204,77 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val polylines: JsonField>, - private val routeId: JsonField, - private val stopGroupings: JsonField>, - private val stopIds: JsonField>, - private val additionalProperties: Map, + @JsonProperty("polylines") + @ExcludeMissing + private val polylines: JsonField> = JsonMissing.of(), + @JsonProperty("routeId") + @ExcludeMissing + private val routeId: JsonField = JsonMissing.of(), + @JsonProperty("stopGroupings") + @ExcludeMissing + private val stopGroupings: JsonField> = JsonMissing.of(), + @JsonProperty("stopIds") + @ExcludeMissing + private val stopIds: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun polylines(): Optional> = Optional.ofNullable(polylines.getNullable("polylines")) @@ -264,26 +286,36 @@ private constructor( fun stopIds(): Optional> = Optional.ofNullable(stopIds.getNullable("stopIds")) - @JsonProperty("polylines") @ExcludeMissing fun _polylines() = polylines + @JsonProperty("polylines") + @ExcludeMissing + fun _polylines(): JsonField> = polylines - @JsonProperty("routeId") @ExcludeMissing fun _routeId() = routeId + @JsonProperty("routeId") @ExcludeMissing fun _routeId(): JsonField = routeId - @JsonProperty("stopGroupings") @ExcludeMissing fun _stopGroupings() = stopGroupings + @JsonProperty("stopGroupings") + @ExcludeMissing + fun _stopGroupings(): JsonField> = stopGroupings - @JsonProperty("stopIds") @ExcludeMissing fun _stopIds() = stopIds + @JsonProperty("stopIds") + @ExcludeMissing + fun _stopIds(): JsonField> = stopIds @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - polylines().map { it.forEach { it.validate() } } - routeId() - stopGroupings().map { it.forEach { it.validate() } } - stopIds() - validated = true + if (validated) { + return@apply } + + polylines().ifPresent { it.forEach { it.validate() } } + routeId() + stopGroupings().ifPresent { it.forEach { it.validate() } } + stopIds() + validated = true } fun toBuilder() = Builder().from(this) @@ -293,60 +325,93 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Entry]. */ + class Builder internal constructor() { - private var polylines: JsonField> = JsonMissing.of() + private var polylines: JsonField>? = null private var routeId: JsonField = JsonMissing.of() - private var stopGroupings: JsonField> = JsonMissing.of() - private var stopIds: JsonField> = JsonMissing.of() + private var stopGroupings: JsonField>? = null + private var stopIds: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(entry: Entry) = apply { - this.polylines = entry.polylines - this.routeId = entry.routeId - this.stopGroupings = entry.stopGroupings - this.stopIds = entry.stopIds - additionalProperties(entry.additionalProperties) + polylines = entry.polylines.map { it.toMutableList() } + routeId = entry.routeId + stopGroupings = entry.stopGroupings.map { it.toMutableList() } + stopIds = entry.stopIds.map { it.toMutableList() } + additionalProperties = entry.additionalProperties.toMutableMap() } fun polylines(polylines: List) = polylines(JsonField.of(polylines)) - @JsonProperty("polylines") - @ExcludeMissing fun polylines(polylines: JsonField>) = apply { - this.polylines = polylines + this.polylines = polylines.map { it.toMutableList() } + } + + fun addPolyline(polyline: Polyline) = apply { + polylines = + (polylines ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(polyline) + } } fun routeId(routeId: String) = routeId(JsonField.of(routeId)) - @JsonProperty("routeId") - @ExcludeMissing fun routeId(routeId: JsonField) = apply { this.routeId = routeId } fun stopGroupings(stopGroupings: List) = stopGroupings(JsonField.of(stopGroupings)) - @JsonProperty("stopGroupings") - @ExcludeMissing fun stopGroupings(stopGroupings: JsonField>) = apply { - this.stopGroupings = stopGroupings + this.stopGroupings = stopGroupings.map { it.toMutableList() } + } + + fun addStopGrouping(stopGrouping: StopGrouping) = apply { + stopGroupings = + (stopGroupings ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stopGrouping) + } } fun stopIds(stopIds: List) = stopIds(JsonField.of(stopIds)) - @JsonProperty("stopIds") - @ExcludeMissing - fun stopIds(stopIds: JsonField>) = apply { this.stopIds = stopIds } + fun stopIds(stopIds: JsonField>) = apply { + this.stopIds = stopIds.map { it.toMutableList() } + } + + fun addStopId(stopId: String) = apply { + stopIds = + (stopIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stopId) + } + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -354,51 +419,68 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( - polylines.map { it.toImmutable() }, + (polylines ?: JsonMissing.of()).map { it.toImmutable() }, routeId, - stopGroupings.map { it.toImmutable() }, - stopIds.map { it.toImmutable() }, + (stopGroupings ?: JsonMissing.of()).map { it.toImmutable() }, + (stopIds ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Polyline.Builder::class) @NoAutoDetect class Polyline + @JsonCreator private constructor( - private val length: JsonField, - private val levels: JsonField, - private val points: JsonField, - private val additionalProperties: Map, + @JsonProperty("length") + @ExcludeMissing + private val length: JsonField = JsonMissing.of(), + @JsonProperty("levels") + @ExcludeMissing + private val levels: JsonField = JsonMissing.of(), + @JsonProperty("points") + @ExcludeMissing + private val points: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun length(): Optional = Optional.ofNullable(length.getNullable("length")) fun levels(): Optional = Optional.ofNullable(levels.getNullable("levels")) fun points(): Optional = Optional.ofNullable(points.getNullable("points")) - @JsonProperty("length") @ExcludeMissing fun _length() = length + @JsonProperty("length") @ExcludeMissing fun _length(): JsonField = length - @JsonProperty("levels") @ExcludeMissing fun _levels() = levels + @JsonProperty("levels") @ExcludeMissing fun _levels(): JsonField = levels - @JsonProperty("points") @ExcludeMissing fun _points() = points + @JsonProperty("points") @ExcludeMissing fun _points(): JsonField = points @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Polyline = apply { - if (!validated) { - length() - levels() - points() - validated = true + if (validated) { + return@apply } + + length() + levels() + points() + validated = true } fun toBuilder() = Builder().from(this) @@ -408,7 +490,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Polyline]. */ + class Builder internal constructor() { private var length: JsonField = JsonMissing.of() private var levels: JsonField = JsonMissing.of() @@ -417,38 +500,31 @@ private constructor( @JvmSynthetic internal fun from(polyline: Polyline) = apply { - this.length = polyline.length - this.levels = polyline.levels - this.points = polyline.points - additionalProperties(polyline.additionalProperties) + length = polyline.length + levels = polyline.levels + points = polyline.points + additionalProperties = polyline.additionalProperties.toMutableMap() } fun length(length: Long) = length(JsonField.of(length)) - @JsonProperty("length") - @ExcludeMissing fun length(length: JsonField) = apply { this.length = length } fun levels(levels: String) = levels(JsonField.of(levels)) - @JsonProperty("levels") - @ExcludeMissing fun levels(levels: JsonField) = apply { this.levels = levels } fun points(points: String) = points(JsonField.of(points)) - @JsonProperty("points") - @ExcludeMissing fun points(points: JsonField) = apply { this.points = points } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -456,6 +532,14 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Polyline = Polyline( length, @@ -470,35 +554,39 @@ private constructor( return true } - return /* spotless:off */ other is Polyline && this.length == other.length && this.levels == other.levels && this.points == other.points && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Polyline && length == other.length && levels == other.levels && points == other.points && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(length, levels, points, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(length, levels, points, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Polyline{length=$length, levels=$levels, points=$points, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = StopGrouping.Builder::class) @NoAutoDetect class StopGrouping + @JsonCreator private constructor( - private val id: JsonField, - private val name: JsonField, - private val polylines: JsonField>, - private val stopIds: JsonField>, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("name") + @ExcludeMissing + private val name: JsonField = JsonMissing.of(), + @JsonProperty("polylines") + @ExcludeMissing + private val polylines: JsonField> = JsonMissing.of(), + @JsonProperty("stopIds") + @ExcludeMissing + private val stopIds: JsonField> = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun id(): Optional = Optional.ofNullable(id.getNullable("id")) fun name(): Optional = Optional.ofNullable(name.getNullable("name")) @@ -509,26 +597,34 @@ private constructor( fun stopIds(): Optional> = Optional.ofNullable(stopIds.getNullable("stopIds")) - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("polylines") @ExcludeMissing fun _polylines() = polylines + @JsonProperty("polylines") + @ExcludeMissing + fun _polylines(): JsonField> = polylines - @JsonProperty("stopIds") @ExcludeMissing fun _stopIds() = stopIds + @JsonProperty("stopIds") + @ExcludeMissing + fun _stopIds(): JsonField> = stopIds @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): StopGrouping = apply { - if (!validated) { - id() - name().map { it.validate() } - polylines().map { it.forEach { it.validate() } } - stopIds() - validated = true + if (validated) { + return@apply } + + id() + name().ifPresent { it.validate() } + polylines().ifPresent { it.forEach { it.validate() } } + stopIds() + validated = true } fun toBuilder() = Builder().from(this) @@ -538,57 +634,77 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopGrouping]. */ + class Builder internal constructor() { private var id: JsonField = JsonMissing.of() private var name: JsonField = JsonMissing.of() - private var polylines: JsonField> = JsonMissing.of() - private var stopIds: JsonField> = JsonMissing.of() + private var polylines: JsonField>? = null + private var stopIds: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(stopGrouping: StopGrouping) = apply { - this.id = stopGrouping.id - this.name = stopGrouping.name - this.polylines = stopGrouping.polylines - this.stopIds = stopGrouping.stopIds - additionalProperties(stopGrouping.additionalProperties) + id = stopGrouping.id + name = stopGrouping.name + polylines = stopGrouping.polylines.map { it.toMutableList() } + stopIds = stopGrouping.stopIds.map { it.toMutableList() } + additionalProperties = stopGrouping.additionalProperties.toMutableMap() } fun id(id: String) = id(JsonField.of(id)) - @JsonProperty("id") - @ExcludeMissing fun id(id: JsonField) = apply { this.id = id } fun name(name: Name) = name(JsonField.of(name)) - @JsonProperty("name") - @ExcludeMissing fun name(name: JsonField) = apply { this.name = name } fun polylines(polylines: List) = polylines(JsonField.of(polylines)) - @JsonProperty("polylines") - @ExcludeMissing fun polylines(polylines: JsonField>) = apply { - this.polylines = polylines + this.polylines = polylines.map { it.toMutableList() } + } + + fun addPolyline(polyline: Polyline) = apply { + polylines = + (polylines ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(polyline) + } } fun stopIds(stopIds: List) = stopIds(JsonField.of(stopIds)) - @JsonProperty("stopIds") - @ExcludeMissing - fun stopIds(stopIds: JsonField>) = apply { this.stopIds = stopIds } + fun stopIds(stopIds: JsonField>) = apply { + this.stopIds = stopIds.map { it.toMutableList() } + } + + fun addStopId(stopId: String) = apply { + stopIds = + (stopIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stopId) + } + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -596,28 +712,41 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopGrouping = StopGrouping( id, name, - polylines.map { it.toImmutable() }, - stopIds.map { it.toImmutable() }, + (polylines ?: JsonMissing.of()).map { it.toImmutable() }, + (stopIds ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Name.Builder::class) @NoAutoDetect class Name + @JsonCreator private constructor( - private val name: JsonField, - private val names: JsonField>, - private val type: JsonField, - private val additionalProperties: Map, + @JsonProperty("name") + @ExcludeMissing + private val name: JsonField = JsonMissing.of(), + @JsonProperty("names") + @ExcludeMissing + private val names: JsonField> = JsonMissing.of(), + @JsonProperty("type") + @ExcludeMissing + private val type: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun name(): Optional = Optional.ofNullable(name.getNullable("name")) fun names(): Optional> = @@ -625,23 +754,29 @@ private constructor( fun type(): Optional = Optional.ofNullable(type.getNullable("type")) - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("names") @ExcludeMissing fun _names() = names + @JsonProperty("names") + @ExcludeMissing + fun _names(): JsonField> = names - @JsonProperty("type") @ExcludeMissing fun _type() = type + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Name = apply { - if (!validated) { - name() - names() - type() - validated = true + if (validated) { + return@apply } + + name() + names() + type() + validated = true } fun toBuilder() = Builder().from(this) @@ -651,10 +786,11 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Name]. */ + class Builder internal constructor() { private var name: JsonField = JsonMissing.of() - private var names: JsonField> = JsonMissing.of() + private var names: JsonField>? = null private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -662,48 +798,64 @@ private constructor( @JvmSynthetic internal fun from(name: Name) = apply { this.name = name.name - this.names = name.names - this.type = name.type - additionalProperties(name.additionalProperties) + names = name.names.map { it.toMutableList() } + type = name.type + additionalProperties = name.additionalProperties.toMutableMap() } fun name(name: String) = name(JsonField.of(name)) - @JsonProperty("name") - @ExcludeMissing fun name(name: JsonField) = apply { this.name = name } fun names(names: List) = names(JsonField.of(names)) - @JsonProperty("names") - @ExcludeMissing - fun names(names: JsonField>) = apply { this.names = names } + fun names(names: JsonField>) = apply { + this.names = names.map { it.toMutableList() } + } + + fun addName(name: String) = apply { + names = + (names ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(name) + } + } fun type(type: String) = type(JsonField.of(type)) - @JsonProperty("type") - @ExcludeMissing fun type(type: JsonField) = apply { this.type = type } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Name = Name( name, - names.map { it.toImmutable() }, + (names ?: JsonMissing.of()).map { it.toImmutable() }, type, additionalProperties.toImmutable(), ) @@ -714,34 +866,36 @@ private constructor( return true } - return /* spotless:off */ other is Name && this.name == other.name && this.names == other.names && this.type == other.type && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Name && name == other.name && names == other.names && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(name, names, type, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(name, names, type, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Name{name=$name, names=$names, type=$type, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = Polyline.Builder::class) @NoAutoDetect class Polyline + @JsonCreator private constructor( - private val length: JsonField, - private val levels: JsonField, - private val points: JsonField, - private val additionalProperties: Map, + @JsonProperty("length") + @ExcludeMissing + private val length: JsonField = JsonMissing.of(), + @JsonProperty("levels") + @ExcludeMissing + private val levels: JsonField = JsonMissing.of(), + @JsonProperty("points") + @ExcludeMissing + private val points: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun length(): Optional = Optional.ofNullable(length.getNullable("length")) fun levels(): Optional = @@ -750,23 +904,31 @@ private constructor( fun points(): Optional = Optional.ofNullable(points.getNullable("points")) - @JsonProperty("length") @ExcludeMissing fun _length() = length + @JsonProperty("length") @ExcludeMissing fun _length(): JsonField = length - @JsonProperty("levels") @ExcludeMissing fun _levels() = levels + @JsonProperty("levels") + @ExcludeMissing + fun _levels(): JsonField = levels - @JsonProperty("points") @ExcludeMissing fun _points() = points + @JsonProperty("points") + @ExcludeMissing + fun _points(): JsonField = points @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Polyline = apply { - if (!validated) { - length() - levels() - points() - validated = true + if (validated) { + return@apply } + + length() + levels() + points() + validated = true } fun toBuilder() = Builder().from(this) @@ -776,7 +938,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Polyline]. */ + class Builder internal constructor() { private var length: JsonField = JsonMissing.of() private var levels: JsonField = JsonMissing.of() @@ -786,45 +949,46 @@ private constructor( @JvmSynthetic internal fun from(polyline: Polyline) = apply { - this.length = polyline.length - this.levels = polyline.levels - this.points = polyline.points - additionalProperties(polyline.additionalProperties) + length = polyline.length + levels = polyline.levels + points = polyline.points + additionalProperties = polyline.additionalProperties.toMutableMap() } fun length(length: Long) = length(JsonField.of(length)) - @JsonProperty("length") - @ExcludeMissing fun length(length: JsonField) = apply { this.length = length } fun levels(levels: String) = levels(JsonField.of(levels)) - @JsonProperty("levels") - @ExcludeMissing fun levels(levels: JsonField) = apply { this.levels = levels } fun points(points: String) = points(JsonField.of(points)) - @JsonProperty("points") - @ExcludeMissing fun points(points: JsonField) = apply { this.points = points } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Polyline = Polyline( length, @@ -839,17 +1003,14 @@ private constructor( return true } - return /* spotless:off */ other is Polyline && this.length == other.length && this.levels == other.levels && this.points == other.points && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Polyline && length == other.length && levels == other.levels && points == other.points && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(length, levels, points, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(length, levels, points, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Polyline{length=$length, levels=$levels, points=$points, additionalProperties=$additionalProperties}" @@ -860,17 +1021,14 @@ private constructor( return true } - return /* spotless:off */ other is StopGrouping && this.id == other.id && this.name == other.name && this.polylines == other.polylines && this.stopIds == other.stopIds && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopGrouping && id == other.id && name == other.name && polylines == other.polylines && stopIds == other.stopIds && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, name, polylines, stopIds, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(id, name, polylines, stopIds, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "StopGrouping{id=$id, name=$name, polylines=$polylines, stopIds=$stopIds, additionalProperties=$additionalProperties}" @@ -881,17 +1039,14 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.polylines == other.polylines && this.routeId == other.routeId && this.stopGroupings == other.stopGroupings && this.stopIds == other.stopIds && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && polylines == other.polylines && routeId == other.routeId && stopGroupings == other.stopGroupings && stopIds == other.stopIds && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(polylines, routeId, stopGroupings, stopIds, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(polylines, routeId, stopGroupings, stopIds, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Entry{polylines=$polylines, routeId=$routeId, stopGroupings=$stopGroupings, stopIds=$stopIds, additionalProperties=$additionalProperties}" @@ -902,17 +1057,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, references=$references, additionalProperties=$additionalProperties}" @@ -923,17 +1075,14 @@ private constructor( return true } - return /* spotless:off */ other is StopsForRouteListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopsForRouteListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "StopsForRouteListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripDetailRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripDetailRetrieveParams.kt index 1564725..fa137cd 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripDetailRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripDetailRetrieveParams.kt @@ -2,50 +2,61 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Retrieve Trip Details */ class TripDetailRetrieveParams -constructor( +private constructor( private val tripId: String, private val includeSchedule: Boolean?, private val includeStatus: Boolean?, private val includeTrip: Boolean?, private val serviceDate: Long?, private val time: Long?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun tripId(): String = tripId + /** + * Whether to include the full schedule element in the tripDetails section (defaults to true). + */ fun includeSchedule(): Optional = Optional.ofNullable(includeSchedule) + /** Whether to include the full status element in the tripDetails section (defaults to true). */ fun includeStatus(): Optional = Optional.ofNullable(includeStatus) + /** Whether to include the full trip element in the references section (defaults to true). */ fun includeTrip(): Optional = Optional.ofNullable(includeTrip) + /** Service date for the trip as Unix time in milliseconds (optional). */ fun serviceDate(): Optional = Optional.ofNullable(serviceDate) + /** Time parameter to query the system at a specific time (optional). */ fun time(): Optional = Optional.ofNullable(time) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.includeSchedule?.let { params.put("includeSchedule", listOf(it.toString())) } - this.includeStatus?.let { params.put("includeStatus", listOf(it.toString())) } - this.includeTrip?.let { params.put("includeTrip", listOf(it.toString())) } - this.serviceDate?.let { params.put("serviceDate", listOf(it.toString())) } - this.time?.let { params.put("time", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.includeSchedule?.let { queryParams.put("includeSchedule", listOf(it.toString())) } + this.includeStatus?.let { queryParams.put("includeStatus", listOf(it.toString())) } + this.includeTrip?.let { queryParams.put("includeTrip", listOf(it.toString())) } + this.serviceDate?.let { queryParams.put("serviceDate", listOf(it.toString())) } + this.time?.let { queryParams.put("time", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } fun getPathParam(index: Int): String { @@ -55,25 +66,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TripDetailRetrieveParams && this.tripId == other.tripId && this.includeSchedule == other.includeSchedule && this.includeStatus == other.includeStatus && this.includeTrip == other.includeTrip && this.serviceDate == other.serviceDate && this.time == other.time && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(tripId, includeSchedule, includeStatus, includeTrip, serviceDate, time, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "TripDetailRetrieveParams{tripId=$tripId, includeSchedule=$includeSchedule, includeStatus=$includeStatus, includeTrip=$includeTrip, serviceDate=$serviceDate, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -81,8 +73,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [TripDetailRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var tripId: String? = null private var includeSchedule: Boolean? = null @@ -90,19 +83,19 @@ constructor( private var includeTrip: Boolean? = null private var serviceDate: Long? = null private var time: Long? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(tripDetailRetrieveParams: TripDetailRetrieveParams) = apply { - this.tripId = tripDetailRetrieveParams.tripId - this.includeSchedule = tripDetailRetrieveParams.includeSchedule - this.includeStatus = tripDetailRetrieveParams.includeStatus - this.includeTrip = tripDetailRetrieveParams.includeTrip - this.serviceDate = tripDetailRetrieveParams.serviceDate - this.time = tripDetailRetrieveParams.time - additionalHeaders(tripDetailRetrieveParams.additionalHeaders) - additionalQueryParams(tripDetailRetrieveParams.additionalQueryParams) + tripId = tripDetailRetrieveParams.tripId + includeSchedule = tripDetailRetrieveParams.includeSchedule + includeStatus = tripDetailRetrieveParams.includeStatus + includeTrip = tripDetailRetrieveParams.includeTrip + serviceDate = tripDetailRetrieveParams.serviceDate + time = tripDetailRetrieveParams.time + additionalHeaders = tripDetailRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = tripDetailRetrieveParams.additionalQueryParams.toBuilder() } fun tripId(tripId: String) = apply { this.tripId = tripId } @@ -111,25 +104,83 @@ constructor( * Whether to include the full schedule element in the tripDetails section (defaults to * true). */ - fun includeSchedule(includeSchedule: Boolean) = apply { + fun includeSchedule(includeSchedule: Boolean?) = apply { this.includeSchedule = includeSchedule } + /** + * Whether to include the full schedule element in the tripDetails section (defaults to + * true). + */ + fun includeSchedule(includeSchedule: Boolean) = includeSchedule(includeSchedule as Boolean?) + + /** + * Whether to include the full schedule element in the tripDetails section (defaults to + * true). + */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun includeSchedule(includeSchedule: Optional) = + includeSchedule(includeSchedule.orElse(null) as Boolean?) + + /** + * Whether to include the full status element in the tripDetails section (defaults to true). + */ + fun includeStatus(includeStatus: Boolean?) = apply { this.includeStatus = includeStatus } + + /** + * Whether to include the full status element in the tripDetails section (defaults to true). + */ + fun includeStatus(includeStatus: Boolean) = includeStatus(includeStatus as Boolean?) + /** * Whether to include the full status element in the tripDetails section (defaults to true). */ - fun includeStatus(includeStatus: Boolean) = apply { this.includeStatus = includeStatus } + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun includeStatus(includeStatus: Optional) = + includeStatus(includeStatus.orElse(null) as Boolean?) /** * Whether to include the full trip element in the references section (defaults to true). */ - fun includeTrip(includeTrip: Boolean) = apply { this.includeTrip = includeTrip } + fun includeTrip(includeTrip: Boolean?) = apply { this.includeTrip = includeTrip } + + /** + * Whether to include the full trip element in the references section (defaults to true). + */ + fun includeTrip(includeTrip: Boolean) = includeTrip(includeTrip as Boolean?) + + /** + * Whether to include the full trip element in the references section (defaults to true). + */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun includeTrip(includeTrip: Optional) = + includeTrip(includeTrip.orElse(null) as Boolean?) + + /** Service date for the trip as Unix time in milliseconds (optional). */ + fun serviceDate(serviceDate: Long?) = apply { this.serviceDate = serviceDate } /** Service date for the trip as Unix time in milliseconds (optional). */ - fun serviceDate(serviceDate: Long) = apply { this.serviceDate = serviceDate } + fun serviceDate(serviceDate: Long) = serviceDate(serviceDate as Long?) + + /** Service date for the trip as Unix time in milliseconds (optional). */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun serviceDate(serviceDate: Optional) = + serviceDate(serviceDate.orElse(null) as Long?) + + /** Time parameter to query the system at a specific time (optional). */ + fun time(time: Long?) = apply { this.time = time } + + /** Time parameter to query the system at a specific time (optional). */ + fun time(time: Long) = time(time as Long?) /** Time parameter to query the system at a specific time (optional). */ - fun time(time: Long) = apply { this.time = time } + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun time(time: Optional) = time(time.orElse(null) as Long?) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -141,29 +192,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -176,51 +240,64 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): TripDetailRetrieveParams = TripDetailRetrieveParams( - checkNotNull(tripId) { "`tripId` is required but was not set" }, + checkRequired("tripId", tripId), includeSchedule, includeStatus, includeTrip, serviceDate, time, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is TripDetailRetrieveParams && tripId == other.tripId && includeSchedule == other.includeSchedule && includeStatus == other.includeStatus && includeTrip == other.includeTrip && serviceDate == other.serviceDate && time == other.time && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(tripId, includeSchedule, includeStatus, includeTrip, serviceDate, time, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "TripDetailRetrieveParams{tripId=$tripId, includeSchedule=$includeSchedule, includeStatus=$includeStatus, includeTrip=$includeTrip, serviceDate=$serviceDate, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripDetailRetrieveResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripDetailRetrieveResponse.kt index dcb12a7..7277b0b 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripDetailRetrieveResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripDetailRetrieveResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = TripDetailRetrieveResponse.Builder::class) @NoAutoDetect class TripDetailRetrieveResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): TripDetailRetrieveResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,109 +87,114 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [TripDetailRetrieveResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(tripDetailRetrieveResponse: TripDetailRetrieveResponse) = apply { - this.code = tripDetailRetrieveResponse.code - this.currentTime = tripDetailRetrieveResponse.currentTime - this.text = tripDetailRetrieveResponse.text - this.version = tripDetailRetrieveResponse.version - this.data = tripDetailRetrieveResponse.data - additionalProperties(tripDetailRetrieveResponse.additionalProperties) + code = tripDetailRetrieveResponse.code + currentTime = tripDetailRetrieveResponse.currentTime + text = tripDetailRetrieveResponse.text + version = tripDetailRetrieveResponse.version + data = tripDetailRetrieveResponse.data + additionalProperties = tripDetailRetrieveResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): TripDetailRetrieveResponse = TripDetailRetrieveResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") fun references(): References = references.getRequired("references") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -191,69 +204,84 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val frequency: JsonField, - private val schedule: JsonField, - private val serviceDate: JsonField, - private val situationIds: JsonField>, - private val status: JsonField, - private val tripId: JsonField, - private val additionalProperties: Map, + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonProperty("schedule") + @ExcludeMissing + private val schedule: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonProperty("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun tripId(): String = tripId.getRequired("tripId") fun frequency(): Optional = Optional.ofNullable(frequency.getNullable("frequency")) @@ -269,34 +297,44 @@ private constructor( fun status(): Optional = Optional.ofNullable(status.getNullable("status")) - fun tripId(): String = tripId.getRequired("tripId") - - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + @JsonProperty("tripId") @ExcludeMissing fun _tripId(): JsonField = tripId - @JsonProperty("schedule") @ExcludeMissing fun _schedule() = schedule + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency - @JsonProperty("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate + @JsonProperty("schedule") + @ExcludeMissing + fun _schedule(): JsonField = schedule - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("situationIds") + @ExcludeMissing + fun _situationIds(): JsonField> = situationIds - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - frequency() - schedule().map { it.validate() } - serviceDate() - situationIds() - status().map { it.validate() } - tripId() - validated = true + if (validated) { + return@apply } + + tripId() + frequency() + schedule().ifPresent { it.validate() } + serviceDate() + situationIds() + status().ifPresent { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -306,43 +344,44 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Entry]. */ + class Builder internal constructor() { + private var tripId: JsonField? = null private var frequency: JsonField = JsonMissing.of() private var schedule: JsonField = JsonMissing.of() private var serviceDate: JsonField = JsonMissing.of() - private var situationIds: JsonField> = JsonMissing.of() + private var situationIds: JsonField>? = null private var status: JsonField = JsonMissing.of() - private var tripId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(entry: Entry) = apply { - this.frequency = entry.frequency - this.schedule = entry.schedule - this.serviceDate = entry.serviceDate - this.situationIds = entry.situationIds - this.status = entry.status - this.tripId = entry.tripId - additionalProperties(entry.additionalProperties) + tripId = entry.tripId + frequency = entry.frequency + schedule = entry.schedule + serviceDate = entry.serviceDate + situationIds = entry.situationIds.map { it.toMutableList() } + status = entry.status + additionalProperties = entry.additionalProperties.toMutableMap() } - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) + fun tripId(tripId: String) = tripId(JsonField.of(tripId)) + + fun tripId(tripId: JsonField) = apply { this.tripId = tripId } + + fun frequency(frequency: String?) = frequency(JsonField.ofNullable(frequency)) + + fun frequency(frequency: Optional) = frequency(frequency.orElse(null)) - @JsonProperty("frequency") - @ExcludeMissing fun frequency(frequency: JsonField) = apply { this.frequency = frequency } fun schedule(schedule: Schedule) = schedule(JsonField.of(schedule)) - @JsonProperty("schedule") - @ExcludeMissing fun schedule(schedule: JsonField) = apply { this.schedule = schedule } fun serviceDate(serviceDate: Long) = serviceDate(JsonField.of(serviceDate)) - @JsonProperty("serviceDate") - @ExcludeMissing fun serviceDate(serviceDate: JsonField) = apply { this.serviceDate = serviceDate } @@ -350,32 +389,34 @@ private constructor( fun situationIds(situationIds: List) = situationIds(JsonField.of(situationIds)) - @JsonProperty("situationIds") - @ExcludeMissing fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds + this.situationIds = situationIds.map { it.toMutableList() } + } + + fun addSituationId(situationId: String) = apply { + situationIds = + (situationIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situationId) + } } fun status(status: Status) = status(JsonField.of(status)) - @JsonProperty("status") - @ExcludeMissing fun status(status: JsonField) = apply { this.status = status } - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - @JsonProperty("tripId") - @ExcludeMissing - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -383,35 +424,49 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( + checkRequired("tripId", tripId), frequency, schedule, serviceDate, - situationIds.map { it.toImmutable() }, + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, status, - tripId, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Schedule.Builder::class) @NoAutoDetect class Schedule + @JsonCreator private constructor( - private val frequency: JsonField, - private val nextTripId: JsonField, - private val previousTripId: JsonField, - private val stopTimes: JsonField>, - private val timeZone: JsonField, - private val additionalProperties: Map, + @JsonProperty("nextTripId") + @ExcludeMissing + private val nextTripId: JsonField = JsonMissing.of(), + @JsonProperty("previousTripId") + @ExcludeMissing + private val previousTripId: JsonField = JsonMissing.of(), + @JsonProperty("stopTimes") + @ExcludeMissing + private val stopTimes: JsonField> = JsonMissing.of(), + @JsonProperty("timeZone") + @ExcludeMissing + private val timeZone: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - fun nextTripId(): String = nextTripId.getRequired("nextTripId") fun previousTripId(): String = previousTripId.getRequired("previousTripId") @@ -420,31 +475,46 @@ private constructor( fun timeZone(): String = timeZone.getRequired("timeZone") - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) - @JsonProperty("nextTripId") @ExcludeMissing fun _nextTripId() = nextTripId + @JsonProperty("nextTripId") + @ExcludeMissing + fun _nextTripId(): JsonField = nextTripId @JsonProperty("previousTripId") @ExcludeMissing - fun _previousTripId() = previousTripId + fun _previousTripId(): JsonField = previousTripId + + @JsonProperty("stopTimes") + @ExcludeMissing + fun _stopTimes(): JsonField> = stopTimes - @JsonProperty("stopTimes") @ExcludeMissing fun _stopTimes() = stopTimes + @JsonProperty("timeZone") + @ExcludeMissing + fun _timeZone(): JsonField = timeZone - @JsonProperty("timeZone") @ExcludeMissing fun _timeZone() = timeZone + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Schedule = apply { - if (!validated) { - frequency() - nextTripId() - previousTripId() - stopTimes().forEach { it.validate() } - timeZone() - validated = true + if (validated) { + return@apply } + + nextTripId() + previousTripId() + stopTimes().forEach { it.validate() } + timeZone() + frequency() + validated = true } fun toBuilder() = Builder().from(this) @@ -454,37 +524,28 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Schedule]. */ + class Builder internal constructor() { + private var nextTripId: JsonField? = null + private var previousTripId: JsonField? = null + private var stopTimes: JsonField>? = null + private var timeZone: JsonField? = null private var frequency: JsonField = JsonMissing.of() - private var nextTripId: JsonField = JsonMissing.of() - private var previousTripId: JsonField = JsonMissing.of() - private var stopTimes: JsonField> = JsonMissing.of() - private var timeZone: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(schedule: Schedule) = apply { - this.frequency = schedule.frequency - this.nextTripId = schedule.nextTripId - this.previousTripId = schedule.previousTripId - this.stopTimes = schedule.stopTimes - this.timeZone = schedule.timeZone - additionalProperties(schedule.additionalProperties) - } - - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - @JsonProperty("frequency") - @ExcludeMissing - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency + nextTripId = schedule.nextTripId + previousTripId = schedule.previousTripId + stopTimes = schedule.stopTimes.map { it.toMutableList() } + timeZone = schedule.timeZone + frequency = schedule.frequency + additionalProperties = schedule.additionalProperties.toMutableMap() } fun nextTripId(nextTripId: String) = nextTripId(JsonField.of(nextTripId)) - @JsonProperty("nextTripId") - @ExcludeMissing fun nextTripId(nextTripId: JsonField) = apply { this.nextTripId = nextTripId } @@ -492,34 +553,48 @@ private constructor( fun previousTripId(previousTripId: String) = previousTripId(JsonField.of(previousTripId)) - @JsonProperty("previousTripId") - @ExcludeMissing fun previousTripId(previousTripId: JsonField) = apply { this.previousTripId = previousTripId } fun stopTimes(stopTimes: List) = stopTimes(JsonField.of(stopTimes)) - @JsonProperty("stopTimes") - @ExcludeMissing fun stopTimes(stopTimes: JsonField>) = apply { - this.stopTimes = stopTimes + this.stopTimes = stopTimes.map { it.toMutableList() } + } + + fun addStopTime(stopTime: StopTime) = apply { + stopTimes = + (stopTimes ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stopTime) + } } fun timeZone(timeZone: String) = timeZone(JsonField.of(timeZone)) - @JsonProperty("timeZone") - @ExcludeMissing fun timeZone(timeZone: JsonField) = apply { this.timeZone = timeZone } + fun frequency(frequency: String?) = frequency(JsonField.ofNullable(frequency)) + + fun frequency(frequency: Optional) = frequency(frequency.orElse(null)) + + fun frequency(frequency: JsonField) = apply { + this.frequency = frequency + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -527,32 +602,51 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Schedule = Schedule( + checkRequired("nextTripId", nextTripId), + checkRequired("previousTripId", previousTripId), + checkRequired("stopTimes", stopTimes).map { it.toImmutable() }, + checkRequired("timeZone", timeZone), frequency, - nextTripId, - previousTripId, - stopTimes.map { it.toImmutable() }, - timeZone, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = StopTime.Builder::class) @NoAutoDetect class StopTime + @JsonCreator private constructor( - private val arrivalTime: JsonField, - private val departureTime: JsonField, - private val distanceAlongTrip: JsonField, - private val historicalOccupancy: JsonField, - private val stopHeadsign: JsonField, - private val stopId: JsonField, - private val additionalProperties: Map, + @JsonProperty("arrivalTime") + @ExcludeMissing + private val arrivalTime: JsonField = JsonMissing.of(), + @JsonProperty("departureTime") + @ExcludeMissing + private val departureTime: JsonField = JsonMissing.of(), + @JsonProperty("distanceAlongTrip") + @ExcludeMissing + private val distanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("historicalOccupancy") + @ExcludeMissing + private val historicalOccupancy: JsonField = JsonMissing.of(), + @JsonProperty("stopHeadsign") + @ExcludeMissing + private val stopHeadsign: JsonField = JsonMissing.of(), + @JsonProperty("stopId") + @ExcludeMissing + private val stopId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun arrivalTime(): Optional = Optional.ofNullable(arrivalTime.getNullable("arrivalTime")) @@ -571,38 +665,48 @@ private constructor( fun stopId(): Optional = Optional.ofNullable(stopId.getNullable("stopId")) - @JsonProperty("arrivalTime") @ExcludeMissing fun _arrivalTime() = arrivalTime + @JsonProperty("arrivalTime") + @ExcludeMissing + fun _arrivalTime(): JsonField = arrivalTime @JsonProperty("departureTime") @ExcludeMissing - fun _departureTime() = departureTime + fun _departureTime(): JsonField = departureTime @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip + fun _distanceAlongTrip(): JsonField = distanceAlongTrip @JsonProperty("historicalOccupancy") @ExcludeMissing - fun _historicalOccupancy() = historicalOccupancy + fun _historicalOccupancy(): JsonField = historicalOccupancy - @JsonProperty("stopHeadsign") @ExcludeMissing fun _stopHeadsign() = stopHeadsign + @JsonProperty("stopHeadsign") + @ExcludeMissing + fun _stopHeadsign(): JsonField = stopHeadsign - @JsonProperty("stopId") @ExcludeMissing fun _stopId() = stopId + @JsonProperty("stopId") + @ExcludeMissing + fun _stopId(): JsonField = stopId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): StopTime = apply { - if (!validated) { - arrivalTime() - departureTime() - distanceAlongTrip() - historicalOccupancy() - stopHeadsign() - stopId() - validated = true + if (validated) { + return@apply } + + arrivalTime() + departureTime() + distanceAlongTrip() + historicalOccupancy() + stopHeadsign() + stopId() + validated = true } fun toBuilder() = Builder().from(this) @@ -612,7 +716,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopTime]. */ + class Builder internal constructor() { private var arrivalTime: JsonField = JsonMissing.of() private var departureTime: JsonField = JsonMissing.of() @@ -625,19 +730,17 @@ private constructor( @JvmSynthetic internal fun from(stopTime: StopTime) = apply { - this.arrivalTime = stopTime.arrivalTime - this.departureTime = stopTime.departureTime - this.distanceAlongTrip = stopTime.distanceAlongTrip - this.historicalOccupancy = stopTime.historicalOccupancy - this.stopHeadsign = stopTime.stopHeadsign - this.stopId = stopTime.stopId - additionalProperties(stopTime.additionalProperties) + arrivalTime = stopTime.arrivalTime + departureTime = stopTime.departureTime + distanceAlongTrip = stopTime.distanceAlongTrip + historicalOccupancy = stopTime.historicalOccupancy + stopHeadsign = stopTime.stopHeadsign + stopId = stopTime.stopId + additionalProperties = stopTime.additionalProperties.toMutableMap() } fun arrivalTime(arrivalTime: Long) = arrivalTime(JsonField.of(arrivalTime)) - @JsonProperty("arrivalTime") - @ExcludeMissing fun arrivalTime(arrivalTime: JsonField) = apply { this.arrivalTime = arrivalTime } @@ -645,8 +748,6 @@ private constructor( fun departureTime(departureTime: Long) = departureTime(JsonField.of(departureTime)) - @JsonProperty("departureTime") - @ExcludeMissing fun departureTime(departureTime: JsonField) = apply { this.departureTime = departureTime } @@ -654,8 +755,6 @@ private constructor( fun distanceAlongTrip(distanceAlongTrip: Double) = distanceAlongTrip(JsonField.of(distanceAlongTrip)) - @JsonProperty("distanceAlongTrip") - @ExcludeMissing fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { this.distanceAlongTrip = distanceAlongTrip } @@ -663,8 +762,6 @@ private constructor( fun historicalOccupancy(historicalOccupancy: String) = historicalOccupancy(JsonField.of(historicalOccupancy)) - @JsonProperty("historicalOccupancy") - @ExcludeMissing fun historicalOccupancy(historicalOccupancy: JsonField) = apply { this.historicalOccupancy = historicalOccupancy } @@ -672,33 +769,36 @@ private constructor( fun stopHeadsign(stopHeadsign: String) = stopHeadsign(JsonField.of(stopHeadsign)) - @JsonProperty("stopHeadsign") - @ExcludeMissing fun stopHeadsign(stopHeadsign: JsonField) = apply { this.stopHeadsign = stopHeadsign } fun stopId(stopId: String) = stopId(JsonField.of(stopId)) - @JsonProperty("stopId") - @ExcludeMissing fun stopId(stopId: JsonField) = apply { this.stopId = stopId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopTime = StopTime( arrivalTime, @@ -716,17 +816,14 @@ private constructor( return true } - return /* spotless:off */ other is StopTime && this.arrivalTime == other.arrivalTime && this.departureTime == other.departureTime && this.distanceAlongTrip == other.distanceAlongTrip && this.historicalOccupancy == other.historicalOccupancy && this.stopHeadsign == other.stopHeadsign && this.stopId == other.stopId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopTime && arrivalTime == other.arrivalTime && departureTime == other.departureTime && distanceAlongTrip == other.distanceAlongTrip && historicalOccupancy == other.historicalOccupancy && stopHeadsign == other.stopHeadsign && stopId == other.stopId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(arrivalTime, departureTime, distanceAlongTrip, historicalOccupancy, stopHeadsign, stopId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(arrivalTime, departureTime, distanceAlongTrip, historicalOccupancy, stopHeadsign, stopId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "StopTime{arrivalTime=$arrivalTime, departureTime=$departureTime, distanceAlongTrip=$distanceAlongTrip, historicalOccupancy=$historicalOccupancy, stopHeadsign=$stopHeadsign, stopId=$stopId, additionalProperties=$additionalProperties}" @@ -737,58 +834,108 @@ private constructor( return true } - return /* spotless:off */ other is Schedule && this.frequency == other.frequency && this.nextTripId == other.nextTripId && this.previousTripId == other.previousTripId && this.stopTimes == other.stopTimes && this.timeZone == other.timeZone && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Schedule && nextTripId == other.nextTripId && previousTripId == other.previousTripId && stopTimes == other.stopTimes && timeZone == other.timeZone && frequency == other.frequency && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(nextTripId, previousTripId, stopTimes, timeZone, frequency, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(frequency, nextTripId, previousTripId, stopTimes, timeZone, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Schedule{frequency=$frequency, nextTripId=$nextTripId, previousTripId=$previousTripId, stopTimes=$stopTimes, timeZone=$timeZone, additionalProperties=$additionalProperties}" + "Schedule{nextTripId=$nextTripId, previousTripId=$previousTripId, stopTimes=$stopTimes, timeZone=$timeZone, frequency=$frequency, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = Status.Builder::class) @NoAutoDetect class Status + @JsonCreator private constructor( - private val activeTripId: JsonField, - private val blockTripSequence: JsonField, - private val closestStop: JsonField, - private val closestStopTimeOffset: JsonField, - private val distanceAlongTrip: JsonField, - private val frequency: JsonField, - private val lastKnownDistanceAlongTrip: JsonField, - private val lastKnownLocation: JsonField, - private val lastKnownOrientation: JsonField, - private val lastLocationUpdateTime: JsonField, - private val lastUpdateTime: JsonField, - private val nextStop: JsonField, - private val nextStopTimeOffset: JsonField, - private val occupancyCapacity: JsonField, - private val occupancyCount: JsonField, - private val occupancyStatus: JsonField, - private val orientation: JsonField, - private val phase: JsonField, - private val position: JsonField, - private val predicted: JsonField, - private val scheduleDeviation: JsonField, - private val scheduledDistanceAlongTrip: JsonField, - private val serviceDate: JsonField, - private val situationIds: JsonField>, - private val status: JsonField, - private val totalDistanceAlongTrip: JsonField, - private val vehicleId: JsonField, - private val additionalProperties: Map, + @JsonProperty("activeTripId") + @ExcludeMissing + private val activeTripId: JsonField = JsonMissing.of(), + @JsonProperty("blockTripSequence") + @ExcludeMissing + private val blockTripSequence: JsonField = JsonMissing.of(), + @JsonProperty("closestStop") + @ExcludeMissing + private val closestStop: JsonField = JsonMissing.of(), + @JsonProperty("distanceAlongTrip") + @ExcludeMissing + private val distanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownDistanceAlongTrip") + @ExcludeMissing + private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastLocationUpdateTime") + @ExcludeMissing + private val lastLocationUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("lastUpdateTime") + @ExcludeMissing + private val lastUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCapacity") + @ExcludeMissing + private val occupancyCapacity: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCount") + @ExcludeMissing + private val occupancyCount: JsonField = JsonMissing.of(), + @JsonProperty("occupancyStatus") + @ExcludeMissing + private val occupancyStatus: JsonField = JsonMissing.of(), + @JsonProperty("phase") + @ExcludeMissing + private val phase: JsonField = JsonMissing.of(), + @JsonProperty("predicted") + @ExcludeMissing + private val predicted: JsonField = JsonMissing.of(), + @JsonProperty("scheduleDeviation") + @ExcludeMissing + private val scheduleDeviation: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonProperty("totalDistanceAlongTrip") + @ExcludeMissing + private val totalDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + private val closestStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownLocation") + @ExcludeMissing + private val lastKnownLocation: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + private val lastKnownOrientation: JsonField = JsonMissing.of(), + @JsonProperty("nextStop") + @ExcludeMissing + private val nextStop: JsonField = JsonMissing.of(), + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + private val nextStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("orientation") + @ExcludeMissing + private val orientation: JsonField = JsonMissing.of(), + @JsonProperty("position") + @ExcludeMissing + private val position: JsonField = JsonMissing.of(), + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + private val scheduledDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), + @JsonProperty("vehicleId") + @ExcludeMissing + private val vehicleId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Trip ID of the trip the vehicle is actively serving. */ fun activeTripId(): String = activeTripId.getRequired("activeTripId") @@ -798,22 +945,11 @@ private constructor( /** ID of the closest stop to the current location of the transit vehicle. */ fun closestStop(): String = closestStop.getRequired("closestStop") - /** - * Time offset from the closest stop to the current position of the transit vehicle - * (in seconds). - */ - fun closestStopTimeOffset(): Optional = - Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) - /** * Distance, in meters, the transit vehicle has progressed along the active trip. */ fun distanceAlongTrip(): Double = distanceAlongTrip.getRequired("distanceAlongTrip") - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -821,14 +957,6 @@ private constructor( fun lastKnownDistanceAlongTrip(): Double = lastKnownDistanceAlongTrip.getRequired("lastKnownDistanceAlongTrip") - /** Last known location of the transit vehicle. */ - fun lastKnownLocation(): Optional = - Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) - - /** Last known orientation value received in real-time from the transit vehicle. */ - fun lastKnownOrientation(): Optional = - Optional.ofNullable(lastKnownOrientation.getNullable("lastKnownOrientation")) - /** * Timestamp of the last known real-time location update from the transit vehicle. */ @@ -838,19 +966,8 @@ private constructor( /** Timestamp of the last known real-time update from the transit vehicle. */ fun lastUpdateTime(): Long = lastUpdateTime.getRequired("lastUpdateTime") - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - fun nextStop(): Optional = - Optional.ofNullable(nextStop.getNullable("nextStop")) - - /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). - */ - fun nextStopTimeOffset(): Optional = - Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) - - /** Capacity of the transit vehicle in terms of occupancy. */ - fun occupancyCapacity(): Long = occupancyCapacity.getRequired("occupancyCapacity") + /** Capacity of the transit vehicle in terms of occupancy. */ + fun occupancyCapacity(): Long = occupancyCapacity.getRequired("occupancyCapacity") /** Current count of occupants in the transit vehicle. */ fun occupancyCount(): Long = occupancyCount.getRequired("occupancyCount") @@ -858,17 +975,9 @@ private constructor( /** Current occupancy status of the transit vehicle. */ fun occupancyStatus(): String = occupancyStatus.getRequired("occupancyStatus") - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - fun orientation(): Optional = - Optional.ofNullable(orientation.getNullable("orientation")) - /** Current journey phase of the trip. */ fun phase(): String = phase.getRequired("phase") - /** Current position of the transit vehicle. */ - fun position(): Optional = - Optional.ofNullable(position.getNullable("position")) - /** Indicates if real-time arrival info is available for this trip. */ fun predicted(): Boolean = predicted.getRequired("predicted") @@ -877,25 +986,12 @@ private constructor( */ fun scheduleDeviation(): Long = scheduleDeviation.getRequired("scheduleDeviation") - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed along - * the active trip. - */ - fun scheduledDistanceAlongTrip(): Optional = - Optional.ofNullable( - scheduledDistanceAlongTrip.getNullable("scheduledDistanceAlongTrip") - ) - /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ fun serviceDate(): Long = serviceDate.getRequired("serviceDate") - /** References to situation elements (if any) applicable to this trip. */ - fun situationIds(): Optional> = - Optional.ofNullable(situationIds.getNullable("situationIds")) - /** Current status modifiers for the trip. */ fun status(): String = status.getRequired("status") @@ -903,38 +999,82 @@ private constructor( fun totalDistanceAlongTrip(): Double = totalDistanceAlongTrip.getRequired("totalDistanceAlongTrip") + /** + * Time offset from the closest stop to the current position of the transit vehicle + * (in seconds). + */ + fun closestStopTimeOffset(): Optional = + Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(): Optional = + Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) + + /** Last known orientation value received in real-time from the transit vehicle. */ + fun lastKnownOrientation(): Optional = + Optional.ofNullable(lastKnownOrientation.getNullable("lastKnownOrientation")) + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(): Optional = + Optional.ofNullable(nextStop.getNullable("nextStop")) + + /** + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). + */ + fun nextStopTimeOffset(): Optional = + Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(): Optional = + Optional.ofNullable(orientation.getNullable("orientation")) + + /** Current position of the transit vehicle. */ + fun position(): Optional = + Optional.ofNullable(position.getNullable("position")) + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed along + * the active trip. + */ + fun scheduledDistanceAlongTrip(): Optional = + Optional.ofNullable( + scheduledDistanceAlongTrip.getNullable("scheduledDistanceAlongTrip") + ) + + /** References to situation elements (if any) applicable to this trip. */ + fun situationIds(): Optional> = + Optional.ofNullable(situationIds.getNullable("situationIds")) + /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(): Optional = Optional.ofNullable(vehicleId.getNullable("vehicleId")) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") @ExcludeMissing fun _activeTripId() = activeTripId + @JsonProperty("activeTripId") + @ExcludeMissing + fun _activeTripId(): JsonField = activeTripId /** Index of the active trip into the sequence of trips for the active block. */ @JsonProperty("blockTripSequence") @ExcludeMissing - fun _blockTripSequence() = blockTripSequence + fun _blockTripSequence(): JsonField = blockTripSequence /** ID of the closest stop to the current location of the transit vehicle. */ - @JsonProperty("closestStop") @ExcludeMissing fun _closestStop() = closestStop - - /** - * Time offset from the closest stop to the current position of the transit vehicle - * (in seconds). - */ - @JsonProperty("closestStopTimeOffset") + @JsonProperty("closestStop") @ExcludeMissing - fun _closestStopTimeOffset() = closestStopTimeOffset + fun _closestStop(): JsonField = closestStop /** * Distance, in meters, the transit vehicle has progressed along the active trip. */ @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + fun _distanceAlongTrip(): JsonField = distanceAlongTrip /** * Last known distance along the trip received in real-time from the transit @@ -942,138 +1082,169 @@ private constructor( */ @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing - fun _lastKnownDistanceAlongTrip() = lastKnownDistanceAlongTrip - - /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun _lastKnownLocation() = lastKnownLocation - - /** Last known orientation value received in real-time from the transit vehicle. */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun _lastKnownOrientation() = lastKnownOrientation + fun _lastKnownDistanceAlongTrip(): JsonField = lastKnownDistanceAlongTrip /** * Timestamp of the last known real-time location update from the transit vehicle. */ @JsonProperty("lastLocationUpdateTime") @ExcludeMissing - fun _lastLocationUpdateTime() = lastLocationUpdateTime + fun _lastLocationUpdateTime(): JsonField = lastLocationUpdateTime /** Timestamp of the last known real-time update from the transit vehicle. */ @JsonProperty("lastUpdateTime") @ExcludeMissing - fun _lastUpdateTime() = lastUpdateTime - - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") @ExcludeMissing fun _nextStop() = nextStop - - /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). - */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - fun _nextStopTimeOffset() = nextStopTimeOffset + fun _lastUpdateTime(): JsonField = lastUpdateTime /** Capacity of the transit vehicle in terms of occupancy. */ @JsonProperty("occupancyCapacity") @ExcludeMissing - fun _occupancyCapacity() = occupancyCapacity + fun _occupancyCapacity(): JsonField = occupancyCapacity /** Current count of occupants in the transit vehicle. */ @JsonProperty("occupancyCount") @ExcludeMissing - fun _occupancyCount() = occupancyCount + fun _occupancyCount(): JsonField = occupancyCount /** Current occupancy status of the transit vehicle. */ @JsonProperty("occupancyStatus") @ExcludeMissing - fun _occupancyStatus() = occupancyStatus - - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") @ExcludeMissing fun _orientation() = orientation + fun _occupancyStatus(): JsonField = occupancyStatus /** Current journey phase of the trip. */ - @JsonProperty("phase") @ExcludeMissing fun _phase() = phase - - /** Current position of the transit vehicle. */ - @JsonProperty("position") @ExcludeMissing fun _position() = position + @JsonProperty("phase") @ExcludeMissing fun _phase(): JsonField = phase /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") @ExcludeMissing fun _predicted() = predicted + @JsonProperty("predicted") + @ExcludeMissing + fun _predicted(): JsonField = predicted /** * Deviation from the schedule in seconds (positive for late, negative for early). */ @JsonProperty("scheduleDeviation") @ExcludeMissing - fun _scheduleDeviation() = scheduleDeviation - - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed along - * the active trip. - */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - fun _scheduledDistanceAlongTrip() = scheduledDistanceAlongTrip + fun _scheduleDeviation(): JsonField = scheduleDeviation /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate - - /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate /** Current status modifiers for the trip. */ - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status /** Total length of the trip, in meters. */ @JsonProperty("totalDistanceAlongTrip") @ExcludeMissing - fun _totalDistanceAlongTrip() = totalDistanceAlongTrip + fun _totalDistanceAlongTrip(): JsonField = totalDistanceAlongTrip + + /** + * Time offset from the closest stop to the current position of the transit vehicle + * (in seconds). + */ + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + fun _closestStopTimeOffset(): JsonField = closestStopTimeOffset + + /** Information about frequency-based scheduling, if applicable to the trip. */ + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency + + /** Last known location of the transit vehicle. */ + @JsonProperty("lastKnownLocation") + @ExcludeMissing + fun _lastKnownLocation(): JsonField = lastKnownLocation + + /** Last known orientation value received in real-time from the transit vehicle. */ + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + fun _lastKnownOrientation(): JsonField = lastKnownOrientation + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + @JsonProperty("nextStop") + @ExcludeMissing + fun _nextStop(): JsonField = nextStop + + /** + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). + */ + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + fun _nextStopTimeOffset(): JsonField = nextStopTimeOffset + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + @JsonProperty("orientation") + @ExcludeMissing + fun _orientation(): JsonField = orientation + + /** Current position of the transit vehicle. */ + @JsonProperty("position") + @ExcludeMissing + fun _position(): JsonField = position + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed along + * the active trip. + */ + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + fun _scheduledDistanceAlongTrip(): JsonField = scheduledDistanceAlongTrip + + /** References to situation elements (if any) applicable to this trip. */ + @JsonProperty("situationIds") + @ExcludeMissing + fun _situationIds(): JsonField> = situationIds /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") @ExcludeMissing fun _vehicleId() = vehicleId + @JsonProperty("vehicleId") + @ExcludeMissing + fun _vehicleId(): JsonField = vehicleId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Status = apply { - if (!validated) { - activeTripId() - blockTripSequence() - closestStop() - closestStopTimeOffset() - distanceAlongTrip() - frequency() - lastKnownDistanceAlongTrip() - lastKnownLocation().map { it.validate() } - lastKnownOrientation() - lastLocationUpdateTime() - lastUpdateTime() - nextStop() - nextStopTimeOffset() - occupancyCapacity() - occupancyCount() - occupancyStatus() - orientation() - phase() - position().map { it.validate() } - predicted() - scheduleDeviation() - scheduledDistanceAlongTrip() - serviceDate() - situationIds() - status() - totalDistanceAlongTrip() - vehicleId() - validated = true + if (validated) { + return@apply } + + activeTripId() + blockTripSequence() + closestStop() + distanceAlongTrip() + lastKnownDistanceAlongTrip() + lastLocationUpdateTime() + lastUpdateTime() + occupancyCapacity() + occupancyCount() + occupancyStatus() + phase() + predicted() + scheduleDeviation() + serviceDate() + status() + totalDistanceAlongTrip() + closestStopTimeOffset() + frequency() + lastKnownLocation().ifPresent { it.validate() } + lastKnownOrientation() + nextStop() + nextStopTimeOffset() + orientation() + position().ifPresent { it.validate() } + scheduledDistanceAlongTrip() + situationIds() + vehicleId() + validated = true } fun toBuilder() = Builder().from(this) @@ -1083,67 +1254,68 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - - private var activeTripId: JsonField = JsonMissing.of() - private var blockTripSequence: JsonField = JsonMissing.of() - private var closestStop: JsonField = JsonMissing.of() + /** A builder for [Status]. */ + class Builder internal constructor() { + + private var activeTripId: JsonField? = null + private var blockTripSequence: JsonField? = null + private var closestStop: JsonField? = null + private var distanceAlongTrip: JsonField? = null + private var lastKnownDistanceAlongTrip: JsonField? = null + private var lastLocationUpdateTime: JsonField? = null + private var lastUpdateTime: JsonField? = null + private var occupancyCapacity: JsonField? = null + private var occupancyCount: JsonField? = null + private var occupancyStatus: JsonField? = null + private var phase: JsonField? = null + private var predicted: JsonField? = null + private var scheduleDeviation: JsonField? = null + private var serviceDate: JsonField? = null + private var status: JsonField? = null + private var totalDistanceAlongTrip: JsonField? = null private var closestStopTimeOffset: JsonField = JsonMissing.of() - private var distanceAlongTrip: JsonField = JsonMissing.of() private var frequency: JsonField = JsonMissing.of() - private var lastKnownDistanceAlongTrip: JsonField = JsonMissing.of() private var lastKnownLocation: JsonField = JsonMissing.of() private var lastKnownOrientation: JsonField = JsonMissing.of() - private var lastLocationUpdateTime: JsonField = JsonMissing.of() - private var lastUpdateTime: JsonField = JsonMissing.of() private var nextStop: JsonField = JsonMissing.of() private var nextStopTimeOffset: JsonField = JsonMissing.of() - private var occupancyCapacity: JsonField = JsonMissing.of() - private var occupancyCount: JsonField = JsonMissing.of() - private var occupancyStatus: JsonField = JsonMissing.of() private var orientation: JsonField = JsonMissing.of() - private var phase: JsonField = JsonMissing.of() private var position: JsonField = JsonMissing.of() - private var predicted: JsonField = JsonMissing.of() - private var scheduleDeviation: JsonField = JsonMissing.of() private var scheduledDistanceAlongTrip: JsonField = JsonMissing.of() - private var serviceDate: JsonField = JsonMissing.of() - private var situationIds: JsonField> = JsonMissing.of() - private var status: JsonField = JsonMissing.of() - private var totalDistanceAlongTrip: JsonField = JsonMissing.of() + private var situationIds: JsonField>? = null private var vehicleId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(status: Status) = apply { - this.activeTripId = status.activeTripId - this.blockTripSequence = status.blockTripSequence - this.closestStop = status.closestStop - this.closestStopTimeOffset = status.closestStopTimeOffset - this.distanceAlongTrip = status.distanceAlongTrip - this.frequency = status.frequency - this.lastKnownDistanceAlongTrip = status.lastKnownDistanceAlongTrip - this.lastKnownLocation = status.lastKnownLocation - this.lastKnownOrientation = status.lastKnownOrientation - this.lastLocationUpdateTime = status.lastLocationUpdateTime - this.lastUpdateTime = status.lastUpdateTime - this.nextStop = status.nextStop - this.nextStopTimeOffset = status.nextStopTimeOffset - this.occupancyCapacity = status.occupancyCapacity - this.occupancyCount = status.occupancyCount - this.occupancyStatus = status.occupancyStatus - this.orientation = status.orientation - this.phase = status.phase - this.position = status.position - this.predicted = status.predicted - this.scheduleDeviation = status.scheduleDeviation - this.scheduledDistanceAlongTrip = status.scheduledDistanceAlongTrip - this.serviceDate = status.serviceDate - this.situationIds = status.situationIds + activeTripId = status.activeTripId + blockTripSequence = status.blockTripSequence + closestStop = status.closestStop + distanceAlongTrip = status.distanceAlongTrip + lastKnownDistanceAlongTrip = status.lastKnownDistanceAlongTrip + lastLocationUpdateTime = status.lastLocationUpdateTime + lastUpdateTime = status.lastUpdateTime + occupancyCapacity = status.occupancyCapacity + occupancyCount = status.occupancyCount + occupancyStatus = status.occupancyStatus + phase = status.phase + predicted = status.predicted + scheduleDeviation = status.scheduleDeviation + serviceDate = status.serviceDate this.status = status.status - this.totalDistanceAlongTrip = status.totalDistanceAlongTrip - this.vehicleId = status.vehicleId - additionalProperties(status.additionalProperties) + totalDistanceAlongTrip = status.totalDistanceAlongTrip + closestStopTimeOffset = status.closestStopTimeOffset + frequency = status.frequency + lastKnownLocation = status.lastKnownLocation + lastKnownOrientation = status.lastKnownOrientation + nextStop = status.nextStop + nextStopTimeOffset = status.nextStopTimeOffset + orientation = status.orientation + position = status.position + scheduledDistanceAlongTrip = status.scheduledDistanceAlongTrip + situationIds = status.situationIds.map { it.toMutableList() } + vehicleId = status.vehicleId + additionalProperties = status.additionalProperties.toMutableMap() } /** Trip ID of the trip the vehicle is actively serving. */ @@ -1151,8 +1323,6 @@ private constructor( activeTripId(JsonField.of(activeTripId)) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") - @ExcludeMissing fun activeTripId(activeTripId: JsonField) = apply { this.activeTripId = activeTripId } @@ -1162,8 +1332,6 @@ private constructor( blockTripSequence(JsonField.of(blockTripSequence)) /** Index of the active trip into the sequence of trips for the active block. */ - @JsonProperty("blockTripSequence") - @ExcludeMissing fun blockTripSequence(blockTripSequence: JsonField) = apply { this.blockTripSequence = blockTripSequence } @@ -1172,29 +1340,10 @@ private constructor( fun closestStop(closestStop: String) = closestStop(JsonField.of(closestStop)) /** ID of the closest stop to the current location of the transit vehicle. */ - @JsonProperty("closestStop") - @ExcludeMissing fun closestStop(closestStop: JsonField) = apply { this.closestStop = closestStop } - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - fun closestStopTimeOffset(closestStopTimeOffset: Long) = - closestStopTimeOffset(JsonField.of(closestStopTimeOffset)) - - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing - fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { - this.closestStopTimeOffset = closestStopTimeOffset - } - /** * Distance, in meters, the transit vehicle has progressed along the active * trip. @@ -1206,22 +1355,10 @@ private constructor( * Distance, in meters, the transit vehicle has progressed along the active * trip. */ - @JsonProperty("distanceAlongTrip") - @ExcludeMissing fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { this.distanceAlongTrip = distanceAlongTrip } - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") - @ExcludeMissing - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1233,39 +1370,11 @@ private constructor( * Last known distance along the trip received in real-time from the transit * vehicle. */ - @JsonProperty("lastKnownDistanceAlongTrip") - @ExcludeMissing fun lastKnownDistanceAlongTrip(lastKnownDistanceAlongTrip: JsonField) = apply { this.lastKnownDistanceAlongTrip = lastKnownDistanceAlongTrip } - /** Last known location of the transit vehicle. */ - fun lastKnownLocation(lastKnownLocation: LastKnownLocation) = - lastKnownLocation(JsonField.of(lastKnownLocation)) - - /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun lastKnownLocation(lastKnownLocation: JsonField) = apply { - this.lastKnownLocation = lastKnownLocation - } - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - fun lastKnownOrientation(lastKnownOrientation: Double) = - lastKnownOrientation(JsonField.of(lastKnownOrientation)) - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun lastKnownOrientation(lastKnownOrientation: JsonField) = apply { - this.lastKnownOrientation = lastKnownOrientation - } - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1277,8 +1386,6 @@ private constructor( * Timestamp of the last known real-time location update from the transit * vehicle. */ - @JsonProperty("lastLocationUpdateTime") - @ExcludeMissing fun lastLocationUpdateTime(lastLocationUpdateTime: JsonField) = apply { this.lastLocationUpdateTime = lastLocationUpdateTime } @@ -1288,44 +1395,15 @@ private constructor( lastUpdateTime(JsonField.of(lastUpdateTime)) /** Timestamp of the last known real-time update from the transit vehicle. */ - @JsonProperty("lastUpdateTime") - @ExcludeMissing fun lastUpdateTime(lastUpdateTime: JsonField) = apply { this.lastUpdateTime = lastUpdateTime } - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - fun nextStop(nextStop: String) = nextStop(JsonField.of(nextStop)) - - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") - @ExcludeMissing - fun nextStop(nextStop: JsonField) = apply { this.nextStop = nextStop } - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - fun nextStopTimeOffset(nextStopTimeOffset: Long) = - nextStopTimeOffset(JsonField.of(nextStopTimeOffset)) - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - fun nextStopTimeOffset(nextStopTimeOffset: JsonField) = apply { - this.nextStopTimeOffset = nextStopTimeOffset - } - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) /** Capacity of the transit vehicle in terms of occupancy. */ - @JsonProperty("occupancyCapacity") - @ExcludeMissing fun occupancyCapacity(occupancyCapacity: JsonField) = apply { this.occupancyCapacity = occupancyCapacity } @@ -1335,8 +1413,6 @@ private constructor( occupancyCount(JsonField.of(occupancyCount)) /** Current count of occupants in the transit vehicle. */ - @JsonProperty("occupancyCount") - @ExcludeMissing fun occupancyCount(occupancyCount: JsonField) = apply { this.occupancyCount = occupancyCount } @@ -1346,44 +1422,20 @@ private constructor( occupancyStatus(JsonField.of(occupancyStatus)) /** Current occupancy status of the transit vehicle. */ - @JsonProperty("occupancyStatus") - @ExcludeMissing fun occupancyStatus(occupancyStatus: JsonField) = apply { this.occupancyStatus = occupancyStatus } - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - fun orientation(orientation: Double) = orientation(JsonField.of(orientation)) - - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") - @ExcludeMissing - fun orientation(orientation: JsonField) = apply { - this.orientation = orientation - } - /** Current journey phase of the trip. */ fun phase(phase: String) = phase(JsonField.of(phase)) /** Current journey phase of the trip. */ - @JsonProperty("phase") - @ExcludeMissing fun phase(phase: JsonField) = apply { this.phase = phase } - /** Current position of the transit vehicle. */ - fun position(position: Position) = position(JsonField.of(position)) - - /** Current position of the transit vehicle. */ - @JsonProperty("position") - @ExcludeMissing - fun position(position: JsonField) = apply { this.position = position } - /** Indicates if real-time arrival info is available for this trip. */ fun predicted(predicted: Boolean) = predicted(JsonField.of(predicted)) /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") - @ExcludeMissing fun predicted(predicted: JsonField) = apply { this.predicted = predicted } @@ -1399,30 +1451,10 @@ private constructor( * Deviation from the schedule in seconds (positive for late, negative for * early). */ - @JsonProperty("scheduleDeviation") - @ExcludeMissing fun scheduleDeviation(scheduleDeviation: JsonField) = apply { this.scheduleDeviation = scheduleDeviation } - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed - * along the active trip. - */ - fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: Double) = - scheduledDistanceAlongTrip(JsonField.of(scheduledDistanceAlongTrip)) - - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed - * along the active trip. - */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: JsonField) = - apply { - this.scheduledDistanceAlongTrip = scheduledDistanceAlongTrip - } - /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. @@ -1433,29 +1465,14 @@ private constructor( * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") - @ExcludeMissing fun serviceDate(serviceDate: JsonField) = apply { this.serviceDate = serviceDate } - /** References to situation elements (if any) applicable to this trip. */ - fun situationIds(situationIds: List) = - situationIds(JsonField.of(situationIds)) - - /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") - @ExcludeMissing - fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds - } - /** Current status modifiers for the trip. */ fun status(status: String) = status(JsonField.of(status)) /** Current status modifiers for the trip. */ - @JsonProperty("status") - @ExcludeMissing fun status(status: JsonField) = apply { this.status = status } /** Total length of the trip, in meters. */ @@ -1463,30 +1480,144 @@ private constructor( totalDistanceAlongTrip(JsonField.of(totalDistanceAlongTrip)) /** Total length of the trip, in meters. */ - @JsonProperty("totalDistanceAlongTrip") - @ExcludeMissing fun totalDistanceAlongTrip(totalDistanceAlongTrip: JsonField) = apply { this.totalDistanceAlongTrip = totalDistanceAlongTrip } + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + fun closestStopTimeOffset(closestStopTimeOffset: Long) = + closestStopTimeOffset(JsonField.of(closestStopTimeOffset)) + + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { + this.closestStopTimeOffset = closestStopTimeOffset + } + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: String) = frequency(JsonField.of(frequency)) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: JsonField) = apply { + this.frequency = frequency + } + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(lastKnownLocation: LastKnownLocation) = + lastKnownLocation(JsonField.of(lastKnownLocation)) + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(lastKnownLocation: JsonField) = apply { + this.lastKnownLocation = lastKnownLocation + } + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + fun lastKnownOrientation(lastKnownOrientation: Double) = + lastKnownOrientation(JsonField.of(lastKnownOrientation)) + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + fun lastKnownOrientation(lastKnownOrientation: JsonField) = apply { + this.lastKnownOrientation = lastKnownOrientation + } + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(nextStop: String) = nextStop(JsonField.of(nextStop)) + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(nextStop: JsonField) = apply { this.nextStop = nextStop } + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + fun nextStopTimeOffset(nextStopTimeOffset: Long) = + nextStopTimeOffset(JsonField.of(nextStopTimeOffset)) + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + fun nextStopTimeOffset(nextStopTimeOffset: JsonField) = apply { + this.nextStopTimeOffset = nextStopTimeOffset + } + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(orientation: Double) = orientation(JsonField.of(orientation)) + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(orientation: JsonField) = apply { + this.orientation = orientation + } + + /** Current position of the transit vehicle. */ + fun position(position: Position) = position(JsonField.of(position)) + + /** Current position of the transit vehicle. */ + fun position(position: JsonField) = apply { this.position = position } + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed + * along the active trip. + */ + fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: Double) = + scheduledDistanceAlongTrip(JsonField.of(scheduledDistanceAlongTrip)) + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed + * along the active trip. + */ + fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: JsonField) = + apply { + this.scheduledDistanceAlongTrip = scheduledDistanceAlongTrip + } + + /** References to situation elements (if any) applicable to this trip. */ + fun situationIds(situationIds: List) = + situationIds(JsonField.of(situationIds)) + + /** References to situation elements (if any) applicable to this trip. */ + fun situationIds(situationIds: JsonField>) = apply { + this.situationIds = situationIds.map { it.toMutableList() } + } + + /** References to situation elements (if any) applicable to this trip. */ + fun addSituationId(situationId: String) = apply { + situationIds = + (situationIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situationId) + } + } + /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(vehicleId: String) = vehicleId(JsonField.of(vehicleId)) /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") - @ExcludeMissing fun vehicleId(vehicleId: JsonField) = apply { this.vehicleId = vehicleId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1494,51 +1625,62 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Status = Status( - activeTripId, - blockTripSequence, - closestStop, + checkRequired("activeTripId", activeTripId), + checkRequired("blockTripSequence", blockTripSequence), + checkRequired("closestStop", closestStop), + checkRequired("distanceAlongTrip", distanceAlongTrip), + checkRequired("lastKnownDistanceAlongTrip", lastKnownDistanceAlongTrip), + checkRequired("lastLocationUpdateTime", lastLocationUpdateTime), + checkRequired("lastUpdateTime", lastUpdateTime), + checkRequired("occupancyCapacity", occupancyCapacity), + checkRequired("occupancyCount", occupancyCount), + checkRequired("occupancyStatus", occupancyStatus), + checkRequired("phase", phase), + checkRequired("predicted", predicted), + checkRequired("scheduleDeviation", scheduleDeviation), + checkRequired("serviceDate", serviceDate), + checkRequired("status", status), + checkRequired("totalDistanceAlongTrip", totalDistanceAlongTrip), closestStopTimeOffset, - distanceAlongTrip, frequency, - lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, - lastLocationUpdateTime, - lastUpdateTime, nextStop, nextStopTimeOffset, - occupancyCapacity, - occupancyCount, - occupancyStatus, orientation, - phase, position, - predicted, - scheduleDeviation, scheduledDistanceAlongTrip, - serviceDate, - situationIds.map { it.toImmutable() }, - status, - totalDistanceAlongTrip, + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, vehicleId, additionalProperties.toImmutable(), ) } /** Last known location of the transit vehicle. */ - @JsonDeserialize(builder = LastKnownLocation.Builder::class) @NoAutoDetect class LastKnownLocation + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the last known location of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -1546,21 +1688,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): LastKnownLocation = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -1570,7 +1716,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [LastKnownLocation]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -1579,42 +1726,46 @@ private constructor( @JvmSynthetic internal fun from(lastKnownLocation: LastKnownLocation) = apply { - this.lat = lastKnownLocation.lat - this.lon = lastKnownLocation.lon - additionalProperties(lastKnownLocation.additionalProperties) + lat = lastKnownLocation.lat + lon = lastKnownLocation.lon + additionalProperties = + lastKnownLocation.additionalProperties.toMutableMap() } /** Latitude of the last known location of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the last known location of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): LastKnownLocation = LastKnownLocation( lat, @@ -1628,34 +1779,34 @@ private constructor( return true } - return /* spotless:off */ other is LastKnownLocation && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is LastKnownLocation && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "LastKnownLocation{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" } /** Current position of the transit vehicle. */ - @JsonDeserialize(builder = Position.Builder::class) @NoAutoDetect class Position + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the current position of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -1663,21 +1814,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Position = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -1687,7 +1842,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Position]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -1696,42 +1852,45 @@ private constructor( @JvmSynthetic internal fun from(position: Position) = apply { - this.lat = position.lat - this.lon = position.lon - additionalProperties(position.additionalProperties) + lat = position.lat + lon = position.lon + additionalProperties = position.additionalProperties.toMutableMap() } /** Latitude of the current position of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the current position of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Position = Position( lat, @@ -1745,17 +1904,14 @@ private constructor( return true } - return /* spotless:off */ other is Position && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Position && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Position{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" @@ -1766,20 +1922,17 @@ private constructor( return true } - return /* spotless:off */ other is Status && this.activeTripId == other.activeTripId && this.blockTripSequence == other.blockTripSequence && this.closestStop == other.closestStop && this.closestStopTimeOffset == other.closestStopTimeOffset && this.distanceAlongTrip == other.distanceAlongTrip && this.frequency == other.frequency && this.lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && this.lastKnownLocation == other.lastKnownLocation && this.lastKnownOrientation == other.lastKnownOrientation && this.lastLocationUpdateTime == other.lastLocationUpdateTime && this.lastUpdateTime == other.lastUpdateTime && this.nextStop == other.nextStop && this.nextStopTimeOffset == other.nextStopTimeOffset && this.occupancyCapacity == other.occupancyCapacity && this.occupancyCount == other.occupancyCount && this.occupancyStatus == other.occupancyStatus && this.orientation == other.orientation && this.phase == other.phase && this.position == other.position && this.predicted == other.predicted && this.scheduleDeviation == other.scheduleDeviation && this.scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && this.serviceDate == other.serviceDate && this.situationIds == other.situationIds && this.status == other.status && this.totalDistanceAlongTrip == other.totalDistanceAlongTrip && this.vehicleId == other.vehicleId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Status && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && distanceAlongTrip == other.distanceAlongTrip && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && phase == other.phase && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && serviceDate == other.serviceDate && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && closestStopTimeOffset == other.closestStopTimeOffset && frequency == other.frequency && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && orientation == other.orientation && position == other.position && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && situationIds == other.situationIds && vehicleId == other.vehicleId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(activeTripId, blockTripSequence, closestStop, distanceAlongTrip, lastKnownDistanceAlongTrip, lastLocationUpdateTime, lastUpdateTime, occupancyCapacity, occupancyCount, occupancyStatus, phase, predicted, scheduleDeviation, serviceDate, status, totalDistanceAlongTrip, closestStopTimeOffset, frequency, lastKnownLocation, lastKnownOrientation, nextStop, nextStopTimeOffset, orientation, position, scheduledDistanceAlongTrip, situationIds, vehicleId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(activeTripId, blockTripSequence, closestStop, closestStopTimeOffset, distanceAlongTrip, frequency, lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, lastLocationUpdateTime, lastUpdateTime, nextStop, nextStopTimeOffset, occupancyCapacity, occupancyCount, occupancyStatus, orientation, phase, position, predicted, scheduleDeviation, scheduledDistanceAlongTrip, serviceDate, situationIds, status, totalDistanceAlongTrip, vehicleId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Status{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, closestStopTimeOffset=$closestStopTimeOffset, distanceAlongTrip=$distanceAlongTrip, frequency=$frequency, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, orientation=$orientation, phase=$phase, position=$position, predicted=$predicted, scheduleDeviation=$scheduleDeviation, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, serviceDate=$serviceDate, situationIds=$situationIds, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" + "Status{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, distanceAlongTrip=$distanceAlongTrip, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, phase=$phase, predicted=$predicted, scheduleDeviation=$scheduleDeviation, serviceDate=$serviceDate, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, closestStopTimeOffset=$closestStopTimeOffset, frequency=$frequency, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, orientation=$orientation, position=$position, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, situationIds=$situationIds, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1787,20 +1940,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.frequency == other.frequency && this.schedule == other.schedule && this.serviceDate == other.serviceDate && this.situationIds == other.situationIds && this.status == other.status && this.tripId == other.tripId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && tripId == other.tripId && frequency == other.frequency && schedule == other.schedule && serviceDate == other.serviceDate && situationIds == other.situationIds && status == other.status && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(tripId, frequency, schedule, serviceDate, situationIds, status, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(frequency, schedule, serviceDate, situationIds, status, tripId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Entry{frequency=$frequency, schedule=$schedule, serviceDate=$serviceDate, situationIds=$situationIds, status=$status, tripId=$tripId, additionalProperties=$additionalProperties}" + "Entry{tripId=$tripId, frequency=$frequency, schedule=$schedule, serviceDate=$serviceDate, situationIds=$situationIds, status=$status, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1808,17 +1958,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, references=$references, additionalProperties=$additionalProperties}" @@ -1829,17 +1976,14 @@ private constructor( return true } - return /* spotless:off */ other is TripDetailRetrieveResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is TripDetailRetrieveResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "TripDetailRetrieveResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripForVehicleRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripForVehicleRetrieveParams.kt index 2d2527b..5d0b04c 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripForVehicleRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripForVehicleRetrieveParams.kt @@ -2,46 +2,63 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Retrieve trip for a specific vehicle */ class TripForVehicleRetrieveParams -constructor( +private constructor( private val vehicleId: String, private val includeSchedule: Boolean?, private val includeStatus: Boolean?, private val includeTrip: Boolean?, private val time: Long?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun vehicleId(): String = vehicleId + /** + * Determines whether full element is included in the section. + * Defaults to false. + */ fun includeSchedule(): Optional = Optional.ofNullable(includeSchedule) + /** + * Determines whether the full element is included in the section. + * Defaults to true. + */ fun includeStatus(): Optional = Optional.ofNullable(includeStatus) + /** + * Determines whether full element is included in the section. Defaults to + * false. + */ fun includeTrip(): Optional = Optional.ofNullable(includeTrip) + /** Time parameter to query the system at a specific time (optional). */ fun time(): Optional = Optional.ofNullable(time) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.includeSchedule?.let { params.put("includeSchedule", listOf(it.toString())) } - this.includeStatus?.let { params.put("includeStatus", listOf(it.toString())) } - this.includeTrip?.let { params.put("includeTrip", listOf(it.toString())) } - this.time?.let { params.put("time", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + fun _additionalHeaders(): Headers = additionalHeaders + + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.includeSchedule?.let { queryParams.put("includeSchedule", listOf(it.toString())) } + this.includeStatus?.let { queryParams.put("includeStatus", listOf(it.toString())) } + this.includeTrip?.let { queryParams.put("includeTrip", listOf(it.toString())) } + this.time?.let { queryParams.put("time", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } fun getPathParam(index: Int): String { @@ -51,25 +68,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TripForVehicleRetrieveParams && this.vehicleId == other.vehicleId && this.includeSchedule == other.includeSchedule && this.includeStatus == other.includeStatus && this.includeTrip == other.includeTrip && this.time == other.time && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(vehicleId, includeSchedule, includeStatus, includeTrip, time, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "TripForVehicleRetrieveParams{vehicleId=$vehicleId, includeSchedule=$includeSchedule, includeStatus=$includeStatus, includeTrip=$includeTrip, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -77,26 +75,27 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [TripForVehicleRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var vehicleId: String? = null private var includeSchedule: Boolean? = null private var includeStatus: Boolean? = null private var includeTrip: Boolean? = null private var time: Long? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(tripForVehicleRetrieveParams: TripForVehicleRetrieveParams) = apply { - this.vehicleId = tripForVehicleRetrieveParams.vehicleId - this.includeSchedule = tripForVehicleRetrieveParams.includeSchedule - this.includeStatus = tripForVehicleRetrieveParams.includeStatus - this.includeTrip = tripForVehicleRetrieveParams.includeTrip - this.time = tripForVehicleRetrieveParams.time - additionalHeaders(tripForVehicleRetrieveParams.additionalHeaders) - additionalQueryParams(tripForVehicleRetrieveParams.additionalQueryParams) + vehicleId = tripForVehicleRetrieveParams.vehicleId + includeSchedule = tripForVehicleRetrieveParams.includeSchedule + includeStatus = tripForVehicleRetrieveParams.includeStatus + includeTrip = tripForVehicleRetrieveParams.includeTrip + time = tripForVehicleRetrieveParams.time + additionalHeaders = tripForVehicleRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = tripForVehicleRetrieveParams.additionalQueryParams.toBuilder() } fun vehicleId(vehicleId: String) = apply { this.vehicleId = vehicleId } @@ -105,24 +104,78 @@ constructor( * Determines whether full element is included in the section. * Defaults to false. */ - fun includeSchedule(includeSchedule: Boolean) = apply { + fun includeSchedule(includeSchedule: Boolean?) = apply { this.includeSchedule = includeSchedule } + /** + * Determines whether full element is included in the section. + * Defaults to false. + */ + fun includeSchedule(includeSchedule: Boolean) = includeSchedule(includeSchedule as Boolean?) + + /** + * Determines whether full element is included in the section. + * Defaults to false. + */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun includeSchedule(includeSchedule: Optional) = + includeSchedule(includeSchedule.orElse(null) as Boolean?) + + /** + * Determines whether the full element is included in the section. + * Defaults to true. + */ + fun includeStatus(includeStatus: Boolean?) = apply { this.includeStatus = includeStatus } + + /** + * Determines whether the full element is included in the section. + * Defaults to true. + */ + fun includeStatus(includeStatus: Boolean) = includeStatus(includeStatus as Boolean?) + /** * Determines whether the full element is included in the section. * Defaults to true. */ - fun includeStatus(includeStatus: Boolean) = apply { this.includeStatus = includeStatus } + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun includeStatus(includeStatus: Optional) = + includeStatus(includeStatus.orElse(null) as Boolean?) /** * Determines whether full element is included in the section. * Defaults to false. */ - fun includeTrip(includeTrip: Boolean) = apply { this.includeTrip = includeTrip } + fun includeTrip(includeTrip: Boolean?) = apply { this.includeTrip = includeTrip } + + /** + * Determines whether full element is included in the section. + * Defaults to false. + */ + fun includeTrip(includeTrip: Boolean) = includeTrip(includeTrip as Boolean?) + + /** + * Determines whether full element is included in the section. + * Defaults to false. + */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun includeTrip(includeTrip: Optional) = + includeTrip(includeTrip.orElse(null) as Boolean?) + + /** Time parameter to query the system at a specific time (optional). */ + fun time(time: Long?) = apply { this.time = time } + + /** Time parameter to query the system at a specific time (optional). */ + fun time(time: Long) = time(time as Long?) /** Time parameter to query the system at a specific time (optional). */ - fun time(time: Long) = apply { this.time = time } + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun time(time: Optional) = time(time.orElse(null) as Long?) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -134,29 +187,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -169,50 +235,63 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): TripForVehicleRetrieveParams = TripForVehicleRetrieveParams( - checkNotNull(vehicleId) { "`vehicleId` is required but was not set" }, + checkRequired("vehicleId", vehicleId), includeSchedule, includeStatus, includeTrip, time, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is TripForVehicleRetrieveParams && vehicleId == other.vehicleId && includeSchedule == other.includeSchedule && includeStatus == other.includeStatus && includeTrip == other.includeTrip && time == other.time && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(vehicleId, includeSchedule, includeStatus, includeTrip, time, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "TripForVehicleRetrieveParams{vehicleId=$vehicleId, includeSchedule=$includeSchedule, includeStatus=$includeStatus, includeTrip=$includeTrip, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripForVehicleRetrieveResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripForVehicleRetrieveResponse.kt index f81f2a8..3b9377f 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripForVehicleRetrieveResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripForVehicleRetrieveResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = TripForVehicleRetrieveResponse.Builder::class) @NoAutoDetect class TripForVehicleRetrieveResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): TripForVehicleRetrieveResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,109 +87,115 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [TripForVehicleRetrieveResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(tripForVehicleRetrieveResponse: TripForVehicleRetrieveResponse) = apply { - this.code = tripForVehicleRetrieveResponse.code - this.currentTime = tripForVehicleRetrieveResponse.currentTime - this.text = tripForVehicleRetrieveResponse.text - this.version = tripForVehicleRetrieveResponse.version - this.data = tripForVehicleRetrieveResponse.data - additionalProperties(tripForVehicleRetrieveResponse.additionalProperties) + code = tripForVehicleRetrieveResponse.code + currentTime = tripForVehicleRetrieveResponse.currentTime + text = tripForVehicleRetrieveResponse.text + version = tripForVehicleRetrieveResponse.version + data = tripForVehicleRetrieveResponse.data + additionalProperties = + tripForVehicleRetrieveResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): TripForVehicleRetrieveResponse = TripForVehicleRetrieveResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") fun references(): References = references.getRequired("references") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -191,69 +205,84 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val frequency: JsonField, - private val schedule: JsonField, - private val serviceDate: JsonField, - private val situationIds: JsonField>, - private val status: JsonField, - private val tripId: JsonField, - private val additionalProperties: Map, + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonProperty("schedule") + @ExcludeMissing + private val schedule: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonProperty("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun tripId(): String = tripId.getRequired("tripId") fun frequency(): Optional = Optional.ofNullable(frequency.getNullable("frequency")) @@ -269,34 +298,44 @@ private constructor( fun status(): Optional = Optional.ofNullable(status.getNullable("status")) - fun tripId(): String = tripId.getRequired("tripId") - - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + @JsonProperty("tripId") @ExcludeMissing fun _tripId(): JsonField = tripId - @JsonProperty("schedule") @ExcludeMissing fun _schedule() = schedule + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency - @JsonProperty("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate + @JsonProperty("schedule") + @ExcludeMissing + fun _schedule(): JsonField = schedule - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("situationIds") + @ExcludeMissing + fun _situationIds(): JsonField> = situationIds - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - frequency() - schedule().map { it.validate() } - serviceDate() - situationIds() - status().map { it.validate() } - tripId() - validated = true + if (validated) { + return@apply } + + tripId() + frequency() + schedule().ifPresent { it.validate() } + serviceDate() + situationIds() + status().ifPresent { it.validate() } + validated = true } fun toBuilder() = Builder().from(this) @@ -306,43 +345,44 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Entry]. */ + class Builder internal constructor() { + private var tripId: JsonField? = null private var frequency: JsonField = JsonMissing.of() private var schedule: JsonField = JsonMissing.of() private var serviceDate: JsonField = JsonMissing.of() - private var situationIds: JsonField> = JsonMissing.of() + private var situationIds: JsonField>? = null private var status: JsonField = JsonMissing.of() - private var tripId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(entry: Entry) = apply { - this.frequency = entry.frequency - this.schedule = entry.schedule - this.serviceDate = entry.serviceDate - this.situationIds = entry.situationIds - this.status = entry.status - this.tripId = entry.tripId - additionalProperties(entry.additionalProperties) + tripId = entry.tripId + frequency = entry.frequency + schedule = entry.schedule + serviceDate = entry.serviceDate + situationIds = entry.situationIds.map { it.toMutableList() } + status = entry.status + additionalProperties = entry.additionalProperties.toMutableMap() } - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) + fun tripId(tripId: String) = tripId(JsonField.of(tripId)) + + fun tripId(tripId: JsonField) = apply { this.tripId = tripId } + + fun frequency(frequency: String?) = frequency(JsonField.ofNullable(frequency)) + + fun frequency(frequency: Optional) = frequency(frequency.orElse(null)) - @JsonProperty("frequency") - @ExcludeMissing fun frequency(frequency: JsonField) = apply { this.frequency = frequency } fun schedule(schedule: Schedule) = schedule(JsonField.of(schedule)) - @JsonProperty("schedule") - @ExcludeMissing fun schedule(schedule: JsonField) = apply { this.schedule = schedule } fun serviceDate(serviceDate: Long) = serviceDate(JsonField.of(serviceDate)) - @JsonProperty("serviceDate") - @ExcludeMissing fun serviceDate(serviceDate: JsonField) = apply { this.serviceDate = serviceDate } @@ -350,32 +390,34 @@ private constructor( fun situationIds(situationIds: List) = situationIds(JsonField.of(situationIds)) - @JsonProperty("situationIds") - @ExcludeMissing fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds + this.situationIds = situationIds.map { it.toMutableList() } + } + + fun addSituationId(situationId: String) = apply { + situationIds = + (situationIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situationId) + } } fun status(status: Status) = status(JsonField.of(status)) - @JsonProperty("status") - @ExcludeMissing fun status(status: JsonField) = apply { this.status = status } - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - @JsonProperty("tripId") - @ExcludeMissing - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -383,35 +425,49 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( + checkRequired("tripId", tripId), frequency, schedule, serviceDate, - situationIds.map { it.toImmutable() }, + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, status, - tripId, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Schedule.Builder::class) @NoAutoDetect class Schedule + @JsonCreator private constructor( - private val frequency: JsonField, - private val nextTripId: JsonField, - private val previousTripId: JsonField, - private val stopTimes: JsonField>, - private val timeZone: JsonField, - private val additionalProperties: Map, + @JsonProperty("nextTripId") + @ExcludeMissing + private val nextTripId: JsonField = JsonMissing.of(), + @JsonProperty("previousTripId") + @ExcludeMissing + private val previousTripId: JsonField = JsonMissing.of(), + @JsonProperty("stopTimes") + @ExcludeMissing + private val stopTimes: JsonField> = JsonMissing.of(), + @JsonProperty("timeZone") + @ExcludeMissing + private val timeZone: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - fun nextTripId(): String = nextTripId.getRequired("nextTripId") fun previousTripId(): String = previousTripId.getRequired("previousTripId") @@ -420,31 +476,46 @@ private constructor( fun timeZone(): String = timeZone.getRequired("timeZone") - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) - @JsonProperty("nextTripId") @ExcludeMissing fun _nextTripId() = nextTripId + @JsonProperty("nextTripId") + @ExcludeMissing + fun _nextTripId(): JsonField = nextTripId @JsonProperty("previousTripId") @ExcludeMissing - fun _previousTripId() = previousTripId + fun _previousTripId(): JsonField = previousTripId + + @JsonProperty("stopTimes") + @ExcludeMissing + fun _stopTimes(): JsonField> = stopTimes - @JsonProperty("stopTimes") @ExcludeMissing fun _stopTimes() = stopTimes + @JsonProperty("timeZone") + @ExcludeMissing + fun _timeZone(): JsonField = timeZone - @JsonProperty("timeZone") @ExcludeMissing fun _timeZone() = timeZone + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Schedule = apply { - if (!validated) { - frequency() - nextTripId() - previousTripId() - stopTimes().forEach { it.validate() } - timeZone() - validated = true + if (validated) { + return@apply } + + nextTripId() + previousTripId() + stopTimes().forEach { it.validate() } + timeZone() + frequency() + validated = true } fun toBuilder() = Builder().from(this) @@ -454,37 +525,28 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Schedule]. */ + class Builder internal constructor() { + private var nextTripId: JsonField? = null + private var previousTripId: JsonField? = null + private var stopTimes: JsonField>? = null + private var timeZone: JsonField? = null private var frequency: JsonField = JsonMissing.of() - private var nextTripId: JsonField = JsonMissing.of() - private var previousTripId: JsonField = JsonMissing.of() - private var stopTimes: JsonField> = JsonMissing.of() - private var timeZone: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(schedule: Schedule) = apply { - this.frequency = schedule.frequency - this.nextTripId = schedule.nextTripId - this.previousTripId = schedule.previousTripId - this.stopTimes = schedule.stopTimes - this.timeZone = schedule.timeZone - additionalProperties(schedule.additionalProperties) - } - - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - @JsonProperty("frequency") - @ExcludeMissing - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency + nextTripId = schedule.nextTripId + previousTripId = schedule.previousTripId + stopTimes = schedule.stopTimes.map { it.toMutableList() } + timeZone = schedule.timeZone + frequency = schedule.frequency + additionalProperties = schedule.additionalProperties.toMutableMap() } fun nextTripId(nextTripId: String) = nextTripId(JsonField.of(nextTripId)) - @JsonProperty("nextTripId") - @ExcludeMissing fun nextTripId(nextTripId: JsonField) = apply { this.nextTripId = nextTripId } @@ -492,34 +554,48 @@ private constructor( fun previousTripId(previousTripId: String) = previousTripId(JsonField.of(previousTripId)) - @JsonProperty("previousTripId") - @ExcludeMissing fun previousTripId(previousTripId: JsonField) = apply { this.previousTripId = previousTripId } fun stopTimes(stopTimes: List) = stopTimes(JsonField.of(stopTimes)) - @JsonProperty("stopTimes") - @ExcludeMissing fun stopTimes(stopTimes: JsonField>) = apply { - this.stopTimes = stopTimes + this.stopTimes = stopTimes.map { it.toMutableList() } + } + + fun addStopTime(stopTime: StopTime) = apply { + stopTimes = + (stopTimes ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stopTime) + } } fun timeZone(timeZone: String) = timeZone(JsonField.of(timeZone)) - @JsonProperty("timeZone") - @ExcludeMissing fun timeZone(timeZone: JsonField) = apply { this.timeZone = timeZone } + fun frequency(frequency: String?) = frequency(JsonField.ofNullable(frequency)) + + fun frequency(frequency: Optional) = frequency(frequency.orElse(null)) + + fun frequency(frequency: JsonField) = apply { + this.frequency = frequency + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -527,32 +603,51 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Schedule = Schedule( + checkRequired("nextTripId", nextTripId), + checkRequired("previousTripId", previousTripId), + checkRequired("stopTimes", stopTimes).map { it.toImmutable() }, + checkRequired("timeZone", timeZone), frequency, - nextTripId, - previousTripId, - stopTimes.map { it.toImmutable() }, - timeZone, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = StopTime.Builder::class) @NoAutoDetect class StopTime + @JsonCreator private constructor( - private val arrivalTime: JsonField, - private val departureTime: JsonField, - private val distanceAlongTrip: JsonField, - private val historicalOccupancy: JsonField, - private val stopHeadsign: JsonField, - private val stopId: JsonField, - private val additionalProperties: Map, + @JsonProperty("arrivalTime") + @ExcludeMissing + private val arrivalTime: JsonField = JsonMissing.of(), + @JsonProperty("departureTime") + @ExcludeMissing + private val departureTime: JsonField = JsonMissing.of(), + @JsonProperty("distanceAlongTrip") + @ExcludeMissing + private val distanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("historicalOccupancy") + @ExcludeMissing + private val historicalOccupancy: JsonField = JsonMissing.of(), + @JsonProperty("stopHeadsign") + @ExcludeMissing + private val stopHeadsign: JsonField = JsonMissing.of(), + @JsonProperty("stopId") + @ExcludeMissing + private val stopId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun arrivalTime(): Optional = Optional.ofNullable(arrivalTime.getNullable("arrivalTime")) @@ -571,38 +666,48 @@ private constructor( fun stopId(): Optional = Optional.ofNullable(stopId.getNullable("stopId")) - @JsonProperty("arrivalTime") @ExcludeMissing fun _arrivalTime() = arrivalTime + @JsonProperty("arrivalTime") + @ExcludeMissing + fun _arrivalTime(): JsonField = arrivalTime @JsonProperty("departureTime") @ExcludeMissing - fun _departureTime() = departureTime + fun _departureTime(): JsonField = departureTime @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip + fun _distanceAlongTrip(): JsonField = distanceAlongTrip @JsonProperty("historicalOccupancy") @ExcludeMissing - fun _historicalOccupancy() = historicalOccupancy + fun _historicalOccupancy(): JsonField = historicalOccupancy - @JsonProperty("stopHeadsign") @ExcludeMissing fun _stopHeadsign() = stopHeadsign + @JsonProperty("stopHeadsign") + @ExcludeMissing + fun _stopHeadsign(): JsonField = stopHeadsign - @JsonProperty("stopId") @ExcludeMissing fun _stopId() = stopId + @JsonProperty("stopId") + @ExcludeMissing + fun _stopId(): JsonField = stopId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): StopTime = apply { - if (!validated) { - arrivalTime() - departureTime() - distanceAlongTrip() - historicalOccupancy() - stopHeadsign() - stopId() - validated = true + if (validated) { + return@apply } + + arrivalTime() + departureTime() + distanceAlongTrip() + historicalOccupancy() + stopHeadsign() + stopId() + validated = true } fun toBuilder() = Builder().from(this) @@ -612,7 +717,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopTime]. */ + class Builder internal constructor() { private var arrivalTime: JsonField = JsonMissing.of() private var departureTime: JsonField = JsonMissing.of() @@ -625,19 +731,17 @@ private constructor( @JvmSynthetic internal fun from(stopTime: StopTime) = apply { - this.arrivalTime = stopTime.arrivalTime - this.departureTime = stopTime.departureTime - this.distanceAlongTrip = stopTime.distanceAlongTrip - this.historicalOccupancy = stopTime.historicalOccupancy - this.stopHeadsign = stopTime.stopHeadsign - this.stopId = stopTime.stopId - additionalProperties(stopTime.additionalProperties) + arrivalTime = stopTime.arrivalTime + departureTime = stopTime.departureTime + distanceAlongTrip = stopTime.distanceAlongTrip + historicalOccupancy = stopTime.historicalOccupancy + stopHeadsign = stopTime.stopHeadsign + stopId = stopTime.stopId + additionalProperties = stopTime.additionalProperties.toMutableMap() } fun arrivalTime(arrivalTime: Long) = arrivalTime(JsonField.of(arrivalTime)) - @JsonProperty("arrivalTime") - @ExcludeMissing fun arrivalTime(arrivalTime: JsonField) = apply { this.arrivalTime = arrivalTime } @@ -645,8 +749,6 @@ private constructor( fun departureTime(departureTime: Long) = departureTime(JsonField.of(departureTime)) - @JsonProperty("departureTime") - @ExcludeMissing fun departureTime(departureTime: JsonField) = apply { this.departureTime = departureTime } @@ -654,8 +756,6 @@ private constructor( fun distanceAlongTrip(distanceAlongTrip: Double) = distanceAlongTrip(JsonField.of(distanceAlongTrip)) - @JsonProperty("distanceAlongTrip") - @ExcludeMissing fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { this.distanceAlongTrip = distanceAlongTrip } @@ -663,8 +763,6 @@ private constructor( fun historicalOccupancy(historicalOccupancy: String) = historicalOccupancy(JsonField.of(historicalOccupancy)) - @JsonProperty("historicalOccupancy") - @ExcludeMissing fun historicalOccupancy(historicalOccupancy: JsonField) = apply { this.historicalOccupancy = historicalOccupancy } @@ -672,33 +770,36 @@ private constructor( fun stopHeadsign(stopHeadsign: String) = stopHeadsign(JsonField.of(stopHeadsign)) - @JsonProperty("stopHeadsign") - @ExcludeMissing fun stopHeadsign(stopHeadsign: JsonField) = apply { this.stopHeadsign = stopHeadsign } fun stopId(stopId: String) = stopId(JsonField.of(stopId)) - @JsonProperty("stopId") - @ExcludeMissing fun stopId(stopId: JsonField) = apply { this.stopId = stopId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopTime = StopTime( arrivalTime, @@ -716,17 +817,14 @@ private constructor( return true } - return /* spotless:off */ other is StopTime && this.arrivalTime == other.arrivalTime && this.departureTime == other.departureTime && this.distanceAlongTrip == other.distanceAlongTrip && this.historicalOccupancy == other.historicalOccupancy && this.stopHeadsign == other.stopHeadsign && this.stopId == other.stopId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopTime && arrivalTime == other.arrivalTime && departureTime == other.departureTime && distanceAlongTrip == other.distanceAlongTrip && historicalOccupancy == other.historicalOccupancy && stopHeadsign == other.stopHeadsign && stopId == other.stopId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(arrivalTime, departureTime, distanceAlongTrip, historicalOccupancy, stopHeadsign, stopId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(arrivalTime, departureTime, distanceAlongTrip, historicalOccupancy, stopHeadsign, stopId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "StopTime{arrivalTime=$arrivalTime, departureTime=$departureTime, distanceAlongTrip=$distanceAlongTrip, historicalOccupancy=$historicalOccupancy, stopHeadsign=$stopHeadsign, stopId=$stopId, additionalProperties=$additionalProperties}" @@ -737,58 +835,108 @@ private constructor( return true } - return /* spotless:off */ other is Schedule && this.frequency == other.frequency && this.nextTripId == other.nextTripId && this.previousTripId == other.previousTripId && this.stopTimes == other.stopTimes && this.timeZone == other.timeZone && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Schedule && nextTripId == other.nextTripId && previousTripId == other.previousTripId && stopTimes == other.stopTimes && timeZone == other.timeZone && frequency == other.frequency && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(nextTripId, previousTripId, stopTimes, timeZone, frequency, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(frequency, nextTripId, previousTripId, stopTimes, timeZone, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Schedule{frequency=$frequency, nextTripId=$nextTripId, previousTripId=$previousTripId, stopTimes=$stopTimes, timeZone=$timeZone, additionalProperties=$additionalProperties}" + "Schedule{nextTripId=$nextTripId, previousTripId=$previousTripId, stopTimes=$stopTimes, timeZone=$timeZone, frequency=$frequency, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = Status.Builder::class) @NoAutoDetect class Status + @JsonCreator private constructor( - private val activeTripId: JsonField, - private val blockTripSequence: JsonField, - private val closestStop: JsonField, - private val closestStopTimeOffset: JsonField, - private val distanceAlongTrip: JsonField, - private val frequency: JsonField, - private val lastKnownDistanceAlongTrip: JsonField, - private val lastKnownLocation: JsonField, - private val lastKnownOrientation: JsonField, - private val lastLocationUpdateTime: JsonField, - private val lastUpdateTime: JsonField, - private val nextStop: JsonField, - private val nextStopTimeOffset: JsonField, - private val occupancyCapacity: JsonField, - private val occupancyCount: JsonField, - private val occupancyStatus: JsonField, - private val orientation: JsonField, - private val phase: JsonField, - private val position: JsonField, - private val predicted: JsonField, - private val scheduleDeviation: JsonField, - private val scheduledDistanceAlongTrip: JsonField, - private val serviceDate: JsonField, - private val situationIds: JsonField>, - private val status: JsonField, - private val totalDistanceAlongTrip: JsonField, - private val vehicleId: JsonField, - private val additionalProperties: Map, + @JsonProperty("activeTripId") + @ExcludeMissing + private val activeTripId: JsonField = JsonMissing.of(), + @JsonProperty("blockTripSequence") + @ExcludeMissing + private val blockTripSequence: JsonField = JsonMissing.of(), + @JsonProperty("closestStop") + @ExcludeMissing + private val closestStop: JsonField = JsonMissing.of(), + @JsonProperty("distanceAlongTrip") + @ExcludeMissing + private val distanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownDistanceAlongTrip") + @ExcludeMissing + private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastLocationUpdateTime") + @ExcludeMissing + private val lastLocationUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("lastUpdateTime") + @ExcludeMissing + private val lastUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCapacity") + @ExcludeMissing + private val occupancyCapacity: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCount") + @ExcludeMissing + private val occupancyCount: JsonField = JsonMissing.of(), + @JsonProperty("occupancyStatus") + @ExcludeMissing + private val occupancyStatus: JsonField = JsonMissing.of(), + @JsonProperty("phase") + @ExcludeMissing + private val phase: JsonField = JsonMissing.of(), + @JsonProperty("predicted") + @ExcludeMissing + private val predicted: JsonField = JsonMissing.of(), + @JsonProperty("scheduleDeviation") + @ExcludeMissing + private val scheduleDeviation: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonProperty("totalDistanceAlongTrip") + @ExcludeMissing + private val totalDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + private val closestStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownLocation") + @ExcludeMissing + private val lastKnownLocation: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + private val lastKnownOrientation: JsonField = JsonMissing.of(), + @JsonProperty("nextStop") + @ExcludeMissing + private val nextStop: JsonField = JsonMissing.of(), + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + private val nextStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("orientation") + @ExcludeMissing + private val orientation: JsonField = JsonMissing.of(), + @JsonProperty("position") + @ExcludeMissing + private val position: JsonField = JsonMissing.of(), + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + private val scheduledDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), + @JsonProperty("vehicleId") + @ExcludeMissing + private val vehicleId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Trip ID of the trip the vehicle is actively serving. */ fun activeTripId(): String = activeTripId.getRequired("activeTripId") @@ -798,22 +946,11 @@ private constructor( /** ID of the closest stop to the current location of the transit vehicle. */ fun closestStop(): String = closestStop.getRequired("closestStop") - /** - * Time offset from the closest stop to the current position of the transit vehicle - * (in seconds). - */ - fun closestStopTimeOffset(): Optional = - Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) - /** * Distance, in meters, the transit vehicle has progressed along the active trip. */ fun distanceAlongTrip(): Double = distanceAlongTrip.getRequired("distanceAlongTrip") - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -821,14 +958,6 @@ private constructor( fun lastKnownDistanceAlongTrip(): Double = lastKnownDistanceAlongTrip.getRequired("lastKnownDistanceAlongTrip") - /** Last known location of the transit vehicle. */ - fun lastKnownLocation(): Optional = - Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) - - /** Last known orientation value received in real-time from the transit vehicle. */ - fun lastKnownOrientation(): Optional = - Optional.ofNullable(lastKnownOrientation.getNullable("lastKnownOrientation")) - /** * Timestamp of the last known real-time location update from the transit vehicle. */ @@ -838,19 +967,8 @@ private constructor( /** Timestamp of the last known real-time update from the transit vehicle. */ fun lastUpdateTime(): Long = lastUpdateTime.getRequired("lastUpdateTime") - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - fun nextStop(): Optional = - Optional.ofNullable(nextStop.getNullable("nextStop")) - - /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). - */ - fun nextStopTimeOffset(): Optional = - Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) - - /** Capacity of the transit vehicle in terms of occupancy. */ - fun occupancyCapacity(): Long = occupancyCapacity.getRequired("occupancyCapacity") + /** Capacity of the transit vehicle in terms of occupancy. */ + fun occupancyCapacity(): Long = occupancyCapacity.getRequired("occupancyCapacity") /** Current count of occupants in the transit vehicle. */ fun occupancyCount(): Long = occupancyCount.getRequired("occupancyCount") @@ -858,17 +976,9 @@ private constructor( /** Current occupancy status of the transit vehicle. */ fun occupancyStatus(): String = occupancyStatus.getRequired("occupancyStatus") - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - fun orientation(): Optional = - Optional.ofNullable(orientation.getNullable("orientation")) - /** Current journey phase of the trip. */ fun phase(): String = phase.getRequired("phase") - /** Current position of the transit vehicle. */ - fun position(): Optional = - Optional.ofNullable(position.getNullable("position")) - /** Indicates if real-time arrival info is available for this trip. */ fun predicted(): Boolean = predicted.getRequired("predicted") @@ -877,25 +987,12 @@ private constructor( */ fun scheduleDeviation(): Long = scheduleDeviation.getRequired("scheduleDeviation") - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed along - * the active trip. - */ - fun scheduledDistanceAlongTrip(): Optional = - Optional.ofNullable( - scheduledDistanceAlongTrip.getNullable("scheduledDistanceAlongTrip") - ) - /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ fun serviceDate(): Long = serviceDate.getRequired("serviceDate") - /** References to situation elements (if any) applicable to this trip. */ - fun situationIds(): Optional> = - Optional.ofNullable(situationIds.getNullable("situationIds")) - /** Current status modifiers for the trip. */ fun status(): String = status.getRequired("status") @@ -903,38 +1000,82 @@ private constructor( fun totalDistanceAlongTrip(): Double = totalDistanceAlongTrip.getRequired("totalDistanceAlongTrip") + /** + * Time offset from the closest stop to the current position of the transit vehicle + * (in seconds). + */ + fun closestStopTimeOffset(): Optional = + Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(): Optional = + Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) + + /** Last known orientation value received in real-time from the transit vehicle. */ + fun lastKnownOrientation(): Optional = + Optional.ofNullable(lastKnownOrientation.getNullable("lastKnownOrientation")) + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(): Optional = + Optional.ofNullable(nextStop.getNullable("nextStop")) + + /** + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). + */ + fun nextStopTimeOffset(): Optional = + Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(): Optional = + Optional.ofNullable(orientation.getNullable("orientation")) + + /** Current position of the transit vehicle. */ + fun position(): Optional = + Optional.ofNullable(position.getNullable("position")) + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed along + * the active trip. + */ + fun scheduledDistanceAlongTrip(): Optional = + Optional.ofNullable( + scheduledDistanceAlongTrip.getNullable("scheduledDistanceAlongTrip") + ) + + /** References to situation elements (if any) applicable to this trip. */ + fun situationIds(): Optional> = + Optional.ofNullable(situationIds.getNullable("situationIds")) + /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(): Optional = Optional.ofNullable(vehicleId.getNullable("vehicleId")) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") @ExcludeMissing fun _activeTripId() = activeTripId + @JsonProperty("activeTripId") + @ExcludeMissing + fun _activeTripId(): JsonField = activeTripId /** Index of the active trip into the sequence of trips for the active block. */ @JsonProperty("blockTripSequence") @ExcludeMissing - fun _blockTripSequence() = blockTripSequence + fun _blockTripSequence(): JsonField = blockTripSequence /** ID of the closest stop to the current location of the transit vehicle. */ - @JsonProperty("closestStop") @ExcludeMissing fun _closestStop() = closestStop - - /** - * Time offset from the closest stop to the current position of the transit vehicle - * (in seconds). - */ - @JsonProperty("closestStopTimeOffset") + @JsonProperty("closestStop") @ExcludeMissing - fun _closestStopTimeOffset() = closestStopTimeOffset + fun _closestStop(): JsonField = closestStop /** * Distance, in meters, the transit vehicle has progressed along the active trip. */ @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + fun _distanceAlongTrip(): JsonField = distanceAlongTrip /** * Last known distance along the trip received in real-time from the transit @@ -942,138 +1083,169 @@ private constructor( */ @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing - fun _lastKnownDistanceAlongTrip() = lastKnownDistanceAlongTrip - - /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun _lastKnownLocation() = lastKnownLocation - - /** Last known orientation value received in real-time from the transit vehicle. */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun _lastKnownOrientation() = lastKnownOrientation + fun _lastKnownDistanceAlongTrip(): JsonField = lastKnownDistanceAlongTrip /** * Timestamp of the last known real-time location update from the transit vehicle. */ @JsonProperty("lastLocationUpdateTime") @ExcludeMissing - fun _lastLocationUpdateTime() = lastLocationUpdateTime + fun _lastLocationUpdateTime(): JsonField = lastLocationUpdateTime /** Timestamp of the last known real-time update from the transit vehicle. */ @JsonProperty("lastUpdateTime") @ExcludeMissing - fun _lastUpdateTime() = lastUpdateTime - - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") @ExcludeMissing fun _nextStop() = nextStop - - /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). - */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - fun _nextStopTimeOffset() = nextStopTimeOffset + fun _lastUpdateTime(): JsonField = lastUpdateTime /** Capacity of the transit vehicle in terms of occupancy. */ @JsonProperty("occupancyCapacity") @ExcludeMissing - fun _occupancyCapacity() = occupancyCapacity + fun _occupancyCapacity(): JsonField = occupancyCapacity /** Current count of occupants in the transit vehicle. */ @JsonProperty("occupancyCount") @ExcludeMissing - fun _occupancyCount() = occupancyCount + fun _occupancyCount(): JsonField = occupancyCount /** Current occupancy status of the transit vehicle. */ @JsonProperty("occupancyStatus") @ExcludeMissing - fun _occupancyStatus() = occupancyStatus - - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") @ExcludeMissing fun _orientation() = orientation + fun _occupancyStatus(): JsonField = occupancyStatus /** Current journey phase of the trip. */ - @JsonProperty("phase") @ExcludeMissing fun _phase() = phase - - /** Current position of the transit vehicle. */ - @JsonProperty("position") @ExcludeMissing fun _position() = position + @JsonProperty("phase") @ExcludeMissing fun _phase(): JsonField = phase /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") @ExcludeMissing fun _predicted() = predicted + @JsonProperty("predicted") + @ExcludeMissing + fun _predicted(): JsonField = predicted /** * Deviation from the schedule in seconds (positive for late, negative for early). */ @JsonProperty("scheduleDeviation") @ExcludeMissing - fun _scheduleDeviation() = scheduleDeviation - - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed along - * the active trip. - */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - fun _scheduledDistanceAlongTrip() = scheduledDistanceAlongTrip + fun _scheduleDeviation(): JsonField = scheduleDeviation /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate - - /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate /** Current status modifiers for the trip. */ - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status /** Total length of the trip, in meters. */ @JsonProperty("totalDistanceAlongTrip") @ExcludeMissing - fun _totalDistanceAlongTrip() = totalDistanceAlongTrip + fun _totalDistanceAlongTrip(): JsonField = totalDistanceAlongTrip + + /** + * Time offset from the closest stop to the current position of the transit vehicle + * (in seconds). + */ + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + fun _closestStopTimeOffset(): JsonField = closestStopTimeOffset + + /** Information about frequency-based scheduling, if applicable to the trip. */ + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency + + /** Last known location of the transit vehicle. */ + @JsonProperty("lastKnownLocation") + @ExcludeMissing + fun _lastKnownLocation(): JsonField = lastKnownLocation + + /** Last known orientation value received in real-time from the transit vehicle. */ + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + fun _lastKnownOrientation(): JsonField = lastKnownOrientation + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + @JsonProperty("nextStop") + @ExcludeMissing + fun _nextStop(): JsonField = nextStop + + /** + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). + */ + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + fun _nextStopTimeOffset(): JsonField = nextStopTimeOffset + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + @JsonProperty("orientation") + @ExcludeMissing + fun _orientation(): JsonField = orientation + + /** Current position of the transit vehicle. */ + @JsonProperty("position") + @ExcludeMissing + fun _position(): JsonField = position + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed along + * the active trip. + */ + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + fun _scheduledDistanceAlongTrip(): JsonField = scheduledDistanceAlongTrip + + /** References to situation elements (if any) applicable to this trip. */ + @JsonProperty("situationIds") + @ExcludeMissing + fun _situationIds(): JsonField> = situationIds /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") @ExcludeMissing fun _vehicleId() = vehicleId + @JsonProperty("vehicleId") + @ExcludeMissing + fun _vehicleId(): JsonField = vehicleId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Status = apply { - if (!validated) { - activeTripId() - blockTripSequence() - closestStop() - closestStopTimeOffset() - distanceAlongTrip() - frequency() - lastKnownDistanceAlongTrip() - lastKnownLocation().map { it.validate() } - lastKnownOrientation() - lastLocationUpdateTime() - lastUpdateTime() - nextStop() - nextStopTimeOffset() - occupancyCapacity() - occupancyCount() - occupancyStatus() - orientation() - phase() - position().map { it.validate() } - predicted() - scheduleDeviation() - scheduledDistanceAlongTrip() - serviceDate() - situationIds() - status() - totalDistanceAlongTrip() - vehicleId() - validated = true + if (validated) { + return@apply } + + activeTripId() + blockTripSequence() + closestStop() + distanceAlongTrip() + lastKnownDistanceAlongTrip() + lastLocationUpdateTime() + lastUpdateTime() + occupancyCapacity() + occupancyCount() + occupancyStatus() + phase() + predicted() + scheduleDeviation() + serviceDate() + status() + totalDistanceAlongTrip() + closestStopTimeOffset() + frequency() + lastKnownLocation().ifPresent { it.validate() } + lastKnownOrientation() + nextStop() + nextStopTimeOffset() + orientation() + position().ifPresent { it.validate() } + scheduledDistanceAlongTrip() + situationIds() + vehicleId() + validated = true } fun toBuilder() = Builder().from(this) @@ -1083,67 +1255,68 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - - private var activeTripId: JsonField = JsonMissing.of() - private var blockTripSequence: JsonField = JsonMissing.of() - private var closestStop: JsonField = JsonMissing.of() + /** A builder for [Status]. */ + class Builder internal constructor() { + + private var activeTripId: JsonField? = null + private var blockTripSequence: JsonField? = null + private var closestStop: JsonField? = null + private var distanceAlongTrip: JsonField? = null + private var lastKnownDistanceAlongTrip: JsonField? = null + private var lastLocationUpdateTime: JsonField? = null + private var lastUpdateTime: JsonField? = null + private var occupancyCapacity: JsonField? = null + private var occupancyCount: JsonField? = null + private var occupancyStatus: JsonField? = null + private var phase: JsonField? = null + private var predicted: JsonField? = null + private var scheduleDeviation: JsonField? = null + private var serviceDate: JsonField? = null + private var status: JsonField? = null + private var totalDistanceAlongTrip: JsonField? = null private var closestStopTimeOffset: JsonField = JsonMissing.of() - private var distanceAlongTrip: JsonField = JsonMissing.of() private var frequency: JsonField = JsonMissing.of() - private var lastKnownDistanceAlongTrip: JsonField = JsonMissing.of() private var lastKnownLocation: JsonField = JsonMissing.of() private var lastKnownOrientation: JsonField = JsonMissing.of() - private var lastLocationUpdateTime: JsonField = JsonMissing.of() - private var lastUpdateTime: JsonField = JsonMissing.of() private var nextStop: JsonField = JsonMissing.of() private var nextStopTimeOffset: JsonField = JsonMissing.of() - private var occupancyCapacity: JsonField = JsonMissing.of() - private var occupancyCount: JsonField = JsonMissing.of() - private var occupancyStatus: JsonField = JsonMissing.of() private var orientation: JsonField = JsonMissing.of() - private var phase: JsonField = JsonMissing.of() private var position: JsonField = JsonMissing.of() - private var predicted: JsonField = JsonMissing.of() - private var scheduleDeviation: JsonField = JsonMissing.of() private var scheduledDistanceAlongTrip: JsonField = JsonMissing.of() - private var serviceDate: JsonField = JsonMissing.of() - private var situationIds: JsonField> = JsonMissing.of() - private var status: JsonField = JsonMissing.of() - private var totalDistanceAlongTrip: JsonField = JsonMissing.of() + private var situationIds: JsonField>? = null private var vehicleId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(status: Status) = apply { - this.activeTripId = status.activeTripId - this.blockTripSequence = status.blockTripSequence - this.closestStop = status.closestStop - this.closestStopTimeOffset = status.closestStopTimeOffset - this.distanceAlongTrip = status.distanceAlongTrip - this.frequency = status.frequency - this.lastKnownDistanceAlongTrip = status.lastKnownDistanceAlongTrip - this.lastKnownLocation = status.lastKnownLocation - this.lastKnownOrientation = status.lastKnownOrientation - this.lastLocationUpdateTime = status.lastLocationUpdateTime - this.lastUpdateTime = status.lastUpdateTime - this.nextStop = status.nextStop - this.nextStopTimeOffset = status.nextStopTimeOffset - this.occupancyCapacity = status.occupancyCapacity - this.occupancyCount = status.occupancyCount - this.occupancyStatus = status.occupancyStatus - this.orientation = status.orientation - this.phase = status.phase - this.position = status.position - this.predicted = status.predicted - this.scheduleDeviation = status.scheduleDeviation - this.scheduledDistanceAlongTrip = status.scheduledDistanceAlongTrip - this.serviceDate = status.serviceDate - this.situationIds = status.situationIds + activeTripId = status.activeTripId + blockTripSequence = status.blockTripSequence + closestStop = status.closestStop + distanceAlongTrip = status.distanceAlongTrip + lastKnownDistanceAlongTrip = status.lastKnownDistanceAlongTrip + lastLocationUpdateTime = status.lastLocationUpdateTime + lastUpdateTime = status.lastUpdateTime + occupancyCapacity = status.occupancyCapacity + occupancyCount = status.occupancyCount + occupancyStatus = status.occupancyStatus + phase = status.phase + predicted = status.predicted + scheduleDeviation = status.scheduleDeviation + serviceDate = status.serviceDate this.status = status.status - this.totalDistanceAlongTrip = status.totalDistanceAlongTrip - this.vehicleId = status.vehicleId - additionalProperties(status.additionalProperties) + totalDistanceAlongTrip = status.totalDistanceAlongTrip + closestStopTimeOffset = status.closestStopTimeOffset + frequency = status.frequency + lastKnownLocation = status.lastKnownLocation + lastKnownOrientation = status.lastKnownOrientation + nextStop = status.nextStop + nextStopTimeOffset = status.nextStopTimeOffset + orientation = status.orientation + position = status.position + scheduledDistanceAlongTrip = status.scheduledDistanceAlongTrip + situationIds = status.situationIds.map { it.toMutableList() } + vehicleId = status.vehicleId + additionalProperties = status.additionalProperties.toMutableMap() } /** Trip ID of the trip the vehicle is actively serving. */ @@ -1151,8 +1324,6 @@ private constructor( activeTripId(JsonField.of(activeTripId)) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") - @ExcludeMissing fun activeTripId(activeTripId: JsonField) = apply { this.activeTripId = activeTripId } @@ -1162,8 +1333,6 @@ private constructor( blockTripSequence(JsonField.of(blockTripSequence)) /** Index of the active trip into the sequence of trips for the active block. */ - @JsonProperty("blockTripSequence") - @ExcludeMissing fun blockTripSequence(blockTripSequence: JsonField) = apply { this.blockTripSequence = blockTripSequence } @@ -1172,29 +1341,10 @@ private constructor( fun closestStop(closestStop: String) = closestStop(JsonField.of(closestStop)) /** ID of the closest stop to the current location of the transit vehicle. */ - @JsonProperty("closestStop") - @ExcludeMissing fun closestStop(closestStop: JsonField) = apply { this.closestStop = closestStop } - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - fun closestStopTimeOffset(closestStopTimeOffset: Long) = - closestStopTimeOffset(JsonField.of(closestStopTimeOffset)) - - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing - fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { - this.closestStopTimeOffset = closestStopTimeOffset - } - /** * Distance, in meters, the transit vehicle has progressed along the active * trip. @@ -1206,22 +1356,10 @@ private constructor( * Distance, in meters, the transit vehicle has progressed along the active * trip. */ - @JsonProperty("distanceAlongTrip") - @ExcludeMissing fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { this.distanceAlongTrip = distanceAlongTrip } - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") - @ExcludeMissing - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1233,39 +1371,11 @@ private constructor( * Last known distance along the trip received in real-time from the transit * vehicle. */ - @JsonProperty("lastKnownDistanceAlongTrip") - @ExcludeMissing fun lastKnownDistanceAlongTrip(lastKnownDistanceAlongTrip: JsonField) = apply { this.lastKnownDistanceAlongTrip = lastKnownDistanceAlongTrip } - /** Last known location of the transit vehicle. */ - fun lastKnownLocation(lastKnownLocation: LastKnownLocation) = - lastKnownLocation(JsonField.of(lastKnownLocation)) - - /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun lastKnownLocation(lastKnownLocation: JsonField) = apply { - this.lastKnownLocation = lastKnownLocation - } - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - fun lastKnownOrientation(lastKnownOrientation: Double) = - lastKnownOrientation(JsonField.of(lastKnownOrientation)) - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun lastKnownOrientation(lastKnownOrientation: JsonField) = apply { - this.lastKnownOrientation = lastKnownOrientation - } - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1277,8 +1387,6 @@ private constructor( * Timestamp of the last known real-time location update from the transit * vehicle. */ - @JsonProperty("lastLocationUpdateTime") - @ExcludeMissing fun lastLocationUpdateTime(lastLocationUpdateTime: JsonField) = apply { this.lastLocationUpdateTime = lastLocationUpdateTime } @@ -1288,44 +1396,15 @@ private constructor( lastUpdateTime(JsonField.of(lastUpdateTime)) /** Timestamp of the last known real-time update from the transit vehicle. */ - @JsonProperty("lastUpdateTime") - @ExcludeMissing fun lastUpdateTime(lastUpdateTime: JsonField) = apply { this.lastUpdateTime = lastUpdateTime } - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - fun nextStop(nextStop: String) = nextStop(JsonField.of(nextStop)) - - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") - @ExcludeMissing - fun nextStop(nextStop: JsonField) = apply { this.nextStop = nextStop } - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - fun nextStopTimeOffset(nextStopTimeOffset: Long) = - nextStopTimeOffset(JsonField.of(nextStopTimeOffset)) - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - fun nextStopTimeOffset(nextStopTimeOffset: JsonField) = apply { - this.nextStopTimeOffset = nextStopTimeOffset - } - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) /** Capacity of the transit vehicle in terms of occupancy. */ - @JsonProperty("occupancyCapacity") - @ExcludeMissing fun occupancyCapacity(occupancyCapacity: JsonField) = apply { this.occupancyCapacity = occupancyCapacity } @@ -1335,8 +1414,6 @@ private constructor( occupancyCount(JsonField.of(occupancyCount)) /** Current count of occupants in the transit vehicle. */ - @JsonProperty("occupancyCount") - @ExcludeMissing fun occupancyCount(occupancyCount: JsonField) = apply { this.occupancyCount = occupancyCount } @@ -1346,44 +1423,20 @@ private constructor( occupancyStatus(JsonField.of(occupancyStatus)) /** Current occupancy status of the transit vehicle. */ - @JsonProperty("occupancyStatus") - @ExcludeMissing fun occupancyStatus(occupancyStatus: JsonField) = apply { this.occupancyStatus = occupancyStatus } - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - fun orientation(orientation: Double) = orientation(JsonField.of(orientation)) - - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") - @ExcludeMissing - fun orientation(orientation: JsonField) = apply { - this.orientation = orientation - } - /** Current journey phase of the trip. */ fun phase(phase: String) = phase(JsonField.of(phase)) /** Current journey phase of the trip. */ - @JsonProperty("phase") - @ExcludeMissing fun phase(phase: JsonField) = apply { this.phase = phase } - /** Current position of the transit vehicle. */ - fun position(position: Position) = position(JsonField.of(position)) - - /** Current position of the transit vehicle. */ - @JsonProperty("position") - @ExcludeMissing - fun position(position: JsonField) = apply { this.position = position } - /** Indicates if real-time arrival info is available for this trip. */ fun predicted(predicted: Boolean) = predicted(JsonField.of(predicted)) /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") - @ExcludeMissing fun predicted(predicted: JsonField) = apply { this.predicted = predicted } @@ -1399,30 +1452,10 @@ private constructor( * Deviation from the schedule in seconds (positive for late, negative for * early). */ - @JsonProperty("scheduleDeviation") - @ExcludeMissing fun scheduleDeviation(scheduleDeviation: JsonField) = apply { this.scheduleDeviation = scheduleDeviation } - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed - * along the active trip. - */ - fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: Double) = - scheduledDistanceAlongTrip(JsonField.of(scheduledDistanceAlongTrip)) - - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed - * along the active trip. - */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: JsonField) = - apply { - this.scheduledDistanceAlongTrip = scheduledDistanceAlongTrip - } - /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. @@ -1433,29 +1466,14 @@ private constructor( * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") - @ExcludeMissing fun serviceDate(serviceDate: JsonField) = apply { this.serviceDate = serviceDate } - /** References to situation elements (if any) applicable to this trip. */ - fun situationIds(situationIds: List) = - situationIds(JsonField.of(situationIds)) - - /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") - @ExcludeMissing - fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds - } - /** Current status modifiers for the trip. */ fun status(status: String) = status(JsonField.of(status)) /** Current status modifiers for the trip. */ - @JsonProperty("status") - @ExcludeMissing fun status(status: JsonField) = apply { this.status = status } /** Total length of the trip, in meters. */ @@ -1463,30 +1481,144 @@ private constructor( totalDistanceAlongTrip(JsonField.of(totalDistanceAlongTrip)) /** Total length of the trip, in meters. */ - @JsonProperty("totalDistanceAlongTrip") - @ExcludeMissing fun totalDistanceAlongTrip(totalDistanceAlongTrip: JsonField) = apply { this.totalDistanceAlongTrip = totalDistanceAlongTrip } + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + fun closestStopTimeOffset(closestStopTimeOffset: Long) = + closestStopTimeOffset(JsonField.of(closestStopTimeOffset)) + + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { + this.closestStopTimeOffset = closestStopTimeOffset + } + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: String) = frequency(JsonField.of(frequency)) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: JsonField) = apply { + this.frequency = frequency + } + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(lastKnownLocation: LastKnownLocation) = + lastKnownLocation(JsonField.of(lastKnownLocation)) + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(lastKnownLocation: JsonField) = apply { + this.lastKnownLocation = lastKnownLocation + } + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + fun lastKnownOrientation(lastKnownOrientation: Double) = + lastKnownOrientation(JsonField.of(lastKnownOrientation)) + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + fun lastKnownOrientation(lastKnownOrientation: JsonField) = apply { + this.lastKnownOrientation = lastKnownOrientation + } + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(nextStop: String) = nextStop(JsonField.of(nextStop)) + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(nextStop: JsonField) = apply { this.nextStop = nextStop } + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + fun nextStopTimeOffset(nextStopTimeOffset: Long) = + nextStopTimeOffset(JsonField.of(nextStopTimeOffset)) + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + fun nextStopTimeOffset(nextStopTimeOffset: JsonField) = apply { + this.nextStopTimeOffset = nextStopTimeOffset + } + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(orientation: Double) = orientation(JsonField.of(orientation)) + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(orientation: JsonField) = apply { + this.orientation = orientation + } + + /** Current position of the transit vehicle. */ + fun position(position: Position) = position(JsonField.of(position)) + + /** Current position of the transit vehicle. */ + fun position(position: JsonField) = apply { this.position = position } + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed + * along the active trip. + */ + fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: Double) = + scheduledDistanceAlongTrip(JsonField.of(scheduledDistanceAlongTrip)) + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed + * along the active trip. + */ + fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: JsonField) = + apply { + this.scheduledDistanceAlongTrip = scheduledDistanceAlongTrip + } + + /** References to situation elements (if any) applicable to this trip. */ + fun situationIds(situationIds: List) = + situationIds(JsonField.of(situationIds)) + + /** References to situation elements (if any) applicable to this trip. */ + fun situationIds(situationIds: JsonField>) = apply { + this.situationIds = situationIds.map { it.toMutableList() } + } + + /** References to situation elements (if any) applicable to this trip. */ + fun addSituationId(situationId: String) = apply { + situationIds = + (situationIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situationId) + } + } + /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(vehicleId: String) = vehicleId(JsonField.of(vehicleId)) /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") - @ExcludeMissing fun vehicleId(vehicleId: JsonField) = apply { this.vehicleId = vehicleId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1494,51 +1626,62 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Status = Status( - activeTripId, - blockTripSequence, - closestStop, + checkRequired("activeTripId", activeTripId), + checkRequired("blockTripSequence", blockTripSequence), + checkRequired("closestStop", closestStop), + checkRequired("distanceAlongTrip", distanceAlongTrip), + checkRequired("lastKnownDistanceAlongTrip", lastKnownDistanceAlongTrip), + checkRequired("lastLocationUpdateTime", lastLocationUpdateTime), + checkRequired("lastUpdateTime", lastUpdateTime), + checkRequired("occupancyCapacity", occupancyCapacity), + checkRequired("occupancyCount", occupancyCount), + checkRequired("occupancyStatus", occupancyStatus), + checkRequired("phase", phase), + checkRequired("predicted", predicted), + checkRequired("scheduleDeviation", scheduleDeviation), + checkRequired("serviceDate", serviceDate), + checkRequired("status", status), + checkRequired("totalDistanceAlongTrip", totalDistanceAlongTrip), closestStopTimeOffset, - distanceAlongTrip, frequency, - lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, - lastLocationUpdateTime, - lastUpdateTime, nextStop, nextStopTimeOffset, - occupancyCapacity, - occupancyCount, - occupancyStatus, orientation, - phase, position, - predicted, - scheduleDeviation, scheduledDistanceAlongTrip, - serviceDate, - situationIds.map { it.toImmutable() }, - status, - totalDistanceAlongTrip, + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, vehicleId, additionalProperties.toImmutable(), ) } /** Last known location of the transit vehicle. */ - @JsonDeserialize(builder = LastKnownLocation.Builder::class) @NoAutoDetect class LastKnownLocation + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the last known location of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -1546,21 +1689,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): LastKnownLocation = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -1570,7 +1717,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [LastKnownLocation]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -1579,42 +1727,46 @@ private constructor( @JvmSynthetic internal fun from(lastKnownLocation: LastKnownLocation) = apply { - this.lat = lastKnownLocation.lat - this.lon = lastKnownLocation.lon - additionalProperties(lastKnownLocation.additionalProperties) + lat = lastKnownLocation.lat + lon = lastKnownLocation.lon + additionalProperties = + lastKnownLocation.additionalProperties.toMutableMap() } /** Latitude of the last known location of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the last known location of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): LastKnownLocation = LastKnownLocation( lat, @@ -1628,34 +1780,34 @@ private constructor( return true } - return /* spotless:off */ other is LastKnownLocation && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is LastKnownLocation && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "LastKnownLocation{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" } /** Current position of the transit vehicle. */ - @JsonDeserialize(builder = Position.Builder::class) @NoAutoDetect class Position + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the current position of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -1663,21 +1815,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Position = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -1687,7 +1843,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Position]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -1696,42 +1853,45 @@ private constructor( @JvmSynthetic internal fun from(position: Position) = apply { - this.lat = position.lat - this.lon = position.lon - additionalProperties(position.additionalProperties) + lat = position.lat + lon = position.lon + additionalProperties = position.additionalProperties.toMutableMap() } /** Latitude of the current position of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the current position of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Position = Position( lat, @@ -1745,17 +1905,14 @@ private constructor( return true } - return /* spotless:off */ other is Position && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Position && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Position{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" @@ -1766,20 +1923,17 @@ private constructor( return true } - return /* spotless:off */ other is Status && this.activeTripId == other.activeTripId && this.blockTripSequence == other.blockTripSequence && this.closestStop == other.closestStop && this.closestStopTimeOffset == other.closestStopTimeOffset && this.distanceAlongTrip == other.distanceAlongTrip && this.frequency == other.frequency && this.lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && this.lastKnownLocation == other.lastKnownLocation && this.lastKnownOrientation == other.lastKnownOrientation && this.lastLocationUpdateTime == other.lastLocationUpdateTime && this.lastUpdateTime == other.lastUpdateTime && this.nextStop == other.nextStop && this.nextStopTimeOffset == other.nextStopTimeOffset && this.occupancyCapacity == other.occupancyCapacity && this.occupancyCount == other.occupancyCount && this.occupancyStatus == other.occupancyStatus && this.orientation == other.orientation && this.phase == other.phase && this.position == other.position && this.predicted == other.predicted && this.scheduleDeviation == other.scheduleDeviation && this.scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && this.serviceDate == other.serviceDate && this.situationIds == other.situationIds && this.status == other.status && this.totalDistanceAlongTrip == other.totalDistanceAlongTrip && this.vehicleId == other.vehicleId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Status && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && distanceAlongTrip == other.distanceAlongTrip && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && phase == other.phase && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && serviceDate == other.serviceDate && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && closestStopTimeOffset == other.closestStopTimeOffset && frequency == other.frequency && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && orientation == other.orientation && position == other.position && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && situationIds == other.situationIds && vehicleId == other.vehicleId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(activeTripId, blockTripSequence, closestStop, distanceAlongTrip, lastKnownDistanceAlongTrip, lastLocationUpdateTime, lastUpdateTime, occupancyCapacity, occupancyCount, occupancyStatus, phase, predicted, scheduleDeviation, serviceDate, status, totalDistanceAlongTrip, closestStopTimeOffset, frequency, lastKnownLocation, lastKnownOrientation, nextStop, nextStopTimeOffset, orientation, position, scheduledDistanceAlongTrip, situationIds, vehicleId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(activeTripId, blockTripSequence, closestStop, closestStopTimeOffset, distanceAlongTrip, frequency, lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, lastLocationUpdateTime, lastUpdateTime, nextStop, nextStopTimeOffset, occupancyCapacity, occupancyCount, occupancyStatus, orientation, phase, position, predicted, scheduleDeviation, scheduledDistanceAlongTrip, serviceDate, situationIds, status, totalDistanceAlongTrip, vehicleId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Status{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, closestStopTimeOffset=$closestStopTimeOffset, distanceAlongTrip=$distanceAlongTrip, frequency=$frequency, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, orientation=$orientation, phase=$phase, position=$position, predicted=$predicted, scheduleDeviation=$scheduleDeviation, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, serviceDate=$serviceDate, situationIds=$situationIds, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" + "Status{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, distanceAlongTrip=$distanceAlongTrip, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, phase=$phase, predicted=$predicted, scheduleDeviation=$scheduleDeviation, serviceDate=$serviceDate, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, closestStopTimeOffset=$closestStopTimeOffset, frequency=$frequency, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, orientation=$orientation, position=$position, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, situationIds=$situationIds, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1787,20 +1941,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.frequency == other.frequency && this.schedule == other.schedule && this.serviceDate == other.serviceDate && this.situationIds == other.situationIds && this.status == other.status && this.tripId == other.tripId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && tripId == other.tripId && frequency == other.frequency && schedule == other.schedule && serviceDate == other.serviceDate && situationIds == other.situationIds && status == other.status && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(tripId, frequency, schedule, serviceDate, situationIds, status, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(frequency, schedule, serviceDate, situationIds, status, tripId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Entry{frequency=$frequency, schedule=$schedule, serviceDate=$serviceDate, situationIds=$situationIds, status=$status, tripId=$tripId, additionalProperties=$additionalProperties}" + "Entry{tripId=$tripId, frequency=$frequency, schedule=$schedule, serviceDate=$serviceDate, situationIds=$situationIds, status=$status, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1808,17 +1959,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, references=$references, additionalProperties=$additionalProperties}" @@ -1829,17 +1977,14 @@ private constructor( return true } - return /* spotless:off */ other is TripForVehicleRetrieveResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is TripForVehicleRetrieveResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "TripForVehicleRetrieveResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripRetrieveParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripRetrieveParams.kt index 76f1f30..d1a60d5 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripRetrieveParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripRetrieveParams.kt @@ -2,25 +2,30 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Get details of a specific trip */ class TripRetrieveParams -constructor( +private constructor( private val tripId: String, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun tripId(): String = tripId - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): Map> = additionalQueryParams + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -29,25 +34,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TripRetrieveParams && this.tripId == other.tripId && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(tripId, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "TripRetrieveParams{tripId=$tripId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -55,22 +41,28 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [TripRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var tripId: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(tripRetrieveParams: TripRetrieveParams) = apply { - this.tripId = tripRetrieveParams.tripId - additionalHeaders(tripRetrieveParams.additionalHeaders) - additionalQueryParams(tripRetrieveParams.additionalQueryParams) + tripId = tripRetrieveParams.tripId + additionalHeaders = tripRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = tripRetrieveParams.additionalQueryParams.toBuilder() } fun tripId(tripId: String) = apply { this.tripId = tripId } + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -81,29 +73,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -116,46 +121,59 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): TripRetrieveParams = TripRetrieveParams( - checkNotNull(tripId) { "`tripId` is required but was not set" }, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + checkRequired("tripId", tripId), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is TripRetrieveParams && tripId == other.tripId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(tripId, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "TripRetrieveParams{tripId=$tripId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripRetrieveResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripRetrieveResponse.kt index 4377e27..c4986cd 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripRetrieveResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripRetrieveResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = TripRetrieveResponse.Builder::class) @NoAutoDetect class TripRetrieveResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): TripRetrieveResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,109 +87,114 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [TripRetrieveResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(tripRetrieveResponse: TripRetrieveResponse) = apply { - this.code = tripRetrieveResponse.code - this.currentTime = tripRetrieveResponse.currentTime - this.text = tripRetrieveResponse.text - this.version = tripRetrieveResponse.version - this.data = tripRetrieveResponse.data - additionalProperties(tripRetrieveResponse.additionalProperties) + code = tripRetrieveResponse.code + currentTime = tripRetrieveResponse.currentTime + text = tripRetrieveResponse.text + version = tripRetrieveResponse.version + data = tripRetrieveResponse.data + additionalProperties = tripRetrieveResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): TripRetrieveResponse = TripRetrieveResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val entry: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("entry") + @ExcludeMissing + private val entry: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun entry(): Entry = entry.getRequired("entry") fun references(): References = references.getRequired("references") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - entry().validate() - references().validate() - validated = true + if (validated) { + return@apply } + + entry().validate() + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -191,92 +204,115 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var entry: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var entry: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.entry = data.entry - this.references = data.references - additionalProperties(data.additionalProperties) + entry = data.entry + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun entry(entry: Entry) = entry(JsonField.of(entry)) - @JsonProperty("entry") - @ExcludeMissing fun entry(entry: JsonField) = apply { this.entry = entry } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Entry.Builder::class) @NoAutoDetect class Entry + @JsonCreator private constructor( - private val blockId: JsonField, - private val directionId: JsonField, - private val id: JsonField, - private val peakOffpeak: JsonField, - private val routeId: JsonField, - private val routeShortName: JsonField, - private val serviceId: JsonField, - private val shapeId: JsonField, - private val timeZone: JsonField, - private val tripHeadsign: JsonField, - private val tripShortName: JsonField, - private val additionalProperties: Map, + @JsonProperty("id") + @ExcludeMissing + private val id: JsonField = JsonMissing.of(), + @JsonProperty("routeId") + @ExcludeMissing + private val routeId: JsonField = JsonMissing.of(), + @JsonProperty("serviceId") + @ExcludeMissing + private val serviceId: JsonField = JsonMissing.of(), + @JsonProperty("blockId") + @ExcludeMissing + private val blockId: JsonField = JsonMissing.of(), + @JsonProperty("directionId") + @ExcludeMissing + private val directionId: JsonField = JsonMissing.of(), + @JsonProperty("peakOffpeak") + @ExcludeMissing + private val peakOffpeak: JsonField = JsonMissing.of(), + @JsonProperty("routeShortName") + @ExcludeMissing + private val routeShortName: JsonField = JsonMissing.of(), + @JsonProperty("shapeId") + @ExcludeMissing + private val shapeId: JsonField = JsonMissing.of(), + @JsonProperty("timeZone") + @ExcludeMissing + private val timeZone: JsonField = JsonMissing.of(), + @JsonProperty("tripHeadsign") + @ExcludeMissing + private val tripHeadsign: JsonField = JsonMissing.of(), + @JsonProperty("tripShortName") + @ExcludeMissing + private val tripShortName: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun id(): String = id.getRequired("id") + + fun routeId(): String = routeId.getRequired("routeId") + + fun serviceId(): String = serviceId.getRequired("serviceId") fun blockId(): Optional = Optional.ofNullable(blockId.getNullable("blockId")) fun directionId(): Optional = Optional.ofNullable(directionId.getNullable("directionId")) - fun id(): String = id.getRequired("id") - fun peakOffpeak(): Optional = Optional.ofNullable(peakOffpeak.getNullable("peakOffpeak")) - fun routeId(): String = routeId.getRequired("routeId") - fun routeShortName(): Optional = Optional.ofNullable(routeShortName.getNullable("routeShortName")) - fun serviceId(): String = serviceId.getRequired("serviceId") - fun shapeId(): Optional = Optional.ofNullable(shapeId.getNullable("shapeId")) fun timeZone(): Optional = Optional.ofNullable(timeZone.getNullable("timeZone")) @@ -287,47 +323,63 @@ private constructor( fun tripShortName(): Optional = Optional.ofNullable(tripShortName.getNullable("tripShortName")) - @JsonProperty("blockId") @ExcludeMissing fun _blockId() = blockId + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - @JsonProperty("directionId") @ExcludeMissing fun _directionId() = directionId + @JsonProperty("routeId") @ExcludeMissing fun _routeId(): JsonField = routeId - @JsonProperty("id") @ExcludeMissing fun _id() = id + @JsonProperty("serviceId") + @ExcludeMissing + fun _serviceId(): JsonField = serviceId - @JsonProperty("peakOffpeak") @ExcludeMissing fun _peakOffpeak() = peakOffpeak + @JsonProperty("blockId") @ExcludeMissing fun _blockId(): JsonField = blockId - @JsonProperty("routeId") @ExcludeMissing fun _routeId() = routeId + @JsonProperty("directionId") + @ExcludeMissing + fun _directionId(): JsonField = directionId - @JsonProperty("routeShortName") @ExcludeMissing fun _routeShortName() = routeShortName + @JsonProperty("peakOffpeak") + @ExcludeMissing + fun _peakOffpeak(): JsonField = peakOffpeak - @JsonProperty("serviceId") @ExcludeMissing fun _serviceId() = serviceId + @JsonProperty("routeShortName") + @ExcludeMissing + fun _routeShortName(): JsonField = routeShortName - @JsonProperty("shapeId") @ExcludeMissing fun _shapeId() = shapeId + @JsonProperty("shapeId") @ExcludeMissing fun _shapeId(): JsonField = shapeId - @JsonProperty("timeZone") @ExcludeMissing fun _timeZone() = timeZone + @JsonProperty("timeZone") @ExcludeMissing fun _timeZone(): JsonField = timeZone - @JsonProperty("tripHeadsign") @ExcludeMissing fun _tripHeadsign() = tripHeadsign + @JsonProperty("tripHeadsign") + @ExcludeMissing + fun _tripHeadsign(): JsonField = tripHeadsign - @JsonProperty("tripShortName") @ExcludeMissing fun _tripShortName() = tripShortName + @JsonProperty("tripShortName") + @ExcludeMissing + fun _tripShortName(): JsonField = tripShortName @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Entry = apply { - if (!validated) { - blockId() - directionId() - id() - peakOffpeak() - routeId() - routeShortName() - serviceId() - shapeId() - timeZone() - tripHeadsign() - tripShortName() - validated = true + if (validated) { + return@apply } + + id() + routeId() + serviceId() + blockId() + directionId() + peakOffpeak() + routeShortName() + shapeId() + timeZone() + tripHeadsign() + tripShortName() + validated = true } fun toBuilder() = Builder().from(this) @@ -337,15 +389,16 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Entry]. */ + class Builder internal constructor() { + private var id: JsonField? = null + private var routeId: JsonField? = null + private var serviceId: JsonField? = null private var blockId: JsonField = JsonMissing.of() private var directionId: JsonField = JsonMissing.of() - private var id: JsonField = JsonMissing.of() private var peakOffpeak: JsonField = JsonMissing.of() - private var routeId: JsonField = JsonMissing.of() private var routeShortName: JsonField = JsonMissing.of() - private var serviceId: JsonField = JsonMissing.of() private var shapeId: JsonField = JsonMissing.of() private var timeZone: JsonField = JsonMissing.of() private var tripHeadsign: JsonField = JsonMissing.of() @@ -354,85 +407,65 @@ private constructor( @JvmSynthetic internal fun from(entry: Entry) = apply { - this.blockId = entry.blockId - this.directionId = entry.directionId - this.id = entry.id - this.peakOffpeak = entry.peakOffpeak - this.routeId = entry.routeId - this.routeShortName = entry.routeShortName - this.serviceId = entry.serviceId - this.shapeId = entry.shapeId - this.timeZone = entry.timeZone - this.tripHeadsign = entry.tripHeadsign - this.tripShortName = entry.tripShortName - additionalProperties(entry.additionalProperties) + id = entry.id + routeId = entry.routeId + serviceId = entry.serviceId + blockId = entry.blockId + directionId = entry.directionId + peakOffpeak = entry.peakOffpeak + routeShortName = entry.routeShortName + shapeId = entry.shapeId + timeZone = entry.timeZone + tripHeadsign = entry.tripHeadsign + tripShortName = entry.tripShortName + additionalProperties = entry.additionalProperties.toMutableMap() } + fun id(id: String) = id(JsonField.of(id)) + + fun id(id: JsonField) = apply { this.id = id } + + fun routeId(routeId: String) = routeId(JsonField.of(routeId)) + + fun routeId(routeId: JsonField) = apply { this.routeId = routeId } + + fun serviceId(serviceId: String) = serviceId(JsonField.of(serviceId)) + + fun serviceId(serviceId: JsonField) = apply { this.serviceId = serviceId } + fun blockId(blockId: String) = blockId(JsonField.of(blockId)) - @JsonProperty("blockId") - @ExcludeMissing fun blockId(blockId: JsonField) = apply { this.blockId = blockId } fun directionId(directionId: String) = directionId(JsonField.of(directionId)) - @JsonProperty("directionId") - @ExcludeMissing fun directionId(directionId: JsonField) = apply { this.directionId = directionId } - fun id(id: String) = id(JsonField.of(id)) - - @JsonProperty("id") - @ExcludeMissing - fun id(id: JsonField) = apply { this.id = id } - fun peakOffpeak(peakOffpeak: Long) = peakOffpeak(JsonField.of(peakOffpeak)) - @JsonProperty("peakOffpeak") - @ExcludeMissing fun peakOffpeak(peakOffpeak: JsonField) = apply { this.peakOffpeak = peakOffpeak } - fun routeId(routeId: String) = routeId(JsonField.of(routeId)) - - @JsonProperty("routeId") - @ExcludeMissing - fun routeId(routeId: JsonField) = apply { this.routeId = routeId } - fun routeShortName(routeShortName: String) = routeShortName(JsonField.of(routeShortName)) - @JsonProperty("routeShortName") - @ExcludeMissing fun routeShortName(routeShortName: JsonField) = apply { this.routeShortName = routeShortName } - fun serviceId(serviceId: String) = serviceId(JsonField.of(serviceId)) - - @JsonProperty("serviceId") - @ExcludeMissing - fun serviceId(serviceId: JsonField) = apply { this.serviceId = serviceId } - fun shapeId(shapeId: String) = shapeId(JsonField.of(shapeId)) - @JsonProperty("shapeId") - @ExcludeMissing fun shapeId(shapeId: JsonField) = apply { this.shapeId = shapeId } fun timeZone(timeZone: String) = timeZone(JsonField.of(timeZone)) - @JsonProperty("timeZone") - @ExcludeMissing fun timeZone(timeZone: JsonField) = apply { this.timeZone = timeZone } fun tripHeadsign(tripHeadsign: String) = tripHeadsign(JsonField.of(tripHeadsign)) - @JsonProperty("tripHeadsign") - @ExcludeMissing fun tripHeadsign(tripHeadsign: JsonField) = apply { this.tripHeadsign = tripHeadsign } @@ -440,20 +473,17 @@ private constructor( fun tripShortName(tripShortName: String) = tripShortName(JsonField.of(tripShortName)) - @JsonProperty("tripShortName") - @ExcludeMissing fun tripShortName(tripShortName: JsonField) = apply { this.tripShortName = tripShortName } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -461,15 +491,23 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Entry = Entry( + checkRequired("id", id), + checkRequired("routeId", routeId), + checkRequired("serviceId", serviceId), blockId, directionId, - id, peakOffpeak, - routeId, routeShortName, - serviceId, shapeId, timeZone, tripHeadsign, @@ -483,20 +521,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && this.blockId == other.blockId && this.directionId == other.directionId && this.id == other.id && this.peakOffpeak == other.peakOffpeak && this.routeId == other.routeId && this.routeShortName == other.routeShortName && this.serviceId == other.serviceId && this.shapeId == other.shapeId && this.timeZone == other.timeZone && this.tripHeadsign == other.tripHeadsign && this.tripShortName == other.tripShortName && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && id == other.id && routeId == other.routeId && serviceId == other.serviceId && blockId == other.blockId && directionId == other.directionId && peakOffpeak == other.peakOffpeak && routeShortName == other.routeShortName && shapeId == other.shapeId && timeZone == other.timeZone && tripHeadsign == other.tripHeadsign && tripShortName == other.tripShortName && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(id, routeId, serviceId, blockId, directionId, peakOffpeak, routeShortName, shapeId, timeZone, tripHeadsign, tripShortName, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(blockId, directionId, id, peakOffpeak, routeId, routeShortName, serviceId, shapeId, timeZone, tripHeadsign, tripShortName, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Entry{blockId=$blockId, directionId=$directionId, id=$id, peakOffpeak=$peakOffpeak, routeId=$routeId, routeShortName=$routeShortName, serviceId=$serviceId, shapeId=$shapeId, timeZone=$timeZone, tripHeadsign=$tripHeadsign, tripShortName=$tripShortName, additionalProperties=$additionalProperties}" + "Entry{id=$id, routeId=$routeId, serviceId=$serviceId, blockId=$blockId, directionId=$directionId, peakOffpeak=$peakOffpeak, routeShortName=$routeShortName, shapeId=$shapeId, timeZone=$timeZone, tripHeadsign=$tripHeadsign, tripShortName=$tripShortName, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -504,17 +539,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.entry == other.entry && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && entry == other.entry && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(entry, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(entry, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{entry=$entry, references=$references, additionalProperties=$additionalProperties}" @@ -525,17 +557,14 @@ private constructor( return true } - return /* spotless:off */ other is TripRetrieveResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is TripRetrieveResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "TripRetrieveResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForLocationListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForLocationListParams.kt index 3c39b79..18afcad 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForLocationListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForLocationListParams.kt @@ -2,16 +2,17 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Retrieve trips for a given location */ class TripsForLocationListParams -constructor( +private constructor( private val lat: Double, private val latSpan: Double, private val lon: Double, @@ -19,59 +20,50 @@ constructor( private val includeSchedule: Boolean?, private val includeTrip: Boolean?, private val time: Long?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + /** The latitude coordinate of the search center */ fun lat(): Double = lat + /** Latitude span of the search bounding box */ fun latSpan(): Double = latSpan + /** The longitude coordinate of the search center */ fun lon(): Double = lon + /** Longitude span of the search bounding box */ fun lonSpan(): Double = lonSpan + /** Whether to include full schedule elements in the tripDetails section. Defaults to false. */ fun includeSchedule(): Optional = Optional.ofNullable(includeSchedule) + /** Whether to include full trip elements in the references section. Defaults to false. */ fun includeTrip(): Optional = Optional.ofNullable(includeTrip) + /** Specific time for the query. Defaults to the current time. */ fun time(): Optional = Optional.ofNullable(time) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders - - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.lat.let { params.put("lat", listOf(it.toString())) } - this.latSpan.let { params.put("latSpan", listOf(it.toString())) } - this.lon.let { params.put("lon", listOf(it.toString())) } - this.lonSpan.let { params.put("lonSpan", listOf(it.toString())) } - this.includeSchedule?.let { params.put("includeSchedule", listOf(it.toString())) } - this.includeTrip?.let { params.put("includeTrip", listOf(it.toString())) } - this.time?.let { params.put("time", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() - } - - fun _additionalHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } + fun _additionalQueryParams(): QueryParams = additionalQueryParams - return /* spotless:off */ other is TripsForLocationListParams && this.lat == other.lat && this.latSpan == other.latSpan && this.lon == other.lon && this.lonSpan == other.lonSpan && this.includeSchedule == other.includeSchedule && this.includeTrip == other.includeTrip && this.time == other.time && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } + override fun _headers(): Headers = additionalHeaders - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(lat, latSpan, lon, lonSpan, includeSchedule, includeTrip, time, additionalHeaders, additionalQueryParams) /* spotless:on */ + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.lat.let { queryParams.put("lat", listOf(it.toString())) } + this.latSpan.let { queryParams.put("latSpan", listOf(it.toString())) } + this.lon.let { queryParams.put("lon", listOf(it.toString())) } + this.lonSpan.let { queryParams.put("lonSpan", listOf(it.toString())) } + this.includeSchedule?.let { queryParams.put("includeSchedule", listOf(it.toString())) } + this.includeTrip?.let { queryParams.put("includeTrip", listOf(it.toString())) } + this.time?.let { queryParams.put("time", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } - override fun toString() = - "TripsForLocationListParams{lat=$lat, latSpan=$latSpan, lon=$lon, lonSpan=$lonSpan, includeSchedule=$includeSchedule, includeTrip=$includeTrip, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -79,8 +71,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [TripsForLocationListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var lat: Double? = null private var latSpan: Double? = null @@ -89,20 +82,20 @@ constructor( private var includeSchedule: Boolean? = null private var includeTrip: Boolean? = null private var time: Long? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(tripsForLocationListParams: TripsForLocationListParams) = apply { - this.lat = tripsForLocationListParams.lat - this.latSpan = tripsForLocationListParams.latSpan - this.lon = tripsForLocationListParams.lon - this.lonSpan = tripsForLocationListParams.lonSpan - this.includeSchedule = tripsForLocationListParams.includeSchedule - this.includeTrip = tripsForLocationListParams.includeTrip - this.time = tripsForLocationListParams.time - additionalHeaders(tripsForLocationListParams.additionalHeaders) - additionalQueryParams(tripsForLocationListParams.additionalQueryParams) + lat = tripsForLocationListParams.lat + latSpan = tripsForLocationListParams.latSpan + lon = tripsForLocationListParams.lon + lonSpan = tripsForLocationListParams.lonSpan + includeSchedule = tripsForLocationListParams.includeSchedule + includeTrip = tripsForLocationListParams.includeTrip + time = tripsForLocationListParams.time + additionalHeaders = tripsForLocationListParams.additionalHeaders.toBuilder() + additionalQueryParams = tripsForLocationListParams.additionalQueryParams.toBuilder() } /** The latitude coordinate of the search center */ @@ -120,15 +113,47 @@ constructor( /** * Whether to include full schedule elements in the tripDetails section. Defaults to false. */ - fun includeSchedule(includeSchedule: Boolean) = apply { + fun includeSchedule(includeSchedule: Boolean?) = apply { this.includeSchedule = includeSchedule } + /** + * Whether to include full schedule elements in the tripDetails section. Defaults to false. + */ + fun includeSchedule(includeSchedule: Boolean) = includeSchedule(includeSchedule as Boolean?) + + /** + * Whether to include full schedule elements in the tripDetails section. Defaults to false. + */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun includeSchedule(includeSchedule: Optional) = + includeSchedule(includeSchedule.orElse(null) as Boolean?) + + /** Whether to include full trip elements in the references section. Defaults to false. */ + fun includeTrip(includeTrip: Boolean?) = apply { this.includeTrip = includeTrip } + /** Whether to include full trip elements in the references section. Defaults to false. */ - fun includeTrip(includeTrip: Boolean) = apply { this.includeTrip = includeTrip } + fun includeTrip(includeTrip: Boolean) = includeTrip(includeTrip as Boolean?) + + /** Whether to include full trip elements in the references section. Defaults to false. */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun includeTrip(includeTrip: Optional) = + includeTrip(includeTrip.orElse(null) as Boolean?) + + /** Specific time for the query. Defaults to the current time. */ + fun time(time: Long?) = apply { this.time = time } /** Specific time for the query. Defaults to the current time. */ - fun time(time: Long) = apply { this.time = time } + fun time(time: Long) = time(time as Long?) + + /** Specific time for the query. Defaults to the current time. */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun time(time: Optional) = time(time.orElse(null) as Long?) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -140,29 +165,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -175,52 +213,65 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): TripsForLocationListParams = TripsForLocationListParams( - checkNotNull(lat) { "`lat` is required but was not set" }, - checkNotNull(latSpan) { "`latSpan` is required but was not set" }, - checkNotNull(lon) { "`lon` is required but was not set" }, - checkNotNull(lonSpan) { "`lonSpan` is required but was not set" }, + checkRequired("lat", lat), + checkRequired("latSpan", latSpan), + checkRequired("lon", lon), + checkRequired("lonSpan", lonSpan), includeSchedule, includeTrip, time, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is TripsForLocationListParams && lat == other.lat && latSpan == other.latSpan && lon == other.lon && lonSpan == other.lonSpan && includeSchedule == other.includeSchedule && includeTrip == other.includeTrip && time == other.time && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(lat, latSpan, lon, lonSpan, includeSchedule, includeTrip, time, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "TripsForLocationListParams{lat=$lat, latSpan=$latSpan, lon=$lon, lonSpan=$lonSpan, includeSchedule=$includeSchedule, includeTrip=$includeTrip, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForLocationListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForLocationListResponse.kt index 62bf5b0..52cc892 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForLocationListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForLocationListResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = TripsForLocationListResponse.Builder::class) @NoAutoDetect class TripsForLocationListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): TripsForLocationListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,126 +87,141 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [TripsForLocationListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(tripsForLocationListResponse: TripsForLocationListResponse) = apply { - this.code = tripsForLocationListResponse.code - this.currentTime = tripsForLocationListResponse.currentTime - this.text = tripsForLocationListResponse.text - this.version = tripsForLocationListResponse.version - this.data = tripsForLocationListResponse.data - additionalProperties(tripsForLocationListResponse.additionalProperties) + code = tripsForLocationListResponse.code + currentTime = tripsForLocationListResponse.currentTime + text = tripsForLocationListResponse.text + version = tripsForLocationListResponse.version + data = tripsForLocationListResponse.data + additionalProperties = tripsForLocationListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): TripsForLocationListResponse = TripsForLocationListResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val limitExceeded: JsonField, - private val list: JsonField>, - private val outOfRange: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("limitExceeded") + @ExcludeMissing + private val limitExceeded: JsonField = JsonMissing.of(), + @JsonProperty("list") + @ExcludeMissing + private val list: JsonField> = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonProperty("outOfRange") + @ExcludeMissing + private val outOfRange: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Indicates if the limit of trips has been exceeded */ fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") fun list(): kotlin.collections.List = list.getRequired("list") + fun references(): References = references.getRequired("references") + /** Indicates if the search location is out of range */ fun outOfRange(): Optional = Optional.ofNullable(outOfRange.getNullable("outOfRange")) - fun references(): References = references.getRequired("references") - /** Indicates if the limit of trips has been exceeded */ - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + @JsonProperty("limitExceeded") + @ExcludeMissing + fun _limitExceeded(): JsonField = limitExceeded - @JsonProperty("list") @ExcludeMissing fun _list() = list + @JsonProperty("list") + @ExcludeMissing + fun _list(): JsonField> = list - /** Indicates if the search location is out of range */ - @JsonProperty("outOfRange") @ExcludeMissing fun _outOfRange() = outOfRange + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references - @JsonProperty("references") @ExcludeMissing fun _references() = references + /** Indicates if the search location is out of range */ + @JsonProperty("outOfRange") + @ExcludeMissing + fun _outOfRange(): JsonField = outOfRange @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - limitExceeded() - list().forEach { it.validate() } - outOfRange() - references().validate() - validated = true + if (validated) { + return@apply } + + limitExceeded() + list().forEach { it.validate() } + references().validate() + outOfRange() + validated = true } fun toBuilder() = Builder().from(this) @@ -208,93 +231,123 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var limitExceeded: JsonField = JsonMissing.of() - private var list: JsonField> = JsonMissing.of() + private var limitExceeded: JsonField? = null + private var list: JsonField>? = null + private var references: JsonField? = null private var outOfRange: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.limitExceeded = data.limitExceeded - this.list = data.list - this.outOfRange = data.outOfRange - this.references = data.references - additionalProperties(data.additionalProperties) + limitExceeded = data.limitExceeded + list = data.list.map { it.toMutableList() } + references = data.references + outOfRange = data.outOfRange + additionalProperties = data.additionalProperties.toMutableMap() } /** Indicates if the limit of trips has been exceeded */ fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) /** Indicates if the limit of trips has been exceeded */ - @JsonProperty("limitExceeded") - @ExcludeMissing fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } fun list(list: kotlin.collections.List) = list(JsonField.of(list)) - @JsonProperty("list") - @ExcludeMissing - fun list(list: JsonField>) = apply { this.list = list } - - /** Indicates if the search location is out of range */ - fun outOfRange(outOfRange: Boolean) = outOfRange(JsonField.of(outOfRange)) + fun list(list: JsonField>) = apply { + this.list = list.map { it.toMutableList() } + } - /** Indicates if the search location is out of range */ - @JsonProperty("outOfRange") - @ExcludeMissing - fun outOfRange(outOfRange: JsonField) = apply { this.outOfRange = outOfRange } + fun addList(list: List) = apply { + this.list = + (this.list ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(list) + } + } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } + /** Indicates if the search location is out of range */ + fun outOfRange(outOfRange: Boolean) = outOfRange(JsonField.of(outOfRange)) + + /** Indicates if the search location is out of range */ + fun outOfRange(outOfRange: JsonField) = apply { this.outOfRange = outOfRange } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), outOfRange, - references, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = List.Builder::class) @NoAutoDetect class List + @JsonCreator private constructor( - private val frequency: JsonField, - private val serviceDate: JsonField, - private val situationIds: JsonField>, - private val tripId: JsonField, - private val schedule: JsonField, - private val status: JsonField, - private val additionalProperties: Map, + @JsonProperty("schedule") + @ExcludeMissing + private val schedule: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonProperty("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun schedule(): Schedule = schedule.getRequired("schedule") + + fun status(): Status = status.getRequired("status") + + fun tripId(): String = tripId.getRequired("tripId") fun frequency(): Optional = Optional.ofNullable(frequency.getNullable("frequency")) @@ -305,38 +358,44 @@ private constructor( fun situationIds(): Optional> = Optional.ofNullable(situationIds.getNullable("situationIds")) - fun tripId(): String = tripId.getRequired("tripId") - - fun schedule(): Schedule = schedule.getRequired("schedule") - - fun status(): Status = status.getRequired("status") - - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + @JsonProperty("schedule") + @ExcludeMissing + fun _schedule(): JsonField = schedule - @JsonProperty("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds + @JsonProperty("tripId") @ExcludeMissing fun _tripId(): JsonField = tripId - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency - @JsonProperty("schedule") @ExcludeMissing fun _schedule() = schedule + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("situationIds") + @ExcludeMissing + fun _situationIds(): JsonField> = situationIds @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): List = apply { - if (!validated) { - frequency() - serviceDate() - situationIds() - tripId() - schedule().validate() - status().validate() - validated = true + if (validated) { + return@apply } + + schedule().validate() + status().validate() + tripId() + frequency() + serviceDate() + situationIds() + validated = true } fun toBuilder() = Builder().from(this) @@ -346,38 +405,48 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [List]. */ + class Builder internal constructor() { + private var schedule: JsonField? = null + private var status: JsonField? = null + private var situationIds: JsonField>? = null + private var tripId: JsonField? = null private var frequency: JsonField = JsonMissing.of() private var serviceDate: JsonField = JsonMissing.of() - private var situationIds: JsonField> = - JsonMissing.of() - private var tripId: JsonField = JsonMissing.of() - private var schedule: JsonField = JsonMissing.of() - private var status: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(list: List) = apply { - this.frequency = list.frequency - this.serviceDate = list.serviceDate - this.situationIds = list.situationIds - this.tripId = list.tripId - this.schedule = list.schedule - this.status = list.status - additionalProperties(list.additionalProperties) + schedule = list.schedule + status = list.status + tripId = list.tripId + frequency = list.frequency + serviceDate = list.serviceDate + situationIds = list.situationIds.map { it.toMutableList() } + additionalProperties = list.additionalProperties.toMutableMap() } - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) + fun schedule(schedule: Schedule) = schedule(JsonField.of(schedule)) + + fun schedule(schedule: JsonField) = apply { this.schedule = schedule } + + fun status(status: Status) = status(JsonField.of(status)) + + fun status(status: JsonField) = apply { this.status = status } + + fun tripId(tripId: String) = tripId(JsonField.of(tripId)) + + fun tripId(tripId: JsonField) = apply { this.tripId = tripId } + + fun frequency(frequency: String?) = frequency(JsonField.ofNullable(frequency)) + + fun frequency(frequency: Optional) = frequency(frequency.orElse(null)) - @JsonProperty("frequency") - @ExcludeMissing fun frequency(frequency: JsonField) = apply { this.frequency = frequency } fun serviceDate(serviceDate: Long) = serviceDate(JsonField.of(serviceDate)) - @JsonProperty("serviceDate") - @ExcludeMissing fun serviceDate(serviceDate: JsonField) = apply { this.serviceDate = serviceDate } @@ -385,38 +454,30 @@ private constructor( fun situationIds(situationIds: kotlin.collections.List) = situationIds(JsonField.of(situationIds)) - @JsonProperty("situationIds") - @ExcludeMissing fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds + this.situationIds = situationIds.map { it.toMutableList() } } - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - @JsonProperty("tripId") - @ExcludeMissing - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - - fun schedule(schedule: Schedule) = schedule(JsonField.of(schedule)) - - @JsonProperty("schedule") - @ExcludeMissing - fun schedule(schedule: JsonField) = apply { this.schedule = schedule } - - fun status(status: Status) = status(JsonField.of(status)) - - @JsonProperty("status") - @ExcludeMissing - fun status(status: JsonField) = apply { this.status = status } + fun addSituationId(situationId: String) = apply { + situationIds = + (situationIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situationId) + } + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -424,35 +485,50 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): List = List( + checkRequired("schedule", schedule), + checkRequired("status", status), + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, + checkRequired("tripId", tripId), frequency, serviceDate, - situationIds.map { it.toImmutable() }, - tripId, - schedule, - status, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Schedule.Builder::class) @NoAutoDetect class Schedule + @JsonCreator private constructor( - private val frequency: JsonField, - private val nextTripId: JsonField, - private val previousTripId: JsonField, - private val stopTimes: JsonField>, - private val timeZone: JsonField, - private val additionalProperties: Map, + @JsonProperty("nextTripId") + @ExcludeMissing + private val nextTripId: JsonField = JsonMissing.of(), + @JsonProperty("previousTripId") + @ExcludeMissing + private val previousTripId: JsonField = JsonMissing.of(), + @JsonProperty("stopTimes") + @ExcludeMissing + private val stopTimes: JsonField> = + JsonMissing.of(), + @JsonProperty("timeZone") + @ExcludeMissing + private val timeZone: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - fun nextTripId(): String = nextTripId.getRequired("nextTripId") fun previousTripId(): String = previousTripId.getRequired("previousTripId") @@ -462,31 +538,46 @@ private constructor( fun timeZone(): String = timeZone.getRequired("timeZone") - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) - @JsonProperty("nextTripId") @ExcludeMissing fun _nextTripId() = nextTripId + @JsonProperty("nextTripId") + @ExcludeMissing + fun _nextTripId(): JsonField = nextTripId @JsonProperty("previousTripId") @ExcludeMissing - fun _previousTripId() = previousTripId + fun _previousTripId(): JsonField = previousTripId - @JsonProperty("stopTimes") @ExcludeMissing fun _stopTimes() = stopTimes + @JsonProperty("stopTimes") + @ExcludeMissing + fun _stopTimes(): JsonField> = stopTimes + + @JsonProperty("timeZone") + @ExcludeMissing + fun _timeZone(): JsonField = timeZone - @JsonProperty("timeZone") @ExcludeMissing fun _timeZone() = timeZone + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Schedule = apply { - if (!validated) { - frequency() - nextTripId() - previousTripId() - stopTimes().forEach { it.validate() } - timeZone() - validated = true + if (validated) { + return@apply } + + nextTripId() + previousTripId() + stopTimes().forEach { it.validate() } + timeZone() + frequency() + validated = true } fun toBuilder() = Builder().from(this) @@ -496,38 +587,28 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Schedule]. */ + class Builder internal constructor() { private var frequency: JsonField = JsonMissing.of() - private var nextTripId: JsonField = JsonMissing.of() - private var previousTripId: JsonField = JsonMissing.of() - private var stopTimes: JsonField> = - JsonMissing.of() - private var timeZone: JsonField = JsonMissing.of() + private var nextTripId: JsonField? = null + private var previousTripId: JsonField? = null + private var stopTimes: JsonField>? = null + private var timeZone: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(schedule: Schedule) = apply { - this.frequency = schedule.frequency - this.nextTripId = schedule.nextTripId - this.previousTripId = schedule.previousTripId - this.stopTimes = schedule.stopTimes - this.timeZone = schedule.timeZone - additionalProperties(schedule.additionalProperties) - } - - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - @JsonProperty("frequency") - @ExcludeMissing - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency + nextTripId = schedule.nextTripId + previousTripId = schedule.previousTripId + stopTimes = schedule.stopTimes.map { it.toMutableList() } + timeZone = schedule.timeZone + frequency = schedule.frequency + additionalProperties = schedule.additionalProperties.toMutableMap() } fun nextTripId(nextTripId: String) = nextTripId(JsonField.of(nextTripId)) - @JsonProperty("nextTripId") - @ExcludeMissing fun nextTripId(nextTripId: JsonField) = apply { this.nextTripId = nextTripId } @@ -535,8 +616,6 @@ private constructor( fun previousTripId(previousTripId: String) = previousTripId(JsonField.of(previousTripId)) - @JsonProperty("previousTripId") - @ExcludeMissing fun previousTripId(previousTripId: JsonField) = apply { this.previousTripId = previousTripId } @@ -544,26 +623,42 @@ private constructor( fun stopTimes(stopTimes: kotlin.collections.List) = stopTimes(JsonField.of(stopTimes)) - @JsonProperty("stopTimes") - @ExcludeMissing fun stopTimes(stopTimes: JsonField>) = apply { - this.stopTimes = stopTimes + this.stopTimes = stopTimes.map { it.toMutableList() } + } + + fun addStopTime(stopTime: StopTime) = apply { + stopTimes = + (stopTimes ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stopTime) + } } fun timeZone(timeZone: String) = timeZone(JsonField.of(timeZone)) - @JsonProperty("timeZone") - @ExcludeMissing fun timeZone(timeZone: JsonField) = apply { this.timeZone = timeZone } + fun frequency(frequency: String?) = frequency(JsonField.ofNullable(frequency)) + + fun frequency(frequency: Optional) = frequency(frequency.orElse(null)) + + fun frequency(frequency: JsonField) = apply { + this.frequency = frequency + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -571,32 +666,51 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Schedule = Schedule( + checkRequired("nextTripId", nextTripId), + checkRequired("previousTripId", previousTripId), + checkRequired("stopTimes", stopTimes).map { it.toImmutable() }, + checkRequired("timeZone", timeZone), frequency, - nextTripId, - previousTripId, - stopTimes.map { it.toImmutable() }, - timeZone, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = StopTime.Builder::class) @NoAutoDetect class StopTime + @JsonCreator private constructor( - private val arrivalTime: JsonField, - private val departureTime: JsonField, - private val distanceAlongTrip: JsonField, - private val historicalOccupancy: JsonField, - private val stopHeadsign: JsonField, - private val stopId: JsonField, - private val additionalProperties: Map, + @JsonProperty("arrivalTime") + @ExcludeMissing + private val arrivalTime: JsonField = JsonMissing.of(), + @JsonProperty("departureTime") + @ExcludeMissing + private val departureTime: JsonField = JsonMissing.of(), + @JsonProperty("distanceAlongTrip") + @ExcludeMissing + private val distanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("historicalOccupancy") + @ExcludeMissing + private val historicalOccupancy: JsonField = JsonMissing.of(), + @JsonProperty("stopHeadsign") + @ExcludeMissing + private val stopHeadsign: JsonField = JsonMissing.of(), + @JsonProperty("stopId") + @ExcludeMissing + private val stopId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun arrivalTime(): Optional = Optional.ofNullable(arrivalTime.getNullable("arrivalTime")) @@ -615,38 +729,48 @@ private constructor( fun stopId(): Optional = Optional.ofNullable(stopId.getNullable("stopId")) - @JsonProperty("arrivalTime") @ExcludeMissing fun _arrivalTime() = arrivalTime + @JsonProperty("arrivalTime") + @ExcludeMissing + fun _arrivalTime(): JsonField = arrivalTime @JsonProperty("departureTime") @ExcludeMissing - fun _departureTime() = departureTime + fun _departureTime(): JsonField = departureTime @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip + fun _distanceAlongTrip(): JsonField = distanceAlongTrip @JsonProperty("historicalOccupancy") @ExcludeMissing - fun _historicalOccupancy() = historicalOccupancy + fun _historicalOccupancy(): JsonField = historicalOccupancy - @JsonProperty("stopHeadsign") @ExcludeMissing fun _stopHeadsign() = stopHeadsign + @JsonProperty("stopHeadsign") + @ExcludeMissing + fun _stopHeadsign(): JsonField = stopHeadsign - @JsonProperty("stopId") @ExcludeMissing fun _stopId() = stopId + @JsonProperty("stopId") + @ExcludeMissing + fun _stopId(): JsonField = stopId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): StopTime = apply { - if (!validated) { - arrivalTime() - departureTime() - distanceAlongTrip() - historicalOccupancy() - stopHeadsign() - stopId() - validated = true + if (validated) { + return@apply } + + arrivalTime() + departureTime() + distanceAlongTrip() + historicalOccupancy() + stopHeadsign() + stopId() + validated = true } fun toBuilder() = Builder().from(this) @@ -656,7 +780,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopTime]. */ + class Builder internal constructor() { private var arrivalTime: JsonField = JsonMissing.of() private var departureTime: JsonField = JsonMissing.of() @@ -669,19 +794,17 @@ private constructor( @JvmSynthetic internal fun from(stopTime: StopTime) = apply { - this.arrivalTime = stopTime.arrivalTime - this.departureTime = stopTime.departureTime - this.distanceAlongTrip = stopTime.distanceAlongTrip - this.historicalOccupancy = stopTime.historicalOccupancy - this.stopHeadsign = stopTime.stopHeadsign - this.stopId = stopTime.stopId - additionalProperties(stopTime.additionalProperties) + arrivalTime = stopTime.arrivalTime + departureTime = stopTime.departureTime + distanceAlongTrip = stopTime.distanceAlongTrip + historicalOccupancy = stopTime.historicalOccupancy + stopHeadsign = stopTime.stopHeadsign + stopId = stopTime.stopId + additionalProperties = stopTime.additionalProperties.toMutableMap() } fun arrivalTime(arrivalTime: Long) = arrivalTime(JsonField.of(arrivalTime)) - @JsonProperty("arrivalTime") - @ExcludeMissing fun arrivalTime(arrivalTime: JsonField) = apply { this.arrivalTime = arrivalTime } @@ -689,8 +812,6 @@ private constructor( fun departureTime(departureTime: Long) = departureTime(JsonField.of(departureTime)) - @JsonProperty("departureTime") - @ExcludeMissing fun departureTime(departureTime: JsonField) = apply { this.departureTime = departureTime } @@ -698,8 +819,6 @@ private constructor( fun distanceAlongTrip(distanceAlongTrip: Double) = distanceAlongTrip(JsonField.of(distanceAlongTrip)) - @JsonProperty("distanceAlongTrip") - @ExcludeMissing fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { this.distanceAlongTrip = distanceAlongTrip } @@ -707,8 +826,6 @@ private constructor( fun historicalOccupancy(historicalOccupancy: String) = historicalOccupancy(JsonField.of(historicalOccupancy)) - @JsonProperty("historicalOccupancy") - @ExcludeMissing fun historicalOccupancy(historicalOccupancy: JsonField) = apply { this.historicalOccupancy = historicalOccupancy } @@ -716,33 +833,36 @@ private constructor( fun stopHeadsign(stopHeadsign: String) = stopHeadsign(JsonField.of(stopHeadsign)) - @JsonProperty("stopHeadsign") - @ExcludeMissing fun stopHeadsign(stopHeadsign: JsonField) = apply { this.stopHeadsign = stopHeadsign } fun stopId(stopId: String) = stopId(JsonField.of(stopId)) - @JsonProperty("stopId") - @ExcludeMissing fun stopId(stopId: JsonField) = apply { this.stopId = stopId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopTime = StopTime( arrivalTime, @@ -760,17 +880,14 @@ private constructor( return true } - return /* spotless:off */ other is StopTime && this.arrivalTime == other.arrivalTime && this.departureTime == other.departureTime && this.distanceAlongTrip == other.distanceAlongTrip && this.historicalOccupancy == other.historicalOccupancy && this.stopHeadsign == other.stopHeadsign && this.stopId == other.stopId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopTime && arrivalTime == other.arrivalTime && departureTime == other.departureTime && distanceAlongTrip == other.distanceAlongTrip && historicalOccupancy == other.historicalOccupancy && stopHeadsign == other.stopHeadsign && stopId == other.stopId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(arrivalTime, departureTime, distanceAlongTrip, historicalOccupancy, stopHeadsign, stopId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(arrivalTime, departureTime, distanceAlongTrip, historicalOccupancy, stopHeadsign, stopId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "StopTime{arrivalTime=$arrivalTime, departureTime=$departureTime, distanceAlongTrip=$distanceAlongTrip, historicalOccupancy=$historicalOccupancy, stopHeadsign=$stopHeadsign, stopId=$stopId, additionalProperties=$additionalProperties}" @@ -781,82 +898,122 @@ private constructor( return true } - return /* spotless:off */ other is Schedule && this.frequency == other.frequency && this.nextTripId == other.nextTripId && this.previousTripId == other.previousTripId && this.stopTimes == other.stopTimes && this.timeZone == other.timeZone && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Schedule && nextTripId == other.nextTripId && previousTripId == other.previousTripId && stopTimes == other.stopTimes && timeZone == other.timeZone && frequency == other.frequency && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(nextTripId, previousTripId, stopTimes, timeZone, frequency, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(frequency, nextTripId, previousTripId, stopTimes, timeZone, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Schedule{frequency=$frequency, nextTripId=$nextTripId, previousTripId=$previousTripId, stopTimes=$stopTimes, timeZone=$timeZone, additionalProperties=$additionalProperties}" + "Schedule{nextTripId=$nextTripId, previousTripId=$previousTripId, stopTimes=$stopTimes, timeZone=$timeZone, frequency=$frequency, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = Status.Builder::class) @NoAutoDetect class Status + @JsonCreator private constructor( - private val activeTripId: JsonField, - private val blockTripSequence: JsonField, - private val closestStop: JsonField, - private val closestStopTimeOffset: JsonField, - private val distanceAlongTrip: JsonField, - private val frequency: JsonField, - private val lastKnownDistanceAlongTrip: JsonField, - private val lastKnownLocation: JsonField, - private val lastKnownOrientation: JsonField, - private val lastLocationUpdateTime: JsonField, - private val lastUpdateTime: JsonField, - private val nextStop: JsonField, - private val nextStopTimeOffset: JsonField, - private val occupancyCapacity: JsonField, - private val occupancyCount: JsonField, - private val occupancyStatus: JsonField, - private val orientation: JsonField, - private val phase: JsonField, - private val position: JsonField, - private val predicted: JsonField, - private val scheduleDeviation: JsonField, - private val scheduledDistanceAlongTrip: JsonField, - private val serviceDate: JsonField, - private val situationIds: JsonField>, - private val status: JsonField, - private val totalDistanceAlongTrip: JsonField, - private val vehicleId: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - /** Trip ID of the trip the vehicle is actively serving. */ - fun activeTripId(): String = activeTripId.getRequired("activeTripId") - - /** Index of the active trip into the sequence of trips for the active block. */ - fun blockTripSequence(): Long = blockTripSequence.getRequired("blockTripSequence") - - /** ID of the closest stop to the current location of the transit vehicle. */ - fun closestStop(): String = closestStop.getRequired("closestStop") - - /** - * Time offset from the closest stop to the current position of the transit vehicle - * (in seconds). - */ - fun closestStopTimeOffset(): Optional = - Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) - - /** - * Distance, in meters, the transit vehicle has progressed along the active trip. - */ - fun distanceAlongTrip(): Double = distanceAlongTrip.getRequired("distanceAlongTrip") + @JsonProperty("activeTripId") + @ExcludeMissing + private val activeTripId: JsonField = JsonMissing.of(), + @JsonProperty("blockTripSequence") + @ExcludeMissing + private val blockTripSequence: JsonField = JsonMissing.of(), + @JsonProperty("closestStop") + @ExcludeMissing + private val closestStop: JsonField = JsonMissing.of(), + @JsonProperty("distanceAlongTrip") + @ExcludeMissing + private val distanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownDistanceAlongTrip") + @ExcludeMissing + private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastLocationUpdateTime") + @ExcludeMissing + private val lastLocationUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("lastUpdateTime") + @ExcludeMissing + private val lastUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCapacity") + @ExcludeMissing + private val occupancyCapacity: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCount") + @ExcludeMissing + private val occupancyCount: JsonField = JsonMissing.of(), + @JsonProperty("occupancyStatus") + @ExcludeMissing + private val occupancyStatus: JsonField = JsonMissing.of(), + @JsonProperty("phase") + @ExcludeMissing + private val phase: JsonField = JsonMissing.of(), + @JsonProperty("predicted") + @ExcludeMissing + private val predicted: JsonField = JsonMissing.of(), + @JsonProperty("scheduleDeviation") + @ExcludeMissing + private val scheduleDeviation: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonProperty("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = + JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonProperty("totalDistanceAlongTrip") + @ExcludeMissing + private val totalDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + private val closestStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownLocation") + @ExcludeMissing + private val lastKnownLocation: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + private val lastKnownOrientation: JsonField = JsonMissing.of(), + @JsonProperty("nextStop") + @ExcludeMissing + private val nextStop: JsonField = JsonMissing.of(), + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + private val nextStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("orientation") + @ExcludeMissing + private val orientation: JsonField = JsonMissing.of(), + @JsonProperty("position") + @ExcludeMissing + private val position: JsonField = JsonMissing.of(), + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + private val scheduledDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("vehicleId") + @ExcludeMissing + private val vehicleId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) + /** Trip ID of the trip the vehicle is actively serving. */ + fun activeTripId(): String = activeTripId.getRequired("activeTripId") + + /** Index of the active trip into the sequence of trips for the active block. */ + fun blockTripSequence(): Long = blockTripSequence.getRequired("blockTripSequence") + + /** ID of the closest stop to the current location of the transit vehicle. */ + fun closestStop(): String = closestStop.getRequired("closestStop") + + /** + * Distance, in meters, the transit vehicle has progressed along the active trip. + */ + fun distanceAlongTrip(): Double = distanceAlongTrip.getRequired("distanceAlongTrip") /** * Last known distance along the trip received in real-time from the transit @@ -865,14 +1022,6 @@ private constructor( fun lastKnownDistanceAlongTrip(): Double = lastKnownDistanceAlongTrip.getRequired("lastKnownDistanceAlongTrip") - /** Last known location of the transit vehicle. */ - fun lastKnownLocation(): Optional = - Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) - - /** Last known orientation value received in real-time from the transit vehicle. */ - fun lastKnownOrientation(): Optional = - Optional.ofNullable(lastKnownOrientation.getNullable("lastKnownOrientation")) - /** * Timestamp of the last known real-time location update from the transit vehicle. */ @@ -882,17 +1031,6 @@ private constructor( /** Timestamp of the last known real-time update from the transit vehicle. */ fun lastUpdateTime(): Long = lastUpdateTime.getRequired("lastUpdateTime") - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - fun nextStop(): Optional = - Optional.ofNullable(nextStop.getNullable("nextStop")) - - /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). - */ - fun nextStopTimeOffset(): Optional = - Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(): Long = occupancyCapacity.getRequired("occupancyCapacity") @@ -902,17 +1040,9 @@ private constructor( /** Current occupancy status of the transit vehicle. */ fun occupancyStatus(): String = occupancyStatus.getRequired("occupancyStatus") - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - fun orientation(): Optional = - Optional.ofNullable(orientation.getNullable("orientation")) - /** Current journey phase of the trip. */ fun phase(): String = phase.getRequired("phase") - /** Current position of the transit vehicle. */ - fun position(): Optional = - Optional.ofNullable(position.getNullable("position")) - /** Indicates if real-time arrival info is available for this trip. */ fun predicted(): Boolean = predicted.getRequired("predicted") @@ -921,15 +1051,6 @@ private constructor( */ fun scheduleDeviation(): Long = scheduleDeviation.getRequired("scheduleDeviation") - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed along - * the active trip. - */ - fun scheduledDistanceAlongTrip(): Optional = - Optional.ofNullable( - scheduledDistanceAlongTrip.getNullable("scheduledDistanceAlongTrip") - ) - /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. @@ -947,38 +1068,78 @@ private constructor( fun totalDistanceAlongTrip(): Double = totalDistanceAlongTrip.getRequired("totalDistanceAlongTrip") + /** + * Time offset from the closest stop to the current position of the transit vehicle + * (in seconds). + */ + fun closestStopTimeOffset(): Optional = + Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(): Optional = + Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) + + /** Last known orientation value received in real-time from the transit vehicle. */ + fun lastKnownOrientation(): Optional = + Optional.ofNullable(lastKnownOrientation.getNullable("lastKnownOrientation")) + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(): Optional = + Optional.ofNullable(nextStop.getNullable("nextStop")) + + /** + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). + */ + fun nextStopTimeOffset(): Optional = + Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(): Optional = + Optional.ofNullable(orientation.getNullable("orientation")) + + /** Current position of the transit vehicle. */ + fun position(): Optional = + Optional.ofNullable(position.getNullable("position")) + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed along + * the active trip. + */ + fun scheduledDistanceAlongTrip(): Optional = + Optional.ofNullable( + scheduledDistanceAlongTrip.getNullable("scheduledDistanceAlongTrip") + ) + /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(): Optional = Optional.ofNullable(vehicleId.getNullable("vehicleId")) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") @ExcludeMissing fun _activeTripId() = activeTripId + @JsonProperty("activeTripId") + @ExcludeMissing + fun _activeTripId(): JsonField = activeTripId /** Index of the active trip into the sequence of trips for the active block. */ @JsonProperty("blockTripSequence") @ExcludeMissing - fun _blockTripSequence() = blockTripSequence + fun _blockTripSequence(): JsonField = blockTripSequence /** ID of the closest stop to the current location of the transit vehicle. */ - @JsonProperty("closestStop") @ExcludeMissing fun _closestStop() = closestStop - - /** - * Time offset from the closest stop to the current position of the transit vehicle - * (in seconds). - */ - @JsonProperty("closestStopTimeOffset") + @JsonProperty("closestStop") @ExcludeMissing - fun _closestStopTimeOffset() = closestStopTimeOffset + fun _closestStop(): JsonField = closestStop /** * Distance, in meters, the transit vehicle has progressed along the active trip. */ @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + fun _distanceAlongTrip(): JsonField = distanceAlongTrip /** * Last known distance along the trip received in real-time from the transit @@ -986,138 +1147,169 @@ private constructor( */ @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing - fun _lastKnownDistanceAlongTrip() = lastKnownDistanceAlongTrip - - /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun _lastKnownLocation() = lastKnownLocation - - /** Last known orientation value received in real-time from the transit vehicle. */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun _lastKnownOrientation() = lastKnownOrientation + fun _lastKnownDistanceAlongTrip(): JsonField = lastKnownDistanceAlongTrip /** * Timestamp of the last known real-time location update from the transit vehicle. */ @JsonProperty("lastLocationUpdateTime") @ExcludeMissing - fun _lastLocationUpdateTime() = lastLocationUpdateTime + fun _lastLocationUpdateTime(): JsonField = lastLocationUpdateTime /** Timestamp of the last known real-time update from the transit vehicle. */ @JsonProperty("lastUpdateTime") @ExcludeMissing - fun _lastUpdateTime() = lastUpdateTime - - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") @ExcludeMissing fun _nextStop() = nextStop - - /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). - */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - fun _nextStopTimeOffset() = nextStopTimeOffset + fun _lastUpdateTime(): JsonField = lastUpdateTime /** Capacity of the transit vehicle in terms of occupancy. */ @JsonProperty("occupancyCapacity") @ExcludeMissing - fun _occupancyCapacity() = occupancyCapacity + fun _occupancyCapacity(): JsonField = occupancyCapacity /** Current count of occupants in the transit vehicle. */ @JsonProperty("occupancyCount") @ExcludeMissing - fun _occupancyCount() = occupancyCount + fun _occupancyCount(): JsonField = occupancyCount /** Current occupancy status of the transit vehicle. */ @JsonProperty("occupancyStatus") @ExcludeMissing - fun _occupancyStatus() = occupancyStatus - - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") @ExcludeMissing fun _orientation() = orientation + fun _occupancyStatus(): JsonField = occupancyStatus /** Current journey phase of the trip. */ - @JsonProperty("phase") @ExcludeMissing fun _phase() = phase - - /** Current position of the transit vehicle. */ - @JsonProperty("position") @ExcludeMissing fun _position() = position + @JsonProperty("phase") @ExcludeMissing fun _phase(): JsonField = phase /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") @ExcludeMissing fun _predicted() = predicted + @JsonProperty("predicted") + @ExcludeMissing + fun _predicted(): JsonField = predicted /** * Deviation from the schedule in seconds (positive for late, negative for early). */ @JsonProperty("scheduleDeviation") @ExcludeMissing - fun _scheduleDeviation() = scheduleDeviation - - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed along - * the active trip. - */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - fun _scheduledDistanceAlongTrip() = scheduledDistanceAlongTrip + fun _scheduleDeviation(): JsonField = scheduleDeviation /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate - - /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate /** Current status modifiers for the trip. */ - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status /** Total length of the trip, in meters. */ @JsonProperty("totalDistanceAlongTrip") @ExcludeMissing - fun _totalDistanceAlongTrip() = totalDistanceAlongTrip + fun _totalDistanceAlongTrip(): JsonField = totalDistanceAlongTrip + + /** + * Time offset from the closest stop to the current position of the transit vehicle + * (in seconds). + */ + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + fun _closestStopTimeOffset(): JsonField = closestStopTimeOffset + + /** Information about frequency-based scheduling, if applicable to the trip. */ + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency + + /** Last known location of the transit vehicle. */ + @JsonProperty("lastKnownLocation") + @ExcludeMissing + fun _lastKnownLocation(): JsonField = lastKnownLocation + + /** Last known orientation value received in real-time from the transit vehicle. */ + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + fun _lastKnownOrientation(): JsonField = lastKnownOrientation + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + @JsonProperty("nextStop") + @ExcludeMissing + fun _nextStop(): JsonField = nextStop + + /** + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). + */ + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + fun _nextStopTimeOffset(): JsonField = nextStopTimeOffset + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + @JsonProperty("orientation") + @ExcludeMissing + fun _orientation(): JsonField = orientation + + /** Current position of the transit vehicle. */ + @JsonProperty("position") + @ExcludeMissing + fun _position(): JsonField = position + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed along + * the active trip. + */ + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + fun _scheduledDistanceAlongTrip(): JsonField = scheduledDistanceAlongTrip + + /** References to situation elements (if any) applicable to this trip. */ + @JsonProperty("situationIds") + @ExcludeMissing + fun _situationIds(): JsonField> = situationIds /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") @ExcludeMissing fun _vehicleId() = vehicleId + @JsonProperty("vehicleId") + @ExcludeMissing + fun _vehicleId(): JsonField = vehicleId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Status = apply { - if (!validated) { - activeTripId() - blockTripSequence() - closestStop() - closestStopTimeOffset() - distanceAlongTrip() - frequency() - lastKnownDistanceAlongTrip() - lastKnownLocation().map { it.validate() } - lastKnownOrientation() - lastLocationUpdateTime() - lastUpdateTime() - nextStop() - nextStopTimeOffset() - occupancyCapacity() - occupancyCount() - occupancyStatus() - orientation() - phase() - position().map { it.validate() } - predicted() - scheduleDeviation() - scheduledDistanceAlongTrip() - serviceDate() - situationIds() - status() - totalDistanceAlongTrip() - vehicleId() - validated = true + if (validated) { + return@apply } + + activeTripId() + blockTripSequence() + closestStop() + distanceAlongTrip() + lastKnownDistanceAlongTrip() + lastLocationUpdateTime() + lastUpdateTime() + occupancyCapacity() + occupancyCount() + occupancyStatus() + phase() + predicted() + scheduleDeviation() + serviceDate() + status() + totalDistanceAlongTrip() + closestStopTimeOffset() + frequency() + lastKnownLocation().ifPresent { it.validate() } + lastKnownOrientation() + nextStop() + nextStopTimeOffset() + orientation() + position().ifPresent { it.validate() } + scheduledDistanceAlongTrip() + situationIds() + vehicleId() + validated = true } fun toBuilder() = Builder().from(this) @@ -1127,68 +1319,68 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - - private var activeTripId: JsonField = JsonMissing.of() - private var blockTripSequence: JsonField = JsonMissing.of() - private var closestStop: JsonField = JsonMissing.of() + /** A builder for [Status]. */ + class Builder internal constructor() { + + private var activeTripId: JsonField? = null + private var blockTripSequence: JsonField? = null + private var closestStop: JsonField? = null + private var distanceAlongTrip: JsonField? = null + private var lastKnownDistanceAlongTrip: JsonField? = null + private var lastLocationUpdateTime: JsonField? = null + private var lastUpdateTime: JsonField? = null + private var occupancyCapacity: JsonField? = null + private var occupancyCount: JsonField? = null + private var occupancyStatus: JsonField? = null + private var phase: JsonField? = null + private var predicted: JsonField? = null + private var scheduleDeviation: JsonField? = null + private var serviceDate: JsonField? = null + private var situationIds: JsonField>? = null + private var status: JsonField? = null + private var totalDistanceAlongTrip: JsonField? = null private var closestStopTimeOffset: JsonField = JsonMissing.of() - private var distanceAlongTrip: JsonField = JsonMissing.of() private var frequency: JsonField = JsonMissing.of() - private var lastKnownDistanceAlongTrip: JsonField = JsonMissing.of() private var lastKnownLocation: JsonField = JsonMissing.of() private var lastKnownOrientation: JsonField = JsonMissing.of() - private var lastLocationUpdateTime: JsonField = JsonMissing.of() - private var lastUpdateTime: JsonField = JsonMissing.of() private var nextStop: JsonField = JsonMissing.of() private var nextStopTimeOffset: JsonField = JsonMissing.of() - private var occupancyCapacity: JsonField = JsonMissing.of() - private var occupancyCount: JsonField = JsonMissing.of() - private var occupancyStatus: JsonField = JsonMissing.of() private var orientation: JsonField = JsonMissing.of() - private var phase: JsonField = JsonMissing.of() private var position: JsonField = JsonMissing.of() - private var predicted: JsonField = JsonMissing.of() - private var scheduleDeviation: JsonField = JsonMissing.of() private var scheduledDistanceAlongTrip: JsonField = JsonMissing.of() - private var serviceDate: JsonField = JsonMissing.of() - private var situationIds: JsonField> = - JsonMissing.of() - private var status: JsonField = JsonMissing.of() - private var totalDistanceAlongTrip: JsonField = JsonMissing.of() private var vehicleId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(status: Status) = apply { - this.activeTripId = status.activeTripId - this.blockTripSequence = status.blockTripSequence - this.closestStop = status.closestStop - this.closestStopTimeOffset = status.closestStopTimeOffset - this.distanceAlongTrip = status.distanceAlongTrip - this.frequency = status.frequency - this.lastKnownDistanceAlongTrip = status.lastKnownDistanceAlongTrip - this.lastKnownLocation = status.lastKnownLocation - this.lastKnownOrientation = status.lastKnownOrientation - this.lastLocationUpdateTime = status.lastLocationUpdateTime - this.lastUpdateTime = status.lastUpdateTime - this.nextStop = status.nextStop - this.nextStopTimeOffset = status.nextStopTimeOffset - this.occupancyCapacity = status.occupancyCapacity - this.occupancyCount = status.occupancyCount - this.occupancyStatus = status.occupancyStatus - this.orientation = status.orientation - this.phase = status.phase - this.position = status.position - this.predicted = status.predicted - this.scheduleDeviation = status.scheduleDeviation - this.scheduledDistanceAlongTrip = status.scheduledDistanceAlongTrip - this.serviceDate = status.serviceDate - this.situationIds = status.situationIds + activeTripId = status.activeTripId + blockTripSequence = status.blockTripSequence + closestStop = status.closestStop + distanceAlongTrip = status.distanceAlongTrip + lastKnownDistanceAlongTrip = status.lastKnownDistanceAlongTrip + lastLocationUpdateTime = status.lastLocationUpdateTime + lastUpdateTime = status.lastUpdateTime + occupancyCapacity = status.occupancyCapacity + occupancyCount = status.occupancyCount + occupancyStatus = status.occupancyStatus + phase = status.phase + predicted = status.predicted + scheduleDeviation = status.scheduleDeviation + serviceDate = status.serviceDate this.status = status.status - this.totalDistanceAlongTrip = status.totalDistanceAlongTrip - this.vehicleId = status.vehicleId - additionalProperties(status.additionalProperties) + totalDistanceAlongTrip = status.totalDistanceAlongTrip + closestStopTimeOffset = status.closestStopTimeOffset + frequency = status.frequency + lastKnownLocation = status.lastKnownLocation + lastKnownOrientation = status.lastKnownOrientation + nextStop = status.nextStop + nextStopTimeOffset = status.nextStopTimeOffset + orientation = status.orientation + position = status.position + scheduledDistanceAlongTrip = status.scheduledDistanceAlongTrip + situationIds = status.situationIds.map { it.toMutableList() } + vehicleId = status.vehicleId + additionalProperties = status.additionalProperties.toMutableMap() } /** Trip ID of the trip the vehicle is actively serving. */ @@ -1196,8 +1388,6 @@ private constructor( activeTripId(JsonField.of(activeTripId)) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") - @ExcludeMissing fun activeTripId(activeTripId: JsonField) = apply { this.activeTripId = activeTripId } @@ -1207,37 +1397,16 @@ private constructor( blockTripSequence(JsonField.of(blockTripSequence)) /** Index of the active trip into the sequence of trips for the active block. */ - @JsonProperty("blockTripSequence") - @ExcludeMissing fun blockTripSequence(blockTripSequence: JsonField) = apply { this.blockTripSequence = blockTripSequence } - - /** ID of the closest stop to the current location of the transit vehicle. */ - fun closestStop(closestStop: String) = closestStop(JsonField.of(closestStop)) - - /** ID of the closest stop to the current location of the transit vehicle. */ - @JsonProperty("closestStop") - @ExcludeMissing - fun closestStop(closestStop: JsonField) = apply { - this.closestStop = closestStop - } - - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - fun closestStopTimeOffset(closestStopTimeOffset: Long) = - closestStopTimeOffset(JsonField.of(closestStopTimeOffset)) - - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing - fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { - this.closestStopTimeOffset = closestStopTimeOffset + + /** ID of the closest stop to the current location of the transit vehicle. */ + fun closestStop(closestStop: String) = closestStop(JsonField.of(closestStop)) + + /** ID of the closest stop to the current location of the transit vehicle. */ + fun closestStop(closestStop: JsonField) = apply { + this.closestStop = closestStop } /** @@ -1251,22 +1420,10 @@ private constructor( * Distance, in meters, the transit vehicle has progressed along the active * trip. */ - @JsonProperty("distanceAlongTrip") - @ExcludeMissing fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { this.distanceAlongTrip = distanceAlongTrip } - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") - @ExcludeMissing - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1278,39 +1435,11 @@ private constructor( * Last known distance along the trip received in real-time from the transit * vehicle. */ - @JsonProperty("lastKnownDistanceAlongTrip") - @ExcludeMissing fun lastKnownDistanceAlongTrip(lastKnownDistanceAlongTrip: JsonField) = apply { this.lastKnownDistanceAlongTrip = lastKnownDistanceAlongTrip } - /** Last known location of the transit vehicle. */ - fun lastKnownLocation(lastKnownLocation: LastKnownLocation) = - lastKnownLocation(JsonField.of(lastKnownLocation)) - - /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun lastKnownLocation(lastKnownLocation: JsonField) = apply { - this.lastKnownLocation = lastKnownLocation - } - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - fun lastKnownOrientation(lastKnownOrientation: Double) = - lastKnownOrientation(JsonField.of(lastKnownOrientation)) - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun lastKnownOrientation(lastKnownOrientation: JsonField) = apply { - this.lastKnownOrientation = lastKnownOrientation - } - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1322,8 +1451,6 @@ private constructor( * Timestamp of the last known real-time location update from the transit * vehicle. */ - @JsonProperty("lastLocationUpdateTime") - @ExcludeMissing fun lastLocationUpdateTime(lastLocationUpdateTime: JsonField) = apply { this.lastLocationUpdateTime = lastLocationUpdateTime } @@ -1333,44 +1460,15 @@ private constructor( lastUpdateTime(JsonField.of(lastUpdateTime)) /** Timestamp of the last known real-time update from the transit vehicle. */ - @JsonProperty("lastUpdateTime") - @ExcludeMissing fun lastUpdateTime(lastUpdateTime: JsonField) = apply { this.lastUpdateTime = lastUpdateTime } - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - fun nextStop(nextStop: String) = nextStop(JsonField.of(nextStop)) - - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") - @ExcludeMissing - fun nextStop(nextStop: JsonField) = apply { this.nextStop = nextStop } - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - fun nextStopTimeOffset(nextStopTimeOffset: Long) = - nextStopTimeOffset(JsonField.of(nextStopTimeOffset)) - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - fun nextStopTimeOffset(nextStopTimeOffset: JsonField) = apply { - this.nextStopTimeOffset = nextStopTimeOffset - } - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) /** Capacity of the transit vehicle in terms of occupancy. */ - @JsonProperty("occupancyCapacity") - @ExcludeMissing fun occupancyCapacity(occupancyCapacity: JsonField) = apply { this.occupancyCapacity = occupancyCapacity } @@ -1380,8 +1478,6 @@ private constructor( occupancyCount(JsonField.of(occupancyCount)) /** Current count of occupants in the transit vehicle. */ - @JsonProperty("occupancyCount") - @ExcludeMissing fun occupancyCount(occupancyCount: JsonField) = apply { this.occupancyCount = occupancyCount } @@ -1391,44 +1487,20 @@ private constructor( occupancyStatus(JsonField.of(occupancyStatus)) /** Current occupancy status of the transit vehicle. */ - @JsonProperty("occupancyStatus") - @ExcludeMissing fun occupancyStatus(occupancyStatus: JsonField) = apply { this.occupancyStatus = occupancyStatus } - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - fun orientation(orientation: Double) = orientation(JsonField.of(orientation)) - - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") - @ExcludeMissing - fun orientation(orientation: JsonField) = apply { - this.orientation = orientation - } - /** Current journey phase of the trip. */ fun phase(phase: String) = phase(JsonField.of(phase)) /** Current journey phase of the trip. */ - @JsonProperty("phase") - @ExcludeMissing fun phase(phase: JsonField) = apply { this.phase = phase } - /** Current position of the transit vehicle. */ - fun position(position: Position) = position(JsonField.of(position)) - - /** Current position of the transit vehicle. */ - @JsonProperty("position") - @ExcludeMissing - fun position(position: JsonField) = apply { this.position = position } - /** Indicates if real-time arrival info is available for this trip. */ fun predicted(predicted: Boolean) = predicted(JsonField.of(predicted)) /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") - @ExcludeMissing fun predicted(predicted: JsonField) = apply { this.predicted = predicted } @@ -1444,30 +1516,10 @@ private constructor( * Deviation from the schedule in seconds (positive for late, negative for * early). */ - @JsonProperty("scheduleDeviation") - @ExcludeMissing fun scheduleDeviation(scheduleDeviation: JsonField) = apply { this.scheduleDeviation = scheduleDeviation } - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed - * along the active trip. - */ - fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: Double) = - scheduledDistanceAlongTrip(JsonField.of(scheduledDistanceAlongTrip)) - - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed - * along the active trip. - */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: JsonField) = - apply { - this.scheduledDistanceAlongTrip = scheduledDistanceAlongTrip - } - /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. @@ -1478,8 +1530,6 @@ private constructor( * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") - @ExcludeMissing fun serviceDate(serviceDate: JsonField) = apply { this.serviceDate = serviceDate } @@ -1489,19 +1539,15 @@ private constructor( situationIds(JsonField.of(situationIds)) /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") - @ExcludeMissing fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds + this.situationIds = situationIds.map { it.toMutableList() } } /** Current status modifiers for the trip. */ fun status(status: String) = status(JsonField.of(status)) /** Current status modifiers for the trip. */ - @JsonProperty("status") - @ExcludeMissing fun status(status: JsonField) = apply { this.status = status } /** Total length of the trip, in meters. */ @@ -1509,30 +1555,135 @@ private constructor( totalDistanceAlongTrip(JsonField.of(totalDistanceAlongTrip)) /** Total length of the trip, in meters. */ - @JsonProperty("totalDistanceAlongTrip") - @ExcludeMissing fun totalDistanceAlongTrip(totalDistanceAlongTrip: JsonField) = apply { this.totalDistanceAlongTrip = totalDistanceAlongTrip } + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + fun closestStopTimeOffset(closestStopTimeOffset: Long) = + closestStopTimeOffset(JsonField.of(closestStopTimeOffset)) + + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { + this.closestStopTimeOffset = closestStopTimeOffset + } + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: String) = frequency(JsonField.of(frequency)) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: JsonField) = apply { + this.frequency = frequency + } + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(lastKnownLocation: LastKnownLocation) = + lastKnownLocation(JsonField.of(lastKnownLocation)) + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(lastKnownLocation: JsonField) = apply { + this.lastKnownLocation = lastKnownLocation + } + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + fun lastKnownOrientation(lastKnownOrientation: Double) = + lastKnownOrientation(JsonField.of(lastKnownOrientation)) + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + fun lastKnownOrientation(lastKnownOrientation: JsonField) = apply { + this.lastKnownOrientation = lastKnownOrientation + } + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(nextStop: String) = nextStop(JsonField.of(nextStop)) + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(nextStop: JsonField) = apply { this.nextStop = nextStop } + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + fun nextStopTimeOffset(nextStopTimeOffset: Long) = + nextStopTimeOffset(JsonField.of(nextStopTimeOffset)) + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + fun nextStopTimeOffset(nextStopTimeOffset: JsonField) = apply { + this.nextStopTimeOffset = nextStopTimeOffset + } + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(orientation: Double) = orientation(JsonField.of(orientation)) + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(orientation: JsonField) = apply { + this.orientation = orientation + } + + /** Current position of the transit vehicle. */ + fun position(position: Position) = position(JsonField.of(position)) + + /** Current position of the transit vehicle. */ + fun position(position: JsonField) = apply { this.position = position } + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed + * along the active trip. + */ + fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: Double) = + scheduledDistanceAlongTrip(JsonField.of(scheduledDistanceAlongTrip)) + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed + * along the active trip. + */ + fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: JsonField) = + apply { + this.scheduledDistanceAlongTrip = scheduledDistanceAlongTrip + } + + /** References to situation elements (if any) applicable to this trip. */ + fun addSituationId(situationId: String) = apply { + situationIds = + (situationIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situationId) + } + } + /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(vehicleId: String) = vehicleId(JsonField.of(vehicleId)) /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") - @ExcludeMissing fun vehicleId(vehicleId: JsonField) = apply { this.vehicleId = vehicleId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1540,51 +1691,62 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Status = Status( - activeTripId, - blockTripSequence, - closestStop, + checkRequired("activeTripId", activeTripId), + checkRequired("blockTripSequence", blockTripSequence), + checkRequired("closestStop", closestStop), + checkRequired("distanceAlongTrip", distanceAlongTrip), + checkRequired("lastKnownDistanceAlongTrip", lastKnownDistanceAlongTrip), + checkRequired("lastLocationUpdateTime", lastLocationUpdateTime), + checkRequired("lastUpdateTime", lastUpdateTime), + checkRequired("occupancyCapacity", occupancyCapacity), + checkRequired("occupancyCount", occupancyCount), + checkRequired("occupancyStatus", occupancyStatus), + checkRequired("phase", phase), + checkRequired("predicted", predicted), + checkRequired("scheduleDeviation", scheduleDeviation), + checkRequired("serviceDate", serviceDate), + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, + checkRequired("status", status), + checkRequired("totalDistanceAlongTrip", totalDistanceAlongTrip), closestStopTimeOffset, - distanceAlongTrip, frequency, - lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, - lastLocationUpdateTime, - lastUpdateTime, nextStop, nextStopTimeOffset, - occupancyCapacity, - occupancyCount, - occupancyStatus, orientation, - phase, position, - predicted, - scheduleDeviation, scheduledDistanceAlongTrip, - serviceDate, - situationIds.map { it.toImmutable() }, - status, - totalDistanceAlongTrip, vehicleId, additionalProperties.toImmutable(), ) } /** Last known location of the transit vehicle. */ - @JsonDeserialize(builder = LastKnownLocation.Builder::class) @NoAutoDetect class LastKnownLocation + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the last known location of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -1592,21 +1754,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): LastKnownLocation = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -1616,7 +1782,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [LastKnownLocation]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -1625,42 +1792,46 @@ private constructor( @JvmSynthetic internal fun from(lastKnownLocation: LastKnownLocation) = apply { - this.lat = lastKnownLocation.lat - this.lon = lastKnownLocation.lon - additionalProperties(lastKnownLocation.additionalProperties) + lat = lastKnownLocation.lat + lon = lastKnownLocation.lon + additionalProperties = + lastKnownLocation.additionalProperties.toMutableMap() } /** Latitude of the last known location of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the last known location of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): LastKnownLocation = LastKnownLocation( lat, @@ -1674,34 +1845,34 @@ private constructor( return true } - return /* spotless:off */ other is LastKnownLocation && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is LastKnownLocation && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "LastKnownLocation{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" } /** Current position of the transit vehicle. */ - @JsonDeserialize(builder = Position.Builder::class) @NoAutoDetect class Position + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the current position of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -1709,21 +1880,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Position = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -1733,7 +1908,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Position]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -1742,42 +1918,45 @@ private constructor( @JvmSynthetic internal fun from(position: Position) = apply { - this.lat = position.lat - this.lon = position.lon - additionalProperties(position.additionalProperties) + lat = position.lat + lon = position.lon + additionalProperties = position.additionalProperties.toMutableMap() } /** Latitude of the current position of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the current position of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Position = Position( lat, @@ -1791,17 +1970,14 @@ private constructor( return true } - return /* spotless:off */ other is Position && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Position && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Position{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" @@ -1812,20 +1988,17 @@ private constructor( return true } - return /* spotless:off */ other is Status && this.activeTripId == other.activeTripId && this.blockTripSequence == other.blockTripSequence && this.closestStop == other.closestStop && this.closestStopTimeOffset == other.closestStopTimeOffset && this.distanceAlongTrip == other.distanceAlongTrip && this.frequency == other.frequency && this.lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && this.lastKnownLocation == other.lastKnownLocation && this.lastKnownOrientation == other.lastKnownOrientation && this.lastLocationUpdateTime == other.lastLocationUpdateTime && this.lastUpdateTime == other.lastUpdateTime && this.nextStop == other.nextStop && this.nextStopTimeOffset == other.nextStopTimeOffset && this.occupancyCapacity == other.occupancyCapacity && this.occupancyCount == other.occupancyCount && this.occupancyStatus == other.occupancyStatus && this.orientation == other.orientation && this.phase == other.phase && this.position == other.position && this.predicted == other.predicted && this.scheduleDeviation == other.scheduleDeviation && this.scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && this.serviceDate == other.serviceDate && this.situationIds == other.situationIds && this.status == other.status && this.totalDistanceAlongTrip == other.totalDistanceAlongTrip && this.vehicleId == other.vehicleId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Status && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && distanceAlongTrip == other.distanceAlongTrip && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && phase == other.phase && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && serviceDate == other.serviceDate && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && closestStopTimeOffset == other.closestStopTimeOffset && frequency == other.frequency && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && orientation == other.orientation && position == other.position && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && situationIds == other.situationIds && vehicleId == other.vehicleId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(activeTripId, blockTripSequence, closestStop, distanceAlongTrip, lastKnownDistanceAlongTrip, lastLocationUpdateTime, lastUpdateTime, occupancyCapacity, occupancyCount, occupancyStatus, phase, predicted, scheduleDeviation, serviceDate, status, totalDistanceAlongTrip, closestStopTimeOffset, frequency, lastKnownLocation, lastKnownOrientation, nextStop, nextStopTimeOffset, orientation, position, scheduledDistanceAlongTrip, situationIds, vehicleId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(activeTripId, blockTripSequence, closestStop, closestStopTimeOffset, distanceAlongTrip, frequency, lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, lastLocationUpdateTime, lastUpdateTime, nextStop, nextStopTimeOffset, occupancyCapacity, occupancyCount, occupancyStatus, orientation, phase, position, predicted, scheduleDeviation, scheduledDistanceAlongTrip, serviceDate, situationIds, status, totalDistanceAlongTrip, vehicleId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Status{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, closestStopTimeOffset=$closestStopTimeOffset, distanceAlongTrip=$distanceAlongTrip, frequency=$frequency, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, orientation=$orientation, phase=$phase, position=$position, predicted=$predicted, scheduleDeviation=$scheduleDeviation, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, serviceDate=$serviceDate, situationIds=$situationIds, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" + "Status{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, distanceAlongTrip=$distanceAlongTrip, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, phase=$phase, predicted=$predicted, scheduleDeviation=$scheduleDeviation, serviceDate=$serviceDate, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, closestStopTimeOffset=$closestStopTimeOffset, frequency=$frequency, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, orientation=$orientation, position=$position, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, situationIds=$situationIds, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1833,20 +2006,17 @@ private constructor( return true } - return /* spotless:off */ other is List && this.frequency == other.frequency && this.serviceDate == other.serviceDate && this.situationIds == other.situationIds && this.tripId == other.tripId && this.schedule == other.schedule && this.status == other.status && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is List && schedule == other.schedule && status == other.status && tripId == other.tripId && frequency == other.frequency && serviceDate == other.serviceDate && situationIds == other.situationIds && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(schedule, status, tripId, frequency, serviceDate, situationIds, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(frequency, serviceDate, situationIds, tripId, schedule, status, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "List{frequency=$frequency, serviceDate=$serviceDate, situationIds=$situationIds, tripId=$tripId, schedule=$schedule, status=$status, additionalProperties=$additionalProperties}" + "List{schedule=$schedule, status=$status, tripId=$tripId, frequency=$frequency, serviceDate=$serviceDate, situationIds=$situationIds, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1854,20 +2024,17 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.limitExceeded == other.limitExceeded && this.list == other.list && this.outOfRange == other.outOfRange && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && list == other.list && references == other.references && outOfRange == other.outOfRange && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, references, outOfRange, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(limitExceeded, list, outOfRange, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Data{limitExceeded=$limitExceeded, list=$list, outOfRange=$outOfRange, references=$references, additionalProperties=$additionalProperties}" + "Data{limitExceeded=$limitExceeded, list=$list, references=$references, outOfRange=$outOfRange, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1875,17 +2042,14 @@ private constructor( return true } - return /* spotless:off */ other is TripsForLocationListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is TripsForLocationListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "TripsForLocationListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForRouteListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForRouteListParams.kt index 2e87437..d583984 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForRouteListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForRouteListParams.kt @@ -2,42 +2,52 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Search for active trips for a specific route. */ class TripsForRouteListParams -constructor( +private constructor( private val routeId: String, private val includeSchedule: Boolean?, private val includeStatus: Boolean?, private val time: Long?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun routeId(): String = routeId + /** Determine whether full schedule elements are included. Defaults to false. */ fun includeSchedule(): Optional = Optional.ofNullable(includeSchedule) + /** + * Determine whether full tripStatus elements with real-time information are included. Defaults + * to false. + */ fun includeStatus(): Optional = Optional.ofNullable(includeStatus) + /** Query the system at a specific time. Useful for testing. */ fun time(): Optional = Optional.ofNullable(time) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.includeSchedule?.let { params.put("includeSchedule", listOf(it.toString())) } - this.includeStatus?.let { params.put("includeStatus", listOf(it.toString())) } - this.time?.let { params.put("time", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.includeSchedule?.let { queryParams.put("includeSchedule", listOf(it.toString())) } + this.includeStatus?.let { queryParams.put("includeStatus", listOf(it.toString())) } + this.time?.let { queryParams.put("time", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } fun getPathParam(index: Int): String { @@ -47,25 +57,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is TripsForRouteListParams && this.routeId == other.routeId && this.includeSchedule == other.includeSchedule && this.includeStatus == other.includeStatus && this.time == other.time && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(routeId, includeSchedule, includeStatus, time, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "TripsForRouteListParams{routeId=$routeId, includeSchedule=$includeSchedule, includeStatus=$includeStatus, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -73,41 +64,76 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [TripsForRouteListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var routeId: String? = null private var includeSchedule: Boolean? = null private var includeStatus: Boolean? = null private var time: Long? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(tripsForRouteListParams: TripsForRouteListParams) = apply { - this.routeId = tripsForRouteListParams.routeId - this.includeSchedule = tripsForRouteListParams.includeSchedule - this.includeStatus = tripsForRouteListParams.includeStatus - this.time = tripsForRouteListParams.time - additionalHeaders(tripsForRouteListParams.additionalHeaders) - additionalQueryParams(tripsForRouteListParams.additionalQueryParams) + routeId = tripsForRouteListParams.routeId + includeSchedule = tripsForRouteListParams.includeSchedule + includeStatus = tripsForRouteListParams.includeStatus + time = tripsForRouteListParams.time + additionalHeaders = tripsForRouteListParams.additionalHeaders.toBuilder() + additionalQueryParams = tripsForRouteListParams.additionalQueryParams.toBuilder() } fun routeId(routeId: String) = apply { this.routeId = routeId } /** Determine whether full schedule elements are included. Defaults to false. */ - fun includeSchedule(includeSchedule: Boolean) = apply { + fun includeSchedule(includeSchedule: Boolean?) = apply { this.includeSchedule = includeSchedule } + /** Determine whether full schedule elements are included. Defaults to false. */ + fun includeSchedule(includeSchedule: Boolean) = includeSchedule(includeSchedule as Boolean?) + + /** Determine whether full schedule elements are included. Defaults to false. */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun includeSchedule(includeSchedule: Optional) = + includeSchedule(includeSchedule.orElse(null) as Boolean?) + /** * Determine whether full tripStatus elements with real-time information are included. * Defaults to false. */ - fun includeStatus(includeStatus: Boolean) = apply { this.includeStatus = includeStatus } + fun includeStatus(includeStatus: Boolean?) = apply { this.includeStatus = includeStatus } + + /** + * Determine whether full tripStatus elements with real-time information are included. + * Defaults to false. + */ + fun includeStatus(includeStatus: Boolean) = includeStatus(includeStatus as Boolean?) + + /** + * Determine whether full tripStatus elements with real-time information are included. + * Defaults to false. + */ + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun includeStatus(includeStatus: Optional) = + includeStatus(includeStatus.orElse(null) as Boolean?) + + /** Query the system at a specific time. Useful for testing. */ + fun time(time: Long?) = apply { this.time = time } + + /** Query the system at a specific time. Useful for testing. */ + fun time(time: Long) = time(time as Long?) /** Query the system at a specific time. Useful for testing. */ - fun time(time: Long) = apply { this.time = time } + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun time(time: Optional) = time(time.orElse(null) as Long?) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -119,29 +145,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -154,49 +193,62 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): TripsForRouteListParams = TripsForRouteListParams( - checkNotNull(routeId) { "`routeId` is required but was not set" }, + checkRequired("routeId", routeId), includeSchedule, includeStatus, time, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is TripsForRouteListParams && routeId == other.routeId && includeSchedule == other.includeSchedule && includeStatus == other.includeStatus && time == other.time && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(routeId, includeSchedule, includeStatus, time, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "TripsForRouteListParams{routeId=$routeId, includeSchedule=$includeSchedule, includeStatus=$includeStatus, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForRouteListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForRouteListResponse.kt index e048b4e..700dcd3 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForRouteListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/TripsForRouteListResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = TripsForRouteListResponse.Builder::class) @NoAutoDetect class TripsForRouteListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): TripsForRouteListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,115 +87,126 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [TripsForRouteListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(tripsForRouteListResponse: TripsForRouteListResponse) = apply { - this.code = tripsForRouteListResponse.code - this.currentTime = tripsForRouteListResponse.currentTime - this.text = tripsForRouteListResponse.text - this.version = tripsForRouteListResponse.version - this.data = tripsForRouteListResponse.data - additionalProperties(tripsForRouteListResponse.additionalProperties) + code = tripsForRouteListResponse.code + currentTime = tripsForRouteListResponse.currentTime + text = tripsForRouteListResponse.text + version = tripsForRouteListResponse.version + data = tripsForRouteListResponse.data + additionalProperties = tripsForRouteListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): TripsForRouteListResponse = TripsForRouteListResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val limitExceeded: JsonField, - private val list: JsonField>, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("limitExceeded") + @ExcludeMissing + private val limitExceeded: JsonField = JsonMissing.of(), + @JsonProperty("list") + @ExcludeMissing + private val list: JsonField> = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") fun list(): kotlin.collections.List = list.getRequired("list") fun references(): References = references.getRequired("references") - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + @JsonProperty("limitExceeded") + @ExcludeMissing + fun _limitExceeded(): JsonField = limitExceeded - @JsonProperty("list") @ExcludeMissing fun _list() = list + @JsonProperty("list") + @ExcludeMissing + fun _list(): JsonField> = list - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - limitExceeded() - list().forEach { it.validate() } - references().validate() - validated = true + if (validated) { + return@apply } + + limitExceeded() + list().forEach { it.validate() } + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -197,80 +216,113 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var limitExceeded: JsonField = JsonMissing.of() - private var list: JsonField> = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var limitExceeded: JsonField? = null + private var list: JsonField>? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.limitExceeded = data.limitExceeded - this.list = data.list - this.references = data.references - additionalProperties(data.additionalProperties) + limitExceeded = data.limitExceeded + list = data.list.map { it.toMutableList() } + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) - @JsonProperty("limitExceeded") - @ExcludeMissing fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } fun list(list: kotlin.collections.List) = list(JsonField.of(list)) - @JsonProperty("list") - @ExcludeMissing - fun list(list: JsonField>) = apply { this.list = list } + fun list(list: JsonField>) = apply { + this.list = list.map { it.toMutableList() } + } + + fun addList(list: List) = apply { + this.list = + (this.list ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(list) + } + } fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = List.Builder::class) @NoAutoDetect class List + @JsonCreator private constructor( - private val frequency: JsonField, - private val serviceDate: JsonField, - private val situationIds: JsonField>, - private val tripId: JsonField, - private val schedule: JsonField, - private val status: JsonField, - private val additionalProperties: Map, + @JsonProperty("schedule") + @ExcludeMissing + private val schedule: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonProperty("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), + @JsonProperty("tripId") + @ExcludeMissing + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false + fun schedule(): Schedule = schedule.getRequired("schedule") + + fun status(): Status = status.getRequired("status") + + fun tripId(): String = tripId.getRequired("tripId") fun frequency(): Optional = Optional.ofNullable(frequency.getNullable("frequency")) @@ -281,38 +333,44 @@ private constructor( fun situationIds(): Optional> = Optional.ofNullable(situationIds.getNullable("situationIds")) - fun tripId(): String = tripId.getRequired("tripId") - - fun schedule(): Schedule = schedule.getRequired("schedule") - - fun status(): Status = status.getRequired("status") - - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + @JsonProperty("schedule") + @ExcludeMissing + fun _schedule(): JsonField = schedule - @JsonProperty("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds + @JsonProperty("tripId") @ExcludeMissing fun _tripId(): JsonField = tripId - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency - @JsonProperty("schedule") @ExcludeMissing fun _schedule() = schedule + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("situationIds") + @ExcludeMissing + fun _situationIds(): JsonField> = situationIds @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): List = apply { - if (!validated) { - frequency() - serviceDate() - situationIds() - tripId() - schedule().validate() - status().validate() - validated = true + if (validated) { + return@apply } + + schedule().validate() + status().validate() + tripId() + frequency() + serviceDate() + situationIds() + validated = true } fun toBuilder() = Builder().from(this) @@ -322,38 +380,48 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [List]. */ + class Builder internal constructor() { + private var schedule: JsonField? = null + private var status: JsonField? = null + private var tripId: JsonField? = null private var frequency: JsonField = JsonMissing.of() private var serviceDate: JsonField = JsonMissing.of() - private var situationIds: JsonField> = - JsonMissing.of() - private var tripId: JsonField = JsonMissing.of() - private var schedule: JsonField = JsonMissing.of() - private var status: JsonField = JsonMissing.of() + private var situationIds: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(list: List) = apply { - this.frequency = list.frequency - this.serviceDate = list.serviceDate - this.situationIds = list.situationIds - this.tripId = list.tripId - this.schedule = list.schedule - this.status = list.status - additionalProperties(list.additionalProperties) + schedule = list.schedule + status = list.status + tripId = list.tripId + frequency = list.frequency + serviceDate = list.serviceDate + situationIds = list.situationIds.map { it.toMutableList() } + additionalProperties = list.additionalProperties.toMutableMap() } - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) + fun schedule(schedule: Schedule) = schedule(JsonField.of(schedule)) + + fun schedule(schedule: JsonField) = apply { this.schedule = schedule } + + fun status(status: Status) = status(JsonField.of(status)) + + fun status(status: JsonField) = apply { this.status = status } + + fun tripId(tripId: String) = tripId(JsonField.of(tripId)) + + fun tripId(tripId: JsonField) = apply { this.tripId = tripId } + + fun frequency(frequency: String?) = frequency(JsonField.ofNullable(frequency)) + + fun frequency(frequency: Optional) = frequency(frequency.orElse(null)) - @JsonProperty("frequency") - @ExcludeMissing fun frequency(frequency: JsonField) = apply { this.frequency = frequency } fun serviceDate(serviceDate: Long) = serviceDate(JsonField.of(serviceDate)) - @JsonProperty("serviceDate") - @ExcludeMissing fun serviceDate(serviceDate: JsonField) = apply { this.serviceDate = serviceDate } @@ -361,38 +429,30 @@ private constructor( fun situationIds(situationIds: kotlin.collections.List) = situationIds(JsonField.of(situationIds)) - @JsonProperty("situationIds") - @ExcludeMissing fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds + this.situationIds = situationIds.map { it.toMutableList() } } - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - @JsonProperty("tripId") - @ExcludeMissing - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - - fun schedule(schedule: Schedule) = schedule(JsonField.of(schedule)) - - @JsonProperty("schedule") - @ExcludeMissing - fun schedule(schedule: JsonField) = apply { this.schedule = schedule } - - fun status(status: Status) = status(JsonField.of(status)) - - @JsonProperty("status") - @ExcludeMissing - fun status(status: JsonField) = apply { this.status = status } + fun addSituationId(situationId: String) = apply { + situationIds = + (situationIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situationId) + } + } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -400,35 +460,50 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): List = List( + checkRequired("schedule", schedule), + checkRequired("status", status), + checkRequired("tripId", tripId), frequency, serviceDate, - situationIds.map { it.toImmutable() }, - tripId, - schedule, - status, + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Schedule.Builder::class) @NoAutoDetect class Schedule + @JsonCreator private constructor( - private val frequency: JsonField, - private val nextTripId: JsonField, - private val previousTripId: JsonField, - private val stopTimes: JsonField>, - private val timeZone: JsonField, - private val additionalProperties: Map, + @JsonProperty("nextTripId") + @ExcludeMissing + private val nextTripId: JsonField = JsonMissing.of(), + @JsonProperty("previousTripId") + @ExcludeMissing + private val previousTripId: JsonField = JsonMissing.of(), + @JsonProperty("stopTimes") + @ExcludeMissing + private val stopTimes: JsonField> = + JsonMissing.of(), + @JsonProperty("timeZone") + @ExcludeMissing + private val timeZone: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - fun nextTripId(): String = nextTripId.getRequired("nextTripId") fun previousTripId(): String = previousTripId.getRequired("previousTripId") @@ -438,31 +513,46 @@ private constructor( fun timeZone(): String = timeZone.getRequired("timeZone") - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) - @JsonProperty("nextTripId") @ExcludeMissing fun _nextTripId() = nextTripId + @JsonProperty("nextTripId") + @ExcludeMissing + fun _nextTripId(): JsonField = nextTripId @JsonProperty("previousTripId") @ExcludeMissing - fun _previousTripId() = previousTripId + fun _previousTripId(): JsonField = previousTripId - @JsonProperty("stopTimes") @ExcludeMissing fun _stopTimes() = stopTimes + @JsonProperty("stopTimes") + @ExcludeMissing + fun _stopTimes(): JsonField> = stopTimes + + @JsonProperty("timeZone") + @ExcludeMissing + fun _timeZone(): JsonField = timeZone - @JsonProperty("timeZone") @ExcludeMissing fun _timeZone() = timeZone + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Schedule = apply { - if (!validated) { - frequency() - nextTripId() - previousTripId() - stopTimes().forEach { it.validate() } - timeZone() - validated = true + if (validated) { + return@apply } + + nextTripId() + previousTripId() + stopTimes().forEach { it.validate() } + timeZone() + frequency() + validated = true } fun toBuilder() = Builder().from(this) @@ -472,38 +562,28 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Schedule]. */ + class Builder internal constructor() { + private var nextTripId: JsonField? = null + private var previousTripId: JsonField? = null + private var stopTimes: JsonField>? = null + private var timeZone: JsonField? = null private var frequency: JsonField = JsonMissing.of() - private var nextTripId: JsonField = JsonMissing.of() - private var previousTripId: JsonField = JsonMissing.of() - private var stopTimes: JsonField> = - JsonMissing.of() - private var timeZone: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(schedule: Schedule) = apply { - this.frequency = schedule.frequency - this.nextTripId = schedule.nextTripId - this.previousTripId = schedule.previousTripId - this.stopTimes = schedule.stopTimes - this.timeZone = schedule.timeZone - additionalProperties(schedule.additionalProperties) - } - - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - @JsonProperty("frequency") - @ExcludeMissing - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency + nextTripId = schedule.nextTripId + previousTripId = schedule.previousTripId + stopTimes = schedule.stopTimes.map { it.toMutableList() } + timeZone = schedule.timeZone + frequency = schedule.frequency + additionalProperties = schedule.additionalProperties.toMutableMap() } fun nextTripId(nextTripId: String) = nextTripId(JsonField.of(nextTripId)) - @JsonProperty("nextTripId") - @ExcludeMissing fun nextTripId(nextTripId: JsonField) = apply { this.nextTripId = nextTripId } @@ -511,8 +591,6 @@ private constructor( fun previousTripId(previousTripId: String) = previousTripId(JsonField.of(previousTripId)) - @JsonProperty("previousTripId") - @ExcludeMissing fun previousTripId(previousTripId: JsonField) = apply { this.previousTripId = previousTripId } @@ -520,26 +598,42 @@ private constructor( fun stopTimes(stopTimes: kotlin.collections.List) = stopTimes(JsonField.of(stopTimes)) - @JsonProperty("stopTimes") - @ExcludeMissing fun stopTimes(stopTimes: JsonField>) = apply { - this.stopTimes = stopTimes + this.stopTimes = stopTimes.map { it.toMutableList() } + } + + fun addStopTime(stopTime: StopTime) = apply { + stopTimes = + (stopTimes ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(stopTime) + } } fun timeZone(timeZone: String) = timeZone(JsonField.of(timeZone)) - @JsonProperty("timeZone") - @ExcludeMissing fun timeZone(timeZone: JsonField) = apply { this.timeZone = timeZone } + fun frequency(frequency: String?) = frequency(JsonField.ofNullable(frequency)) + + fun frequency(frequency: Optional) = frequency(frequency.orElse(null)) + + fun frequency(frequency: JsonField) = apply { + this.frequency = frequency + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -547,32 +641,51 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Schedule = Schedule( + checkRequired("nextTripId", nextTripId), + checkRequired("previousTripId", previousTripId), + checkRequired("stopTimes", stopTimes).map { it.toImmutable() }, + checkRequired("timeZone", timeZone), frequency, - nextTripId, - previousTripId, - stopTimes.map { it.toImmutable() }, - timeZone, additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = StopTime.Builder::class) @NoAutoDetect class StopTime + @JsonCreator private constructor( - private val arrivalTime: JsonField, - private val departureTime: JsonField, - private val distanceAlongTrip: JsonField, - private val historicalOccupancy: JsonField, - private val stopHeadsign: JsonField, - private val stopId: JsonField, - private val additionalProperties: Map, + @JsonProperty("arrivalTime") + @ExcludeMissing + private val arrivalTime: JsonField = JsonMissing.of(), + @JsonProperty("departureTime") + @ExcludeMissing + private val departureTime: JsonField = JsonMissing.of(), + @JsonProperty("distanceAlongTrip") + @ExcludeMissing + private val distanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("historicalOccupancy") + @ExcludeMissing + private val historicalOccupancy: JsonField = JsonMissing.of(), + @JsonProperty("stopHeadsign") + @ExcludeMissing + private val stopHeadsign: JsonField = JsonMissing.of(), + @JsonProperty("stopId") + @ExcludeMissing + private val stopId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun arrivalTime(): Optional = Optional.ofNullable(arrivalTime.getNullable("arrivalTime")) @@ -591,38 +704,48 @@ private constructor( fun stopId(): Optional = Optional.ofNullable(stopId.getNullable("stopId")) - @JsonProperty("arrivalTime") @ExcludeMissing fun _arrivalTime() = arrivalTime + @JsonProperty("arrivalTime") + @ExcludeMissing + fun _arrivalTime(): JsonField = arrivalTime @JsonProperty("departureTime") @ExcludeMissing - fun _departureTime() = departureTime + fun _departureTime(): JsonField = departureTime @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip + fun _distanceAlongTrip(): JsonField = distanceAlongTrip @JsonProperty("historicalOccupancy") @ExcludeMissing - fun _historicalOccupancy() = historicalOccupancy + fun _historicalOccupancy(): JsonField = historicalOccupancy - @JsonProperty("stopHeadsign") @ExcludeMissing fun _stopHeadsign() = stopHeadsign + @JsonProperty("stopHeadsign") + @ExcludeMissing + fun _stopHeadsign(): JsonField = stopHeadsign - @JsonProperty("stopId") @ExcludeMissing fun _stopId() = stopId + @JsonProperty("stopId") + @ExcludeMissing + fun _stopId(): JsonField = stopId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): StopTime = apply { - if (!validated) { - arrivalTime() - departureTime() - distanceAlongTrip() - historicalOccupancy() - stopHeadsign() - stopId() - validated = true + if (validated) { + return@apply } + + arrivalTime() + departureTime() + distanceAlongTrip() + historicalOccupancy() + stopHeadsign() + stopId() + validated = true } fun toBuilder() = Builder().from(this) @@ -632,7 +755,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [StopTime]. */ + class Builder internal constructor() { private var arrivalTime: JsonField = JsonMissing.of() private var departureTime: JsonField = JsonMissing.of() @@ -645,19 +769,17 @@ private constructor( @JvmSynthetic internal fun from(stopTime: StopTime) = apply { - this.arrivalTime = stopTime.arrivalTime - this.departureTime = stopTime.departureTime - this.distanceAlongTrip = stopTime.distanceAlongTrip - this.historicalOccupancy = stopTime.historicalOccupancy - this.stopHeadsign = stopTime.stopHeadsign - this.stopId = stopTime.stopId - additionalProperties(stopTime.additionalProperties) + arrivalTime = stopTime.arrivalTime + departureTime = stopTime.departureTime + distanceAlongTrip = stopTime.distanceAlongTrip + historicalOccupancy = stopTime.historicalOccupancy + stopHeadsign = stopTime.stopHeadsign + stopId = stopTime.stopId + additionalProperties = stopTime.additionalProperties.toMutableMap() } fun arrivalTime(arrivalTime: Long) = arrivalTime(JsonField.of(arrivalTime)) - @JsonProperty("arrivalTime") - @ExcludeMissing fun arrivalTime(arrivalTime: JsonField) = apply { this.arrivalTime = arrivalTime } @@ -665,8 +787,6 @@ private constructor( fun departureTime(departureTime: Long) = departureTime(JsonField.of(departureTime)) - @JsonProperty("departureTime") - @ExcludeMissing fun departureTime(departureTime: JsonField) = apply { this.departureTime = departureTime } @@ -674,8 +794,6 @@ private constructor( fun distanceAlongTrip(distanceAlongTrip: Double) = distanceAlongTrip(JsonField.of(distanceAlongTrip)) - @JsonProperty("distanceAlongTrip") - @ExcludeMissing fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { this.distanceAlongTrip = distanceAlongTrip } @@ -683,8 +801,6 @@ private constructor( fun historicalOccupancy(historicalOccupancy: String) = historicalOccupancy(JsonField.of(historicalOccupancy)) - @JsonProperty("historicalOccupancy") - @ExcludeMissing fun historicalOccupancy(historicalOccupancy: JsonField) = apply { this.historicalOccupancy = historicalOccupancy } @@ -692,33 +808,36 @@ private constructor( fun stopHeadsign(stopHeadsign: String) = stopHeadsign(JsonField.of(stopHeadsign)) - @JsonProperty("stopHeadsign") - @ExcludeMissing fun stopHeadsign(stopHeadsign: JsonField) = apply { this.stopHeadsign = stopHeadsign } fun stopId(stopId: String) = stopId(JsonField.of(stopId)) - @JsonProperty("stopId") - @ExcludeMissing fun stopId(stopId: JsonField) = apply { this.stopId = stopId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): StopTime = StopTime( arrivalTime, @@ -736,17 +855,14 @@ private constructor( return true } - return /* spotless:off */ other is StopTime && this.arrivalTime == other.arrivalTime && this.departureTime == other.departureTime && this.distanceAlongTrip == other.distanceAlongTrip && this.historicalOccupancy == other.historicalOccupancy && this.stopHeadsign == other.stopHeadsign && this.stopId == other.stopId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is StopTime && arrivalTime == other.arrivalTime && departureTime == other.departureTime && distanceAlongTrip == other.distanceAlongTrip && historicalOccupancy == other.historicalOccupancy && stopHeadsign == other.stopHeadsign && stopId == other.stopId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(arrivalTime, departureTime, distanceAlongTrip, historicalOccupancy, stopHeadsign, stopId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(arrivalTime, departureTime, distanceAlongTrip, historicalOccupancy, stopHeadsign, stopId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "StopTime{arrivalTime=$arrivalTime, departureTime=$departureTime, distanceAlongTrip=$distanceAlongTrip, historicalOccupancy=$historicalOccupancy, stopHeadsign=$stopHeadsign, stopId=$stopId, additionalProperties=$additionalProperties}" @@ -757,97 +873,129 @@ private constructor( return true } - return /* spotless:off */ other is Schedule && this.frequency == other.frequency && this.nextTripId == other.nextTripId && this.previousTripId == other.previousTripId && this.stopTimes == other.stopTimes && this.timeZone == other.timeZone && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Schedule && nextTripId == other.nextTripId && previousTripId == other.previousTripId && stopTimes == other.stopTimes && timeZone == other.timeZone && frequency == other.frequency && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(nextTripId, previousTripId, stopTimes, timeZone, frequency, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(frequency, nextTripId, previousTripId, stopTimes, timeZone, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Schedule{frequency=$frequency, nextTripId=$nextTripId, previousTripId=$previousTripId, stopTimes=$stopTimes, timeZone=$timeZone, additionalProperties=$additionalProperties}" + "Schedule{nextTripId=$nextTripId, previousTripId=$previousTripId, stopTimes=$stopTimes, timeZone=$timeZone, frequency=$frequency, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = Status.Builder::class) @NoAutoDetect class Status + @JsonCreator private constructor( - private val activeTripId: JsonField, - private val blockTripSequence: JsonField, - private val closestStop: JsonField, - private val closestStopTimeOffset: JsonField, - private val distanceAlongTrip: JsonField, - private val frequency: JsonField, - private val lastKnownDistanceAlongTrip: JsonField, - private val lastKnownLocation: JsonField, - private val lastKnownOrientation: JsonField, - private val lastLocationUpdateTime: JsonField, - private val lastUpdateTime: JsonField, - private val nextStop: JsonField, - private val nextStopTimeOffset: JsonField, - private val occupancyCapacity: JsonField, - private val occupancyCount: JsonField, - private val occupancyStatus: JsonField, - private val orientation: JsonField, - private val phase: JsonField, - private val position: JsonField, - private val predicted: JsonField, - private val scheduleDeviation: JsonField, - private val scheduledDistanceAlongTrip: JsonField, - private val serviceDate: JsonField, - private val situationIds: JsonField>, - private val status: JsonField, - private val totalDistanceAlongTrip: JsonField, - private val vehicleId: JsonField, - private val additionalProperties: Map, - ) { - - private var validated: Boolean = false - - /** Trip ID of the trip the vehicle is actively serving. */ - fun activeTripId(): String = activeTripId.getRequired("activeTripId") - - /** Index of the active trip into the sequence of trips for the active block. */ - fun blockTripSequence(): Long = blockTripSequence.getRequired("blockTripSequence") - - /** ID of the closest stop to the current location of the transit vehicle. */ - fun closestStop(): String = closestStop.getRequired("closestStop") - - /** - * Time offset from the closest stop to the current position of the transit vehicle - * (in seconds). - */ - fun closestStopTimeOffset(): Optional = - Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) - - /** - * Distance, in meters, the transit vehicle has progressed along the active trip. - */ - fun distanceAlongTrip(): Double = distanceAlongTrip.getRequired("distanceAlongTrip") - - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - - /** - * Last known distance along the trip received in real-time from the transit - * vehicle. - */ - fun lastKnownDistanceAlongTrip(): Double = - lastKnownDistanceAlongTrip.getRequired("lastKnownDistanceAlongTrip") - - /** Last known location of the transit vehicle. */ - fun lastKnownLocation(): Optional = - Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) - - /** Last known orientation value received in real-time from the transit vehicle. */ - fun lastKnownOrientation(): Optional = - Optional.ofNullable(lastKnownOrientation.getNullable("lastKnownOrientation")) + @JsonProperty("activeTripId") + @ExcludeMissing + private val activeTripId: JsonField = JsonMissing.of(), + @JsonProperty("blockTripSequence") + @ExcludeMissing + private val blockTripSequence: JsonField = JsonMissing.of(), + @JsonProperty("closestStop") + @ExcludeMissing + private val closestStop: JsonField = JsonMissing.of(), + @JsonProperty("distanceAlongTrip") + @ExcludeMissing + private val distanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownDistanceAlongTrip") + @ExcludeMissing + private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastLocationUpdateTime") + @ExcludeMissing + private val lastLocationUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("lastUpdateTime") + @ExcludeMissing + private val lastUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCapacity") + @ExcludeMissing + private val occupancyCapacity: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCount") + @ExcludeMissing + private val occupancyCount: JsonField = JsonMissing.of(), + @JsonProperty("occupancyStatus") + @ExcludeMissing + private val occupancyStatus: JsonField = JsonMissing.of(), + @JsonProperty("phase") + @ExcludeMissing + private val phase: JsonField = JsonMissing.of(), + @JsonProperty("predicted") + @ExcludeMissing + private val predicted: JsonField = JsonMissing.of(), + @JsonProperty("scheduleDeviation") + @ExcludeMissing + private val scheduleDeviation: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonProperty("totalDistanceAlongTrip") + @ExcludeMissing + private val totalDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + private val closestStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownLocation") + @ExcludeMissing + private val lastKnownLocation: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + private val lastKnownOrientation: JsonField = JsonMissing.of(), + @JsonProperty("nextStop") + @ExcludeMissing + private val nextStop: JsonField = JsonMissing.of(), + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + private val nextStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("orientation") + @ExcludeMissing + private val orientation: JsonField = JsonMissing.of(), + @JsonProperty("position") + @ExcludeMissing + private val position: JsonField = JsonMissing.of(), + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + private val scheduledDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = + JsonMissing.of(), + @JsonProperty("vehicleId") + @ExcludeMissing + private val vehicleId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), + ) { + + /** Trip ID of the trip the vehicle is actively serving. */ + fun activeTripId(): String = activeTripId.getRequired("activeTripId") + + /** Index of the active trip into the sequence of trips for the active block. */ + fun blockTripSequence(): Long = blockTripSequence.getRequired("blockTripSequence") + + /** ID of the closest stop to the current location of the transit vehicle. */ + fun closestStop(): String = closestStop.getRequired("closestStop") + + /** + * Distance, in meters, the transit vehicle has progressed along the active trip. + */ + fun distanceAlongTrip(): Double = distanceAlongTrip.getRequired("distanceAlongTrip") + + /** + * Last known distance along the trip received in real-time from the transit + * vehicle. + */ + fun lastKnownDistanceAlongTrip(): Double = + lastKnownDistanceAlongTrip.getRequired("lastKnownDistanceAlongTrip") /** * Timestamp of the last known real-time location update from the transit vehicle. @@ -858,17 +1006,6 @@ private constructor( /** Timestamp of the last known real-time update from the transit vehicle. */ fun lastUpdateTime(): Long = lastUpdateTime.getRequired("lastUpdateTime") - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - fun nextStop(): Optional = - Optional.ofNullable(nextStop.getNullable("nextStop")) - - /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). - */ - fun nextStopTimeOffset(): Optional = - Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(): Long = occupancyCapacity.getRequired("occupancyCapacity") @@ -878,17 +1015,9 @@ private constructor( /** Current occupancy status of the transit vehicle. */ fun occupancyStatus(): String = occupancyStatus.getRequired("occupancyStatus") - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - fun orientation(): Optional = - Optional.ofNullable(orientation.getNullable("orientation")) - /** Current journey phase of the trip. */ fun phase(): String = phase.getRequired("phase") - /** Current position of the transit vehicle. */ - fun position(): Optional = - Optional.ofNullable(position.getNullable("position")) - /** Indicates if real-time arrival info is available for this trip. */ fun predicted(): Boolean = predicted.getRequired("predicted") @@ -897,25 +1026,12 @@ private constructor( */ fun scheduleDeviation(): Long = scheduleDeviation.getRequired("scheduleDeviation") - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed along - * the active trip. - */ - fun scheduledDistanceAlongTrip(): Optional = - Optional.ofNullable( - scheduledDistanceAlongTrip.getNullable("scheduledDistanceAlongTrip") - ) - /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ fun serviceDate(): Long = serviceDate.getRequired("serviceDate") - /** References to situation elements (if any) applicable to this trip. */ - fun situationIds(): Optional> = - Optional.ofNullable(situationIds.getNullable("situationIds")) - /** Current status modifiers for the trip. */ fun status(): String = status.getRequired("status") @@ -923,38 +1039,82 @@ private constructor( fun totalDistanceAlongTrip(): Double = totalDistanceAlongTrip.getRequired("totalDistanceAlongTrip") + /** + * Time offset from the closest stop to the current position of the transit vehicle + * (in seconds). + */ + fun closestStopTimeOffset(): Optional = + Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(): Optional = + Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) + + /** Last known orientation value received in real-time from the transit vehicle. */ + fun lastKnownOrientation(): Optional = + Optional.ofNullable(lastKnownOrientation.getNullable("lastKnownOrientation")) + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(): Optional = + Optional.ofNullable(nextStop.getNullable("nextStop")) + + /** + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). + */ + fun nextStopTimeOffset(): Optional = + Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(): Optional = + Optional.ofNullable(orientation.getNullable("orientation")) + + /** Current position of the transit vehicle. */ + fun position(): Optional = + Optional.ofNullable(position.getNullable("position")) + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed along + * the active trip. + */ + fun scheduledDistanceAlongTrip(): Optional = + Optional.ofNullable( + scheduledDistanceAlongTrip.getNullable("scheduledDistanceAlongTrip") + ) + + /** References to situation elements (if any) applicable to this trip. */ + fun situationIds(): Optional> = + Optional.ofNullable(situationIds.getNullable("situationIds")) + /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(): Optional = Optional.ofNullable(vehicleId.getNullable("vehicleId")) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") @ExcludeMissing fun _activeTripId() = activeTripId + @JsonProperty("activeTripId") + @ExcludeMissing + fun _activeTripId(): JsonField = activeTripId /** Index of the active trip into the sequence of trips for the active block. */ @JsonProperty("blockTripSequence") @ExcludeMissing - fun _blockTripSequence() = blockTripSequence + fun _blockTripSequence(): JsonField = blockTripSequence /** ID of the closest stop to the current location of the transit vehicle. */ - @JsonProperty("closestStop") @ExcludeMissing fun _closestStop() = closestStop - - /** - * Time offset from the closest stop to the current position of the transit vehicle - * (in seconds). - */ - @JsonProperty("closestStopTimeOffset") + @JsonProperty("closestStop") @ExcludeMissing - fun _closestStopTimeOffset() = closestStopTimeOffset + fun _closestStop(): JsonField = closestStop /** * Distance, in meters, the transit vehicle has progressed along the active trip. */ @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + fun _distanceAlongTrip(): JsonField = distanceAlongTrip /** * Last known distance along the trip received in real-time from the transit @@ -962,138 +1122,169 @@ private constructor( */ @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing - fun _lastKnownDistanceAlongTrip() = lastKnownDistanceAlongTrip - - /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun _lastKnownLocation() = lastKnownLocation - - /** Last known orientation value received in real-time from the transit vehicle. */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun _lastKnownOrientation() = lastKnownOrientation + fun _lastKnownDistanceAlongTrip(): JsonField = lastKnownDistanceAlongTrip /** * Timestamp of the last known real-time location update from the transit vehicle. */ @JsonProperty("lastLocationUpdateTime") @ExcludeMissing - fun _lastLocationUpdateTime() = lastLocationUpdateTime + fun _lastLocationUpdateTime(): JsonField = lastLocationUpdateTime /** Timestamp of the last known real-time update from the transit vehicle. */ @JsonProperty("lastUpdateTime") @ExcludeMissing - fun _lastUpdateTime() = lastUpdateTime - - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") @ExcludeMissing fun _nextStop() = nextStop - - /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). - */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - fun _nextStopTimeOffset() = nextStopTimeOffset + fun _lastUpdateTime(): JsonField = lastUpdateTime /** Capacity of the transit vehicle in terms of occupancy. */ @JsonProperty("occupancyCapacity") @ExcludeMissing - fun _occupancyCapacity() = occupancyCapacity + fun _occupancyCapacity(): JsonField = occupancyCapacity /** Current count of occupants in the transit vehicle. */ @JsonProperty("occupancyCount") @ExcludeMissing - fun _occupancyCount() = occupancyCount + fun _occupancyCount(): JsonField = occupancyCount /** Current occupancy status of the transit vehicle. */ @JsonProperty("occupancyStatus") @ExcludeMissing - fun _occupancyStatus() = occupancyStatus - - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") @ExcludeMissing fun _orientation() = orientation + fun _occupancyStatus(): JsonField = occupancyStatus /** Current journey phase of the trip. */ - @JsonProperty("phase") @ExcludeMissing fun _phase() = phase - - /** Current position of the transit vehicle. */ - @JsonProperty("position") @ExcludeMissing fun _position() = position + @JsonProperty("phase") @ExcludeMissing fun _phase(): JsonField = phase /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") @ExcludeMissing fun _predicted() = predicted + @JsonProperty("predicted") + @ExcludeMissing + fun _predicted(): JsonField = predicted /** * Deviation from the schedule in seconds (positive for late, negative for early). */ @JsonProperty("scheduleDeviation") @ExcludeMissing - fun _scheduleDeviation() = scheduleDeviation - - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed along - * the active trip. - */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - fun _scheduledDistanceAlongTrip() = scheduledDistanceAlongTrip + fun _scheduleDeviation(): JsonField = scheduleDeviation /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate - - /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate /** Current status modifiers for the trip. */ - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status /** Total length of the trip, in meters. */ @JsonProperty("totalDistanceAlongTrip") @ExcludeMissing - fun _totalDistanceAlongTrip() = totalDistanceAlongTrip + fun _totalDistanceAlongTrip(): JsonField = totalDistanceAlongTrip + + /** + * Time offset from the closest stop to the current position of the transit vehicle + * (in seconds). + */ + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + fun _closestStopTimeOffset(): JsonField = closestStopTimeOffset + + /** Information about frequency-based scheduling, if applicable to the trip. */ + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency + + /** Last known location of the transit vehicle. */ + @JsonProperty("lastKnownLocation") + @ExcludeMissing + fun _lastKnownLocation(): JsonField = lastKnownLocation + + /** Last known orientation value received in real-time from the transit vehicle. */ + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + fun _lastKnownOrientation(): JsonField = lastKnownOrientation + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + @JsonProperty("nextStop") + @ExcludeMissing + fun _nextStop(): JsonField = nextStop + + /** + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). + */ + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + fun _nextStopTimeOffset(): JsonField = nextStopTimeOffset + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + @JsonProperty("orientation") + @ExcludeMissing + fun _orientation(): JsonField = orientation + + /** Current position of the transit vehicle. */ + @JsonProperty("position") + @ExcludeMissing + fun _position(): JsonField = position + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed along + * the active trip. + */ + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + fun _scheduledDistanceAlongTrip(): JsonField = scheduledDistanceAlongTrip + + /** References to situation elements (if any) applicable to this trip. */ + @JsonProperty("situationIds") + @ExcludeMissing + fun _situationIds(): JsonField> = situationIds /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") @ExcludeMissing fun _vehicleId() = vehicleId + @JsonProperty("vehicleId") + @ExcludeMissing + fun _vehicleId(): JsonField = vehicleId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Status = apply { - if (!validated) { - activeTripId() - blockTripSequence() - closestStop() - closestStopTimeOffset() - distanceAlongTrip() - frequency() - lastKnownDistanceAlongTrip() - lastKnownLocation().map { it.validate() } - lastKnownOrientation() - lastLocationUpdateTime() - lastUpdateTime() - nextStop() - nextStopTimeOffset() - occupancyCapacity() - occupancyCount() - occupancyStatus() - orientation() - phase() - position().map { it.validate() } - predicted() - scheduleDeviation() - scheduledDistanceAlongTrip() - serviceDate() - situationIds() - status() - totalDistanceAlongTrip() - vehicleId() - validated = true + if (validated) { + return@apply } + + activeTripId() + blockTripSequence() + closestStop() + distanceAlongTrip() + lastKnownDistanceAlongTrip() + lastLocationUpdateTime() + lastUpdateTime() + occupancyCapacity() + occupancyCount() + occupancyStatus() + phase() + predicted() + scheduleDeviation() + serviceDate() + status() + totalDistanceAlongTrip() + closestStopTimeOffset() + frequency() + lastKnownLocation().ifPresent { it.validate() } + lastKnownOrientation() + nextStop() + nextStopTimeOffset() + orientation() + position().ifPresent { it.validate() } + scheduledDistanceAlongTrip() + situationIds() + vehicleId() + validated = true } fun toBuilder() = Builder().from(this) @@ -1103,68 +1294,68 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - - private var activeTripId: JsonField = JsonMissing.of() - private var blockTripSequence: JsonField = JsonMissing.of() - private var closestStop: JsonField = JsonMissing.of() + /** A builder for [Status]. */ + class Builder internal constructor() { + + private var activeTripId: JsonField? = null + private var blockTripSequence: JsonField? = null + private var closestStop: JsonField? = null + private var distanceAlongTrip: JsonField? = null + private var lastKnownDistanceAlongTrip: JsonField? = null + private var lastLocationUpdateTime: JsonField? = null + private var lastUpdateTime: JsonField? = null + private var occupancyCapacity: JsonField? = null + private var occupancyCount: JsonField? = null + private var occupancyStatus: JsonField? = null + private var phase: JsonField? = null + private var predicted: JsonField? = null + private var scheduleDeviation: JsonField? = null + private var serviceDate: JsonField? = null + private var status: JsonField? = null + private var totalDistanceAlongTrip: JsonField? = null private var closestStopTimeOffset: JsonField = JsonMissing.of() - private var distanceAlongTrip: JsonField = JsonMissing.of() private var frequency: JsonField = JsonMissing.of() - private var lastKnownDistanceAlongTrip: JsonField = JsonMissing.of() private var lastKnownLocation: JsonField = JsonMissing.of() private var lastKnownOrientation: JsonField = JsonMissing.of() - private var lastLocationUpdateTime: JsonField = JsonMissing.of() - private var lastUpdateTime: JsonField = JsonMissing.of() private var nextStop: JsonField = JsonMissing.of() private var nextStopTimeOffset: JsonField = JsonMissing.of() - private var occupancyCapacity: JsonField = JsonMissing.of() - private var occupancyCount: JsonField = JsonMissing.of() - private var occupancyStatus: JsonField = JsonMissing.of() private var orientation: JsonField = JsonMissing.of() - private var phase: JsonField = JsonMissing.of() private var position: JsonField = JsonMissing.of() - private var predicted: JsonField = JsonMissing.of() - private var scheduleDeviation: JsonField = JsonMissing.of() private var scheduledDistanceAlongTrip: JsonField = JsonMissing.of() - private var serviceDate: JsonField = JsonMissing.of() - private var situationIds: JsonField> = - JsonMissing.of() - private var status: JsonField = JsonMissing.of() - private var totalDistanceAlongTrip: JsonField = JsonMissing.of() + private var situationIds: JsonField>? = null private var vehicleId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(status: Status) = apply { - this.activeTripId = status.activeTripId - this.blockTripSequence = status.blockTripSequence - this.closestStop = status.closestStop - this.closestStopTimeOffset = status.closestStopTimeOffset - this.distanceAlongTrip = status.distanceAlongTrip - this.frequency = status.frequency - this.lastKnownDistanceAlongTrip = status.lastKnownDistanceAlongTrip - this.lastKnownLocation = status.lastKnownLocation - this.lastKnownOrientation = status.lastKnownOrientation - this.lastLocationUpdateTime = status.lastLocationUpdateTime - this.lastUpdateTime = status.lastUpdateTime - this.nextStop = status.nextStop - this.nextStopTimeOffset = status.nextStopTimeOffset - this.occupancyCapacity = status.occupancyCapacity - this.occupancyCount = status.occupancyCount - this.occupancyStatus = status.occupancyStatus - this.orientation = status.orientation - this.phase = status.phase - this.position = status.position - this.predicted = status.predicted - this.scheduleDeviation = status.scheduleDeviation - this.scheduledDistanceAlongTrip = status.scheduledDistanceAlongTrip - this.serviceDate = status.serviceDate - this.situationIds = status.situationIds + activeTripId = status.activeTripId + blockTripSequence = status.blockTripSequence + closestStop = status.closestStop + distanceAlongTrip = status.distanceAlongTrip + lastKnownDistanceAlongTrip = status.lastKnownDistanceAlongTrip + lastLocationUpdateTime = status.lastLocationUpdateTime + lastUpdateTime = status.lastUpdateTime + occupancyCapacity = status.occupancyCapacity + occupancyCount = status.occupancyCount + occupancyStatus = status.occupancyStatus + phase = status.phase + predicted = status.predicted + scheduleDeviation = status.scheduleDeviation + serviceDate = status.serviceDate this.status = status.status - this.totalDistanceAlongTrip = status.totalDistanceAlongTrip - this.vehicleId = status.vehicleId - additionalProperties(status.additionalProperties) + totalDistanceAlongTrip = status.totalDistanceAlongTrip + closestStopTimeOffset = status.closestStopTimeOffset + frequency = status.frequency + lastKnownLocation = status.lastKnownLocation + lastKnownOrientation = status.lastKnownOrientation + nextStop = status.nextStop + nextStopTimeOffset = status.nextStopTimeOffset + orientation = status.orientation + position = status.position + scheduledDistanceAlongTrip = status.scheduledDistanceAlongTrip + situationIds = status.situationIds.map { it.toMutableList() } + vehicleId = status.vehicleId + additionalProperties = status.additionalProperties.toMutableMap() } /** Trip ID of the trip the vehicle is actively serving. */ @@ -1172,8 +1363,6 @@ private constructor( activeTripId(JsonField.of(activeTripId)) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") - @ExcludeMissing fun activeTripId(activeTripId: JsonField) = apply { this.activeTripId = activeTripId } @@ -1183,8 +1372,6 @@ private constructor( blockTripSequence(JsonField.of(blockTripSequence)) /** Index of the active trip into the sequence of trips for the active block. */ - @JsonProperty("blockTripSequence") - @ExcludeMissing fun blockTripSequence(blockTripSequence: JsonField) = apply { this.blockTripSequence = blockTripSequence } @@ -1193,29 +1380,10 @@ private constructor( fun closestStop(closestStop: String) = closestStop(JsonField.of(closestStop)) /** ID of the closest stop to the current location of the transit vehicle. */ - @JsonProperty("closestStop") - @ExcludeMissing fun closestStop(closestStop: JsonField) = apply { this.closestStop = closestStop } - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - fun closestStopTimeOffset(closestStopTimeOffset: Long) = - closestStopTimeOffset(JsonField.of(closestStopTimeOffset)) - - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing - fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { - this.closestStopTimeOffset = closestStopTimeOffset - } - /** * Distance, in meters, the transit vehicle has progressed along the active * trip. @@ -1227,22 +1395,10 @@ private constructor( * Distance, in meters, the transit vehicle has progressed along the active * trip. */ - @JsonProperty("distanceAlongTrip") - @ExcludeMissing fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { this.distanceAlongTrip = distanceAlongTrip } - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") - @ExcludeMissing - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1254,39 +1410,11 @@ private constructor( * Last known distance along the trip received in real-time from the transit * vehicle. */ - @JsonProperty("lastKnownDistanceAlongTrip") - @ExcludeMissing fun lastKnownDistanceAlongTrip(lastKnownDistanceAlongTrip: JsonField) = apply { this.lastKnownDistanceAlongTrip = lastKnownDistanceAlongTrip } - /** Last known location of the transit vehicle. */ - fun lastKnownLocation(lastKnownLocation: LastKnownLocation) = - lastKnownLocation(JsonField.of(lastKnownLocation)) - - /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun lastKnownLocation(lastKnownLocation: JsonField) = apply { - this.lastKnownLocation = lastKnownLocation - } - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - fun lastKnownOrientation(lastKnownOrientation: Double) = - lastKnownOrientation(JsonField.of(lastKnownOrientation)) - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun lastKnownOrientation(lastKnownOrientation: JsonField) = apply { - this.lastKnownOrientation = lastKnownOrientation - } - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1298,8 +1426,6 @@ private constructor( * Timestamp of the last known real-time location update from the transit * vehicle. */ - @JsonProperty("lastLocationUpdateTime") - @ExcludeMissing fun lastLocationUpdateTime(lastLocationUpdateTime: JsonField) = apply { this.lastLocationUpdateTime = lastLocationUpdateTime } @@ -1309,44 +1435,15 @@ private constructor( lastUpdateTime(JsonField.of(lastUpdateTime)) /** Timestamp of the last known real-time update from the transit vehicle. */ - @JsonProperty("lastUpdateTime") - @ExcludeMissing fun lastUpdateTime(lastUpdateTime: JsonField) = apply { this.lastUpdateTime = lastUpdateTime } - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - fun nextStop(nextStop: String) = nextStop(JsonField.of(nextStop)) - - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") - @ExcludeMissing - fun nextStop(nextStop: JsonField) = apply { this.nextStop = nextStop } - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - fun nextStopTimeOffset(nextStopTimeOffset: Long) = - nextStopTimeOffset(JsonField.of(nextStopTimeOffset)) - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - fun nextStopTimeOffset(nextStopTimeOffset: JsonField) = apply { - this.nextStopTimeOffset = nextStopTimeOffset - } - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) /** Capacity of the transit vehicle in terms of occupancy. */ - @JsonProperty("occupancyCapacity") - @ExcludeMissing fun occupancyCapacity(occupancyCapacity: JsonField) = apply { this.occupancyCapacity = occupancyCapacity } @@ -1356,8 +1453,6 @@ private constructor( occupancyCount(JsonField.of(occupancyCount)) /** Current count of occupants in the transit vehicle. */ - @JsonProperty("occupancyCount") - @ExcludeMissing fun occupancyCount(occupancyCount: JsonField) = apply { this.occupancyCount = occupancyCount } @@ -1367,44 +1462,20 @@ private constructor( occupancyStatus(JsonField.of(occupancyStatus)) /** Current occupancy status of the transit vehicle. */ - @JsonProperty("occupancyStatus") - @ExcludeMissing fun occupancyStatus(occupancyStatus: JsonField) = apply { this.occupancyStatus = occupancyStatus } - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - fun orientation(orientation: Double) = orientation(JsonField.of(orientation)) - - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") - @ExcludeMissing - fun orientation(orientation: JsonField) = apply { - this.orientation = orientation - } - /** Current journey phase of the trip. */ fun phase(phase: String) = phase(JsonField.of(phase)) /** Current journey phase of the trip. */ - @JsonProperty("phase") - @ExcludeMissing fun phase(phase: JsonField) = apply { this.phase = phase } - /** Current position of the transit vehicle. */ - fun position(position: Position) = position(JsonField.of(position)) - - /** Current position of the transit vehicle. */ - @JsonProperty("position") - @ExcludeMissing - fun position(position: JsonField) = apply { this.position = position } - /** Indicates if real-time arrival info is available for this trip. */ fun predicted(predicted: Boolean) = predicted(JsonField.of(predicted)) /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") - @ExcludeMissing fun predicted(predicted: JsonField) = apply { this.predicted = predicted } @@ -1420,30 +1491,10 @@ private constructor( * Deviation from the schedule in seconds (positive for late, negative for * early). */ - @JsonProperty("scheduleDeviation") - @ExcludeMissing fun scheduleDeviation(scheduleDeviation: JsonField) = apply { this.scheduleDeviation = scheduleDeviation } - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed - * along the active trip. - */ - fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: Double) = - scheduledDistanceAlongTrip(JsonField.of(scheduledDistanceAlongTrip)) - - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed - * along the active trip. - */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: JsonField) = - apply { - this.scheduledDistanceAlongTrip = scheduledDistanceAlongTrip - } - /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. @@ -1454,30 +1505,14 @@ private constructor( * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") - @ExcludeMissing fun serviceDate(serviceDate: JsonField) = apply { this.serviceDate = serviceDate } - /** References to situation elements (if any) applicable to this trip. */ - fun situationIds(situationIds: kotlin.collections.List) = - situationIds(JsonField.of(situationIds)) - - /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") - @ExcludeMissing - fun situationIds(situationIds: JsonField>) = - apply { - this.situationIds = situationIds - } - /** Current status modifiers for the trip. */ fun status(status: String) = status(JsonField.of(status)) /** Current status modifiers for the trip. */ - @JsonProperty("status") - @ExcludeMissing fun status(status: JsonField) = apply { this.status = status } /** Total length of the trip, in meters. */ @@ -1485,30 +1520,145 @@ private constructor( totalDistanceAlongTrip(JsonField.of(totalDistanceAlongTrip)) /** Total length of the trip, in meters. */ - @JsonProperty("totalDistanceAlongTrip") - @ExcludeMissing fun totalDistanceAlongTrip(totalDistanceAlongTrip: JsonField) = apply { this.totalDistanceAlongTrip = totalDistanceAlongTrip } + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + fun closestStopTimeOffset(closestStopTimeOffset: Long) = + closestStopTimeOffset(JsonField.of(closestStopTimeOffset)) + + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { + this.closestStopTimeOffset = closestStopTimeOffset + } + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: String) = frequency(JsonField.of(frequency)) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: JsonField) = apply { + this.frequency = frequency + } + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(lastKnownLocation: LastKnownLocation) = + lastKnownLocation(JsonField.of(lastKnownLocation)) + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(lastKnownLocation: JsonField) = apply { + this.lastKnownLocation = lastKnownLocation + } + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + fun lastKnownOrientation(lastKnownOrientation: Double) = + lastKnownOrientation(JsonField.of(lastKnownOrientation)) + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + fun lastKnownOrientation(lastKnownOrientation: JsonField) = apply { + this.lastKnownOrientation = lastKnownOrientation + } + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(nextStop: String) = nextStop(JsonField.of(nextStop)) + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(nextStop: JsonField) = apply { this.nextStop = nextStop } + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + fun nextStopTimeOffset(nextStopTimeOffset: Long) = + nextStopTimeOffset(JsonField.of(nextStopTimeOffset)) + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + fun nextStopTimeOffset(nextStopTimeOffset: JsonField) = apply { + this.nextStopTimeOffset = nextStopTimeOffset + } + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(orientation: Double) = orientation(JsonField.of(orientation)) + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(orientation: JsonField) = apply { + this.orientation = orientation + } + + /** Current position of the transit vehicle. */ + fun position(position: Position) = position(JsonField.of(position)) + + /** Current position of the transit vehicle. */ + fun position(position: JsonField) = apply { this.position = position } + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed + * along the active trip. + */ + fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: Double) = + scheduledDistanceAlongTrip(JsonField.of(scheduledDistanceAlongTrip)) + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed + * along the active trip. + */ + fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: JsonField) = + apply { + this.scheduledDistanceAlongTrip = scheduledDistanceAlongTrip + } + + /** References to situation elements (if any) applicable to this trip. */ + fun situationIds(situationIds: kotlin.collections.List) = + situationIds(JsonField.of(situationIds)) + + /** References to situation elements (if any) applicable to this trip. */ + fun situationIds(situationIds: JsonField>) = + apply { + this.situationIds = situationIds.map { it.toMutableList() } + } + + /** References to situation elements (if any) applicable to this trip. */ + fun addSituationId(situationId: String) = apply { + situationIds = + (situationIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situationId) + } + } + /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(vehicleId: String) = vehicleId(JsonField.of(vehicleId)) /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") - @ExcludeMissing fun vehicleId(vehicleId: JsonField) = apply { this.vehicleId = vehicleId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1516,51 +1666,62 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Status = Status( - activeTripId, - blockTripSequence, - closestStop, + checkRequired("activeTripId", activeTripId), + checkRequired("blockTripSequence", blockTripSequence), + checkRequired("closestStop", closestStop), + checkRequired("distanceAlongTrip", distanceAlongTrip), + checkRequired("lastKnownDistanceAlongTrip", lastKnownDistanceAlongTrip), + checkRequired("lastLocationUpdateTime", lastLocationUpdateTime), + checkRequired("lastUpdateTime", lastUpdateTime), + checkRequired("occupancyCapacity", occupancyCapacity), + checkRequired("occupancyCount", occupancyCount), + checkRequired("occupancyStatus", occupancyStatus), + checkRequired("phase", phase), + checkRequired("predicted", predicted), + checkRequired("scheduleDeviation", scheduleDeviation), + checkRequired("serviceDate", serviceDate), + checkRequired("status", status), + checkRequired("totalDistanceAlongTrip", totalDistanceAlongTrip), closestStopTimeOffset, - distanceAlongTrip, frequency, - lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, - lastLocationUpdateTime, - lastUpdateTime, nextStop, nextStopTimeOffset, - occupancyCapacity, - occupancyCount, - occupancyStatus, orientation, - phase, position, - predicted, - scheduleDeviation, scheduledDistanceAlongTrip, - serviceDate, - situationIds.map { it.toImmutable() }, - status, - totalDistanceAlongTrip, + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, vehicleId, additionalProperties.toImmutable(), ) } /** Last known location of the transit vehicle. */ - @JsonDeserialize(builder = LastKnownLocation.Builder::class) @NoAutoDetect class LastKnownLocation + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the last known location of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -1568,21 +1729,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): LastKnownLocation = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -1592,7 +1757,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [LastKnownLocation]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -1601,42 +1767,46 @@ private constructor( @JvmSynthetic internal fun from(lastKnownLocation: LastKnownLocation) = apply { - this.lat = lastKnownLocation.lat - this.lon = lastKnownLocation.lon - additionalProperties(lastKnownLocation.additionalProperties) + lat = lastKnownLocation.lat + lon = lastKnownLocation.lon + additionalProperties = + lastKnownLocation.additionalProperties.toMutableMap() } /** Latitude of the last known location of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the last known location of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): LastKnownLocation = LastKnownLocation( lat, @@ -1650,34 +1820,34 @@ private constructor( return true } - return /* spotless:off */ other is LastKnownLocation && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is LastKnownLocation && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "LastKnownLocation{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" } /** Current position of the transit vehicle. */ - @JsonDeserialize(builder = Position.Builder::class) @NoAutoDetect class Position + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the current position of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -1685,21 +1855,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Position = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -1709,7 +1883,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Position]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -1718,42 +1893,45 @@ private constructor( @JvmSynthetic internal fun from(position: Position) = apply { - this.lat = position.lat - this.lon = position.lon - additionalProperties(position.additionalProperties) + lat = position.lat + lon = position.lon + additionalProperties = position.additionalProperties.toMutableMap() } /** Latitude of the current position of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the current position of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Position = Position( lat, @@ -1767,17 +1945,14 @@ private constructor( return true } - return /* spotless:off */ other is Position && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Position && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Position{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" @@ -1788,20 +1963,17 @@ private constructor( return true } - return /* spotless:off */ other is Status && this.activeTripId == other.activeTripId && this.blockTripSequence == other.blockTripSequence && this.closestStop == other.closestStop && this.closestStopTimeOffset == other.closestStopTimeOffset && this.distanceAlongTrip == other.distanceAlongTrip && this.frequency == other.frequency && this.lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && this.lastKnownLocation == other.lastKnownLocation && this.lastKnownOrientation == other.lastKnownOrientation && this.lastLocationUpdateTime == other.lastLocationUpdateTime && this.lastUpdateTime == other.lastUpdateTime && this.nextStop == other.nextStop && this.nextStopTimeOffset == other.nextStopTimeOffset && this.occupancyCapacity == other.occupancyCapacity && this.occupancyCount == other.occupancyCount && this.occupancyStatus == other.occupancyStatus && this.orientation == other.orientation && this.phase == other.phase && this.position == other.position && this.predicted == other.predicted && this.scheduleDeviation == other.scheduleDeviation && this.scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && this.serviceDate == other.serviceDate && this.situationIds == other.situationIds && this.status == other.status && this.totalDistanceAlongTrip == other.totalDistanceAlongTrip && this.vehicleId == other.vehicleId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Status && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && distanceAlongTrip == other.distanceAlongTrip && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && phase == other.phase && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && serviceDate == other.serviceDate && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && closestStopTimeOffset == other.closestStopTimeOffset && frequency == other.frequency && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && orientation == other.orientation && position == other.position && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && situationIds == other.situationIds && vehicleId == other.vehicleId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(activeTripId, blockTripSequence, closestStop, distanceAlongTrip, lastKnownDistanceAlongTrip, lastLocationUpdateTime, lastUpdateTime, occupancyCapacity, occupancyCount, occupancyStatus, phase, predicted, scheduleDeviation, serviceDate, status, totalDistanceAlongTrip, closestStopTimeOffset, frequency, lastKnownLocation, lastKnownOrientation, nextStop, nextStopTimeOffset, orientation, position, scheduledDistanceAlongTrip, situationIds, vehicleId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(activeTripId, blockTripSequence, closestStop, closestStopTimeOffset, distanceAlongTrip, frequency, lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, lastLocationUpdateTime, lastUpdateTime, nextStop, nextStopTimeOffset, occupancyCapacity, occupancyCount, occupancyStatus, orientation, phase, position, predicted, scheduleDeviation, scheduledDistanceAlongTrip, serviceDate, situationIds, status, totalDistanceAlongTrip, vehicleId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "Status{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, closestStopTimeOffset=$closestStopTimeOffset, distanceAlongTrip=$distanceAlongTrip, frequency=$frequency, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, orientation=$orientation, phase=$phase, position=$position, predicted=$predicted, scheduleDeviation=$scheduleDeviation, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, serviceDate=$serviceDate, situationIds=$situationIds, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" + "Status{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, distanceAlongTrip=$distanceAlongTrip, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, phase=$phase, predicted=$predicted, scheduleDeviation=$scheduleDeviation, serviceDate=$serviceDate, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, closestStopTimeOffset=$closestStopTimeOffset, frequency=$frequency, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, orientation=$orientation, position=$position, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, situationIds=$situationIds, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1809,20 +1981,17 @@ private constructor( return true } - return /* spotless:off */ other is List && this.frequency == other.frequency && this.serviceDate == other.serviceDate && this.situationIds == other.situationIds && this.tripId == other.tripId && this.schedule == other.schedule && this.status == other.status && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is List && schedule == other.schedule && status == other.status && tripId == other.tripId && frequency == other.frequency && serviceDate == other.serviceDate && situationIds == other.situationIds && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(schedule, status, tripId, frequency, serviceDate, situationIds, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(frequency, serviceDate, situationIds, tripId, schedule, status, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "List{frequency=$frequency, serviceDate=$serviceDate, situationIds=$situationIds, tripId=$tripId, schedule=$schedule, status=$status, additionalProperties=$additionalProperties}" + "List{schedule=$schedule, status=$status, tripId=$tripId, frequency=$frequency, serviceDate=$serviceDate, situationIds=$situationIds, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1830,17 +1999,14 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.limitExceeded == other.limitExceeded && this.list == other.list && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && list == other.list && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, references, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(limitExceeded, list, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Data{limitExceeded=$limitExceeded, list=$list, references=$references, additionalProperties=$additionalProperties}" @@ -1851,17 +2017,14 @@ private constructor( return true } - return /* spotless:off */ other is TripsForRouteListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is TripsForRouteListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "TripsForRouteListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/VehiclesForAgencyListParams.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/VehiclesForAgencyListParams.kt index 0fccd78..37a0200 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/VehiclesForAgencyListParams.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/VehiclesForAgencyListParams.kt @@ -2,34 +2,39 @@ package org.onebusaway.models -import com.google.common.collect.ArrayListMultimap -import com.google.common.collect.ListMultimap import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect -import org.onebusaway.core.toImmutable -import org.onebusaway.models.* +import org.onebusaway.core.Params +import org.onebusaway.core.checkRequired +import org.onebusaway.core.http.Headers +import org.onebusaway.core.http.QueryParams +/** Get vehicles for a specific agency */ class VehiclesForAgencyListParams -constructor( +private constructor( private val agencyId: String, private val time: String?, - private val additionalHeaders: Map>, - private val additionalQueryParams: Map>, -) { + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { fun agencyId(): String = agencyId + /** Specific time for querying the status (timestamp format) */ fun time(): Optional = Optional.ofNullable(time) - @JvmSynthetic internal fun getHeaders(): Map> = additionalHeaders + fun _additionalHeaders(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): Map> { - val params = mutableMapOf>() - this.time?.let { params.put("time", listOf(it.toString())) } - params.putAll(additionalQueryParams) - return params.toImmutable() + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams { + val queryParams = QueryParams.builder() + this.time?.let { queryParams.put("time", listOf(it.toString())) } + queryParams.putAll(additionalQueryParams) + return queryParams.build() } fun getPathParam(index: Int): String { @@ -39,25 +44,6 @@ constructor( } } - fun _additionalHeaders(): Map> = additionalHeaders - - fun _additionalQueryParams(): Map> = additionalQueryParams - - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - - return /* spotless:off */ other is VehiclesForAgencyListParams && this.agencyId == other.agencyId && this.time == other.time && this.additionalHeaders == other.additionalHeaders && this.additionalQueryParams == other.additionalQueryParams /* spotless:on */ - } - - override fun hashCode(): Int { - return /* spotless:off */ Objects.hash(agencyId, time, additionalHeaders, additionalQueryParams) /* spotless:on */ - } - - override fun toString() = - "VehiclesForAgencyListParams{agencyId=$agencyId, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" - fun toBuilder() = Builder().from(this) companion object { @@ -65,26 +51,35 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [VehiclesForAgencyListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var agencyId: String? = null private var time: String? = null - private var additionalHeaders: ListMultimap = ArrayListMultimap.create() - private var additionalQueryParams: ListMultimap = ArrayListMultimap.create() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(vehiclesForAgencyListParams: VehiclesForAgencyListParams) = apply { - this.agencyId = vehiclesForAgencyListParams.agencyId - this.time = vehiclesForAgencyListParams.time - additionalHeaders(vehiclesForAgencyListParams.additionalHeaders) - additionalQueryParams(vehiclesForAgencyListParams.additionalQueryParams) + agencyId = vehiclesForAgencyListParams.agencyId + time = vehiclesForAgencyListParams.time + additionalHeaders = vehiclesForAgencyListParams.additionalHeaders.toBuilder() + additionalQueryParams = vehiclesForAgencyListParams.additionalQueryParams.toBuilder() } fun agencyId(agencyId: String) = apply { this.agencyId = agencyId } /** Specific time for querying the status (timestamp format) */ - fun time(time: String) = apply { this.time = time } + fun time(time: String?) = apply { this.time = time } + + /** Specific time for querying the status (timestamp format) */ + fun time(time: Optional) = time(time.orElse(null)) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } fun additionalHeaders(additionalHeaders: Map>) = apply { this.additionalHeaders.clear() @@ -96,29 +91,42 @@ constructor( } fun putAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.putAll(name, values) + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) } fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::putAdditionalHeaders) + this.additionalHeaders.putAll(additionalHeaders) } fun replaceAdditionalHeaders(name: String, value: String) = apply { - additionalHeaders.replaceValues(name, listOf(value)) + additionalHeaders.replace(name, value) } fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { - additionalHeaders.replaceValues(name, values) + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) } fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { - additionalHeaders.forEach(::replaceAdditionalHeaders) + this.additionalHeaders.replaceAll(additionalHeaders) } - fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.removeAll(name) } + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } fun removeAllAdditionalHeaders(names: Set) = apply { - names.forEach(::removeAdditionalHeaders) + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) } fun additionalQueryParams(additionalQueryParams: Map>) = apply { @@ -131,47 +139,60 @@ constructor( } fun putAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.putAll(key, values) + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) } fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::putAdditionalQueryParams) + this.additionalQueryParams.putAll(additionalQueryParams) } fun replaceAdditionalQueryParams(key: String, value: String) = apply { - additionalQueryParams.replaceValues(key, listOf(value)) + additionalQueryParams.replace(key, value) } fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { - additionalQueryParams.replaceValues(key, values) + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) } fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = apply { - additionalQueryParams.forEach(::replaceAdditionalQueryParams) + this.additionalQueryParams.replaceAll(additionalQueryParams) } - fun removeAdditionalQueryParams(key: String) = apply { - additionalQueryParams.removeAll(key) - } + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } fun removeAllAdditionalQueryParams(keys: Set) = apply { - keys.forEach(::removeAdditionalQueryParams) + additionalQueryParams.removeAll(keys) } fun build(): VehiclesForAgencyListParams = VehiclesForAgencyListParams( - checkNotNull(agencyId) { "`agencyId` is required but was not set" }, + checkRequired("agencyId", agencyId), time, - additionalHeaders - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), - additionalQueryParams - .asMap() - .mapValues { it.value.toList().toImmutable() } - .toImmutable(), + additionalHeaders.build(), + additionalQueryParams.build(), ) } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return /* spotless:off */ other is VehiclesForAgencyListParams && agencyId == other.agencyId && time == other.time && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */ + } + + override fun hashCode(): Int = /* spotless:off */ Objects.hash(agencyId, time, additionalHeaders, additionalQueryParams) /* spotless:on */ + + override fun toString() = + "VehiclesForAgencyListParams{agencyId=$agencyId, time=$time, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/VehiclesForAgencyListResponse.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/VehiclesForAgencyListResponse.kt index 6adbe4f..98ae4a2 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/VehiclesForAgencyListResponse.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/VehiclesForAgencyListResponse.kt @@ -4,8 +4,8 @@ package org.onebusaway.models import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty -import com.fasterxml.jackson.databind.annotation.JsonDeserialize import java.util.Objects import java.util.Optional import org.onebusaway.core.ExcludeMissing @@ -13,22 +13,26 @@ import org.onebusaway.core.JsonField import org.onebusaway.core.JsonMissing import org.onebusaway.core.JsonValue import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.checkRequired +import org.onebusaway.core.immutableEmptyMap import org.onebusaway.core.toImmutable -@JsonDeserialize(builder = VehiclesForAgencyListResponse.Builder::class) @NoAutoDetect class VehiclesForAgencyListResponse +@JsonCreator private constructor( - private val code: JsonField, - private val currentTime: JsonField, - private val text: JsonField, - private val version: JsonField, - private val data: JsonField, - private val additionalProperties: Map, + @JsonProperty("code") @ExcludeMissing private val code: JsonField = JsonMissing.of(), + @JsonProperty("currentTime") + @ExcludeMissing + private val currentTime: JsonField = JsonMissing.of(), + @JsonProperty("text") @ExcludeMissing private val text: JsonField = JsonMissing.of(), + @JsonProperty("version") + @ExcludeMissing + private val version: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing private val data: JsonField = JsonMissing.of(), + @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun code(): Long = code.getRequired("code") fun currentTime(): Long = currentTime.getRequired("currentTime") @@ -39,37 +43,41 @@ private constructor( fun data(): Data = data.getRequired("data") - fun toResponseWrapper(): ResponseWrapper = - ResponseWrapper.builder() - .code(code) - .currentTime(currentTime) - .text(text) - .version(version) - .build() - - @JsonProperty("code") @ExcludeMissing fun _code() = code + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("data") @ExcludeMissing fun _data() = data + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + fun toResponseWrapper(): ResponseWrapper = + ResponseWrapper.builder() + .code(code) + .currentTime(currentTime) + .text(text) + .version(version) + .build() + + private var validated: Boolean = false + fun validate(): VehiclesForAgencyListResponse = apply { - if (!validated) { - code() - currentTime() - text() - version() - data().validate() - validated = true + if (validated) { + return@apply } + + code() + currentTime() + text() + version() + data().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -79,117 +87,125 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [VehiclesForAgencyListResponse]. */ + class Builder internal constructor() { - private var code: JsonField = JsonMissing.of() - private var currentTime: JsonField = JsonMissing.of() - private var text: JsonField = JsonMissing.of() - private var version: JsonField = JsonMissing.of() - private var data: JsonField = JsonMissing.of() + private var code: JsonField? = null + private var currentTime: JsonField? = null + private var text: JsonField? = null + private var version: JsonField? = null + private var data: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(vehiclesForAgencyListResponse: VehiclesForAgencyListResponse) = apply { - this.code = vehiclesForAgencyListResponse.code - this.currentTime = vehiclesForAgencyListResponse.currentTime - this.text = vehiclesForAgencyListResponse.text - this.version = vehiclesForAgencyListResponse.version - this.data = vehiclesForAgencyListResponse.data - additionalProperties(vehiclesForAgencyListResponse.additionalProperties) + code = vehiclesForAgencyListResponse.code + currentTime = vehiclesForAgencyListResponse.currentTime + text = vehiclesForAgencyListResponse.text + version = vehiclesForAgencyListResponse.version + data = vehiclesForAgencyListResponse.data + additionalProperties = vehiclesForAgencyListResponse.additionalProperties.toMutableMap() } fun code(code: Long) = code(JsonField.of(code)) - @JsonProperty("code") - @ExcludeMissing fun code(code: JsonField) = apply { this.code = code } fun currentTime(currentTime: Long) = currentTime(JsonField.of(currentTime)) - @JsonProperty("currentTime") - @ExcludeMissing fun currentTime(currentTime: JsonField) = apply { this.currentTime = currentTime } fun text(text: String) = text(JsonField.of(text)) - @JsonProperty("text") - @ExcludeMissing fun text(text: JsonField) = apply { this.text = text } fun version(version: Long) = version(JsonField.of(version)) - @JsonProperty("version") - @ExcludeMissing fun version(version: JsonField) = apply { this.version = version } fun data(data: Data) = data(JsonField.of(data)) - @JsonProperty("data") - @ExcludeMissing fun data(data: JsonField) = apply { this.data = data } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): VehiclesForAgencyListResponse = VehiclesForAgencyListResponse( - code, - currentTime, - text, - version, - data, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), + checkRequired("data", data), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = Data.Builder::class) @NoAutoDetect class Data + @JsonCreator private constructor( - private val list: JsonField>, - private val limitExceeded: JsonField, - private val references: JsonField, - private val additionalProperties: Map, + @JsonProperty("list") + @ExcludeMissing + private val list: JsonField> = JsonMissing.of(), + @JsonProperty("limitExceeded") + @ExcludeMissing + private val limitExceeded: JsonField = JsonMissing.of(), + @JsonProperty("references") + @ExcludeMissing + private val references: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - - private var validated: Boolean = false - - private var hashCode: Int = 0 - fun list(): kotlin.collections.List = list.getRequired("list") fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") fun references(): References = references.getRequired("references") - @JsonProperty("list") @ExcludeMissing fun _list() = list + @JsonProperty("limitExceeded") + @ExcludeMissing + fun _limitExceeded(): JsonField = limitExceeded - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + @JsonProperty("list") + @ExcludeMissing + fun _list(): JsonField> = list - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Data = apply { - if (!validated) { - list().forEach { it.validate() } - limitExceeded() - references().validate() - validated = true + if (validated) { + return@apply } + + limitExceeded() + list().forEach { it.validate() } + references().validate() + validated = true } fun toBuilder() = Builder().from(this) @@ -199,99 +215,135 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Data]. */ + class Builder internal constructor() { - private var list: JsonField> = JsonMissing.of() - private var limitExceeded: JsonField = JsonMissing.of() - private var references: JsonField = JsonMissing.of() + private var list: JsonField>? = null + private var limitExceeded: JsonField? = null + private var references: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(data: Data) = apply { - this.list = data.list - this.limitExceeded = data.limitExceeded - this.references = data.references - additionalProperties(data.additionalProperties) + limitExceeded = data.limitExceeded + list = data.list.map { it.toMutableList() } + references = data.references + additionalProperties = data.additionalProperties.toMutableMap() } fun list(list: kotlin.collections.List) = list(JsonField.of(list)) - @JsonProperty("list") - @ExcludeMissing - fun list(list: JsonField>) = apply { this.list = list } + fun list(list: JsonField>) = apply { + this.list = list.map { it.toMutableList() } + } fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) - @JsonProperty("limitExceeded") - @ExcludeMissing fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } + fun addList(list: List) = apply { + this.list = + (this.list ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(list) + } + } + fun references(references: References) = references(JsonField.of(references)) - @JsonProperty("references") - @ExcludeMissing fun references(references: JsonField) = apply { this.references = references } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Data = Data( - list.map { it.toImmutable() }, - limitExceeded, - references, + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("limitExceeded", limitExceeded), + checkRequired("references", references), additionalProperties.toImmutable(), ) } - @JsonDeserialize(builder = List.Builder::class) @NoAutoDetect class List + @JsonCreator private constructor( - private val vehicleId: JsonField, - private val lastUpdateTime: JsonField, - private val lastLocationUpdateTime: JsonField, - private val location: JsonField, - private val tripId: JsonField, - private val tripStatus: JsonField, - private val occupancyCapacity: JsonField, - private val occupancyCount: JsonField, - private val occupancyStatus: JsonField, - private val phase: JsonField, - private val status: JsonField, - private val additionalProperties: Map, + @JsonProperty("lastLocationUpdateTime") + @ExcludeMissing + private val lastLocationUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("lastUpdateTime") + @ExcludeMissing + private val lastUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("location") + @ExcludeMissing + private val location: JsonField = JsonMissing.of(), + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), + @JsonProperty("tripStatus") + @ExcludeMissing + private val tripStatus: JsonField = JsonMissing.of(), + @JsonProperty("vehicleId") + @ExcludeMissing + private val vehicleId: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCapacity") + @ExcludeMissing + private val occupancyCapacity: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCount") + @ExcludeMissing + private val occupancyCount: JsonField = JsonMissing.of(), + @JsonProperty("occupancyStatus") + @ExcludeMissing + private val occupancyStatus: JsonField = JsonMissing.of(), + @JsonProperty("phase") + @ExcludeMissing + private val phase: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - - fun vehicleId(): String = vehicleId.getRequired("vehicleId") - - fun lastUpdateTime(): Long = lastUpdateTime.getRequired("lastUpdateTime") - fun lastLocationUpdateTime(): Long = lastLocationUpdateTime.getRequired("lastLocationUpdateTime") + fun lastUpdateTime(): Long = lastUpdateTime.getRequired("lastUpdateTime") + fun location(): Location = location.getRequired("location") fun tripId(): String = tripId.getRequired("tripId") fun tripStatus(): TripStatus = tripStatus.getRequired("tripStatus") + fun vehicleId(): String = vehicleId.getRequired("vehicleId") + fun occupancyCapacity(): Optional = Optional.ofNullable(occupancyCapacity.getNullable("occupancyCapacity")) @@ -305,53 +357,67 @@ private constructor( fun status(): Optional = Optional.ofNullable(status.getNullable("status")) - @JsonProperty("vehicleId") @ExcludeMissing fun _vehicleId() = vehicleId + @JsonProperty("lastLocationUpdateTime") + @ExcludeMissing + fun _lastLocationUpdateTime(): JsonField = lastLocationUpdateTime - @JsonProperty("lastUpdateTime") @ExcludeMissing fun _lastUpdateTime() = lastUpdateTime + @JsonProperty("lastUpdateTime") + @ExcludeMissing + fun _lastUpdateTime(): JsonField = lastUpdateTime - @JsonProperty("lastLocationUpdateTime") + @JsonProperty("location") @ExcludeMissing - fun _lastLocationUpdateTime() = lastLocationUpdateTime + fun _location(): JsonField = location - @JsonProperty("location") @ExcludeMissing fun _location() = location + @JsonProperty("tripId") @ExcludeMissing fun _tripId(): JsonField = tripId - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + @JsonProperty("tripStatus") + @ExcludeMissing + fun _tripStatus(): JsonField = tripStatus - @JsonProperty("tripStatus") @ExcludeMissing fun _tripStatus() = tripStatus + @JsonProperty("vehicleId") + @ExcludeMissing + fun _vehicleId(): JsonField = vehicleId @JsonProperty("occupancyCapacity") @ExcludeMissing - fun _occupancyCapacity() = occupancyCapacity + fun _occupancyCapacity(): JsonField = occupancyCapacity - @JsonProperty("occupancyCount") @ExcludeMissing fun _occupancyCount() = occupancyCount + @JsonProperty("occupancyCount") + @ExcludeMissing + fun _occupancyCount(): JsonField = occupancyCount @JsonProperty("occupancyStatus") @ExcludeMissing - fun _occupancyStatus() = occupancyStatus + fun _occupancyStatus(): JsonField = occupancyStatus - @JsonProperty("phase") @ExcludeMissing fun _phase() = phase + @JsonProperty("phase") @ExcludeMissing fun _phase(): JsonField = phase - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): List = apply { - if (!validated) { - vehicleId() - lastUpdateTime() - lastLocationUpdateTime() - location().validate() - tripId() - tripStatus().validate() - occupancyCapacity() - occupancyCount() - occupancyStatus() - phase() - status() - validated = true + if (validated) { + return@apply } + + lastLocationUpdateTime() + lastUpdateTime() + location().validate() + tripId() + tripStatus().validate() + vehicleId() + occupancyCapacity() + occupancyCount() + occupancyStatus() + phase() + status() + validated = true } fun toBuilder() = Builder().from(this) @@ -361,14 +427,15 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [List]. */ + class Builder internal constructor() { - private var vehicleId: JsonField = JsonMissing.of() - private var lastUpdateTime: JsonField = JsonMissing.of() - private var lastLocationUpdateTime: JsonField = JsonMissing.of() - private var location: JsonField = JsonMissing.of() - private var tripId: JsonField = JsonMissing.of() - private var tripStatus: JsonField = JsonMissing.of() + private var lastLocationUpdateTime: JsonField? = null + private var lastUpdateTime: JsonField? = null + private var location: JsonField? = null + private var tripId: JsonField? = null + private var tripStatus: JsonField? = null + private var vehicleId: JsonField? = null private var occupancyCapacity: JsonField = JsonMissing.of() private var occupancyCount: JsonField = JsonMissing.of() private var occupancyStatus: JsonField = JsonMissing.of() @@ -378,69 +445,55 @@ private constructor( @JvmSynthetic internal fun from(list: List) = apply { - this.vehicleId = list.vehicleId - this.lastUpdateTime = list.lastUpdateTime - this.lastLocationUpdateTime = list.lastLocationUpdateTime - this.location = list.location - this.tripId = list.tripId - this.tripStatus = list.tripStatus - this.occupancyCapacity = list.occupancyCapacity - this.occupancyCount = list.occupancyCount - this.occupancyStatus = list.occupancyStatus - this.phase = list.phase - this.status = list.status - additionalProperties(list.additionalProperties) + lastLocationUpdateTime = list.lastLocationUpdateTime + lastUpdateTime = list.lastUpdateTime + location = list.location + tripId = list.tripId + tripStatus = list.tripStatus + vehicleId = list.vehicleId + occupancyCapacity = list.occupancyCapacity + occupancyCount = list.occupancyCount + occupancyStatus = list.occupancyStatus + phase = list.phase + status = list.status + additionalProperties = list.additionalProperties.toMutableMap() } - fun vehicleId(vehicleId: String) = vehicleId(JsonField.of(vehicleId)) + fun lastLocationUpdateTime(lastLocationUpdateTime: Long) = + lastLocationUpdateTime(JsonField.of(lastLocationUpdateTime)) - @JsonProperty("vehicleId") - @ExcludeMissing - fun vehicleId(vehicleId: JsonField) = apply { this.vehicleId = vehicleId } + fun lastLocationUpdateTime(lastLocationUpdateTime: JsonField) = apply { + this.lastLocationUpdateTime = lastLocationUpdateTime + } fun lastUpdateTime(lastUpdateTime: Long) = lastUpdateTime(JsonField.of(lastUpdateTime)) - @JsonProperty("lastUpdateTime") - @ExcludeMissing fun lastUpdateTime(lastUpdateTime: JsonField) = apply { this.lastUpdateTime = lastUpdateTime } - fun lastLocationUpdateTime(lastLocationUpdateTime: Long) = - lastLocationUpdateTime(JsonField.of(lastLocationUpdateTime)) - - @JsonProperty("lastLocationUpdateTime") - @ExcludeMissing - fun lastLocationUpdateTime(lastLocationUpdateTime: JsonField) = apply { - this.lastLocationUpdateTime = lastLocationUpdateTime - } - fun location(location: Location) = location(JsonField.of(location)) - @JsonProperty("location") - @ExcludeMissing fun location(location: JsonField) = apply { this.location = location } fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - @JsonProperty("tripId") - @ExcludeMissing fun tripId(tripId: JsonField) = apply { this.tripId = tripId } fun tripStatus(tripStatus: TripStatus) = tripStatus(JsonField.of(tripStatus)) - @JsonProperty("tripStatus") - @ExcludeMissing fun tripStatus(tripStatus: JsonField) = apply { this.tripStatus = tripStatus } + fun vehicleId(vehicleId: String) = vehicleId(JsonField.of(vehicleId)) + + fun vehicleId(vehicleId: JsonField) = apply { this.vehicleId = vehicleId } + fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) - @JsonProperty("occupancyCapacity") - @ExcludeMissing fun occupancyCapacity(occupancyCapacity: JsonField) = apply { this.occupancyCapacity = occupancyCapacity } @@ -448,8 +501,6 @@ private constructor( fun occupancyCount(occupancyCount: Long) = occupancyCount(JsonField.of(occupancyCount)) - @JsonProperty("occupancyCount") - @ExcludeMissing fun occupancyCount(occupancyCount: JsonField) = apply { this.occupancyCount = occupancyCount } @@ -457,32 +508,25 @@ private constructor( fun occupancyStatus(occupancyStatus: String) = occupancyStatus(JsonField.of(occupancyStatus)) - @JsonProperty("occupancyStatus") - @ExcludeMissing fun occupancyStatus(occupancyStatus: JsonField) = apply { this.occupancyStatus = occupancyStatus } fun phase(phase: String) = phase(JsonField.of(phase)) - @JsonProperty("phase") - @ExcludeMissing fun phase(phase: JsonField) = apply { this.phase = phase } fun status(status: String) = status(JsonField.of(status)) - @JsonProperty("status") - @ExcludeMissing fun status(status: JsonField) = apply { this.status = status } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -490,14 +534,22 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): List = List( - vehicleId, - lastUpdateTime, - lastLocationUpdateTime, - location, - tripId, - tripStatus, + checkRequired("lastLocationUpdateTime", lastLocationUpdateTime), + checkRequired("lastUpdateTime", lastUpdateTime), + checkRequired("location", location), + checkRequired("tripId", tripId), + checkRequired("tripStatus", tripStatus), + checkRequired("vehicleId", vehicleId), occupancyCapacity, occupancyCount, occupancyStatus, @@ -507,35 +559,42 @@ private constructor( ) } - @JsonDeserialize(builder = Location.Builder::class) @NoAutoDetect class Location + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Location = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -545,7 +604,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Location]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -553,31 +613,26 @@ private constructor( @JvmSynthetic internal fun from(location: Location) = apply { - this.lat = location.lat - this.lon = location.lon - additionalProperties(location.additionalProperties) + lat = location.lat + lon = location.lon + additionalProperties = location.additionalProperties.toMutableMap() } fun lat(lat: Double) = lat(JsonField.of(lat)) - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } fun lon(lon: Double) = lon(JsonField.of(lon)) - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -585,6 +640,14 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Location = Location( lat, @@ -598,58 +661,109 @@ private constructor( return true } - return /* spotless:off */ other is Location && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Location && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Location{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" } - @JsonDeserialize(builder = TripStatus.Builder::class) @NoAutoDetect class TripStatus + @JsonCreator private constructor( - private val activeTripId: JsonField, - private val blockTripSequence: JsonField, - private val closestStop: JsonField, - private val closestStopTimeOffset: JsonField, - private val distanceAlongTrip: JsonField, - private val frequency: JsonField, - private val lastKnownDistanceAlongTrip: JsonField, - private val lastKnownLocation: JsonField, - private val lastKnownOrientation: JsonField, - private val lastLocationUpdateTime: JsonField, - private val lastUpdateTime: JsonField, - private val nextStop: JsonField, - private val nextStopTimeOffset: JsonField, - private val occupancyCapacity: JsonField, - private val occupancyCount: JsonField, - private val occupancyStatus: JsonField, - private val orientation: JsonField, - private val phase: JsonField, - private val position: JsonField, - private val predicted: JsonField, - private val scheduleDeviation: JsonField, - private val scheduledDistanceAlongTrip: JsonField, - private val serviceDate: JsonField, - private val situationIds: JsonField>, - private val status: JsonField, - private val totalDistanceAlongTrip: JsonField, - private val vehicleId: JsonField, - private val additionalProperties: Map, + @JsonProperty("activeTripId") + @ExcludeMissing + private val activeTripId: JsonField = JsonMissing.of(), + @JsonProperty("blockTripSequence") + @ExcludeMissing + private val blockTripSequence: JsonField = JsonMissing.of(), + @JsonProperty("closestStop") + @ExcludeMissing + private val closestStop: JsonField = JsonMissing.of(), + @JsonProperty("distanceAlongTrip") + @ExcludeMissing + private val distanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownDistanceAlongTrip") + @ExcludeMissing + private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("lastLocationUpdateTime") + @ExcludeMissing + private val lastLocationUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("lastUpdateTime") + @ExcludeMissing + private val lastUpdateTime: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCapacity") + @ExcludeMissing + private val occupancyCapacity: JsonField = JsonMissing.of(), + @JsonProperty("occupancyCount") + @ExcludeMissing + private val occupancyCount: JsonField = JsonMissing.of(), + @JsonProperty("occupancyStatus") + @ExcludeMissing + private val occupancyStatus: JsonField = JsonMissing.of(), + @JsonProperty("phase") + @ExcludeMissing + private val phase: JsonField = JsonMissing.of(), + @JsonProperty("predicted") + @ExcludeMissing + private val predicted: JsonField = JsonMissing.of(), + @JsonProperty("scheduleDeviation") + @ExcludeMissing + private val scheduleDeviation: JsonField = JsonMissing.of(), + @JsonProperty("serviceDate") + @ExcludeMissing + private val serviceDate: JsonField = JsonMissing.of(), + @JsonProperty("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = + JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + private val status: JsonField = JsonMissing.of(), + @JsonProperty("totalDistanceAlongTrip") + @ExcludeMissing + private val totalDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + private val closestStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownLocation") + @ExcludeMissing + private val lastKnownLocation: JsonField = JsonMissing.of(), + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + private val lastKnownOrientation: JsonField = JsonMissing.of(), + @JsonProperty("nextStop") + @ExcludeMissing + private val nextStop: JsonField = JsonMissing.of(), + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + private val nextStopTimeOffset: JsonField = JsonMissing.of(), + @JsonProperty("orientation") + @ExcludeMissing + private val orientation: JsonField = JsonMissing.of(), + @JsonProperty("position") + @ExcludeMissing + private val position: JsonField = JsonMissing.of(), + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + private val scheduledDistanceAlongTrip: JsonField = JsonMissing.of(), + @JsonProperty("vehicleId") + @ExcludeMissing + private val vehicleId: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Trip ID of the trip the vehicle is actively serving. */ fun activeTripId(): String = activeTripId.getRequired("activeTripId") @@ -659,22 +773,11 @@ private constructor( /** ID of the closest stop to the current location of the transit vehicle. */ fun closestStop(): String = closestStop.getRequired("closestStop") - /** - * Time offset from the closest stop to the current position of the transit vehicle - * (in seconds). - */ - fun closestStopTimeOffset(): Optional = - Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) - /** * Distance, in meters, the transit vehicle has progressed along the active trip. */ fun distanceAlongTrip(): Double = distanceAlongTrip.getRequired("distanceAlongTrip") - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -682,14 +785,6 @@ private constructor( fun lastKnownDistanceAlongTrip(): Double = lastKnownDistanceAlongTrip.getRequired("lastKnownDistanceAlongTrip") - /** Last known location of the transit vehicle. */ - fun lastKnownLocation(): Optional = - Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) - - /** Last known orientation value received in real-time from the transit vehicle. */ - fun lastKnownOrientation(): Optional = - Optional.ofNullable(lastKnownOrientation.getNullable("lastKnownOrientation")) - /** * Timestamp of the last known real-time location update from the transit vehicle. */ @@ -699,17 +794,6 @@ private constructor( /** Timestamp of the last known real-time update from the transit vehicle. */ fun lastUpdateTime(): Long = lastUpdateTime.getRequired("lastUpdateTime") - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - fun nextStop(): Optional = - Optional.ofNullable(nextStop.getNullable("nextStop")) - - /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). - */ - fun nextStopTimeOffset(): Optional = - Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(): Long = occupancyCapacity.getRequired("occupancyCapacity") @@ -719,17 +803,9 @@ private constructor( /** Current occupancy status of the transit vehicle. */ fun occupancyStatus(): String = occupancyStatus.getRequired("occupancyStatus") - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - fun orientation(): Optional = - Optional.ofNullable(orientation.getNullable("orientation")) - /** Current journey phase of the trip. */ fun phase(): String = phase.getRequired("phase") - /** Current position of the transit vehicle. */ - fun position(): Optional = - Optional.ofNullable(position.getNullable("position")) - /** Indicates if real-time arrival info is available for this trip. */ fun predicted(): Boolean = predicted.getRequired("predicted") @@ -738,15 +814,6 @@ private constructor( */ fun scheduleDeviation(): Long = scheduleDeviation.getRequired("scheduleDeviation") - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed along - * the active trip. - */ - fun scheduledDistanceAlongTrip(): Optional = - Optional.ofNullable( - scheduledDistanceAlongTrip.getNullable("scheduledDistanceAlongTrip") - ) - /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. @@ -764,38 +831,78 @@ private constructor( fun totalDistanceAlongTrip(): Double = totalDistanceAlongTrip.getRequired("totalDistanceAlongTrip") + /** + * Time offset from the closest stop to the current position of the transit vehicle + * (in seconds). + */ + fun closestStopTimeOffset(): Optional = + Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(): Optional = + Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) + + /** Last known orientation value received in real-time from the transit vehicle. */ + fun lastKnownOrientation(): Optional = + Optional.ofNullable(lastKnownOrientation.getNullable("lastKnownOrientation")) + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(): Optional = + Optional.ofNullable(nextStop.getNullable("nextStop")) + + /** + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). + */ + fun nextStopTimeOffset(): Optional = + Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(): Optional = + Optional.ofNullable(orientation.getNullable("orientation")) + + /** Current position of the transit vehicle. */ + fun position(): Optional = + Optional.ofNullable(position.getNullable("position")) + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed along + * the active trip. + */ + fun scheduledDistanceAlongTrip(): Optional = + Optional.ofNullable( + scheduledDistanceAlongTrip.getNullable("scheduledDistanceAlongTrip") + ) + /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(): Optional = Optional.ofNullable(vehicleId.getNullable("vehicleId")) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") @ExcludeMissing fun _activeTripId() = activeTripId + @JsonProperty("activeTripId") + @ExcludeMissing + fun _activeTripId(): JsonField = activeTripId /** Index of the active trip into the sequence of trips for the active block. */ @JsonProperty("blockTripSequence") @ExcludeMissing - fun _blockTripSequence() = blockTripSequence + fun _blockTripSequence(): JsonField = blockTripSequence /** ID of the closest stop to the current location of the transit vehicle. */ - @JsonProperty("closestStop") @ExcludeMissing fun _closestStop() = closestStop - - /** - * Time offset from the closest stop to the current position of the transit vehicle - * (in seconds). - */ - @JsonProperty("closestStopTimeOffset") + @JsonProperty("closestStop") @ExcludeMissing - fun _closestStopTimeOffset() = closestStopTimeOffset + fun _closestStop(): JsonField = closestStop /** * Distance, in meters, the transit vehicle has progressed along the active trip. */ @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency + fun _distanceAlongTrip(): JsonField = distanceAlongTrip /** * Last known distance along the trip received in real-time from the transit @@ -803,138 +910,169 @@ private constructor( */ @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing - fun _lastKnownDistanceAlongTrip() = lastKnownDistanceAlongTrip - - /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun _lastKnownLocation() = lastKnownLocation - - /** Last known orientation value received in real-time from the transit vehicle. */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun _lastKnownOrientation() = lastKnownOrientation + fun _lastKnownDistanceAlongTrip(): JsonField = lastKnownDistanceAlongTrip /** * Timestamp of the last known real-time location update from the transit vehicle. */ @JsonProperty("lastLocationUpdateTime") @ExcludeMissing - fun _lastLocationUpdateTime() = lastLocationUpdateTime + fun _lastLocationUpdateTime(): JsonField = lastLocationUpdateTime /** Timestamp of the last known real-time update from the transit vehicle. */ @JsonProperty("lastUpdateTime") @ExcludeMissing - fun _lastUpdateTime() = lastUpdateTime - - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") @ExcludeMissing fun _nextStop() = nextStop - - /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). - */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - fun _nextStopTimeOffset() = nextStopTimeOffset + fun _lastUpdateTime(): JsonField = lastUpdateTime /** Capacity of the transit vehicle in terms of occupancy. */ @JsonProperty("occupancyCapacity") @ExcludeMissing - fun _occupancyCapacity() = occupancyCapacity + fun _occupancyCapacity(): JsonField = occupancyCapacity /** Current count of occupants in the transit vehicle. */ @JsonProperty("occupancyCount") @ExcludeMissing - fun _occupancyCount() = occupancyCount + fun _occupancyCount(): JsonField = occupancyCount /** Current occupancy status of the transit vehicle. */ @JsonProperty("occupancyStatus") @ExcludeMissing - fun _occupancyStatus() = occupancyStatus - - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") @ExcludeMissing fun _orientation() = orientation + fun _occupancyStatus(): JsonField = occupancyStatus /** Current journey phase of the trip. */ - @JsonProperty("phase") @ExcludeMissing fun _phase() = phase - - /** Current position of the transit vehicle. */ - @JsonProperty("position") @ExcludeMissing fun _position() = position + @JsonProperty("phase") @ExcludeMissing fun _phase(): JsonField = phase /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") @ExcludeMissing fun _predicted() = predicted + @JsonProperty("predicted") + @ExcludeMissing + fun _predicted(): JsonField = predicted /** * Deviation from the schedule in seconds (positive for late, negative for early). */ @JsonProperty("scheduleDeviation") @ExcludeMissing - fun _scheduleDeviation() = scheduleDeviation - - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed along - * the active trip. - */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - fun _scheduledDistanceAlongTrip() = scheduledDistanceAlongTrip + fun _scheduleDeviation(): JsonField = scheduleDeviation /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate - - /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate /** Current status modifiers for the trip. */ - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status /** Total length of the trip, in meters. */ @JsonProperty("totalDistanceAlongTrip") @ExcludeMissing - fun _totalDistanceAlongTrip() = totalDistanceAlongTrip + fun _totalDistanceAlongTrip(): JsonField = totalDistanceAlongTrip + + /** + * Time offset from the closest stop to the current position of the transit vehicle + * (in seconds). + */ + @JsonProperty("closestStopTimeOffset") + @ExcludeMissing + fun _closestStopTimeOffset(): JsonField = closestStopTimeOffset + + /** Information about frequency-based scheduling, if applicable to the trip. */ + @JsonProperty("frequency") + @ExcludeMissing + fun _frequency(): JsonField = frequency + + /** Last known location of the transit vehicle. */ + @JsonProperty("lastKnownLocation") + @ExcludeMissing + fun _lastKnownLocation(): JsonField = lastKnownLocation + + /** Last known orientation value received in real-time from the transit vehicle. */ + @JsonProperty("lastKnownOrientation") + @ExcludeMissing + fun _lastKnownOrientation(): JsonField = lastKnownOrientation + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + @JsonProperty("nextStop") + @ExcludeMissing + fun _nextStop(): JsonField = nextStop + + /** + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). + */ + @JsonProperty("nextStopTimeOffset") + @ExcludeMissing + fun _nextStopTimeOffset(): JsonField = nextStopTimeOffset + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + @JsonProperty("orientation") + @ExcludeMissing + fun _orientation(): JsonField = orientation + + /** Current position of the transit vehicle. */ + @JsonProperty("position") + @ExcludeMissing + fun _position(): JsonField = position + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed along + * the active trip. + */ + @JsonProperty("scheduledDistanceAlongTrip") + @ExcludeMissing + fun _scheduledDistanceAlongTrip(): JsonField = scheduledDistanceAlongTrip + + /** References to situation elements (if any) applicable to this trip. */ + @JsonProperty("situationIds") + @ExcludeMissing + fun _situationIds(): JsonField> = situationIds /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") @ExcludeMissing fun _vehicleId() = vehicleId + @JsonProperty("vehicleId") + @ExcludeMissing + fun _vehicleId(): JsonField = vehicleId @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): TripStatus = apply { - if (!validated) { - activeTripId() - blockTripSequence() - closestStop() - closestStopTimeOffset() - distanceAlongTrip() - frequency() - lastKnownDistanceAlongTrip() - lastKnownLocation().map { it.validate() } - lastKnownOrientation() - lastLocationUpdateTime() - lastUpdateTime() - nextStop() - nextStopTimeOffset() - occupancyCapacity() - occupancyCount() - occupancyStatus() - orientation() - phase() - position().map { it.validate() } - predicted() - scheduleDeviation() - scheduledDistanceAlongTrip() - serviceDate() - situationIds() - status() - totalDistanceAlongTrip() - vehicleId() - validated = true + if (validated) { + return@apply } + + activeTripId() + blockTripSequence() + closestStop() + distanceAlongTrip() + lastKnownDistanceAlongTrip() + lastLocationUpdateTime() + lastUpdateTime() + occupancyCapacity() + occupancyCount() + occupancyStatus() + phase() + predicted() + scheduleDeviation() + serviceDate() + status() + totalDistanceAlongTrip() + closestStopTimeOffset() + frequency() + lastKnownLocation().ifPresent { it.validate() } + lastKnownOrientation() + nextStop() + nextStopTimeOffset() + orientation() + position().ifPresent { it.validate() } + scheduledDistanceAlongTrip() + situationIds() + vehicleId() + validated = true } fun toBuilder() = Builder().from(this) @@ -944,68 +1082,68 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { - - private var activeTripId: JsonField = JsonMissing.of() - private var blockTripSequence: JsonField = JsonMissing.of() - private var closestStop: JsonField = JsonMissing.of() + /** A builder for [TripStatus]. */ + class Builder internal constructor() { + + private var activeTripId: JsonField? = null + private var blockTripSequence: JsonField? = null + private var closestStop: JsonField? = null + private var distanceAlongTrip: JsonField? = null + private var lastKnownDistanceAlongTrip: JsonField? = null + private var lastLocationUpdateTime: JsonField? = null + private var lastUpdateTime: JsonField? = null + private var occupancyCapacity: JsonField? = null + private var occupancyCount: JsonField? = null + private var occupancyStatus: JsonField? = null + private var phase: JsonField? = null + private var predicted: JsonField? = null + private var scheduleDeviation: JsonField? = null + private var serviceDate: JsonField? = null + private var situationIds: JsonField>? = null + private var status: JsonField? = null + private var totalDistanceAlongTrip: JsonField? = null private var closestStopTimeOffset: JsonField = JsonMissing.of() - private var distanceAlongTrip: JsonField = JsonMissing.of() private var frequency: JsonField = JsonMissing.of() - private var lastKnownDistanceAlongTrip: JsonField = JsonMissing.of() private var lastKnownLocation: JsonField = JsonMissing.of() private var lastKnownOrientation: JsonField = JsonMissing.of() - private var lastLocationUpdateTime: JsonField = JsonMissing.of() - private var lastUpdateTime: JsonField = JsonMissing.of() private var nextStop: JsonField = JsonMissing.of() private var nextStopTimeOffset: JsonField = JsonMissing.of() - private var occupancyCapacity: JsonField = JsonMissing.of() - private var occupancyCount: JsonField = JsonMissing.of() - private var occupancyStatus: JsonField = JsonMissing.of() private var orientation: JsonField = JsonMissing.of() - private var phase: JsonField = JsonMissing.of() private var position: JsonField = JsonMissing.of() - private var predicted: JsonField = JsonMissing.of() - private var scheduleDeviation: JsonField = JsonMissing.of() private var scheduledDistanceAlongTrip: JsonField = JsonMissing.of() - private var serviceDate: JsonField = JsonMissing.of() - private var situationIds: JsonField> = - JsonMissing.of() - private var status: JsonField = JsonMissing.of() - private var totalDistanceAlongTrip: JsonField = JsonMissing.of() private var vehicleId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(tripStatus: TripStatus) = apply { - this.activeTripId = tripStatus.activeTripId - this.blockTripSequence = tripStatus.blockTripSequence - this.closestStop = tripStatus.closestStop - this.closestStopTimeOffset = tripStatus.closestStopTimeOffset - this.distanceAlongTrip = tripStatus.distanceAlongTrip - this.frequency = tripStatus.frequency - this.lastKnownDistanceAlongTrip = tripStatus.lastKnownDistanceAlongTrip - this.lastKnownLocation = tripStatus.lastKnownLocation - this.lastKnownOrientation = tripStatus.lastKnownOrientation - this.lastLocationUpdateTime = tripStatus.lastLocationUpdateTime - this.lastUpdateTime = tripStatus.lastUpdateTime - this.nextStop = tripStatus.nextStop - this.nextStopTimeOffset = tripStatus.nextStopTimeOffset - this.occupancyCapacity = tripStatus.occupancyCapacity - this.occupancyCount = tripStatus.occupancyCount - this.occupancyStatus = tripStatus.occupancyStatus - this.orientation = tripStatus.orientation - this.phase = tripStatus.phase - this.position = tripStatus.position - this.predicted = tripStatus.predicted - this.scheduleDeviation = tripStatus.scheduleDeviation - this.scheduledDistanceAlongTrip = tripStatus.scheduledDistanceAlongTrip - this.serviceDate = tripStatus.serviceDate - this.situationIds = tripStatus.situationIds - this.status = tripStatus.status - this.totalDistanceAlongTrip = tripStatus.totalDistanceAlongTrip - this.vehicleId = tripStatus.vehicleId - additionalProperties(tripStatus.additionalProperties) + activeTripId = tripStatus.activeTripId + blockTripSequence = tripStatus.blockTripSequence + closestStop = tripStatus.closestStop + distanceAlongTrip = tripStatus.distanceAlongTrip + lastKnownDistanceAlongTrip = tripStatus.lastKnownDistanceAlongTrip + lastLocationUpdateTime = tripStatus.lastLocationUpdateTime + lastUpdateTime = tripStatus.lastUpdateTime + occupancyCapacity = tripStatus.occupancyCapacity + occupancyCount = tripStatus.occupancyCount + occupancyStatus = tripStatus.occupancyStatus + phase = tripStatus.phase + predicted = tripStatus.predicted + scheduleDeviation = tripStatus.scheduleDeviation + serviceDate = tripStatus.serviceDate + status = tripStatus.status + totalDistanceAlongTrip = tripStatus.totalDistanceAlongTrip + closestStopTimeOffset = tripStatus.closestStopTimeOffset + frequency = tripStatus.frequency + lastKnownLocation = tripStatus.lastKnownLocation + lastKnownOrientation = tripStatus.lastKnownOrientation + nextStop = tripStatus.nextStop + nextStopTimeOffset = tripStatus.nextStopTimeOffset + orientation = tripStatus.orientation + position = tripStatus.position + scheduledDistanceAlongTrip = tripStatus.scheduledDistanceAlongTrip + situationIds = tripStatus.situationIds.map { it.toMutableList() } + vehicleId = tripStatus.vehicleId + additionalProperties = tripStatus.additionalProperties.toMutableMap() } /** Trip ID of the trip the vehicle is actively serving. */ @@ -1013,8 +1151,6 @@ private constructor( activeTripId(JsonField.of(activeTripId)) /** Trip ID of the trip the vehicle is actively serving. */ - @JsonProperty("activeTripId") - @ExcludeMissing fun activeTripId(activeTripId: JsonField) = apply { this.activeTripId = activeTripId } @@ -1024,8 +1160,6 @@ private constructor( blockTripSequence(JsonField.of(blockTripSequence)) /** Index of the active trip into the sequence of trips for the active block. */ - @JsonProperty("blockTripSequence") - @ExcludeMissing fun blockTripSequence(blockTripSequence: JsonField) = apply { this.blockTripSequence = blockTripSequence } @@ -1034,29 +1168,10 @@ private constructor( fun closestStop(closestStop: String) = closestStop(JsonField.of(closestStop)) /** ID of the closest stop to the current location of the transit vehicle. */ - @JsonProperty("closestStop") - @ExcludeMissing fun closestStop(closestStop: JsonField) = apply { this.closestStop = closestStop } - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - fun closestStopTimeOffset(closestStopTimeOffset: Long) = - closestStopTimeOffset(JsonField.of(closestStopTimeOffset)) - - /** - * Time offset from the closest stop to the current position of the transit - * vehicle (in seconds). - */ - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing - fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { - this.closestStopTimeOffset = closestStopTimeOffset - } - /** * Distance, in meters, the transit vehicle has progressed along the active * trip. @@ -1068,22 +1183,10 @@ private constructor( * Distance, in meters, the transit vehicle has progressed along the active * trip. */ - @JsonProperty("distanceAlongTrip") - @ExcludeMissing fun distanceAlongTrip(distanceAlongTrip: JsonField) = apply { this.distanceAlongTrip = distanceAlongTrip } - /** Information about frequency-based scheduling, if applicable to the trip. */ - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") - @ExcludeMissing - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1095,39 +1198,11 @@ private constructor( * Last known distance along the trip received in real-time from the transit * vehicle. */ - @JsonProperty("lastKnownDistanceAlongTrip") - @ExcludeMissing fun lastKnownDistanceAlongTrip(lastKnownDistanceAlongTrip: JsonField) = apply { this.lastKnownDistanceAlongTrip = lastKnownDistanceAlongTrip } - /** Last known location of the transit vehicle. */ - fun lastKnownLocation(lastKnownLocation: LastKnownLocation) = - lastKnownLocation(JsonField.of(lastKnownLocation)) - - /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun lastKnownLocation(lastKnownLocation: JsonField) = apply { - this.lastKnownLocation = lastKnownLocation - } - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - fun lastKnownOrientation(lastKnownOrientation: Double) = - lastKnownOrientation(JsonField.of(lastKnownOrientation)) - - /** - * Last known orientation value received in real-time from the transit vehicle. - */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun lastKnownOrientation(lastKnownOrientation: JsonField) = apply { - this.lastKnownOrientation = lastKnownOrientation - } - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1139,8 +1214,6 @@ private constructor( * Timestamp of the last known real-time location update from the transit * vehicle. */ - @JsonProperty("lastLocationUpdateTime") - @ExcludeMissing fun lastLocationUpdateTime(lastLocationUpdateTime: JsonField) = apply { this.lastLocationUpdateTime = lastLocationUpdateTime } @@ -1150,44 +1223,15 @@ private constructor( lastUpdateTime(JsonField.of(lastUpdateTime)) /** Timestamp of the last known real-time update from the transit vehicle. */ - @JsonProperty("lastUpdateTime") - @ExcludeMissing fun lastUpdateTime(lastUpdateTime: JsonField) = apply { this.lastUpdateTime = lastUpdateTime } - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - fun nextStop(nextStop: String) = nextStop(JsonField.of(nextStop)) - - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") - @ExcludeMissing - fun nextStop(nextStop: JsonField) = apply { this.nextStop = nextStop } - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - fun nextStopTimeOffset(nextStopTimeOffset: Long) = - nextStopTimeOffset(JsonField.of(nextStopTimeOffset)) - - /** - * Time offset from the next stop to the current position of the transit vehicle - * (in seconds). - */ - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - fun nextStopTimeOffset(nextStopTimeOffset: JsonField) = apply { - this.nextStopTimeOffset = nextStopTimeOffset - } - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) /** Capacity of the transit vehicle in terms of occupancy. */ - @JsonProperty("occupancyCapacity") - @ExcludeMissing fun occupancyCapacity(occupancyCapacity: JsonField) = apply { this.occupancyCapacity = occupancyCapacity } @@ -1197,8 +1241,6 @@ private constructor( occupancyCount(JsonField.of(occupancyCount)) /** Current count of occupants in the transit vehicle. */ - @JsonProperty("occupancyCount") - @ExcludeMissing fun occupancyCount(occupancyCount: JsonField) = apply { this.occupancyCount = occupancyCount } @@ -1208,44 +1250,20 @@ private constructor( occupancyStatus(JsonField.of(occupancyStatus)) /** Current occupancy status of the transit vehicle. */ - @JsonProperty("occupancyStatus") - @ExcludeMissing fun occupancyStatus(occupancyStatus: JsonField) = apply { this.occupancyStatus = occupancyStatus } - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - fun orientation(orientation: Double) = orientation(JsonField.of(orientation)) - - /** Orientation of the transit vehicle, represented as an angle in degrees. */ - @JsonProperty("orientation") - @ExcludeMissing - fun orientation(orientation: JsonField) = apply { - this.orientation = orientation - } - /** Current journey phase of the trip. */ fun phase(phase: String) = phase(JsonField.of(phase)) /** Current journey phase of the trip. */ - @JsonProperty("phase") - @ExcludeMissing fun phase(phase: JsonField) = apply { this.phase = phase } - /** Current position of the transit vehicle. */ - fun position(position: Position) = position(JsonField.of(position)) - - /** Current position of the transit vehicle. */ - @JsonProperty("position") - @ExcludeMissing - fun position(position: JsonField) = apply { this.position = position } - /** Indicates if real-time arrival info is available for this trip. */ fun predicted(predicted: Boolean) = predicted(JsonField.of(predicted)) /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") - @ExcludeMissing fun predicted(predicted: JsonField) = apply { this.predicted = predicted } @@ -1261,30 +1279,10 @@ private constructor( * Deviation from the schedule in seconds (positive for late, negative for * early). */ - @JsonProperty("scheduleDeviation") - @ExcludeMissing fun scheduleDeviation(scheduleDeviation: JsonField) = apply { this.scheduleDeviation = scheduleDeviation } - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed - * along the active trip. - */ - fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: Double) = - scheduledDistanceAlongTrip(JsonField.of(scheduledDistanceAlongTrip)) - - /** - * Distance, in meters, the transit vehicle is scheduled to have progressed - * along the active trip. - */ - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: JsonField) = - apply { - this.scheduledDistanceAlongTrip = scheduledDistanceAlongTrip - } - /** * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. @@ -1295,8 +1293,6 @@ private constructor( * Time, in milliseconds since the Unix epoch, of midnight for the start of the * service date for the trip. */ - @JsonProperty("serviceDate") - @ExcludeMissing fun serviceDate(serviceDate: JsonField) = apply { this.serviceDate = serviceDate } @@ -1306,19 +1302,15 @@ private constructor( situationIds(JsonField.of(situationIds)) /** References to situation elements (if any) applicable to this trip. */ - @JsonProperty("situationIds") - @ExcludeMissing fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds + this.situationIds = situationIds.map { it.toMutableList() } } /** Current status modifiers for the trip. */ fun status(status: String) = status(JsonField.of(status)) /** Current status modifiers for the trip. */ - @JsonProperty("status") - @ExcludeMissing fun status(status: JsonField) = apply { this.status = status } /** Total length of the trip, in meters. */ @@ -1326,30 +1318,135 @@ private constructor( totalDistanceAlongTrip(JsonField.of(totalDistanceAlongTrip)) /** Total length of the trip, in meters. */ - @JsonProperty("totalDistanceAlongTrip") - @ExcludeMissing fun totalDistanceAlongTrip(totalDistanceAlongTrip: JsonField) = apply { this.totalDistanceAlongTrip = totalDistanceAlongTrip } + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + fun closestStopTimeOffset(closestStopTimeOffset: Long) = + closestStopTimeOffset(JsonField.of(closestStopTimeOffset)) + + /** + * Time offset from the closest stop to the current position of the transit + * vehicle (in seconds). + */ + fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { + this.closestStopTimeOffset = closestStopTimeOffset + } + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: String) = frequency(JsonField.of(frequency)) + + /** Information about frequency-based scheduling, if applicable to the trip. */ + fun frequency(frequency: JsonField) = apply { + this.frequency = frequency + } + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(lastKnownLocation: LastKnownLocation) = + lastKnownLocation(JsonField.of(lastKnownLocation)) + + /** Last known location of the transit vehicle. */ + fun lastKnownLocation(lastKnownLocation: JsonField) = apply { + this.lastKnownLocation = lastKnownLocation + } + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + fun lastKnownOrientation(lastKnownOrientation: Double) = + lastKnownOrientation(JsonField.of(lastKnownOrientation)) + + /** + * Last known orientation value received in real-time from the transit vehicle. + */ + fun lastKnownOrientation(lastKnownOrientation: JsonField) = apply { + this.lastKnownOrientation = lastKnownOrientation + } + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(nextStop: String) = nextStop(JsonField.of(nextStop)) + + /** ID of the next stop the transit vehicle is scheduled to arrive at. */ + fun nextStop(nextStop: JsonField) = apply { this.nextStop = nextStop } + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + fun nextStopTimeOffset(nextStopTimeOffset: Long) = + nextStopTimeOffset(JsonField.of(nextStopTimeOffset)) + + /** + * Time offset from the next stop to the current position of the transit vehicle + * (in seconds). + */ + fun nextStopTimeOffset(nextStopTimeOffset: JsonField) = apply { + this.nextStopTimeOffset = nextStopTimeOffset + } + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(orientation: Double) = orientation(JsonField.of(orientation)) + + /** Orientation of the transit vehicle, represented as an angle in degrees. */ + fun orientation(orientation: JsonField) = apply { + this.orientation = orientation + } + + /** Current position of the transit vehicle. */ + fun position(position: Position) = position(JsonField.of(position)) + + /** Current position of the transit vehicle. */ + fun position(position: JsonField) = apply { this.position = position } + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed + * along the active trip. + */ + fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: Double) = + scheduledDistanceAlongTrip(JsonField.of(scheduledDistanceAlongTrip)) + + /** + * Distance, in meters, the transit vehicle is scheduled to have progressed + * along the active trip. + */ + fun scheduledDistanceAlongTrip(scheduledDistanceAlongTrip: JsonField) = + apply { + this.scheduledDistanceAlongTrip = scheduledDistanceAlongTrip + } + + /** References to situation elements (if any) applicable to this trip. */ + fun addSituationId(situationId: String) = apply { + situationIds = + (situationIds ?: JsonField.of(mutableListOf())).apply { + asKnown() + .orElseThrow { + IllegalStateException( + "Field was set to non-list type: ${javaClass.simpleName}" + ) + } + .add(situationId) + } + } + /** ID of the transit vehicle currently serving the trip. */ fun vehicleId(vehicleId: String) = vehicleId(JsonField.of(vehicleId)) /** ID of the transit vehicle currently serving the trip. */ - @JsonProperty("vehicleId") - @ExcludeMissing fun vehicleId(vehicleId: JsonField) = apply { this.vehicleId = vehicleId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties(additionalProperties: Map) = @@ -1357,51 +1454,62 @@ private constructor( this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): TripStatus = TripStatus( - activeTripId, - blockTripSequence, - closestStop, + checkRequired("activeTripId", activeTripId), + checkRequired("blockTripSequence", blockTripSequence), + checkRequired("closestStop", closestStop), + checkRequired("distanceAlongTrip", distanceAlongTrip), + checkRequired("lastKnownDistanceAlongTrip", lastKnownDistanceAlongTrip), + checkRequired("lastLocationUpdateTime", lastLocationUpdateTime), + checkRequired("lastUpdateTime", lastUpdateTime), + checkRequired("occupancyCapacity", occupancyCapacity), + checkRequired("occupancyCount", occupancyCount), + checkRequired("occupancyStatus", occupancyStatus), + checkRequired("phase", phase), + checkRequired("predicted", predicted), + checkRequired("scheduleDeviation", scheduleDeviation), + checkRequired("serviceDate", serviceDate), + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, + checkRequired("status", status), + checkRequired("totalDistanceAlongTrip", totalDistanceAlongTrip), closestStopTimeOffset, - distanceAlongTrip, frequency, - lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, - lastLocationUpdateTime, - lastUpdateTime, nextStop, nextStopTimeOffset, - occupancyCapacity, - occupancyCount, - occupancyStatus, orientation, - phase, position, - predicted, - scheduleDeviation, scheduledDistanceAlongTrip, - serviceDate, - situationIds.map { it.toImmutable() }, - status, - totalDistanceAlongTrip, vehicleId, additionalProperties.toImmutable(), ) } /** Last known location of the transit vehicle. */ - @JsonDeserialize(builder = LastKnownLocation.Builder::class) @NoAutoDetect class LastKnownLocation + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the last known location of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -1409,21 +1517,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): LastKnownLocation = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -1433,7 +1545,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [LastKnownLocation]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -1442,42 +1555,46 @@ private constructor( @JvmSynthetic internal fun from(lastKnownLocation: LastKnownLocation) = apply { - this.lat = lastKnownLocation.lat - this.lon = lastKnownLocation.lon - additionalProperties(lastKnownLocation.additionalProperties) + lat = lastKnownLocation.lat + lon = lastKnownLocation.lon + additionalProperties = + lastKnownLocation.additionalProperties.toMutableMap() } /** Latitude of the last known location of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the last known location of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the last known location of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the last known location of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): LastKnownLocation = LastKnownLocation( lat, @@ -1491,34 +1608,34 @@ private constructor( return true } - return /* spotless:off */ other is LastKnownLocation && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is LastKnownLocation && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "LastKnownLocation{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" } /** Current position of the transit vehicle. */ - @JsonDeserialize(builder = Position.Builder::class) @NoAutoDetect class Position + @JsonCreator private constructor( - private val lat: JsonField, - private val lon: JsonField, - private val additionalProperties: Map, + @JsonProperty("lat") + @ExcludeMissing + private val lat: JsonField = JsonMissing.of(), + @JsonProperty("lon") + @ExcludeMissing + private val lon: JsonField = JsonMissing.of(), + @JsonAnySetter + private val additionalProperties: Map = immutableEmptyMap(), ) { - private var validated: Boolean = false - /** Latitude of the current position of the transit vehicle. */ fun lat(): Optional = Optional.ofNullable(lat.getNullable("lat")) @@ -1526,21 +1643,25 @@ private constructor( fun lon(): Optional = Optional.ofNullable(lon.getNullable("lon")) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("lat") @ExcludeMissing fun _lat(): JsonField = lat /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("lon") @ExcludeMissing fun _lon(): JsonField = lon @JsonAnyGetter @ExcludeMissing fun _additionalProperties(): Map = additionalProperties + private var validated: Boolean = false + fun validate(): Position = apply { - if (!validated) { - lat() - lon() - validated = true + if (validated) { + return@apply } + + lat() + lon() + validated = true } fun toBuilder() = Builder().from(this) @@ -1550,7 +1671,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [Position]. */ + class Builder internal constructor() { private var lat: JsonField = JsonMissing.of() private var lon: JsonField = JsonMissing.of() @@ -1559,42 +1681,45 @@ private constructor( @JvmSynthetic internal fun from(position: Position) = apply { - this.lat = position.lat - this.lon = position.lon - additionalProperties(position.additionalProperties) + lat = position.lat + lon = position.lon + additionalProperties = position.additionalProperties.toMutableMap() } /** Latitude of the current position of the transit vehicle. */ fun lat(lat: Double) = lat(JsonField.of(lat)) /** Latitude of the current position of the transit vehicle. */ - @JsonProperty("lat") - @ExcludeMissing fun lat(lat: JsonField) = apply { this.lat = lat } /** Longitude of the current position of the transit vehicle. */ fun lon(lon: Double) = lon(JsonField.of(lon)) /** Longitude of the current position of the transit vehicle. */ - @JsonProperty("lon") - @ExcludeMissing fun lon(lon: JsonField) = apply { this.lon = lon } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() - this.additionalProperties.putAll(additionalProperties) + putAllAdditionalProperties(additionalProperties) } - @JsonAnySetter fun putAdditionalProperty(key: String, value: JsonValue) = apply { - this.additionalProperties.put(key, value) + additionalProperties.put(key, value) } fun putAllAdditionalProperties( additionalProperties: Map ) = apply { this.additionalProperties.putAll(additionalProperties) } + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + fun build(): Position = Position( lat, @@ -1608,17 +1733,14 @@ private constructor( return true } - return /* spotless:off */ other is Position && this.lat == other.lat && this.lon == other.lon && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Position && lat == other.lat && lon == other.lon && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lat, lon, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(lat, lon, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "Position{lat=$lat, lon=$lon, additionalProperties=$additionalProperties}" @@ -1629,20 +1751,17 @@ private constructor( return true } - return /* spotless:off */ other is TripStatus && this.activeTripId == other.activeTripId && this.blockTripSequence == other.blockTripSequence && this.closestStop == other.closestStop && this.closestStopTimeOffset == other.closestStopTimeOffset && this.distanceAlongTrip == other.distanceAlongTrip && this.frequency == other.frequency && this.lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && this.lastKnownLocation == other.lastKnownLocation && this.lastKnownOrientation == other.lastKnownOrientation && this.lastLocationUpdateTime == other.lastLocationUpdateTime && this.lastUpdateTime == other.lastUpdateTime && this.nextStop == other.nextStop && this.nextStopTimeOffset == other.nextStopTimeOffset && this.occupancyCapacity == other.occupancyCapacity && this.occupancyCount == other.occupancyCount && this.occupancyStatus == other.occupancyStatus && this.orientation == other.orientation && this.phase == other.phase && this.position == other.position && this.predicted == other.predicted && this.scheduleDeviation == other.scheduleDeviation && this.scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && this.serviceDate == other.serviceDate && this.situationIds == other.situationIds && this.status == other.status && this.totalDistanceAlongTrip == other.totalDistanceAlongTrip && this.vehicleId == other.vehicleId && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is TripStatus && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && distanceAlongTrip == other.distanceAlongTrip && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && phase == other.phase && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && serviceDate == other.serviceDate && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && closestStopTimeOffset == other.closestStopTimeOffset && frequency == other.frequency && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && orientation == other.orientation && position == other.position && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && situationIds == other.situationIds && vehicleId == other.vehicleId && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(activeTripId, blockTripSequence, closestStop, distanceAlongTrip, lastKnownDistanceAlongTrip, lastLocationUpdateTime, lastUpdateTime, occupancyCapacity, occupancyCount, occupancyStatus, phase, predicted, scheduleDeviation, serviceDate, status, totalDistanceAlongTrip, closestStopTimeOffset, frequency, lastKnownLocation, lastKnownOrientation, nextStop, nextStopTimeOffset, orientation, position, scheduledDistanceAlongTrip, situationIds, vehicleId, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(activeTripId, blockTripSequence, closestStop, closestStopTimeOffset, distanceAlongTrip, frequency, lastKnownDistanceAlongTrip, lastKnownLocation, lastKnownOrientation, lastLocationUpdateTime, lastUpdateTime, nextStop, nextStopTimeOffset, occupancyCapacity, occupancyCount, occupancyStatus, orientation, phase, position, predicted, scheduleDeviation, scheduledDistanceAlongTrip, serviceDate, situationIds, status, totalDistanceAlongTrip, vehicleId, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "TripStatus{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, closestStopTimeOffset=$closestStopTimeOffset, distanceAlongTrip=$distanceAlongTrip, frequency=$frequency, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, orientation=$orientation, phase=$phase, position=$position, predicted=$predicted, scheduleDeviation=$scheduleDeviation, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, serviceDate=$serviceDate, situationIds=$situationIds, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" + "TripStatus{activeTripId=$activeTripId, blockTripSequence=$blockTripSequence, closestStop=$closestStop, distanceAlongTrip=$distanceAlongTrip, lastKnownDistanceAlongTrip=$lastKnownDistanceAlongTrip, lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, phase=$phase, predicted=$predicted, scheduleDeviation=$scheduleDeviation, serviceDate=$serviceDate, status=$status, totalDistanceAlongTrip=$totalDistanceAlongTrip, closestStopTimeOffset=$closestStopTimeOffset, frequency=$frequency, lastKnownLocation=$lastKnownLocation, lastKnownOrientation=$lastKnownOrientation, nextStop=$nextStop, nextStopTimeOffset=$nextStopTimeOffset, orientation=$orientation, position=$position, scheduledDistanceAlongTrip=$scheduledDistanceAlongTrip, situationIds=$situationIds, vehicleId=$vehicleId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1650,20 +1769,17 @@ private constructor( return true } - return /* spotless:off */ other is List && this.vehicleId == other.vehicleId && this.lastUpdateTime == other.lastUpdateTime && this.lastLocationUpdateTime == other.lastLocationUpdateTime && this.location == other.location && this.tripId == other.tripId && this.tripStatus == other.tripStatus && this.occupancyCapacity == other.occupancyCapacity && this.occupancyCount == other.occupancyCount && this.occupancyStatus == other.occupancyStatus && this.phase == other.phase && this.status == other.status && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is List && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && location == other.location && tripId == other.tripId && tripStatus == other.tripStatus && vehicleId == other.vehicleId && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && phase == other.phase && status == other.status && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(lastLocationUpdateTime, lastUpdateTime, location, tripId, tripStatus, vehicleId, occupancyCapacity, occupancyCount, occupancyStatus, phase, status, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(vehicleId, lastUpdateTime, lastLocationUpdateTime, location, tripId, tripStatus, occupancyCapacity, occupancyCount, occupancyStatus, phase, status, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = - "List{vehicleId=$vehicleId, lastUpdateTime=$lastUpdateTime, lastLocationUpdateTime=$lastLocationUpdateTime, location=$location, tripId=$tripId, tripStatus=$tripStatus, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, phase=$phase, status=$status, additionalProperties=$additionalProperties}" + "List{lastLocationUpdateTime=$lastLocationUpdateTime, lastUpdateTime=$lastUpdateTime, location=$location, tripId=$tripId, tripStatus=$tripStatus, vehicleId=$vehicleId, occupancyCapacity=$occupancyCapacity, occupancyCount=$occupancyCount, occupancyStatus=$occupancyStatus, phase=$phase, status=$status, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1671,18 +1787,17 @@ private constructor( return true } - return /* spotless:off */ other is Data && this.list == other.list && this.limitExceeded == other.limitExceeded && this.references == other.references && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && list == other.list && references == other.references && additionalProperties == other.additionalProperties /* spotless:on */ } - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(list, limitExceeded, references, additionalProperties) /* spotless:on */ - } - return hashCode - } + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, references, additionalProperties) } + /* spotless:on */ + + override fun hashCode(): Int = hashCode override fun toString() = - "Data{list=$list, limitExceeded=$limitExceeded, references=$references, additionalProperties=$additionalProperties}" + "Data{limitExceeded=$limitExceeded, list=$list, references=$references, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -1690,17 +1805,14 @@ private constructor( return true } - return /* spotless:off */ other is VehiclesForAgencyListResponse && this.code == other.code && this.currentTime == other.currentTime && this.text == other.text && this.version == other.version && this.data == other.data && this.additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is VehiclesForAgencyListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && data == other.data && additionalProperties == other.additionalProperties /* spotless:on */ } - private var hashCode: Int = 0 + /* spotless:off */ + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, data, additionalProperties) } + /* spotless:on */ - override fun hashCode(): Int { - if (hashCode == 0) { - hashCode = /* spotless:off */ Objects.hash(code, currentTime, text, version, data, additionalProperties) /* spotless:on */ - } - return hashCode - } + override fun hashCode(): Int = hashCode override fun toString() = "VehiclesForAgencyListResponse{code=$code, currentTime=$currentTime, text=$text, version=$version, data=$data, additionalProperties=$additionalProperties}" diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/AgenciesWithCoverageServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/AgenciesWithCoverageServiceAsyncImpl.kt index 323fc27..987fee8 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/AgenciesWithCoverageServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/AgenciesWithCoverageServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.AgenciesWithCoverageListParams import org.onebusaway.models.AgenciesWithCoverageListResponse class AgenciesWithCoverageServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : AgenciesWithCoverageServiceAsync { @@ -38,20 +39,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "agencies-with-coverage.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/AgencyServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/AgencyServiceAsyncImpl.kt index cb99dec..f11f454 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/AgencyServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/AgencyServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.AgencyRetrieveParams import org.onebusaway.models.AgencyRetrieveResponse class AgencyServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : AgencyServiceAsync { @@ -34,20 +35,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "agency", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ArrivalAndDepartureServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ArrivalAndDepartureServiceAsyncImpl.kt index 44a3670..f78eb4a 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ArrivalAndDepartureServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ArrivalAndDepartureServiceAsyncImpl.kt @@ -11,6 +11,7 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ArrivalAndDepartureListParams import org.onebusaway.models.ArrivalAndDepartureListResponse @@ -18,7 +19,7 @@ import org.onebusaway.models.ArrivalAndDepartureRetrieveParams import org.onebusaway.models.ArrivalAndDepartureRetrieveResponse class ArrivalAndDepartureServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ArrivalAndDepartureServiceAsync { @@ -42,21 +43,19 @@ constructor( "arrival-and-departure-for-stop", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } private val listHandler: Handler = @@ -77,20 +76,18 @@ constructor( "arrivals-and-departures-for-stop", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/BlockServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/BlockServiceAsyncImpl.kt index a0f011e..0ecc49b 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/BlockServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/BlockServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.BlockRetrieveParams import org.onebusaway.models.BlockRetrieveResponse class BlockServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : BlockServiceAsync { @@ -34,20 +35,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "block", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ConfigServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ConfigServiceAsyncImpl.kt index 4ab63ba..f3b57a2 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ConfigServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ConfigServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ConfigRetrieveParams import org.onebusaway.models.ConfigRetrieveResponse class ConfigServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ConfigServiceAsync { @@ -34,20 +35,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "config.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/CurrentTimeServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/CurrentTimeServiceAsyncImpl.kt index fb53cef..399e61e 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/CurrentTimeServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/CurrentTimeServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.CurrentTimeRetrieveParams import org.onebusaway.models.CurrentTimeRetrieveResponse class CurrentTimeServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : CurrentTimeServiceAsync { @@ -35,20 +36,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "current-time.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ReportProblemWithStopServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ReportProblemWithStopServiceAsyncImpl.kt index d1fdd21..63945b6 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ReportProblemWithStopServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ReportProblemWithStopServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ReportProblemWithStopRetrieveParams import org.onebusaway.models.ResponseWrapper class ReportProblemWithStopServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ReportProblemWithStopServiceAsync { @@ -39,20 +40,18 @@ constructor( "report-problem-with-stop", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ReportProblemWithTripServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ReportProblemWithTripServiceAsyncImpl.kt index a9684b4..f97f9ec 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ReportProblemWithTripServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ReportProblemWithTripServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ReportProblemWithTripRetrieveParams import org.onebusaway.models.ResponseWrapper class ReportProblemWithTripServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ReportProblemWithTripServiceAsync { @@ -39,20 +40,18 @@ constructor( "report-problem-with-trip", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RouteIdsForAgencyServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RouteIdsForAgencyServiceAsyncImpl.kt index 946e9e5..fe189de 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RouteIdsForAgencyServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RouteIdsForAgencyServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.RouteIdsForAgencyListParams import org.onebusaway.models.RouteIdsForAgencyListResponse class RouteIdsForAgencyServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : RouteIdsForAgencyServiceAsync { @@ -40,20 +41,18 @@ constructor( "route-ids-for-agency", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RouteServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RouteServiceAsyncImpl.kt index 2053d9f..0cb2551 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RouteServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RouteServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.RouteRetrieveParams import org.onebusaway.models.RouteRetrieveResponse class RouteServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : RouteServiceAsync { @@ -34,20 +35,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "route", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RoutesForAgencyServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RoutesForAgencyServiceAsyncImpl.kt index be8954a..73593ee 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RoutesForAgencyServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RoutesForAgencyServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.RoutesForAgencyListParams import org.onebusaway.models.RoutesForAgencyListResponse class RoutesForAgencyServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : RoutesForAgencyServiceAsync { @@ -40,20 +41,18 @@ constructor( "routes-for-agency", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RoutesForLocationServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RoutesForLocationServiceAsyncImpl.kt index 3da5cf6..092cc9e 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RoutesForLocationServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/RoutesForLocationServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.RoutesForLocationListParams import org.onebusaway.models.RoutesForLocationListResponse class RoutesForLocationServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : RoutesForLocationServiceAsync { @@ -35,20 +36,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "routes-for-location.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ScheduleForRouteServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ScheduleForRouteServiceAsyncImpl.kt index 4d0fed3..16c23fa 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ScheduleForRouteServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ScheduleForRouteServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ScheduleForRouteRetrieveParams import org.onebusaway.models.ScheduleForRouteRetrieveResponse class ScheduleForRouteServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ScheduleForRouteServiceAsync { @@ -40,20 +41,18 @@ constructor( "schedule-for-route", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ScheduleForStopServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ScheduleForStopServiceAsyncImpl.kt index 5b4b0f3..3461606 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ScheduleForStopServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ScheduleForStopServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ScheduleForStopRetrieveParams import org.onebusaway.models.ScheduleForStopRetrieveResponse class ScheduleForStopServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ScheduleForStopServiceAsync { @@ -40,20 +41,18 @@ constructor( "schedule-for-stop", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/SearchForRouteServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/SearchForRouteServiceAsyncImpl.kt index 0dd6fb7..b2cbde6 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/SearchForRouteServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/SearchForRouteServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.SearchForRouteListParams import org.onebusaway.models.SearchForRouteListResponse class SearchForRouteServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : SearchForRouteServiceAsync { @@ -35,20 +36,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "search", "route.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/SearchForStopServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/SearchForStopServiceAsyncImpl.kt index e644aa3..ffc950d 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/SearchForStopServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/SearchForStopServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.SearchForStopListParams import org.onebusaway.models.SearchForStopListResponse class SearchForStopServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : SearchForStopServiceAsync { @@ -35,20 +36,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "search", "stop.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ShapeServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ShapeServiceAsyncImpl.kt index 456938b..cc692d4 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ShapeServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/ShapeServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ShapeRetrieveParams import org.onebusaway.models.ShapeRetrieveResponse class ShapeServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ShapeServiceAsync { @@ -34,20 +35,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "shape", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopIdsForAgencyServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopIdsForAgencyServiceAsyncImpl.kt index 80f9fe1..2269905 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopIdsForAgencyServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopIdsForAgencyServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.StopIdsForAgencyListParams import org.onebusaway.models.StopIdsForAgencyListResponse class StopIdsForAgencyServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : StopIdsForAgencyServiceAsync { @@ -40,20 +41,18 @@ constructor( "stop-ids-for-agency", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopServiceAsyncImpl.kt index 134682e..783e18b 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.StopRetrieveParams import org.onebusaway.models.StopRetrieveResponse class StopServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : StopServiceAsync { @@ -34,20 +35,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "stop", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopsForAgencyServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopsForAgencyServiceAsyncImpl.kt index e77c0d7..1cb4bcf 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopsForAgencyServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopsForAgencyServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.StopsForAgencyListParams import org.onebusaway.models.StopsForAgencyListResponse class StopsForAgencyServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : StopsForAgencyServiceAsync { @@ -40,20 +41,18 @@ constructor( "stops-for-agency", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopsForLocationServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopsForLocationServiceAsyncImpl.kt index e646761..cd2d5ac 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopsForLocationServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopsForLocationServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.StopsForLocationListParams import org.onebusaway.models.StopsForLocationListResponse class StopsForLocationServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : StopsForLocationServiceAsync { @@ -35,20 +36,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "stops-for-location.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopsForRouteServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopsForRouteServiceAsyncImpl.kt index f65a3d9..c218860 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopsForRouteServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/StopsForRouteServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.StopsForRouteListParams import org.onebusaway.models.StopsForRouteListResponse class StopsForRouteServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : StopsForRouteServiceAsync { @@ -40,20 +41,18 @@ constructor( "stops-for-route", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripDetailServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripDetailServiceAsyncImpl.kt index 653962f..8f03c39 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripDetailServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripDetailServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.TripDetailRetrieveParams import org.onebusaway.models.TripDetailRetrieveResponse class TripDetailServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : TripDetailServiceAsync { @@ -35,20 +36,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "trip-details", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripForVehicleServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripForVehicleServiceAsyncImpl.kt index 222c4ce..a2a4297 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripForVehicleServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripForVehicleServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.TripForVehicleRetrieveParams import org.onebusaway.models.TripForVehicleRetrieveResponse class TripForVehicleServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : TripForVehicleServiceAsync { @@ -40,20 +41,18 @@ constructor( "trip-for-vehicle", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripServiceAsyncImpl.kt index 784b015..3313c58 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.TripRetrieveParams import org.onebusaway.models.TripRetrieveResponse class TripServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : TripServiceAsync { @@ -34,20 +35,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "trip", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripsForLocationServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripsForLocationServiceAsyncImpl.kt index d4eb6e1..cdc234d 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripsForLocationServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripsForLocationServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.TripsForLocationListParams import org.onebusaway.models.TripsForLocationListResponse class TripsForLocationServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : TripsForLocationServiceAsync { @@ -35,20 +36,18 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "trips-for-location.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripsForRouteServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripsForRouteServiceAsyncImpl.kt index 0ab7488..a68955e 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripsForRouteServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/TripsForRouteServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.TripsForRouteListParams import org.onebusaway.models.TripsForRouteListResponse class TripsForRouteServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : TripsForRouteServiceAsync { @@ -40,20 +41,18 @@ constructor( "trips-for-route", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/VehiclesForAgencyServiceAsyncImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/VehiclesForAgencyServiceAsyncImpl.kt index 81658bb..ed8e4a9 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/VehiclesForAgencyServiceAsyncImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/async/VehiclesForAgencyServiceAsyncImpl.kt @@ -11,12 +11,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepareAsync import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.VehiclesForAgencyListParams import org.onebusaway.models.VehiclesForAgencyListResponse class VehiclesForAgencyServiceAsyncImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : VehiclesForAgencyServiceAsync { @@ -40,20 +41,18 @@ constructor( "vehicles-for-agency", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.executeAsync(request, requestOptions).thenApply { response - -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() + .prepareAsync(clientOptions, params) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() + } } - } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/AgenciesWithCoverageServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/AgenciesWithCoverageServiceImpl.kt index 1c8cfeb..f1781f8 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/AgenciesWithCoverageServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/AgenciesWithCoverageServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.AgenciesWithCoverageListParams import org.onebusaway.models.AgenciesWithCoverageListResponse class AgenciesWithCoverageServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : AgenciesWithCoverageService { @@ -37,19 +38,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "agencies-with-coverage.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/AgencyServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/AgencyServiceImpl.kt index c39bf09..1c98da6 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/AgencyServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/AgencyServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.AgencyRetrieveParams import org.onebusaway.models.AgencyRetrieveResponse class AgencyServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : AgencyService { @@ -33,19 +34,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "agency", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ArrivalAndDepartureServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ArrivalAndDepartureServiceImpl.kt index aa760e4..20a92a7 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ArrivalAndDepartureServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ArrivalAndDepartureServiceImpl.kt @@ -10,6 +10,7 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ArrivalAndDepartureListParams import org.onebusaway.models.ArrivalAndDepartureListResponse @@ -17,7 +18,7 @@ import org.onebusaway.models.ArrivalAndDepartureRetrieveParams import org.onebusaway.models.ArrivalAndDepartureRetrieveResponse class ArrivalAndDepartureServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ArrivalAndDepartureService { @@ -41,20 +42,16 @@ constructor( "arrival-and-departure-for-stop", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } private val listHandler: Handler = @@ -75,19 +72,15 @@ constructor( "arrivals-and-departures-for-stop", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/BlockServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/BlockServiceImpl.kt index c540ec2..95c79c1 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/BlockServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/BlockServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.BlockRetrieveParams import org.onebusaway.models.BlockRetrieveResponse class BlockServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : BlockService { @@ -33,19 +34,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "block", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ConfigServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ConfigServiceImpl.kt index 574e7b2..4f8b585 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ConfigServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ConfigServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ConfigRetrieveParams import org.onebusaway.models.ConfigRetrieveResponse class ConfigServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ConfigService { @@ -33,19 +34,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "config.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/CurrentTimeServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/CurrentTimeServiceImpl.kt index b5abf2f..a468a87 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/CurrentTimeServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/CurrentTimeServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.CurrentTimeRetrieveParams import org.onebusaway.models.CurrentTimeRetrieveResponse class CurrentTimeServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : CurrentTimeService { @@ -34,19 +35,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "current-time.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ReportProblemWithStopServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ReportProblemWithStopServiceImpl.kt index fc36bc6..4899729 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ReportProblemWithStopServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ReportProblemWithStopServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ReportProblemWithStopRetrieveParams import org.onebusaway.models.ResponseWrapper class ReportProblemWithStopServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ReportProblemWithStopService { @@ -38,19 +39,15 @@ constructor( "report-problem-with-stop", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ReportProblemWithTripServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ReportProblemWithTripServiceImpl.kt index e6b700e..76b40c0 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ReportProblemWithTripServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ReportProblemWithTripServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ReportProblemWithTripRetrieveParams import org.onebusaway.models.ResponseWrapper class ReportProblemWithTripServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ReportProblemWithTripService { @@ -38,19 +39,15 @@ constructor( "report-problem-with-trip", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RouteIdsForAgencyServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RouteIdsForAgencyServiceImpl.kt index b6f67da..afc9602 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RouteIdsForAgencyServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RouteIdsForAgencyServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.RouteIdsForAgencyListParams import org.onebusaway.models.RouteIdsForAgencyListResponse class RouteIdsForAgencyServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : RouteIdsForAgencyService { @@ -39,19 +40,15 @@ constructor( "route-ids-for-agency", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RouteServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RouteServiceImpl.kt index 0e6ea10..64d3eb2 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RouteServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RouteServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.RouteRetrieveParams import org.onebusaway.models.RouteRetrieveResponse class RouteServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : RouteService { @@ -33,19 +34,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "route", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RoutesForAgencyServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RoutesForAgencyServiceImpl.kt index 858cf23..f1850cb 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RoutesForAgencyServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RoutesForAgencyServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.RoutesForAgencyListParams import org.onebusaway.models.RoutesForAgencyListResponse class RoutesForAgencyServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : RoutesForAgencyService { @@ -39,19 +40,15 @@ constructor( "routes-for-agency", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RoutesForLocationServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RoutesForLocationServiceImpl.kt index 0abe6fc..c28bfc4 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RoutesForLocationServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/RoutesForLocationServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.RoutesForLocationListParams import org.onebusaway.models.RoutesForLocationListResponse class RoutesForLocationServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : RoutesForLocationService { @@ -34,19 +35,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "routes-for-location.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ScheduleForRouteServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ScheduleForRouteServiceImpl.kt index 00372d5..ffbfe43 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ScheduleForRouteServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ScheduleForRouteServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ScheduleForRouteRetrieveParams import org.onebusaway.models.ScheduleForRouteRetrieveResponse class ScheduleForRouteServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ScheduleForRouteService { @@ -39,19 +40,15 @@ constructor( "schedule-for-route", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ScheduleForStopServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ScheduleForStopServiceImpl.kt index bbeb9f0..114f9b2 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ScheduleForStopServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ScheduleForStopServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ScheduleForStopRetrieveParams import org.onebusaway.models.ScheduleForStopRetrieveResponse class ScheduleForStopServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ScheduleForStopService { @@ -39,19 +40,15 @@ constructor( "schedule-for-stop", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/SearchForRouteServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/SearchForRouteServiceImpl.kt index c772d84..3be0bc5 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/SearchForRouteServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/SearchForRouteServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.SearchForRouteListParams import org.onebusaway.models.SearchForRouteListResponse class SearchForRouteServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : SearchForRouteService { @@ -34,19 +35,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "search", "route.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/SearchForStopServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/SearchForStopServiceImpl.kt index 4392c97..ec7bcd4 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/SearchForStopServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/SearchForStopServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.SearchForStopListParams import org.onebusaway.models.SearchForStopListResponse class SearchForStopServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : SearchForStopService { @@ -34,19 +35,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "search", "stop.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ShapeServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ShapeServiceImpl.kt index 72b6132..1ddb284 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ShapeServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/ShapeServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.ShapeRetrieveParams import org.onebusaway.models.ShapeRetrieveResponse class ShapeServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : ShapeService { @@ -33,19 +34,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "shape", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopIdsForAgencyServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopIdsForAgencyServiceImpl.kt index e78aca1..fe012fc 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopIdsForAgencyServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopIdsForAgencyServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.StopIdsForAgencyListParams import org.onebusaway.models.StopIdsForAgencyListResponse class StopIdsForAgencyServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : StopIdsForAgencyService { @@ -39,19 +40,15 @@ constructor( "stop-ids-for-agency", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopServiceImpl.kt index 9a72422..7a5d88a 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.StopRetrieveParams import org.onebusaway.models.StopRetrieveResponse class StopServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : StopService { @@ -33,19 +34,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "stop", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopsForAgencyServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopsForAgencyServiceImpl.kt index 6b64894..5fdab39 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopsForAgencyServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopsForAgencyServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.StopsForAgencyListParams import org.onebusaway.models.StopsForAgencyListResponse class StopsForAgencyServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : StopsForAgencyService { @@ -39,19 +40,15 @@ constructor( "stops-for-agency", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopsForLocationServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopsForLocationServiceImpl.kt index 89b6807..69c3566 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopsForLocationServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopsForLocationServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.StopsForLocationListParams import org.onebusaway.models.StopsForLocationListResponse class StopsForLocationServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : StopsForLocationService { @@ -34,19 +35,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "stops-for-location.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopsForRouteServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopsForRouteServiceImpl.kt index f5a5459..0468d86 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopsForRouteServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/StopsForRouteServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.StopsForRouteListParams import org.onebusaway.models.StopsForRouteListResponse class StopsForRouteServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : StopsForRouteService { @@ -39,19 +40,15 @@ constructor( "stops-for-route", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripDetailServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripDetailServiceImpl.kt index 4229393..0db93f0 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripDetailServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripDetailServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.TripDetailRetrieveParams import org.onebusaway.models.TripDetailRetrieveResponse class TripDetailServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : TripDetailService { @@ -34,19 +35,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "trip-details", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripForVehicleServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripForVehicleServiceImpl.kt index a1251db..3718f47 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripForVehicleServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripForVehicleServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.TripForVehicleRetrieveParams import org.onebusaway.models.TripForVehicleRetrieveResponse class TripForVehicleServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : TripForVehicleService { @@ -39,19 +40,15 @@ constructor( "trip-for-vehicle", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripServiceImpl.kt index 484fe4c..57d1a7a 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.TripRetrieveParams import org.onebusaway.models.TripRetrieveResponse class TripServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : TripService { @@ -33,19 +34,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "trip", "${params.getPathParam(0)}.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { retrieveHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripsForLocationServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripsForLocationServiceImpl.kt index 7133779..536a1d1 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripsForLocationServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripsForLocationServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.TripsForLocationListParams import org.onebusaway.models.TripsForLocationListResponse class TripsForLocationServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : TripsForLocationService { @@ -34,19 +35,15 @@ constructor( HttpRequest.builder() .method(HttpMethod.GET) .addPathSegments("api", "where", "trips-for-location.json") - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripsForRouteServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripsForRouteServiceImpl.kt index b7f5799..7e3fe19 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripsForRouteServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/TripsForRouteServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.TripsForRouteListParams import org.onebusaway.models.TripsForRouteListResponse class TripsForRouteServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : TripsForRouteService { @@ -39,19 +40,15 @@ constructor( "trips-for-route", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/VehiclesForAgencyServiceImpl.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/VehiclesForAgencyServiceImpl.kt index 65a44c4..7030568 100644 --- a/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/VehiclesForAgencyServiceImpl.kt +++ b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/services/blocking/VehiclesForAgencyServiceImpl.kt @@ -10,12 +10,13 @@ import org.onebusaway.core.handlers.withErrorHandler import org.onebusaway.core.http.HttpMethod import org.onebusaway.core.http.HttpRequest import org.onebusaway.core.http.HttpResponse.Handler +import org.onebusaway.core.prepare import org.onebusaway.errors.OnebusawaySdkError import org.onebusaway.models.VehiclesForAgencyListParams import org.onebusaway.models.VehiclesForAgencyListResponse class VehiclesForAgencyServiceImpl -constructor( +internal constructor( private val clientOptions: ClientOptions, ) : VehiclesForAgencyService { @@ -39,19 +40,15 @@ constructor( "vehicles-for-agency", "${params.getPathParam(0)}.json" ) - .putAllQueryParams(clientOptions.queryParams.asMap()) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers.asMap()) - .replaceAllHeaders(params.getHeaders()) .build() - return clientOptions.httpClient.execute(request, requestOptions).let { response -> - response - .use { listHandler.handle(it) } - .apply { - if (requestOptions.responseValidation ?: clientOptions.responseValidation) { - validate() - } + .prepare(clientOptions, params) + val response = clientOptions.httpClient.execute(request, requestOptions) + return response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation ?: clientOptions.responseValidation) { + it.validate() } - } + } } } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/core/http/HttpRequestTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/core/http/HttpRequestTest.kt deleted file mode 100644 index 1a19904..0000000 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/core/http/HttpRequestTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package org.onebusaway.core.http - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test - -internal class HttpRequestTest { - - @Test - fun caseInsensitiveHeadersAccessors() { - val request = - HttpRequest.builder() - .method(HttpMethod.POST) - .putHeader("something_lowercase", "lowercase") - .putHeader("Something_Capitalized", "Capitalized") - .putHeader("SOMETHING_UPPERCASE", "UPPERCASE") - .build() - assertThat(request.headers.get("SOMETHING_LOWERCASE").getOrNull(0)).isEqualTo("lowercase") - assertThat(request.headers.get("something_capitalized").getOrNull(0)) - .isEqualTo("Capitalized") - assertThat(request.headers.get("Something_Uppercase").getOrNull(0)).isEqualTo("UPPERCASE") - } -} diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/core/http/RetryingHttpClientTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/core/http/RetryingHttpClientTest.kt index 22b8b7f..0cda7ea 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/core/http/RetryingHttpClientTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/core/http/RetryingHttpClientTest.kt @@ -4,39 +4,84 @@ import com.github.tomakehurst.wiremock.client.WireMock.* import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo import com.github.tomakehurst.wiremock.junit5.WireMockTest import com.github.tomakehurst.wiremock.stubbing.Scenario +import java.io.InputStream +import java.util.concurrent.CompletableFuture import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource import org.onebusaway.client.okhttp.OkHttpClient +import org.onebusaway.core.RequestOptions @WireMockTest internal class RetryingHttpClientTest { + private var openResponseCount = 0 private lateinit var httpClient: HttpClient @BeforeEach fun beforeEach(wmRuntimeInfo: WireMockRuntimeInfo) { - httpClient = OkHttpClient.builder().baseUrl(wmRuntimeInfo.httpBaseUrl).build() + val okHttpClient = OkHttpClient.builder().baseUrl(wmRuntimeInfo.httpBaseUrl).build() + httpClient = + object : HttpClient { + override fun execute( + request: HttpRequest, + requestOptions: RequestOptions + ): HttpResponse = trackClose(okHttpClient.execute(request, requestOptions)) + + override fun executeAsync( + request: HttpRequest, + requestOptions: RequestOptions + ): CompletableFuture = + okHttpClient.executeAsync(request, requestOptions).thenApply { trackClose(it) } + + override fun close() = okHttpClient.close() + + private fun trackClose(response: HttpResponse): HttpResponse { + openResponseCount++ + return object : HttpResponse { + private var isClosed = false + + override fun statusCode(): Int = response.statusCode() + + override fun headers(): Headers = response.headers() + + override fun body(): InputStream = response.body() + + override fun close() { + response.close() + if (isClosed) { + return + } + openResponseCount-- + isClosed = true + } + } + } + } resetAllScenarios() } - @Test - fun byDefaultShouldNotAddIdempotencyHeaderToRequest() { - val request = - HttpRequest.builder().method(HttpMethod.POST).addPathSegment("something").build() + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun execute(async: Boolean) { stubFor(post(urlPathEqualTo("/something")).willReturn(ok())) val retryingClient = RetryingHttpClient.builder().httpClient(httpClient).build() - val response = retryingClient.execute(request) + + val response = + retryingClient.execute( + HttpRequest.builder().method(HttpMethod.POST).addPathSegment("something").build(), + async + ) + assertThat(response.statusCode()).isEqualTo(200) verify(1, postRequestedFor(urlPathEqualTo("/something"))) + assertNoResponseLeaks() } - @Test - fun whenProvidedShouldAddIdempotencyHeaderToRequest() { - val request = - HttpRequest.builder().method(HttpMethod.POST).addPathSegment("something").build() + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun execute_withIdempotencyHeader(async: Boolean) { stubFor( post(urlPathEqualTo("/something")) .withHeader("X-Some-Header", matching("stainless-java-retry-.+")) @@ -45,21 +90,28 @@ internal class RetryingHttpClientTest { val retryingClient = RetryingHttpClient.builder() .httpClient(httpClient) + .maxRetries(2) .idempotencyHeader("X-Some-Header") .build() - val response = retryingClient.execute(request) + + val response = + retryingClient.execute( + HttpRequest.builder().method(HttpMethod.POST).addPathSegment("something").build(), + async + ) + assertThat(response.statusCode()).isEqualTo(200) verify(1, postRequestedFor(urlPathEqualTo("/something"))) + assertNoResponseLeaks() } @ParameterizedTest @ValueSource(booleans = [false, true]) - fun retryAfterHeader(async: Boolean) { - val request = - HttpRequest.builder().method(HttpMethod.POST).addPathSegment("something").build() + fun execute_withRetryAfterHeader(async: Boolean) { stubFor( post(urlPathEqualTo("/something")) - .inScenario("foo") // first we fail with a retry after header given as a date + // First we fail with a retry after header given as a date + .inScenario("foo") .whenScenarioStateIs(Scenario.STARTED) .willReturn( serviceUnavailable().withHeader("Retry-After", "Wed, 21 Oct 2015 07:28:00 GMT") @@ -68,14 +120,16 @@ internal class RetryingHttpClientTest { ) stubFor( post(urlPathEqualTo("/something")) - .inScenario("foo") // then we fail with a retry after header given as a delay + // Then we fail with a retry after header given as a delay + .inScenario("foo") .whenScenarioStateIs("RETRY_AFTER_DATE") .willReturn(serviceUnavailable().withHeader("Retry-After", "1.234")) .willSetStateTo("RETRY_AFTER_DELAY") ) stubFor( post(urlPathEqualTo("/something")) - .inScenario("foo") // then we return a success + // Then we return a success + .inScenario("foo") .whenScenarioStateIs("RETRY_AFTER_DELAY") .willReturn(ok()) .willSetStateTo("COMPLETED") @@ -84,8 +138,10 @@ internal class RetryingHttpClientTest { RetryingHttpClient.builder().httpClient(httpClient).maxRetries(2).build() val response = - if (async) retryingClient.executeAsync(request).get() - else retryingClient.execute(request) + retryingClient.execute( + HttpRequest.builder().method(HttpMethod.POST).addPathSegment("something").build(), + async + ) assertThat(response.statusCode()).isEqualTo(200) verify( @@ -103,17 +159,12 @@ internal class RetryingHttpClientTest { postRequestedFor(urlPathEqualTo("/something")) .withHeader("x-stainless-retry-count", equalTo("2")) ) + assertNoResponseLeaks() } @ParameterizedTest @ValueSource(booleans = [false, true]) - fun overwriteRetryCountHeader(async: Boolean) { - val request = - HttpRequest.builder() - .method(HttpMethod.POST) - .addPathSegment("something") - .putHeader("x-stainless-retry-count", "42") - .build() + fun execute_withOverwrittenRetryCountHeader(async: Boolean) { stubFor( post(urlPathEqualTo("/something")) .inScenario("foo") // first we fail with a retry after header given as a date @@ -134,8 +185,14 @@ internal class RetryingHttpClientTest { RetryingHttpClient.builder().httpClient(httpClient).maxRetries(2).build() val response = - if (async) retryingClient.executeAsync(request).get() - else retryingClient.execute(request) + retryingClient.execute( + HttpRequest.builder() + .method(HttpMethod.POST) + .addPathSegment("something") + .putHeader("x-stainless-retry-count", "42") + .build(), + async + ) assertThat(response.statusCode()).isEqualTo(200) verify( @@ -143,12 +200,12 @@ internal class RetryingHttpClientTest { postRequestedFor(urlPathEqualTo("/something")) .withHeader("x-stainless-retry-count", equalTo("42")) ) + assertNoResponseLeaks() } - @Test - fun retryAfterMsHeader() { - val request = - HttpRequest.builder().method(HttpMethod.POST).addPathSegment("something").build() + @ParameterizedTest + @ValueSource(booleans = [false, true]) + fun execute_withRetryAfterMsHeader(async: Boolean) { stubFor( post(urlPathEqualTo("/something")) .inScenario("foo") @@ -165,8 +222,22 @@ internal class RetryingHttpClientTest { ) val retryingClient = RetryingHttpClient.builder().httpClient(httpClient).maxRetries(1).build() - val response = retryingClient.execute(request) + + val response = + retryingClient.execute( + HttpRequest.builder().method(HttpMethod.POST).addPathSegment("something").build(), + async + ) + assertThat(response.statusCode()).isEqualTo(200) verify(2, postRequestedFor(urlPathEqualTo("/something"))) + assertNoResponseLeaks() } + + private fun HttpClient.execute(request: HttpRequest, async: Boolean): HttpResponse = + if (async) executeAsync(request).get() else execute(request) + + // When retrying, all failed responses should be closed. Only the final returned response should + // be open. + private fun assertNoResponseLeaks() = assertThat(openResponseCount).isEqualTo(1) } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/core/http/SerializerTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/core/http/SerializerTest.kt index 8a87713..22f9102 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/core/http/SerializerTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/core/http/SerializerTest.kt @@ -65,7 +65,8 @@ internal class SerializerTest { } @NoAutoDetect - class Builder { + class Builder internal constructor() { + private var isActive: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/AgenciesWithCoverageListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/AgenciesWithCoverageListParamsTest.kt index b9a2bd0..7a32ee3 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/AgenciesWithCoverageListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/AgenciesWithCoverageListParamsTest.kt @@ -3,12 +3,11 @@ package org.onebusaway.models import org.junit.jupiter.api.Test -import org.onebusaway.models.* class AgenciesWithCoverageListParamsTest { @Test - fun createAgenciesWithCoverageListParams() { + fun create() { AgenciesWithCoverageListParams.builder().build() } } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/AgencyRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/AgencyRetrieveParamsTest.kt index ac27d2d..9b28a54 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/AgencyRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/AgencyRetrieveParamsTest.kt @@ -4,12 +4,11 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* class AgencyRetrieveParamsTest { @Test - fun createAgencyRetrieveParams() { + fun create() { AgencyRetrieveParams.builder().agencyId("agencyID").build() } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ArrivalAndDepartureListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ArrivalAndDepartureListParamsTest.kt index a926379..26808dd 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ArrivalAndDepartureListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ArrivalAndDepartureListParamsTest.kt @@ -5,49 +5,49 @@ package org.onebusaway.models import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class ArrivalAndDepartureListParamsTest { @Test - fun createArrivalAndDepartureListParams() { + fun create() { ArrivalAndDepartureListParams.builder() - .stopId("stopID") - .minutesAfter(123L) - .minutesBefore(123L) + .stopId("1_75403") + .minutesAfter(0L) + .minutesBefore(0L) .time(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() } @Test - fun getQueryParams() { + fun queryParams() { val params = ArrivalAndDepartureListParams.builder() - .stopId("stopID") - .minutesAfter(123L) - .minutesBefore(123L) + .stopId("1_75403") + .minutesAfter(0L) + .minutesBefore(0L) .time(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() - val expected = mutableMapOf>() - expected.put("minutesAfter", listOf("123")) - expected.put("minutesBefore", listOf("123")) - expected.put("time", listOf("2019-12-27T18:11:19.117Z")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("minutesAfter", "0") + expected.put("minutesBefore", "0") + expected.put("time", "2019-12-27T18:11:19.117Z") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { - val params = ArrivalAndDepartureListParams.builder().stopId("stopID").build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + fun queryParamsWithoutOptionalFields() { + val params = ArrivalAndDepartureListParams.builder().stopId("1_75403").build() + val expected = QueryParams.builder() + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test fun getPathParam() { - val params = ArrivalAndDepartureListParams.builder().stopId("stopID").build() + val params = ArrivalAndDepartureListParams.builder().stopId("1_75403").build() assertThat(params).isNotNull // path param "stopId" - assertThat(params.getPathParam(0)).isEqualTo("stopID") + assertThat(params.getPathParam(0)).isEqualTo("1_75403") // out-of-bound path param assertThat(params.getPathParam(1)).isEqualTo("") } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ArrivalAndDepartureRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ArrivalAndDepartureRetrieveParamsTest.kt index 1dcf6c7..37b7569 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ArrivalAndDepartureRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ArrivalAndDepartureRetrieveParamsTest.kt @@ -4,67 +4,67 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class ArrivalAndDepartureRetrieveParamsTest { @Test - fun createArrivalAndDepartureRetrieveParams() { + fun create() { ArrivalAndDepartureRetrieveParams.builder() - .stopId("stopID") - .serviceDate(123L) + .stopId("1_75403") + .serviceDate(0L) .tripId("tripId") - .stopSequence(123L) - .time(123L) + .stopSequence(0L) + .time(0L) .vehicleId("vehicleId") .build() } @Test - fun getQueryParams() { + fun queryParams() { val params = ArrivalAndDepartureRetrieveParams.builder() - .stopId("stopID") - .serviceDate(123L) + .stopId("1_75403") + .serviceDate(0L) .tripId("tripId") - .stopSequence(123L) - .time(123L) + .stopSequence(0L) + .time(0L) .vehicleId("vehicleId") .build() - val expected = mutableMapOf>() - expected.put("serviceDate", listOf("123")) - expected.put("tripId", listOf("tripId")) - expected.put("stopSequence", listOf("123")) - expected.put("time", listOf("123")) - expected.put("vehicleId", listOf("vehicleId")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("serviceDate", "0") + expected.put("tripId", "tripId") + expected.put("stopSequence", "0") + expected.put("time", "0") + expected.put("vehicleId", "vehicleId") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = ArrivalAndDepartureRetrieveParams.builder() - .stopId("stopID") - .serviceDate(123L) + .stopId("1_75403") + .serviceDate(0L) .tripId("tripId") .build() - val expected = mutableMapOf>() - expected.put("serviceDate", listOf("123")) - expected.put("tripId", listOf("tripId")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("serviceDate", "0") + expected.put("tripId", "tripId") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test fun getPathParam() { val params = ArrivalAndDepartureRetrieveParams.builder() - .stopId("stopID") - .serviceDate(123L) + .stopId("1_75403") + .serviceDate(0L) .tripId("tripId") .build() assertThat(params).isNotNull // path param "stopId" - assertThat(params.getPathParam(0)).isEqualTo("stopID") + assertThat(params.getPathParam(0)).isEqualTo("1_75403") // out-of-bound path param assertThat(params.getPathParam(1)).isEqualTo("") } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/BlockRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/BlockRetrieveParamsTest.kt index ce5a695..e3d6b10 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/BlockRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/BlockRetrieveParamsTest.kt @@ -4,12 +4,11 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* class BlockRetrieveParamsTest { @Test - fun createBlockRetrieveParams() { + fun create() { BlockRetrieveParams.builder().blockId("blockID").build() } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ConfigRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ConfigRetrieveParamsTest.kt index 2a94f4c..09c62a4 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ConfigRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ConfigRetrieveParamsTest.kt @@ -3,12 +3,11 @@ package org.onebusaway.models import org.junit.jupiter.api.Test -import org.onebusaway.models.* class ConfigRetrieveParamsTest { @Test - fun createConfigRetrieveParams() { + fun create() { ConfigRetrieveParams.builder().build() } } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/CurrentTimeRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/CurrentTimeRetrieveParamsTest.kt index 673dba1..7045aac 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/CurrentTimeRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/CurrentTimeRetrieveParamsTest.kt @@ -3,12 +3,11 @@ package org.onebusaway.models import org.junit.jupiter.api.Test -import org.onebusaway.models.* class CurrentTimeRetrieveParamsTest { @Test - fun createCurrentTimeRetrieveParams() { + fun create() { CurrentTimeRetrieveParams.builder().build() } } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ReferencesTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ReferencesTest.kt index 85bbd9b..7111a2c 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ReferencesTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ReferencesTest.kt @@ -11,163 +11,130 @@ class ReferencesTest { fun createReferences() { val references = References.builder() - .agencies( - listOf( - References.Agency.builder() - .id("id") - .name("name") - .timezone("timezone") - .url("url") - .disclaimer("disclaimer") - .email("email") - .fareUrl("fareUrl") - .lang("lang") - .phone("phone") - .privateService(true) - .build() - ) + .addAgency( + References.Agency.builder() + .id("id") + .name("name") + .timezone("timezone") + .url("url") + .disclaimer("disclaimer") + .email("email") + .fareUrl("fareUrl") + .lang("lang") + .phone("phone") + .privateService(true) + .build() ) - .routes( - listOf( - References.Route.builder() - .id("id") - .agencyId("agencyId") - .type(123L) - .color("color") - .description("description") - .longName("longName") - .nullSafeShortName("nullSafeShortName") - .shortName("shortName") - .textColor("textColor") - .url("url") - .build() - ) + .addRoute( + References.Route.builder() + .id("id") + .agencyId("agencyId") + .type(0L) + .color("color") + .description("description") + .longName("longName") + .nullSafeShortName("nullSafeShortName") + .shortName("shortName") + .textColor("textColor") + .url("url") + .build() ) - .situations( - listOf( - References.Situation.builder() - .id("id") - .creationTime(123L) - .activeWindows( - listOf( - References.Situation.ActiveWindow.builder() - .from(123L) - .to(123L) - .build() - ) - ) - .allAffects( - listOf( - References.Situation.AllAffect.builder() - .agencyId("agencyId") - .applicationId("applicationId") - .directionId("directionId") - .routeId("routeId") - .stopId("stopId") - .tripId("tripId") - .build() - ) - ) - .consequenceMessage("consequenceMessage") - .consequences( - listOf( - References.Situation.Consequence.builder() - .condition("condition") - .conditionDetails( + .addSituation( + References.Situation.builder() + .id("id") + .creationTime(0L) + .addActiveWindow( + References.Situation.ActiveWindow.builder().from(0L).to(0L).build() + ) + .addAllAffect( + References.Situation.AllAffect.builder() + .agencyId("agencyId") + .applicationId("applicationId") + .directionId("directionId") + .routeId("routeId") + .stopId("stopId") + .tripId("tripId") + .build() + ) + .consequenceMessage("consequenceMessage") + .addConsequence( + References.Situation.Consequence.builder() + .condition("condition") + .conditionDetails( + References.Situation.Consequence.ConditionDetails.builder() + .diversionPath( References.Situation.Consequence.ConditionDetails + .DiversionPath .builder() - .diversionPath( - References.Situation.Consequence - .ConditionDetails - .DiversionPath - .builder() - .length(123L) - .levels("levels") - .points("points") - .build() - ) - .diversionStopIds(listOf("string")) + .length(0L) + .levels("levels") + .points("points") .build() ) + .addDiversionStopId("string") .build() ) - ) - .description( - References.Situation.Description.builder() - .lang("lang") - .value("value") - .build() - ) - .publicationWindows( - listOf( - References.Situation.PublicationWindow.builder() - .from(123L) - .to(123L) - .build() - ) - ) - .reason(References.Situation.Reason.EQUIPMENT_REASON) - .severity("severity") - .summary( - References.Situation.Summary.builder() - .lang("lang") - .value("value") - .build() - ) - .url( - References.Situation.Url.builder() - .lang("lang") - .value("value") - .build() - ) - .build() - ) + .build() + ) + .description( + References.Situation.Description.builder() + .lang("lang") + .value("value") + .build() + ) + .addPublicationWindow( + References.Situation.PublicationWindow.builder().from(0L).to(0L).build() + ) + .reason(References.Situation.Reason.EQUIPMENT_REASON) + .severity("severity") + .summary( + References.Situation.Summary.builder() + .lang("lang") + .value("value") + .build() + ) + .url(References.Situation.Url.builder().lang("lang").value("value").build()) + .build() ) - .stops( - listOf( - References.Stop.builder() - .id("id") - .lat(42.23) - .lon(42.23) - .name("name") - .parent("parent") - .routeIds(listOf("string")) - .staticRouteIds(listOf("string")) - .code("code") - .direction("direction") - .locationType(123L) - .wheelchairBoarding("wheelchairBoarding") - .build() - ) + .addStop( + References.Stop.builder() + .id("id") + .lat(0.0) + .locationType(0L) + .lon(0.0) + .name("name") + .parent("parent") + .addRouteId("string") + .addStaticRouteId("string") + .code("code") + .direction("direction") + .wheelchairBoarding("wheelchairBoarding") + .build() ) - .stopTimes( - listOf( - References.StopTime.builder() - .arrivalTime(123L) - .departureTime(123L) - .distanceAlongTrip(42.23) - .historicalOccupancy("historicalOccupancy") - .stopHeadsign("stopHeadsign") - .stopId("stopId") - .build() - ) + .addStopTime( + References.StopTime.builder() + .arrivalTime(0L) + .departureTime(0L) + .distanceAlongTrip(0.0) + .historicalOccupancy("historicalOccupancy") + .stopHeadsign("stopHeadsign") + .stopId("stopId") + .build() ) - .trips( - listOf( - References.Trip.builder() - .id("id") - .routeId("routeId") - .serviceId("serviceId") - .blockId("blockId") - .directionId("directionId") - .peakOffpeak(123L) - .routeShortName("routeShortName") - .shapeId("shapeId") - .timeZone("timeZone") - .tripHeadsign("tripHeadsign") - .tripShortName("tripShortName") - .build() - ) + .addTrip( + References.Trip.builder() + .id("id") + .routeId("routeId") + .serviceId("serviceId") + .blockId("blockId") + .directionId("directionId") + .peakOffpeak(0L) + .routeShortName("routeShortName") + .shapeId("shapeId") + .timeZone("timeZone") + .tripHeadsign("tripHeadsign") + .tripShortName("tripShortName") + .build() ) .build() assertThat(references).isNotNull @@ -191,7 +158,7 @@ class ReferencesTest { References.Route.builder() .id("id") .agencyId("agencyId") - .type(123L) + .type(0L) .color("color") .description("description") .longName("longName") @@ -205,45 +172,39 @@ class ReferencesTest { .containsExactly( References.Situation.builder() .id("id") - .creationTime(123L) - .activeWindows( - listOf( - References.Situation.ActiveWindow.builder().from(123L).to(123L).build() - ) + .creationTime(0L) + .addActiveWindow( + References.Situation.ActiveWindow.builder().from(0L).to(0L).build() ) - .allAffects( - listOf( - References.Situation.AllAffect.builder() - .agencyId("agencyId") - .applicationId("applicationId") - .directionId("directionId") - .routeId("routeId") - .stopId("stopId") - .tripId("tripId") - .build() - ) + .addAllAffect( + References.Situation.AllAffect.builder() + .agencyId("agencyId") + .applicationId("applicationId") + .directionId("directionId") + .routeId("routeId") + .stopId("stopId") + .tripId("tripId") + .build() ) .consequenceMessage("consequenceMessage") - .consequences( - listOf( - References.Situation.Consequence.builder() - .condition("condition") - .conditionDetails( - References.Situation.Consequence.ConditionDetails.builder() - .diversionPath( - References.Situation.Consequence.ConditionDetails - .DiversionPath - .builder() - .length(123L) - .levels("levels") - .points("points") - .build() - ) - .diversionStopIds(listOf("string")) - .build() - ) - .build() - ) + .addConsequence( + References.Situation.Consequence.builder() + .condition("condition") + .conditionDetails( + References.Situation.Consequence.ConditionDetails.builder() + .diversionPath( + References.Situation.Consequence.ConditionDetails + .DiversionPath + .builder() + .length(0L) + .levels("levels") + .points("points") + .build() + ) + .addDiversionStopId("string") + .build() + ) + .build() ) .description( References.Situation.Description.builder() @@ -251,13 +212,8 @@ class ReferencesTest { .value("value") .build() ) - .publicationWindows( - listOf( - References.Situation.PublicationWindow.builder() - .from(123L) - .to(123L) - .build() - ) + .addPublicationWindow( + References.Situation.PublicationWindow.builder().from(0L).to(0L).build() ) .reason(References.Situation.Reason.EQUIPMENT_REASON) .severity("severity") @@ -271,24 +227,24 @@ class ReferencesTest { .containsExactly( References.Stop.builder() .id("id") - .lat(42.23) - .lon(42.23) + .lat(0.0) + .locationType(0L) + .lon(0.0) .name("name") .parent("parent") - .routeIds(listOf("string")) - .staticRouteIds(listOf("string")) + .addRouteId("string") + .addStaticRouteId("string") .code("code") .direction("direction") - .locationType(123L) .wheelchairBoarding("wheelchairBoarding") .build() ) assertThat(references.stopTimes()) .containsExactly( References.StopTime.builder() - .arrivalTime(123L) - .departureTime(123L) - .distanceAlongTrip(42.23) + .arrivalTime(0L) + .departureTime(0L) + .distanceAlongTrip(0.0) .historicalOccupancy("historicalOccupancy") .stopHeadsign("stopHeadsign") .stopId("stopId") @@ -302,7 +258,7 @@ class ReferencesTest { .serviceId("serviceId") .blockId("blockId") .directionId("directionId") - .peakOffpeak(123L) + .peakOffpeak(0L) .routeShortName("routeShortName") .shapeId("shapeId") .timeZone("timeZone") diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ReportProblemWithStopRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ReportProblemWithStopRetrieveParamsTest.kt index ca3f9e6..a4a0191 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ReportProblemWithStopRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ReportProblemWithStopRetrieveParamsTest.kt @@ -4,50 +4,47 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class ReportProblemWithStopRetrieveParamsTest { @Test - fun createReportProblemWithStopRetrieveParams() { + fun create() { ReportProblemWithStopRetrieveParams.builder() .stopId("stopID") .code(ReportProblemWithStopRetrieveParams.Code.STOP_NAME_WRONG) .userComment("userComment") - .userLat(42.23) - .userLocationAccuracy(42.23) - .userLon(42.23) + .userLat(0.0) + .userLocationAccuracy(0.0) + .userLon(0.0) .build() } @Test - fun getQueryParams() { + fun queryParams() { val params = ReportProblemWithStopRetrieveParams.builder() .stopId("stopID") .code(ReportProblemWithStopRetrieveParams.Code.STOP_NAME_WRONG) .userComment("userComment") - .userLat(42.23) - .userLocationAccuracy(42.23) - .userLon(42.23) + .userLat(0.0) + .userLocationAccuracy(0.0) + .userLon(0.0) .build() - val expected = mutableMapOf>() - expected.put( - "code", - listOf(ReportProblemWithStopRetrieveParams.Code.STOP_NAME_WRONG.toString()) - ) - expected.put("userComment", listOf("userComment")) - expected.put("userLat", listOf("42.23")) - expected.put("userLocationAccuracy", listOf("42.23")) - expected.put("userLon", listOf("42.23")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("code", ReportProblemWithStopRetrieveParams.Code.STOP_NAME_WRONG.toString()) + expected.put("userComment", "userComment") + expected.put("userLat", "0.0") + expected.put("userLocationAccuracy", "0.0") + expected.put("userLon", "0.0") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = ReportProblemWithStopRetrieveParams.builder().stopId("stopID").build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ReportProblemWithTripRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ReportProblemWithTripRetrieveParamsTest.kt index 64ed4cc..45cbdba 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ReportProblemWithTripRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ReportProblemWithTripRetrieveParamsTest.kt @@ -4,21 +4,21 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class ReportProblemWithTripRetrieveParamsTest { @Test - fun createReportProblemWithTripRetrieveParams() { + fun create() { ReportProblemWithTripRetrieveParams.builder() .tripId("tripID") .code(ReportProblemWithTripRetrieveParams.Code.VEHICLE_NEVER_CAME) - .serviceDate(123L) + .serviceDate(0L) .stopId("stopID") .userComment("userComment") - .userLat(42.23) - .userLocationAccuracy(42.23) - .userLon(42.23) + .userLat(0.0) + .userLocationAccuracy(0.0) + .userLon(0.0) .userOnVehicle(true) .userVehicleNumber("userVehicleNumber") .vehicleId("vehicleID") @@ -26,43 +26,40 @@ class ReportProblemWithTripRetrieveParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = ReportProblemWithTripRetrieveParams.builder() .tripId("tripID") .code(ReportProblemWithTripRetrieveParams.Code.VEHICLE_NEVER_CAME) - .serviceDate(123L) + .serviceDate(0L) .stopId("stopID") .userComment("userComment") - .userLat(42.23) - .userLocationAccuracy(42.23) - .userLon(42.23) + .userLat(0.0) + .userLocationAccuracy(0.0) + .userLon(0.0) .userOnVehicle(true) .userVehicleNumber("userVehicleNumber") .vehicleId("vehicleID") .build() - val expected = mutableMapOf>() - expected.put( - "code", - listOf(ReportProblemWithTripRetrieveParams.Code.VEHICLE_NEVER_CAME.toString()) - ) - expected.put("serviceDate", listOf("123")) - expected.put("stopID", listOf("stopID")) - expected.put("userComment", listOf("userComment")) - expected.put("userLat", listOf("42.23")) - expected.put("userLocationAccuracy", listOf("42.23")) - expected.put("userLon", listOf("42.23")) - expected.put("userOnVehicle", listOf("true")) - expected.put("userVehicleNumber", listOf("userVehicleNumber")) - expected.put("vehicleID", listOf("vehicleID")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("code", ReportProblemWithTripRetrieveParams.Code.VEHICLE_NEVER_CAME.toString()) + expected.put("serviceDate", "0") + expected.put("stopID", "stopID") + expected.put("userComment", "userComment") + expected.put("userLat", "0.0") + expected.put("userLocationAccuracy", "0.0") + expected.put("userLon", "0.0") + expected.put("userOnVehicle", "true") + expected.put("userVehicleNumber", "userVehicleNumber") + expected.put("vehicleID", "vehicleID") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = ReportProblemWithTripRetrieveParams.builder().tripId("tripID").build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ResponseWrapperTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ResponseWrapperTest.kt index c9dabeb..92b875c 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ResponseWrapperTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ResponseWrapperTest.kt @@ -10,16 +10,11 @@ class ResponseWrapperTest { @Test fun createResponseWrapper() { val responseWrapper = - ResponseWrapper.builder() - .code(123L) - .currentTime(123L) - .text("text") - .version(123L) - .build() + ResponseWrapper.builder().code(0L).currentTime(0L).text("text").version(0L).build() assertThat(responseWrapper).isNotNull - assertThat(responseWrapper.code()).isEqualTo(123L) - assertThat(responseWrapper.currentTime()).isEqualTo(123L) + assertThat(responseWrapper.code()).isEqualTo(0L) + assertThat(responseWrapper.currentTime()).isEqualTo(0L) assertThat(responseWrapper.text()).isEqualTo("text") - assertThat(responseWrapper.version()).isEqualTo(123L) + assertThat(responseWrapper.version()).isEqualTo(0L) } } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RouteIdsForAgencyListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RouteIdsForAgencyListParamsTest.kt index ade68cb..6f4a70b 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RouteIdsForAgencyListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RouteIdsForAgencyListParamsTest.kt @@ -4,12 +4,11 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* class RouteIdsForAgencyListParamsTest { @Test - fun createRouteIdsForAgencyListParams() { + fun create() { RouteIdsForAgencyListParams.builder().agencyId("agencyID").build() } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RouteRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RouteRetrieveParamsTest.kt index 5af4c59..beb1604 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RouteRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RouteRetrieveParamsTest.kt @@ -4,12 +4,11 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* class RouteRetrieveParamsTest { @Test - fun createRouteRetrieveParams() { + fun create() { RouteRetrieveParams.builder().routeId("routeID").build() } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RoutesForAgencyListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RoutesForAgencyListParamsTest.kt index 798f270..c9c18f8 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RoutesForAgencyListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RoutesForAgencyListParamsTest.kt @@ -4,21 +4,20 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* class RoutesForAgencyListParamsTest { @Test - fun createRoutesForAgencyListParams() { - RoutesForAgencyListParams.builder().agencyId("agencyID").build() + fun create() { + RoutesForAgencyListParams.builder().agencyId("40").build() } @Test fun getPathParam() { - val params = RoutesForAgencyListParams.builder().agencyId("agencyID").build() + val params = RoutesForAgencyListParams.builder().agencyId("40").build() assertThat(params).isNotNull // path param "agencyId" - assertThat(params.getPathParam(0)).isEqualTo("agencyID") + assertThat(params.getPathParam(0)).isEqualTo("40") // out-of-bound path param assertThat(params.getPathParam(1)).isEqualTo("") } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RoutesForLocationListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RoutesForLocationListParamsTest.kt index 946a91a..895f0e8 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RoutesForLocationListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/RoutesForLocationListParamsTest.kt @@ -4,49 +4,49 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class RoutesForLocationListParamsTest { @Test - fun createRoutesForLocationListParams() { + fun create() { RoutesForLocationListParams.builder() - .lat(42.23) - .lon(42.23) - .latSpan(42.23) - .lonSpan(42.23) + .lat(0.0) + .lon(0.0) + .latSpan(0.0) + .lonSpan(0.0) .query("query") - .radius(42.23) + .radius(0.0) .build() } @Test - fun getQueryParams() { + fun queryParams() { val params = RoutesForLocationListParams.builder() - .lat(42.23) - .lon(42.23) - .latSpan(42.23) - .lonSpan(42.23) + .lat(0.0) + .lon(0.0) + .latSpan(0.0) + .lonSpan(0.0) .query("query") - .radius(42.23) + .radius(0.0) .build() - val expected = mutableMapOf>() - expected.put("lat", listOf("42.23")) - expected.put("lon", listOf("42.23")) - expected.put("latSpan", listOf("42.23")) - expected.put("lonSpan", listOf("42.23")) - expected.put("query", listOf("query")) - expected.put("radius", listOf("42.23")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("lat", "0.0") + expected.put("lon", "0.0") + expected.put("latSpan", "0.0") + expected.put("lonSpan", "0.0") + expected.put("query", "query") + expected.put("radius", "0.0") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { - val params = RoutesForLocationListParams.builder().lat(42.23).lon(42.23).build() - val expected = mutableMapOf>() - expected.put("lat", listOf("42.23")) - expected.put("lon", listOf("42.23")) - assertThat(params.getQueryParams()).isEqualTo(expected) + fun queryParamsWithoutOptionalFields() { + val params = RoutesForLocationListParams.builder().lat(0.0).lon(0.0).build() + val expected = QueryParams.builder() + expected.put("lat", "0.0") + expected.put("lon", "0.0") + assertThat(params._queryParams()).isEqualTo(expected.build()) } } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ScheduleForRouteRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ScheduleForRouteRetrieveParamsTest.kt index 98f2520..75b741c 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ScheduleForRouteRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ScheduleForRouteRetrieveParamsTest.kt @@ -5,43 +5,43 @@ package org.onebusaway.models import java.time.LocalDate import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class ScheduleForRouteRetrieveParamsTest { @Test - fun createScheduleForRouteRetrieveParams() { + fun create() { ScheduleForRouteRetrieveParams.builder() - .routeId("routeID") + .routeId("1_100223") .date(LocalDate.parse("2019-12-27")) .build() } @Test - fun getQueryParams() { + fun queryParams() { val params = ScheduleForRouteRetrieveParams.builder() - .routeId("routeID") + .routeId("1_100223") .date(LocalDate.parse("2019-12-27")) .build() - val expected = mutableMapOf>() - expected.put("date", listOf("2019-12-27")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("date", "2019-12-27") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { - val params = ScheduleForRouteRetrieveParams.builder().routeId("routeID").build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + fun queryParamsWithoutOptionalFields() { + val params = ScheduleForRouteRetrieveParams.builder().routeId("1_100223").build() + val expected = QueryParams.builder() + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test fun getPathParam() { - val params = ScheduleForRouteRetrieveParams.builder().routeId("routeID").build() + val params = ScheduleForRouteRetrieveParams.builder().routeId("1_100223").build() assertThat(params).isNotNull // path param "routeId" - assertThat(params.getPathParam(0)).isEqualTo("routeID") + assertThat(params.getPathParam(0)).isEqualTo("1_100223") // out-of-bound path param assertThat(params.getPathParam(1)).isEqualTo("") } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ScheduleForStopRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ScheduleForStopRetrieveParamsTest.kt index 645d47e..a1704c2 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ScheduleForStopRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ScheduleForStopRetrieveParamsTest.kt @@ -5,12 +5,12 @@ package org.onebusaway.models import java.time.LocalDate import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class ScheduleForStopRetrieveParamsTest { @Test - fun createScheduleForStopRetrieveParams() { + fun create() { ScheduleForStopRetrieveParams.builder() .stopId("stopID") .date(LocalDate.parse("2019-12-27")) @@ -18,22 +18,22 @@ class ScheduleForStopRetrieveParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = ScheduleForStopRetrieveParams.builder() .stopId("stopID") .date(LocalDate.parse("2019-12-27")) .build() - val expected = mutableMapOf>() - expected.put("date", listOf("2019-12-27")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("date", "2019-12-27") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = ScheduleForStopRetrieveParams.builder().stopId("stopID").build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/SearchForRouteListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/SearchForRouteListParamsTest.kt index 1b2453d..0f323d3 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/SearchForRouteListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/SearchForRouteListParamsTest.kt @@ -4,29 +4,29 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class SearchForRouteListParamsTest { @Test - fun createSearchForRouteListParams() { - SearchForRouteListParams.builder().input("input").maxCount(123L).build() + fun create() { + SearchForRouteListParams.builder().input("input").maxCount(0L).build() } @Test - fun getQueryParams() { - val params = SearchForRouteListParams.builder().input("input").maxCount(123L).build() - val expected = mutableMapOf>() - expected.put("input", listOf("input")) - expected.put("maxCount", listOf("123")) - assertThat(params.getQueryParams()).isEqualTo(expected) + fun queryParams() { + val params = SearchForRouteListParams.builder().input("input").maxCount(0L).build() + val expected = QueryParams.builder() + expected.put("input", "input") + expected.put("maxCount", "0") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = SearchForRouteListParams.builder().input("input").build() - val expected = mutableMapOf>() - expected.put("input", listOf("input")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("input", "input") + assertThat(params._queryParams()).isEqualTo(expected.build()) } } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/SearchForStopListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/SearchForStopListParamsTest.kt index 1825b87..2581cf1 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/SearchForStopListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/SearchForStopListParamsTest.kt @@ -4,29 +4,29 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class SearchForStopListParamsTest { @Test - fun createSearchForStopListParams() { - SearchForStopListParams.builder().input("input").maxCount(123L).build() + fun create() { + SearchForStopListParams.builder().input("input").maxCount(0L).build() } @Test - fun getQueryParams() { - val params = SearchForStopListParams.builder().input("input").maxCount(123L).build() - val expected = mutableMapOf>() - expected.put("input", listOf("input")) - expected.put("maxCount", listOf("123")) - assertThat(params.getQueryParams()).isEqualTo(expected) + fun queryParams() { + val params = SearchForStopListParams.builder().input("input").maxCount(0L).build() + val expected = QueryParams.builder() + expected.put("input", "input") + expected.put("maxCount", "0") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = SearchForStopListParams.builder().input("input").build() - val expected = mutableMapOf>() - expected.put("input", listOf("input")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("input", "input") + assertThat(params._queryParams()).isEqualTo(expected.build()) } } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ShapeRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ShapeRetrieveParamsTest.kt index 41e8572..9ddb3bf 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ShapeRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/ShapeRetrieveParamsTest.kt @@ -4,12 +4,11 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* class ShapeRetrieveParamsTest { @Test - fun createShapeRetrieveParams() { + fun create() { ShapeRetrieveParams.builder().shapeId("shapeID").build() } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopIdsForAgencyListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopIdsForAgencyListParamsTest.kt index f87b32a..e9f8805 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopIdsForAgencyListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopIdsForAgencyListParamsTest.kt @@ -4,12 +4,11 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* class StopIdsForAgencyListParamsTest { @Test - fun createStopIdsForAgencyListParams() { + fun create() { StopIdsForAgencyListParams.builder().agencyId("agencyID").build() } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopRetrieveParamsTest.kt index 7fa9cd9..2ca4aab 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopRetrieveParamsTest.kt @@ -4,12 +4,11 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* class StopRetrieveParamsTest { @Test - fun createStopRetrieveParams() { + fun create() { StopRetrieveParams.builder().stopId("stopID").build() } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopsForAgencyListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopsForAgencyListParamsTest.kt index 4559d12..5df5004 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopsForAgencyListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopsForAgencyListParamsTest.kt @@ -4,12 +4,11 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* class StopsForAgencyListParamsTest { @Test - fun createStopsForAgencyListParams() { + fun create() { StopsForAgencyListParams.builder().agencyId("agencyID").build() } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopsForLocationListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopsForLocationListParamsTest.kt index 07dde7e..e88198b 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopsForLocationListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopsForLocationListParamsTest.kt @@ -4,49 +4,49 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class StopsForLocationListParamsTest { @Test - fun createStopsForLocationListParams() { + fun create() { StopsForLocationListParams.builder() - .lat(42.23) - .lon(42.23) - .latSpan(42.23) - .lonSpan(42.23) + .lat(0.0) + .lon(0.0) + .latSpan(0.0) + .lonSpan(0.0) .query("query") - .radius(42.23) + .radius(0.0) .build() } @Test - fun getQueryParams() { + fun queryParams() { val params = StopsForLocationListParams.builder() - .lat(42.23) - .lon(42.23) - .latSpan(42.23) - .lonSpan(42.23) + .lat(0.0) + .lon(0.0) + .latSpan(0.0) + .lonSpan(0.0) .query("query") - .radius(42.23) + .radius(0.0) .build() - val expected = mutableMapOf>() - expected.put("lat", listOf("42.23")) - expected.put("lon", listOf("42.23")) - expected.put("latSpan", listOf("42.23")) - expected.put("lonSpan", listOf("42.23")) - expected.put("query", listOf("query")) - expected.put("radius", listOf("42.23")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("lat", "0.0") + expected.put("lon", "0.0") + expected.put("latSpan", "0.0") + expected.put("lonSpan", "0.0") + expected.put("query", "query") + expected.put("radius", "0.0") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { - val params = StopsForLocationListParams.builder().lat(42.23).lon(42.23).build() - val expected = mutableMapOf>() - expected.put("lat", listOf("42.23")) - expected.put("lon", listOf("42.23")) - assertThat(params.getQueryParams()).isEqualTo(expected) + fun queryParamsWithoutOptionalFields() { + val params = StopsForLocationListParams.builder().lat(0.0).lon(0.0).build() + val expected = QueryParams.builder() + expected.put("lat", "0.0") + expected.put("lon", "0.0") + assertThat(params._queryParams()).isEqualTo(expected.build()) } } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopsForRouteListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopsForRouteListParamsTest.kt index 607e832..69c1b8f 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopsForRouteListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/StopsForRouteListParamsTest.kt @@ -4,12 +4,12 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class StopsForRouteListParamsTest { @Test - fun createStopsForRouteListParams() { + fun create() { StopsForRouteListParams.builder() .routeId("routeID") .includePolylines(true) @@ -18,24 +18,24 @@ class StopsForRouteListParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = StopsForRouteListParams.builder() .routeId("routeID") .includePolylines(true) .time("time") .build() - val expected = mutableMapOf>() - expected.put("includePolylines", listOf("true")) - expected.put("time", listOf("time")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("includePolylines", "true") + expected.put("time", "time") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = StopsForRouteListParams.builder().routeId("routeID").build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripDetailRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripDetailRetrieveParamsTest.kt index 2e4eaa9..13efd64 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripDetailRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripDetailRetrieveParamsTest.kt @@ -4,47 +4,47 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class TripDetailRetrieveParamsTest { @Test - fun createTripDetailRetrieveParams() { + fun create() { TripDetailRetrieveParams.builder() .tripId("tripID") .includeSchedule(true) .includeStatus(true) .includeTrip(true) - .serviceDate(123L) - .time(123L) + .serviceDate(0L) + .time(0L) .build() } @Test - fun getQueryParams() { + fun queryParams() { val params = TripDetailRetrieveParams.builder() .tripId("tripID") .includeSchedule(true) .includeStatus(true) .includeTrip(true) - .serviceDate(123L) - .time(123L) + .serviceDate(0L) + .time(0L) .build() - val expected = mutableMapOf>() - expected.put("includeSchedule", listOf("true")) - expected.put("includeStatus", listOf("true")) - expected.put("includeTrip", listOf("true")) - expected.put("serviceDate", listOf("123")) - expected.put("time", listOf("123")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("includeSchedule", "true") + expected.put("includeStatus", "true") + expected.put("includeTrip", "true") + expected.put("serviceDate", "0") + expected.put("time", "0") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = TripDetailRetrieveParams.builder().tripId("tripID").build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripForVehicleRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripForVehicleRetrieveParamsTest.kt index e30e5e3..1792d80 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripForVehicleRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripForVehicleRetrieveParamsTest.kt @@ -4,44 +4,44 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class TripForVehicleRetrieveParamsTest { @Test - fun createTripForVehicleRetrieveParams() { + fun create() { TripForVehicleRetrieveParams.builder() .vehicleId("vehicleID") .includeSchedule(true) .includeStatus(true) .includeTrip(true) - .time(123L) + .time(0L) .build() } @Test - fun getQueryParams() { + fun queryParams() { val params = TripForVehicleRetrieveParams.builder() .vehicleId("vehicleID") .includeSchedule(true) .includeStatus(true) .includeTrip(true) - .time(123L) + .time(0L) .build() - val expected = mutableMapOf>() - expected.put("includeSchedule", listOf("true")) - expected.put("includeStatus", listOf("true")) - expected.put("includeTrip", listOf("true")) - expected.put("time", listOf("123")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("includeSchedule", "true") + expected.put("includeStatus", "true") + expected.put("includeTrip", "true") + expected.put("time", "0") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = TripForVehicleRetrieveParams.builder().vehicleId("vehicleID").build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripRetrieveParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripRetrieveParamsTest.kt index 61d3ab0..cd59a34 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripRetrieveParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripRetrieveParamsTest.kt @@ -4,12 +4,11 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* class TripRetrieveParamsTest { @Test - fun createTripRetrieveParams() { + fun create() { TripRetrieveParams.builder().tripId("tripID").build() } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripsForLocationListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripsForLocationListParamsTest.kt index e92df58..d5df439 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripsForLocationListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripsForLocationListParamsTest.kt @@ -4,60 +4,55 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class TripsForLocationListParamsTest { @Test - fun createTripsForLocationListParams() { + fun create() { TripsForLocationListParams.builder() - .lat(42.23) - .latSpan(42.23) - .lon(42.23) - .lonSpan(42.23) + .lat(0.0) + .latSpan(0.0) + .lon(0.0) + .lonSpan(0.0) .includeSchedule(true) .includeTrip(true) - .time(123L) + .time(0L) .build() } @Test - fun getQueryParams() { + fun queryParams() { val params = TripsForLocationListParams.builder() - .lat(42.23) - .latSpan(42.23) - .lon(42.23) - .lonSpan(42.23) + .lat(0.0) + .latSpan(0.0) + .lon(0.0) + .lonSpan(0.0) .includeSchedule(true) .includeTrip(true) - .time(123L) + .time(0L) .build() - val expected = mutableMapOf>() - expected.put("lat", listOf("42.23")) - expected.put("latSpan", listOf("42.23")) - expected.put("lon", listOf("42.23")) - expected.put("lonSpan", listOf("42.23")) - expected.put("includeSchedule", listOf("true")) - expected.put("includeTrip", listOf("true")) - expected.put("time", listOf("123")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("lat", "0.0") + expected.put("latSpan", "0.0") + expected.put("lon", "0.0") + expected.put("lonSpan", "0.0") + expected.put("includeSchedule", "true") + expected.put("includeTrip", "true") + expected.put("time", "0") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = - TripsForLocationListParams.builder() - .lat(42.23) - .latSpan(42.23) - .lon(42.23) - .lonSpan(42.23) - .build() - val expected = mutableMapOf>() - expected.put("lat", listOf("42.23")) - expected.put("latSpan", listOf("42.23")) - expected.put("lon", listOf("42.23")) - expected.put("lonSpan", listOf("42.23")) - assertThat(params.getQueryParams()).isEqualTo(expected) + TripsForLocationListParams.builder().lat(0.0).latSpan(0.0).lon(0.0).lonSpan(0.0).build() + val expected = QueryParams.builder() + expected.put("lat", "0.0") + expected.put("latSpan", "0.0") + expected.put("lon", "0.0") + expected.put("lonSpan", "0.0") + assertThat(params._queryParams()).isEqualTo(expected.build()) } } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripsForRouteListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripsForRouteListParamsTest.kt index 6914198..85d5cea 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripsForRouteListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/TripsForRouteListParamsTest.kt @@ -4,41 +4,41 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class TripsForRouteListParamsTest { @Test - fun createTripsForRouteListParams() { + fun create() { TripsForRouteListParams.builder() .routeId("routeID") .includeSchedule(true) .includeStatus(true) - .time(123L) + .time(0L) .build() } @Test - fun getQueryParams() { + fun queryParams() { val params = TripsForRouteListParams.builder() .routeId("routeID") .includeSchedule(true) .includeStatus(true) - .time(123L) + .time(0L) .build() - val expected = mutableMapOf>() - expected.put("includeSchedule", listOf("true")) - expected.put("includeStatus", listOf("true")) - expected.put("time", listOf("123")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("includeSchedule", "true") + expected.put("includeStatus", "true") + expected.put("time", "0") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = TripsForRouteListParams.builder().routeId("routeID").build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/VehiclesForAgencyListParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/VehiclesForAgencyListParamsTest.kt index 93762bd..cf6f7e1 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/VehiclesForAgencyListParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/models/VehiclesForAgencyListParamsTest.kt @@ -4,28 +4,28 @@ package org.onebusaway.models import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test -import org.onebusaway.models.* +import org.onebusaway.core.http.QueryParams class VehiclesForAgencyListParamsTest { @Test - fun createVehiclesForAgencyListParams() { + fun create() { VehiclesForAgencyListParams.builder().agencyId("agencyID").time("time").build() } @Test - fun getQueryParams() { + fun queryParams() { val params = VehiclesForAgencyListParams.builder().agencyId("agencyID").time("time").build() - val expected = mutableMapOf>() - expected.put("time", listOf("time")) - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + expected.put("time", "time") + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = VehiclesForAgencyListParams.builder().agencyId("agencyID").build() - val expected = mutableMapOf>() - assertThat(params.getQueryParams()).isEqualTo(expected) + val expected = QueryParams.builder() + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/ErrorHandlingTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/ErrorHandlingTest.kt index 04f50bf..5b505b3 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/ErrorHandlingTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/ErrorHandlingTest.kt @@ -10,17 +10,15 @@ import com.github.tomakehurst.wiremock.client.WireMock.status import com.github.tomakehurst.wiremock.client.WireMock.stubFor import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo import com.github.tomakehurst.wiremock.junit5.WireMockTest -import com.google.common.collect.ImmutableListMultimap -import com.google.common.collect.ListMultimap import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.assertj.core.api.InstanceOfAssertFactories -import org.assertj.guava.api.Assertions.assertThat import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.onebusaway.client.OnebusawaySdkClient import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.core.JsonString +import org.onebusaway.core.JsonValue +import org.onebusaway.core.http.Headers import org.onebusaway.core.jsonMapper import org.onebusaway.errors.BadRequestException import org.onebusaway.errors.InternalServerException @@ -32,7 +30,9 @@ import org.onebusaway.errors.RateLimitException import org.onebusaway.errors.UnauthorizedException import org.onebusaway.errors.UnexpectedStatusCodeException import org.onebusaway.errors.UnprocessableEntityException -import org.onebusaway.models.* +import org.onebusaway.models.CurrentTimeRetrieveParams +import org.onebusaway.models.CurrentTimeRetrieveResponse +import org.onebusaway.models.References @WireMockTest class ErrorHandlingTest { @@ -40,7 +40,7 @@ class ErrorHandlingTest { private val JSON_MAPPER: JsonMapper = jsonMapper() private val ONEBUSAWAY_SDK_ERROR: OnebusawaySdkError = - OnebusawaySdkError.builder().putAdditionalProperty("key", JsonString.of("value")).build() + OnebusawaySdkError.builder().putAdditionalProperty("key", JsonValue.from("value")).build() private lateinit var client: OnebusawaySdkClient @@ -57,7 +57,166 @@ class ErrorHandlingTest { fun currentTimesRetrieve200() { val params = CurrentTimeRetrieveParams.builder().build() - val expected = CurrentTimeRetrieveResponse.builder().build() + val expected = + CurrentTimeRetrieveResponse.builder() + .code(0L) + .currentTime(0L) + .text("text") + .version(0L) + .data( + CurrentTimeRetrieveResponse.Data.builder() + .entry( + CurrentTimeRetrieveResponse.Data.Entry.builder() + .readableTime("readableTime") + .time(0L) + .build() + ) + .references( + References.builder() + .addAgency( + References.Agency.builder() + .id("id") + .name("name") + .timezone("timezone") + .url("url") + .disclaimer("disclaimer") + .email("email") + .fareUrl("fareUrl") + .lang("lang") + .phone("phone") + .privateService(true) + .build() + ) + .addRoute( + References.Route.builder() + .id("id") + .agencyId("agencyId") + .type(0L) + .color("color") + .description("description") + .longName("longName") + .nullSafeShortName("nullSafeShortName") + .shortName("shortName") + .textColor("textColor") + .url("url") + .build() + ) + .addSituation( + References.Situation.builder() + .id("id") + .creationTime(0L) + .addActiveWindow( + References.Situation.ActiveWindow.builder() + .from(0L) + .to(0L) + .build() + ) + .addAllAffect( + References.Situation.AllAffect.builder() + .agencyId("agencyId") + .applicationId("applicationId") + .directionId("directionId") + .routeId("routeId") + .stopId("stopId") + .tripId("tripId") + .build() + ) + .consequenceMessage("consequenceMessage") + .addConsequence( + References.Situation.Consequence.builder() + .condition("condition") + .conditionDetails( + References.Situation.Consequence + .ConditionDetails + .builder() + .diversionPath( + References.Situation.Consequence + .ConditionDetails + .DiversionPath + .builder() + .length(0L) + .levels("levels") + .points("points") + .build() + ) + .addDiversionStopId("string") + .build() + ) + .build() + ) + .description( + References.Situation.Description.builder() + .lang("lang") + .value("value") + .build() + ) + .addPublicationWindow( + References.Situation.PublicationWindow.builder() + .from(0L) + .to(0L) + .build() + ) + .reason(References.Situation.Reason.EQUIPMENT_REASON) + .severity("severity") + .summary( + References.Situation.Summary.builder() + .lang("lang") + .value("value") + .build() + ) + .url( + References.Situation.Url.builder() + .lang("lang") + .value("value") + .build() + ) + .build() + ) + .addStop( + References.Stop.builder() + .id("id") + .lat(0.0) + .locationType(0L) + .lon(0.0) + .name("name") + .parent("parent") + .addRouteId("string") + .addStaticRouteId("string") + .code("code") + .direction("direction") + .wheelchairBoarding("wheelchairBoarding") + .build() + ) + .addStopTime( + References.StopTime.builder() + .arrivalTime(0L) + .departureTime(0L) + .distanceAlongTrip(0.0) + .historicalOccupancy("historicalOccupancy") + .stopHeadsign("stopHeadsign") + .stopId("stopId") + .build() + ) + .addTrip( + References.Trip.builder() + .id("id") + .routeId("routeId") + .serviceId("serviceId") + .blockId("blockId") + .directionId("directionId") + .peakOffpeak(0L) + .routeShortName("routeShortName") + .shapeId("shapeId") + .timeZone("timeZone") + .tripHeadsign("tripHeadsign") + .tripShortName("tripShortName") + .build() + ) + .build() + ) + .build() + ) + .build() stubFor(get(anyUrl()).willReturn(ok().withBody(toJson(expected)))) @@ -77,7 +236,11 @@ class ErrorHandlingTest { assertThatThrownBy({ client.currentTime().retrieve(params) }) .satisfies({ e -> - assertBadRequest(e, ImmutableListMultimap.of("Foo", "Bar"), ONEBUSAWAY_SDK_ERROR) + assertBadRequest( + e, + Headers.builder().put("Foo", "Bar").build(), + ONEBUSAWAY_SDK_ERROR + ) }) } @@ -94,7 +257,11 @@ class ErrorHandlingTest { assertThatThrownBy({ client.currentTime().retrieve(params) }) .satisfies({ e -> - assertUnauthorized(e, ImmutableListMultimap.of("Foo", "Bar"), ONEBUSAWAY_SDK_ERROR) + assertUnauthorized( + e, + Headers.builder().put("Foo", "Bar").build(), + ONEBUSAWAY_SDK_ERROR + ) }) } @@ -113,7 +280,7 @@ class ErrorHandlingTest { .satisfies({ e -> assertPermissionDenied( e, - ImmutableListMultimap.of("Foo", "Bar"), + Headers.builder().put("Foo", "Bar").build(), ONEBUSAWAY_SDK_ERROR ) }) @@ -132,7 +299,7 @@ class ErrorHandlingTest { assertThatThrownBy({ client.currentTime().retrieve(params) }) .satisfies({ e -> - assertNotFound(e, ImmutableListMultimap.of("Foo", "Bar"), ONEBUSAWAY_SDK_ERROR) + assertNotFound(e, Headers.builder().put("Foo", "Bar").build(), ONEBUSAWAY_SDK_ERROR) }) } @@ -151,7 +318,7 @@ class ErrorHandlingTest { .satisfies({ e -> assertUnprocessableEntity( e, - ImmutableListMultimap.of("Foo", "Bar"), + Headers.builder().put("Foo", "Bar").build(), ONEBUSAWAY_SDK_ERROR ) }) @@ -170,7 +337,11 @@ class ErrorHandlingTest { assertThatThrownBy({ client.currentTime().retrieve(params) }) .satisfies({ e -> - assertRateLimit(e, ImmutableListMultimap.of("Foo", "Bar"), ONEBUSAWAY_SDK_ERROR) + assertRateLimit( + e, + Headers.builder().put("Foo", "Bar").build(), + ONEBUSAWAY_SDK_ERROR + ) }) } @@ -189,7 +360,7 @@ class ErrorHandlingTest { .satisfies({ e -> assertInternalServer( e, - ImmutableListMultimap.of("Foo", "Bar"), + Headers.builder().put("Foo", "Bar").build(), ONEBUSAWAY_SDK_ERROR ) }) @@ -211,7 +382,7 @@ class ErrorHandlingTest { assertUnexpectedStatusCodeException( e, 999, - ImmutableListMultimap.of("Foo", "Bar"), + Headers.builder().put("Foo", "Bar").build(), toJson(ONEBUSAWAY_SDK_ERROR) ) }) @@ -239,11 +410,7 @@ class ErrorHandlingTest { assertThatThrownBy({ client.currentTime().retrieve(params) }) .satisfies({ e -> - assertBadRequest( - e, - ImmutableListMultimap.of(), - OnebusawaySdkError.builder().build() - ) + assertBadRequest(e, Headers.builder().build(), OnebusawaySdkError.builder().build()) }) } @@ -254,7 +421,7 @@ class ErrorHandlingTest { private fun assertUnexpectedStatusCodeException( throwable: Throwable, statusCode: Int, - headers: ListMultimap, + headers: Headers, responseBody: ByteArray ) { assertThat(throwable) @@ -264,13 +431,13 @@ class ErrorHandlingTest { .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(statusCode) assertThat(e.body()).isEqualTo(String(responseBody)) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } private fun assertBadRequest( throwable: Throwable, - headers: ListMultimap, + headers: Headers, error: OnebusawaySdkError ) { assertThat(throwable) @@ -278,13 +445,13 @@ class ErrorHandlingTest { .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(400) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } private fun assertUnauthorized( throwable: Throwable, - headers: ListMultimap, + headers: Headers, error: OnebusawaySdkError ) { assertThat(throwable) @@ -292,13 +459,13 @@ class ErrorHandlingTest { .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(401) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } private fun assertPermissionDenied( throwable: Throwable, - headers: ListMultimap, + headers: Headers, error: OnebusawaySdkError ) { assertThat(throwable) @@ -308,27 +475,23 @@ class ErrorHandlingTest { .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(403) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } - private fun assertNotFound( - throwable: Throwable, - headers: ListMultimap, - error: OnebusawaySdkError - ) { + private fun assertNotFound(throwable: Throwable, headers: Headers, error: OnebusawaySdkError) { assertThat(throwable) .asInstanceOf(InstanceOfAssertFactories.throwable(NotFoundException::class.java)) .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(404) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } private fun assertUnprocessableEntity( throwable: Throwable, - headers: ListMultimap, + headers: Headers, error: OnebusawaySdkError ) { assertThat(throwable) @@ -338,27 +501,23 @@ class ErrorHandlingTest { .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(422) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } - private fun assertRateLimit( - throwable: Throwable, - headers: ListMultimap, - error: OnebusawaySdkError - ) { + private fun assertRateLimit(throwable: Throwable, headers: Headers, error: OnebusawaySdkError) { assertThat(throwable) .asInstanceOf(InstanceOfAssertFactories.throwable(RateLimitException::class.java)) .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(429) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } private fun assertInternalServer( throwable: Throwable, - headers: ListMultimap, + headers: Headers, error: OnebusawaySdkError ) { assertThat(throwable) @@ -366,7 +525,12 @@ class ErrorHandlingTest { .satisfies({ e -> assertThat(e.statusCode()).isEqualTo(500) assertThat(e.error()).isEqualTo(error) - assertThat(e.headers()).containsAllEntriesOf(headers) + assertThat(e.headers().toMap()).containsAllEntriesOf(headers.toMap()) }) } + + private fun Headers.toMap(): Map> = + mutableMapOf>().also { map -> + names().forEach { map[it] = values(it) } + } } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/ServiceParamsTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/ServiceParamsTest.kt index 519ab15..b16e585 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/ServiceParamsTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/ServiceParamsTest.kt @@ -8,7 +8,6 @@ import com.github.tomakehurst.wiremock.client.WireMock.equalTo import com.github.tomakehurst.wiremock.client.WireMock.get import com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor import com.github.tomakehurst.wiremock.client.WireMock.ok -import com.github.tomakehurst.wiremock.client.WireMock.put import com.github.tomakehurst.wiremock.client.WireMock.stubFor import com.github.tomakehurst.wiremock.client.WireMock.verify import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo @@ -18,7 +17,9 @@ import org.junit.jupiter.api.Test import org.onebusaway.client.OnebusawaySdkClient import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient import org.onebusaway.core.jsonMapper -import org.onebusaway.models.* +import org.onebusaway.models.CurrentTimeRetrieveParams +import org.onebusaway.models.CurrentTimeRetrieveResponse +import org.onebusaway.models.References @WireMockTest class ServiceParamsTest { @@ -52,7 +53,166 @@ class ServiceParamsTest { .additionalQueryParams(additionalQueryParams) .build() - val apiResponse = CurrentTimeRetrieveResponse.builder().build() + val apiResponse = + CurrentTimeRetrieveResponse.builder() + .code(0L) + .currentTime(0L) + .text("text") + .version(0L) + .data( + CurrentTimeRetrieveResponse.Data.builder() + .entry( + CurrentTimeRetrieveResponse.Data.Entry.builder() + .readableTime("readableTime") + .time(0L) + .build() + ) + .references( + References.builder() + .addAgency( + References.Agency.builder() + .id("id") + .name("name") + .timezone("timezone") + .url("url") + .disclaimer("disclaimer") + .email("email") + .fareUrl("fareUrl") + .lang("lang") + .phone("phone") + .privateService(true) + .build() + ) + .addRoute( + References.Route.builder() + .id("id") + .agencyId("agencyId") + .type(0L) + .color("color") + .description("description") + .longName("longName") + .nullSafeShortName("nullSafeShortName") + .shortName("shortName") + .textColor("textColor") + .url("url") + .build() + ) + .addSituation( + References.Situation.builder() + .id("id") + .creationTime(0L) + .addActiveWindow( + References.Situation.ActiveWindow.builder() + .from(0L) + .to(0L) + .build() + ) + .addAllAffect( + References.Situation.AllAffect.builder() + .agencyId("agencyId") + .applicationId("applicationId") + .directionId("directionId") + .routeId("routeId") + .stopId("stopId") + .tripId("tripId") + .build() + ) + .consequenceMessage("consequenceMessage") + .addConsequence( + References.Situation.Consequence.builder() + .condition("condition") + .conditionDetails( + References.Situation.Consequence + .ConditionDetails + .builder() + .diversionPath( + References.Situation.Consequence + .ConditionDetails + .DiversionPath + .builder() + .length(0L) + .levels("levels") + .points("points") + .build() + ) + .addDiversionStopId("string") + .build() + ) + .build() + ) + .description( + References.Situation.Description.builder() + .lang("lang") + .value("value") + .build() + ) + .addPublicationWindow( + References.Situation.PublicationWindow.builder() + .from(0L) + .to(0L) + .build() + ) + .reason(References.Situation.Reason.EQUIPMENT_REASON) + .severity("severity") + .summary( + References.Situation.Summary.builder() + .lang("lang") + .value("value") + .build() + ) + .url( + References.Situation.Url.builder() + .lang("lang") + .value("value") + .build() + ) + .build() + ) + .addStop( + References.Stop.builder() + .id("id") + .lat(0.0) + .locationType(0L) + .lon(0.0) + .name("name") + .parent("parent") + .addRouteId("string") + .addStaticRouteId("string") + .code("code") + .direction("direction") + .wheelchairBoarding("wheelchairBoarding") + .build() + ) + .addStopTime( + References.StopTime.builder() + .arrivalTime(0L) + .departureTime(0L) + .distanceAlongTrip(0.0) + .historicalOccupancy("historicalOccupancy") + .stopHeadsign("stopHeadsign") + .stopId("stopId") + .build() + ) + .addTrip( + References.Trip.builder() + .id("id") + .routeId("routeId") + .serviceId("serviceId") + .blockId("blockId") + .directionId("directionId") + .peakOffpeak(0L) + .routeShortName("routeShortName") + .shapeId("shapeId") + .timeZone("timeZone") + .tripHeadsign("tripHeadsign") + .tripShortName("tripShortName") + .build() + ) + .build() + ) + .build() + ) + .build() stubFor( get(anyUrl()) diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/AgenciesWithCoverageServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/AgenciesWithCoverageServiceTest.kt index 7b094a1..a4753b7 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/AgenciesWithCoverageServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/AgenciesWithCoverageServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.AgenciesWithCoverageListParams @ExtendWith(TestServerExtension::class) class AgenciesWithCoverageServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/AgencyServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/AgencyServiceTest.kt index 0572732..63c9d69 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/AgencyServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/AgencyServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.AgencyRetrieveParams @ExtendWith(TestServerExtension::class) class AgencyServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ArrivalAndDepartureServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ArrivalAndDepartureServiceTest.kt index 8e0a8ee..9e3e729 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ArrivalAndDepartureServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ArrivalAndDepartureServiceTest.kt @@ -7,7 +7,8 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.ArrivalAndDepartureListParams +import org.onebusaway.models.ArrivalAndDepartureRetrieveParams @ExtendWith(TestServerExtension::class) class ArrivalAndDepartureServiceTest { @@ -23,11 +24,11 @@ class ArrivalAndDepartureServiceTest { val arrivalAndDepartureRetrieveResponse = arrivalAndDepartureService.retrieve( ArrivalAndDepartureRetrieveParams.builder() - .stopId("stopID") - .serviceDate(123L) + .stopId("1_75403") + .serviceDate(0L) .tripId("tripId") - .stopSequence(123L) - .time(123L) + .stopSequence(0L) + .time(0L) .vehicleId("vehicleId") .build() ) @@ -45,9 +46,9 @@ class ArrivalAndDepartureServiceTest { val arrivalAndDepartureListResponse = arrivalAndDepartureService.list( ArrivalAndDepartureListParams.builder() - .stopId("stopID") - .minutesAfter(123L) - .minutesBefore(123L) + .stopId("1_75403") + .minutesAfter(0L) + .minutesBefore(0L) .time(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .build() ) diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/BlockServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/BlockServiceTest.kt index f6f35a3..14682c9 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/BlockServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/BlockServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.BlockRetrieveParams @ExtendWith(TestServerExtension::class) class BlockServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ConfigServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ConfigServiceTest.kt index bc5911c..70704a4 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ConfigServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ConfigServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.ConfigRetrieveParams @ExtendWith(TestServerExtension::class) class ConfigServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/CurrentTimeServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/CurrentTimeServiceTest.kt index cdb4072..10b9f47 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/CurrentTimeServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/CurrentTimeServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.CurrentTimeRetrieveParams @ExtendWith(TestServerExtension::class) class CurrentTimeServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ReportProblemWithStopServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ReportProblemWithStopServiceTest.kt index c736e3d..3c67aff 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ReportProblemWithStopServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ReportProblemWithStopServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.ReportProblemWithStopRetrieveParams @ExtendWith(TestServerExtension::class) class ReportProblemWithStopServiceTest { @@ -25,9 +25,9 @@ class ReportProblemWithStopServiceTest { .stopId("stopID") .code(ReportProblemWithStopRetrieveParams.Code.STOP_NAME_WRONG) .userComment("userComment") - .userLat(42.23) - .userLocationAccuracy(42.23) - .userLon(42.23) + .userLat(0.0) + .userLocationAccuracy(0.0) + .userLon(0.0) .build() ) println(responseWrapper) diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ReportProblemWithTripServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ReportProblemWithTripServiceTest.kt index cef72e1..ae4a9fc 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ReportProblemWithTripServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ReportProblemWithTripServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.ReportProblemWithTripRetrieveParams @ExtendWith(TestServerExtension::class) class ReportProblemWithTripServiceTest { @@ -24,12 +24,12 @@ class ReportProblemWithTripServiceTest { ReportProblemWithTripRetrieveParams.builder() .tripId("tripID") .code(ReportProblemWithTripRetrieveParams.Code.VEHICLE_NEVER_CAME) - .serviceDate(123L) + .serviceDate(0L) .stopId("stopID") .userComment("userComment") - .userLat(42.23) - .userLocationAccuracy(42.23) - .userLon(42.23) + .userLat(0.0) + .userLocationAccuracy(0.0) + .userLon(0.0) .userOnVehicle(true) .userVehicleNumber("userVehicleNumber") .vehicleId("vehicleID") diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RouteIdsForAgencyServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RouteIdsForAgencyServiceTest.kt index c3a7118..295d8b9 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RouteIdsForAgencyServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RouteIdsForAgencyServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.RouteIdsForAgencyListParams @ExtendWith(TestServerExtension::class) class RouteIdsForAgencyServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RouteServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RouteServiceTest.kt index 4047e42..26ff366 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RouteServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RouteServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.RouteRetrieveParams @ExtendWith(TestServerExtension::class) class RouteServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RoutesForAgencyServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RoutesForAgencyServiceTest.kt index 4171539..873ce86 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RoutesForAgencyServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RoutesForAgencyServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.RoutesForAgencyListParams @ExtendWith(TestServerExtension::class) class RoutesForAgencyServiceTest { @@ -20,9 +20,7 @@ class RoutesForAgencyServiceTest { .build() val routesForAgencyService = client.routesForAgency() val routesForAgencyListResponse = - routesForAgencyService.list( - RoutesForAgencyListParams.builder().agencyId("agencyID").build() - ) + routesForAgencyService.list(RoutesForAgencyListParams.builder().agencyId("40").build()) println(routesForAgencyListResponse) } } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RoutesForLocationServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RoutesForLocationServiceTest.kt index be1c92e..f93bec8 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RoutesForLocationServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/RoutesForLocationServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.RoutesForLocationListParams @ExtendWith(TestServerExtension::class) class RoutesForLocationServiceTest { @@ -22,12 +22,12 @@ class RoutesForLocationServiceTest { val routesForLocationListResponse = routesForLocationService.list( RoutesForLocationListParams.builder() - .lat(42.23) - .lon(42.23) - .latSpan(42.23) - .lonSpan(42.23) + .lat(0.0) + .lon(0.0) + .latSpan(0.0) + .lonSpan(0.0) .query("query") - .radius(42.23) + .radius(0.0) .build() ) println(routesForLocationListResponse) diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ScheduleForRouteServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ScheduleForRouteServiceTest.kt index f684ec5..c44474c 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ScheduleForRouteServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ScheduleForRouteServiceTest.kt @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.ScheduleForRouteRetrieveParams @ExtendWith(TestServerExtension::class) class ScheduleForRouteServiceTest { @@ -23,7 +23,7 @@ class ScheduleForRouteServiceTest { val scheduleForRouteRetrieveResponse = scheduleForRouteService.retrieve( ScheduleForRouteRetrieveParams.builder() - .routeId("routeID") + .routeId("1_100223") .date(LocalDate.parse("2019-12-27")) .build() ) diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ScheduleForStopServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ScheduleForStopServiceTest.kt index 84fa8e0..95db8e9 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ScheduleForStopServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ScheduleForStopServiceTest.kt @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.ScheduleForStopRetrieveParams @ExtendWith(TestServerExtension::class) class ScheduleForStopServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/SearchForRouteServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/SearchForRouteServiceTest.kt index 2c1a5fa..ad95562 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/SearchForRouteServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/SearchForRouteServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.SearchForRouteListParams @ExtendWith(TestServerExtension::class) class SearchForRouteServiceTest { @@ -21,7 +21,7 @@ class SearchForRouteServiceTest { val searchForRouteService = client.searchForRoute() val searchForRouteListResponse = searchForRouteService.list( - SearchForRouteListParams.builder().input("input").maxCount(123L).build() + SearchForRouteListParams.builder().input("input").maxCount(0L).build() ) println(searchForRouteListResponse) } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/SearchForStopServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/SearchForStopServiceTest.kt index b9b1a95..3fcdb97 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/SearchForStopServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/SearchForStopServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.SearchForStopListParams @ExtendWith(TestServerExtension::class) class SearchForStopServiceTest { @@ -21,7 +21,7 @@ class SearchForStopServiceTest { val searchForStopService = client.searchForStop() val searchForStopListResponse = searchForStopService.list( - SearchForStopListParams.builder().input("input").maxCount(123L).build() + SearchForStopListParams.builder().input("input").maxCount(0L).build() ) println(searchForStopListResponse) } diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ShapeServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ShapeServiceTest.kt index 25431d2..25f3dab 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ShapeServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/ShapeServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.ShapeRetrieveParams @ExtendWith(TestServerExtension::class) class ShapeServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopIdsForAgencyServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopIdsForAgencyServiceTest.kt index 143e7ce..5c32068 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopIdsForAgencyServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopIdsForAgencyServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.StopIdsForAgencyListParams @ExtendWith(TestServerExtension::class) class StopIdsForAgencyServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopServiceTest.kt index 898436b..191397a 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.StopRetrieveParams @ExtendWith(TestServerExtension::class) class StopServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopsForAgencyServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopsForAgencyServiceTest.kt index 7cba930..c3a7cc9 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopsForAgencyServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopsForAgencyServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.StopsForAgencyListParams @ExtendWith(TestServerExtension::class) class StopsForAgencyServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopsForLocationServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopsForLocationServiceTest.kt index d3828a0..d56ef06 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopsForLocationServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopsForLocationServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.StopsForLocationListParams @ExtendWith(TestServerExtension::class) class StopsForLocationServiceTest { @@ -22,12 +22,12 @@ class StopsForLocationServiceTest { val stopsForLocationListResponse = stopsForLocationService.list( StopsForLocationListParams.builder() - .lat(42.23) - .lon(42.23) - .latSpan(42.23) - .lonSpan(42.23) + .lat(0.0) + .lon(0.0) + .latSpan(0.0) + .lonSpan(0.0) .query("query") - .radius(42.23) + .radius(0.0) .build() ) println(stopsForLocationListResponse) diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopsForRouteServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopsForRouteServiceTest.kt index d5a42a4..a8ce387 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopsForRouteServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/StopsForRouteServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.StopsForRouteListParams @ExtendWith(TestServerExtension::class) class StopsForRouteServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripDetailServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripDetailServiceTest.kt index a5e8820..fbd85e5 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripDetailServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripDetailServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.TripDetailRetrieveParams @ExtendWith(TestServerExtension::class) class TripDetailServiceTest { @@ -26,8 +26,8 @@ class TripDetailServiceTest { .includeSchedule(true) .includeStatus(true) .includeTrip(true) - .serviceDate(123L) - .time(123L) + .serviceDate(0L) + .time(0L) .build() ) println(tripDetailRetrieveResponse) diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripForVehicleServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripForVehicleServiceTest.kt index c3344e5..5842671 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripForVehicleServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripForVehicleServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.TripForVehicleRetrieveParams @ExtendWith(TestServerExtension::class) class TripForVehicleServiceTest { @@ -26,7 +26,7 @@ class TripForVehicleServiceTest { .includeSchedule(true) .includeStatus(true) .includeTrip(true) - .time(123L) + .time(0L) .build() ) println(tripForVehicleRetrieveResponse) diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripServiceTest.kt index ce7d73b..994e4b0 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.TripRetrieveParams @ExtendWith(TestServerExtension::class) class TripServiceTest { diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripsForLocationServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripsForLocationServiceTest.kt index 7c539e8..9ceb3fb 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripsForLocationServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripsForLocationServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.TripsForLocationListParams @ExtendWith(TestServerExtension::class) class TripsForLocationServiceTest { @@ -22,13 +22,13 @@ class TripsForLocationServiceTest { val tripsForLocationListResponse = tripsForLocationService.list( TripsForLocationListParams.builder() - .lat(42.23) - .latSpan(42.23) - .lon(42.23) - .lonSpan(42.23) + .lat(0.0) + .latSpan(0.0) + .lon(0.0) + .lonSpan(0.0) .includeSchedule(true) .includeTrip(true) - .time(123L) + .time(0L) .build() ) println(tripsForLocationListResponse) diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripsForRouteServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripsForRouteServiceTest.kt index 8568827..afe7a9f 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripsForRouteServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/TripsForRouteServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.TripsForRouteListParams @ExtendWith(TestServerExtension::class) class TripsForRouteServiceTest { @@ -25,7 +25,7 @@ class TripsForRouteServiceTest { .routeId("routeID") .includeSchedule(true) .includeStatus(true) - .time(123L) + .time(0L) .build() ) println(tripsForRouteListResponse) diff --git a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/VehiclesForAgencyServiceTest.kt b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/VehiclesForAgencyServiceTest.kt index 701f148..36a099f 100644 --- a/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/VehiclesForAgencyServiceTest.kt +++ b/onebusaway-sdk-java-core/src/test/kotlin/org/onebusaway/services/blocking/VehiclesForAgencyServiceTest.kt @@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.onebusaway.TestServerExtension import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient -import org.onebusaway.models.* +import org.onebusaway.models.VehiclesForAgencyListParams @ExtendWith(TestServerExtension::class) class VehiclesForAgencyServiceTest { diff --git a/onebusaway-sdk-java-example/build.gradle.kts b/onebusaway-sdk-java-example/build.gradle.kts index 2245a97..a310e71 100644 --- a/onebusaway-sdk-java-example/build.gradle.kts +++ b/onebusaway-sdk-java-example/build.gradle.kts @@ -1,24 +1,18 @@ plugins { + id("onebusaway-sdk.kotlin") id("java") -} - -group = "org.onebusaway" -version = "0.1.0-alpha.4" - -repositories { - mavenCentral() + application } dependencies { - implementation(project(":onebusaway-sdk-java")) - implementation(project(mapOf("path" to ":onebusaway-sdk-java-core"))) - +} - testImplementation(platform("org.junit:junit-bom:5.9.1")) - testImplementation("org.junit.jupiter:junit-jupiter") +tasks.withType().configureEach { + // Allow using more modern APIs, like `List.of` and `Map.of`, in examples. + options.release.set(9) } -tasks.test { - useJUnitPlatform() -} \ No newline at end of file +application { + mainClass = "org.onebusaway.example.Main" +} diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/AgenciesWithCoverage.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/AgenciesWithCoverage.java index c7986e5..5e8d626 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/AgenciesWithCoverage.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/AgenciesWithCoverage.java @@ -7,8 +7,11 @@ public class AgenciesWithCoverage { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -19,10 +22,12 @@ public class AgenciesWithCoverage { public static void main(String[] args) { // Define the required Params - AgenciesWithCoverageListParams params = AgenciesWithCoverageListParams.builder().build(); + AgenciesWithCoverageListParams params = + AgenciesWithCoverageListParams.builder().build(); // Get the agencies with coverage - AgenciesWithCoverageListResponse agencies = client.agenciesWithCoverage().list(params); + AgenciesWithCoverageListResponse agencies = + client.agenciesWithCoverage().list(params); for (AgenciesWithCoverageListResponse.Data.List agency : agencies.data().list()) { System.out.println(agency); diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Agency.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Agency.java index 24323c4..fd80deb 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Agency.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Agency.java @@ -7,8 +7,11 @@ public class Agency { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -16,18 +19,18 @@ public class Agency { .baseUrl(BASE_URL) .build(); - public static void main(String[] args) { - // Define the agency ID - String agencyId = "1"; + // Define the agency ID + String agencyId = "1"; - // Define the parameters for the agency retrieval request - AgencyRetrieveParams params = AgencyRetrieveParams.builder().agencyId(agencyId).build(); + // Define the parameters for the agency retrieval request + AgencyRetrieveParams params = + AgencyRetrieveParams.builder().agencyId(agencyId).build(); - // Retrieve the agency information - AgencyRetrieveResponse agency = client.agency().retrieve(params); + // Retrieve the agency information + AgencyRetrieveResponse agency = client.agency().retrieve(params); - System.out.println(agency); + System.out.println(agency); } } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/ArrivalAndDepartureForStop.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/ArrivalAndDepartureForStop.java index 1797047..ec62a01 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/ArrivalAndDepartureForStop.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/ArrivalAndDepartureForStop.java @@ -7,8 +7,11 @@ public class ArrivalAndDepartureForStop { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -32,8 +35,9 @@ public static void main(String[] args) { .serviceDate(serviceDate) // Use the Unix timestamp directly .build(); - // Retrieve arrival and departure information - ArrivalAndDepartureRetrieveResponse arrivalAndDepartureForStop = client.arrivalAndDeparture().retrieve(params); - System.out.println(arrivalAndDepartureForStop); + // Retrieve arrival and departure information + ArrivalAndDepartureRetrieveResponse arrivalAndDepartureForStop = + client.arrivalAndDeparture().retrieve(params); + System.out.println(arrivalAndDepartureForStop); } } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/ArrivalsAndDeparturesForStop.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/ArrivalsAndDeparturesForStop.java index 0646d70..5343f7d 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/ArrivalsAndDeparturesForStop.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/ArrivalsAndDeparturesForStop.java @@ -3,11 +3,15 @@ import org.onebusaway.client.OnebusawaySdkClient; import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient; import org.onebusaway.models.*; + public class ArrivalsAndDeparturesForStop { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -15,7 +19,6 @@ public class ArrivalsAndDeparturesForStop { .baseUrl(BASE_URL) .build(); - public static void main(String[] args) { // Define the stop ID @@ -31,11 +34,12 @@ public static void main(String[] args) { .build(); // Retrieve arrival and departure information - ArrivalAndDepartureListResponse arrivalsAndDeparturesForStop = client.arrivalAndDeparture().list(params); + ArrivalAndDepartureListResponse arrivalsAndDeparturesForStop = + client.arrivalAndDeparture().list(params); - for (ArrivalAndDepartureListResponse.Data.Entry.ArrivalsAndDeparture arrivalAndDeparture : arrivalsAndDeparturesForStop.data().entry().arrivalsAndDepartures()) { + for (ArrivalAndDepartureListResponse.Data.Entry.ArrivalsAndDeparture arrivalAndDeparture : + arrivalsAndDeparturesForStop.data().entry().arrivalsAndDepartures()) { System.out.println(arrivalAndDeparture); } } - } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Block.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Block.java index 504088d..afc4611 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Block.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Block.java @@ -4,11 +4,15 @@ import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient; import org.onebusaway.errors.OnebusawaySdkServiceException; import org.onebusaway.models.*; + public class Block { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -16,7 +20,6 @@ public class Block { .baseUrl(BASE_URL) .build(); - public static void main(String[] args) { // Define the block ID @@ -24,7 +27,8 @@ public static void main(String[] args) { try { // Define the parameters for the block retrieval request - BlockRetrieveParams params = BlockRetrieveParams.builder().blockId(blockId).build(); + BlockRetrieveParams params = + BlockRetrieveParams.builder().blockId(blockId).build(); // Retrieve the block information BlockRetrieveResponse block = client.block().retrieve(params); diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/CurrentTime.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/CurrentTime.java index 4e8cbc0..db9bc4a 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/CurrentTime.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/CurrentTime.java @@ -7,8 +7,11 @@ public class CurrentTime { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -16,7 +19,6 @@ public class CurrentTime { .baseUrl(BASE_URL) .build(); - public static void main(String[] args) { // Define the parameters for the current time retrieval request @@ -27,6 +29,4 @@ public static void main(String[] args) { System.out.println(currentTime); } - - } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Route.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Route.java index a5a3232..906af64 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Route.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Route.java @@ -4,12 +4,14 @@ import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient; import org.onebusaway.models.*; - public class Route { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -17,23 +19,24 @@ public class Route { .baseUrl(BASE_URL) .build(); - public static void main(String[] args) { - // Define the route ID - String routeId = "1_100224"; + // Define the route ID + String routeId = "1_100224"; - try { + try { - RouteRetrieveParams params = org.onebusaway.models.RouteRetrieveParams.builder().routeId(routeId).build(); + RouteRetrieveParams params = org.onebusaway.models.RouteRetrieveParams.builder() + .routeId(routeId) + .build(); - RouteRetrieveResponse route = client.route().retrieve(params); + RouteRetrieveResponse route = client.route().retrieve(params); - System.out.println(route); + System.out.println(route); - } catch (org.onebusaway.errors.OnebusawaySdkServiceException e) { - System.err.println("Error occurred: " + e.getMessage()); - System.err.println("Status Code: " + e.statusCode()); - } + } catch (org.onebusaway.errors.OnebusawaySdkServiceException e) { + System.err.println("Error occurred: " + e.getMessage()); + System.err.println("Status Code: " + e.statusCode()); + } } } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/RouteForAgency.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/RouteForAgency.java index 06e9f4a..e34a32b 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/RouteForAgency.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/RouteForAgency.java @@ -8,8 +8,11 @@ public class RouteForAgency { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -17,7 +20,6 @@ public class RouteForAgency { .baseUrl(BASE_URL) .build(); - public static void main(String[] args) { try { @@ -26,24 +28,22 @@ public static void main(String[] args) { String agencyId = "1"; // Create the parameters for the routes for agency list request - RoutesForAgencyListParams params = RoutesForAgencyListParams.builder() - .agencyId(agencyId) - .build(); + RoutesForAgencyListParams params = + RoutesForAgencyListParams.builder().agencyId(agencyId).build(); // Retrieve the routes for the agency - RoutesForAgencyListResponse routesForAgency = client.routesForAgency().list(params); + RoutesForAgencyListResponse routesForAgency = + client.routesForAgency().list(params); - for (RoutesForAgencyListResponse.Data.List route : routesForAgency.data().list()) { + for (RoutesForAgencyListResponse.Data.List route : + routesForAgency.data().list()) { System.out.println(route); } - } - catch (OnebusawaySdkServiceException e) { + } catch (OnebusawaySdkServiceException e) { System.err.println("Error occurred: " + e.getMessage()); System.err.println("Status Code: " + e.statusCode()); - } - catch (Exception e) { + } catch (Exception e) { System.err.println("Error occurred: " + e.getMessage()); } } - } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/RoutesForLocation.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/RoutesForLocation.java index e5fcf33..bd5eb0e 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/RoutesForLocation.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/RoutesForLocation.java @@ -7,8 +7,11 @@ public class RoutesForLocation { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -16,7 +19,6 @@ public class RoutesForLocation { .baseUrl(BASE_URL) .build(); - public static void main(String[] args) { try { @@ -33,15 +35,15 @@ public static void main(String[] args) { .build(); // Retrieve the routes for location - RoutesForLocationListResponse routesForLocation = client.routesForLocation().list(params); + RoutesForLocationListResponse routesForLocation = + client.routesForLocation().list(params); - for (RoutesForLocationListResponse.Data.List route : routesForLocation.data().list()) { + for (RoutesForLocationListResponse.Data.List route : + routesForLocation.data().list()) { System.out.println(route); } - } - catch (Exception e) { + } catch (Exception e) { System.err.println("Error occurred: " + e.getMessage()); } } - } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/ScheduleForRoute.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/ScheduleForRoute.java index 6c755c1..cc0cc04 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/ScheduleForRoute.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/ScheduleForRoute.java @@ -7,8 +7,11 @@ public class ScheduleForRoute { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -24,12 +27,12 @@ public static void main(String[] args) { try { // Define the parameters for the schedule for route request - ScheduleForRouteRetrieveParams params = ScheduleForRouteRetrieveParams.builder() - .routeId(routeId) - .build(); + ScheduleForRouteRetrieveParams params = + ScheduleForRouteRetrieveParams.builder().routeId(routeId).build(); // Retrieve the schedule for the route - ScheduleForRouteRetrieveResponse scheduleForRoute = client.scheduleForRoute().retrieve(params); + ScheduleForRouteRetrieveResponse scheduleForRoute = + client.scheduleForRoute().retrieve(params); System.out.println(scheduleForRoute); @@ -43,6 +46,5 @@ public static void main(String[] args) { catch (Exception e) { System.err.println("Error occurred: " + e.getMessage()); } - } } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/SearchForRoute.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/SearchForRoute.java index 476086a..a4d6840 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/SearchForRoute.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/SearchForRoute.java @@ -7,8 +7,11 @@ public class SearchForRoute { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -16,19 +19,19 @@ public class SearchForRoute { .baseUrl(BASE_URL) .build(); - public static void main(String[] args) { - // Define the search input - String searchInput = "crysta"; - - // Create the parameters for the route search request - SearchForRouteListParams params = SearchForRouteListParams.builder().input(searchInput).build(); + // Define the search input + String searchInput = "crysta"; - // Retrieve the route search results - SearchForRouteListResponse searchForRouteListResponse = client.searchForRoute().list(params); + // Create the parameters for the route search request + SearchForRouteListParams params = + SearchForRouteListParams.builder().input(searchInput).build(); - System.out.println(searchForRouteListResponse); + // Retrieve the route search results + SearchForRouteListResponse searchForRouteListResponse = + client.searchForRoute().list(params); + System.out.println(searchForRouteListResponse); } } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/SearchForStop.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/SearchForStop.java index 2894aa9..cc8a08a 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/SearchForStop.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/SearchForStop.java @@ -7,8 +7,11 @@ public class SearchForStop { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -16,19 +19,19 @@ public class SearchForStop { .baseUrl(BASE_URL) .build(); - public static void main(String[] args) { // Define the search input String searchInput = "crysta"; // Create the parameters for the stop search request - SearchForStopListParams params = SearchForStopListParams.builder().input(searchInput).build(); + SearchForStopListParams params = + SearchForStopListParams.builder().input(searchInput).build(); // Retrieve the stop search results - SearchForStopListResponse searchForStopListResponse = client.searchForStop().list(params); + SearchForStopListResponse searchForStopListResponse = + client.searchForStop().list(params); System.out.println(searchForStopListResponse); - } } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Shape.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Shape.java index 9c8e4aa..a3971a2 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Shape.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Shape.java @@ -7,28 +7,29 @@ public class Shape { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() .apiKey(API_KEY) .baseUrl(BASE_URL) .build(); - public static void main(String[] args) { // Define the shape ID String shapeId = "1_10002005"; // Define the parameters for the shape retrieval request - ShapeRetrieveParams params = ShapeRetrieveParams.builder().shapeId(shapeId).build(); + ShapeRetrieveParams params = + ShapeRetrieveParams.builder().shapeId(shapeId).build(); // Retrieve the shape information ShapeRetrieveResponse shape = client.shape().retrieve(params); System.out.println(shape.data()); } - - } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Stop.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Stop.java index 4f28923..352ab02 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Stop.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Stop.java @@ -7,8 +7,11 @@ public class Stop { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -16,7 +19,6 @@ public class Stop { .baseUrl(BASE_URL) .build(); - public static void main(String[] args) { // Define the stop ID @@ -30,5 +32,4 @@ public static void main(String[] args) { System.out.println(stop); } - } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/StopsForLocation.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/StopsForLocation.java index 9238b18..8fb4045 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/StopsForLocation.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/StopsForLocation.java @@ -1,18 +1,20 @@ package org.onebusaway.example; -import org.onebusaway.client.OnebusawaySdkClient; -import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient; -import org.onebusaway.models.*; - import java.util.HashMap; import java.util.List; import java.util.Map; +import org.onebusaway.client.OnebusawaySdkClient; +import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient; +import org.onebusaway.models.*; public class StopsForLocation { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -56,14 +58,14 @@ public static void main(String[] args) { // For each stop, print associated routes for (String routeId : stop.routeIds()) { References.Route route = referenceMap.get(routeId); - if (route == null) continue; // Skip if route is not found + if (route == null) continue; // Skip if route is not found // Build a description for the route String routeDescription = buildRouteDescription(route); System.out.printf(" %s\n", routeDescription); } - System.out.println(); // Add a blank line between stops for clarity + System.out.println(); // Add a blank line between stops for clarity } } @@ -76,7 +78,7 @@ private static String buildRouteDescription(References.Route route) { // Append description if present route.description().ifPresent(desc -> { - if (!description.isEmpty()) { + if (description.length() > 0) { description.append(" - "); } description.append(desc); diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/StopsForRoute.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/StopsForRoute.java index d103715..0819576 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/StopsForRoute.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/StopsForRoute.java @@ -3,11 +3,15 @@ import org.onebusaway.client.OnebusawaySdkClient; import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient; import org.onebusaway.models.*; + public class StopsForRoute { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -19,12 +23,12 @@ public static void main(String[] args) { // Define the route ID String routeId = "1_100229"; - StopsForRouteListParams params = StopsForRouteListParams.builder().routeId(routeId).build(); + StopsForRouteListParams params = + StopsForRouteListParams.builder().routeId(routeId).build(); // Get the stops for the route StopsForRouteListResponse stops = client.stopsForRoute().list(params); System.out.println(stops); } - } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/StopsIdsForAgency.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/StopsIdsForAgency.java index 134ab61..36b1795 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/StopsIdsForAgency.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/StopsIdsForAgency.java @@ -7,8 +7,11 @@ public class StopsIdsForAgency { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -20,7 +23,8 @@ public static void main(String[] args) { // Define the agency ID String agencyId = "1"; - StopIdsForAgencyListParams params = StopIdsForAgencyListParams.builder().agencyId(agencyId).build(); + StopIdsForAgencyListParams params = + StopIdsForAgencyListParams.builder().agencyId(agencyId).build(); // Get the list of stop IDs for the agency StopIdsForAgencyListResponse stopIds = client.stopIdsForAgency().list(params); @@ -29,5 +33,4 @@ public static void main(String[] args) { System.out.println(stopId); } } - } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Trip.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Trip.java index 90deb20..68f7c6d 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Trip.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/Trip.java @@ -7,8 +7,11 @@ public class Trip { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -22,14 +25,11 @@ public static void main(String[] args) { String tripId = "40_608344966"; // Create the parameters for the trip retrieve request - TripRetrieveParams params = TripRetrieveParams.builder() - .tripId(tripId) - .build(); + TripRetrieveParams params = TripRetrieveParams.builder().tripId(tripId).build(); // Retrieve the trip TripRetrieveResponse trip = client.trip().retrieve(params); System.out.println(trip); } - } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/TripDetails.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/TripDetails.java index 3dfba06..cbd86df 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/TripDetails.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/TripDetails.java @@ -3,11 +3,15 @@ import org.onebusaway.client.OnebusawaySdkClient; import org.onebusaway.client.okhttp.OnebusawaySdkOkHttpClient; import org.onebusaway.models.*; + public class TripDetails { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -17,19 +21,16 @@ public class TripDetails { public static void main(String[] args) { - // Define the trip ID - String tripId = "40_608344966"; - - // Create the parameters for the trip details request - TripDetailRetrieveParams params = TripDetailRetrieveParams .builder() - .tripId(tripId) - .build(); + // Define the trip ID + String tripId = "40_608344966"; + // Create the parameters for the trip details request + TripDetailRetrieveParams params = + TripDetailRetrieveParams.builder().tripId(tripId).build(); - // Retrieve the trip details - TripDetailRetrieveResponse tripDetails = client.tripDetails().retrieve(params); + // Retrieve the trip details + TripDetailRetrieveResponse tripDetails = client.tripDetails().retrieve(params); - System.out.println(tripDetails); + System.out.println(tripDetails); } - } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/TripForVehicle.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/TripForVehicle.java index ae4a33d..d997a02 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/TripForVehicle.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/TripForVehicle.java @@ -7,8 +7,11 @@ public class TripForVehicle { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -22,14 +25,12 @@ public static void main(String[] args) { String vehicleId = "1_3520"; // Retrieve the trip for the vehicle - TripForVehicleRetrieveParams params = TripForVehicleRetrieveParams.builder() - .vehicleId(vehicleId) - .build(); + TripForVehicleRetrieveParams params = + TripForVehicleRetrieveParams.builder().vehicleId(vehicleId).build(); // Retrieve the trip for the vehicle TripForVehicleRetrieveResponse tripForVehicle = client.tripForVehicle().retrieve(params); System.out.println(tripForVehicle); } - } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/TripsForRoute.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/TripsForRoute.java index 44c3ffb..886ee1e 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/TripsForRoute.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/TripsForRoute.java @@ -7,8 +7,11 @@ public class TripsForRoute { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -20,12 +23,12 @@ public static void main(String[] args) { // Define the route ID String routeId = "1_100224"; - TripsForRouteListParams params = TripsForRouteListParams.builder().routeId(routeId).build(); + TripsForRouteListParams params = + TripsForRouteListParams.builder().routeId(routeId).build(); // Get the trips for the route TripsForRouteListResponse trips = client.tripsForRoute().list(params); System.out.println(trips); } - } diff --git a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/VehiclesForAgency.java b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/VehiclesForAgency.java index 6ed210f..0d40893 100644 --- a/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/VehiclesForAgency.java +++ b/onebusaway-sdk-java-example/src/main/java/org/onebusaway/example/VehiclesForAgency.java @@ -7,8 +7,11 @@ public class VehiclesForAgency { // Retrieve constants from environment variables or fallback to default values - static final String API_KEY = System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; - static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null ? System.getenv("ONEBUSAWAY_BASE_URL") : "https://api.pugetsound.onebusaway.org"; + static final String API_KEY = + System.getenv("ONEBUSAWAY_API_KEY") != null ? System.getenv("ONEBUSAWAY_API_KEY") : "TEST"; + static final String BASE_URL = System.getenv("ONEBUSAWAY_BASE_URL") != null + ? System.getenv("ONEBUSAWAY_BASE_URL") + : "https://api.pugetsound.onebusaway.org"; // Initialize the Onebusaway SDK client static final OnebusawaySdkClient client = OnebusawaySdkOkHttpClient.builder() @@ -20,12 +23,12 @@ public static void main(String[] args) { // Define the agency ID String agencyId = "1"; - VehiclesForAgencyListParams params = VehiclesForAgencyListParams.builder().agencyId(agencyId).build(); + VehiclesForAgencyListParams params = + VehiclesForAgencyListParams.builder().agencyId(agencyId).build(); // Get the vehicles for the agency VehiclesForAgencyListResponse vehicles = client.vehiclesForAgency().list(params); System.out.println(vehicles); } - }