diff --git a/README.md b/README.md index a9b8ed2..6224414 100644 --- a/README.md +++ b/README.md @@ -6,31 +6,25 @@ -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") ``` -#### Maven +### Maven ```xml @@ -42,6 +36,12 @@ implementation("org.onebusaway:onebusaway-sdk-java:0.1.0-alpha.23") +## 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()`: @@ -98,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.core.JsonValue; -import org.onebusaway.models.CurrentTimeRetrieveParams; - -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 @@ -238,18 +226,26 @@ This library is typed for convenient access to the documented API. If you need t ### 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. + +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 -FooCreateParams address = FooCreateParams.builder() - .id("my_id") - .putAdditionalProperty("secret_prop", JsonValue.from("hello")) +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 @@ -271,13 +267,9 @@ $ export ONEBUSAWAY_SDK_LOG=debug 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..6c2c685 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 } - - 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/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 0635f4e..5ac20b7 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 @@ -18,6 +18,7 @@ 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 @@ -30,36 +31,11 @@ class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val baseUrl: HttpUrl) : HttpClient { - private fun getClient(requestOptions: RequestOptions): okhttp3.OkHttpClient { - val clientBuilder = okHttpClient.newBuilder() - - 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)) - } - - return clientBuilder.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() @@ -78,18 +54,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 } @@ -100,10 +76,35 @@ 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() + + 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() } @@ -112,9 +113,33 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val 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 @@ -168,7 +193,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val @JvmStatic fun builder() = Builder() } - class Builder { + class Builder internal constructor() { private var baseUrl: HttpUrl? = null // The default timeout is 1 minute. @@ -190,7 +215,7 @@ 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), ) } } 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 dfb3f1b..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 @@ -21,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 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 37c60ab..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 @@ -21,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 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 085a275..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 @@ -31,8 +31,28 @@ 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 @@ -90,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 d259172..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 @@ -31,8 +31,28 @@ 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 @@ -90,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 b319d18..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 @@ -61,8 +61,7 @@ import org.onebusaway.services.async.TripsForRouteServiceAsyncImpl import org.onebusaway.services.async.VehiclesForAgencyServiceAsync import org.onebusaway.services.async.VehiclesForAgencyServiceAsyncImpl -class OnebusawaySdkClientAsyncImpl -constructor( +class OnebusawaySdkClientAsyncImpl( private val clientOptions: ClientOptions, ) : OnebusawaySdkClientAsync { @@ -242,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 f5665e9..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 @@ -61,8 +61,7 @@ import org.onebusaway.services.blocking.TripsForRouteServiceImpl import org.onebusaway.services.blocking.VehiclesForAgencyService import org.onebusaway.services.blocking.VehiclesForAgencyServiceImpl -class OnebusawaySdkClientImpl -constructor( +class OnebusawaySdkClientImpl( private val clientOptions: ClientOptions, ) : OnebusawaySdkClient { @@ -234,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 7f4054b..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 @@ -35,7 +35,8 @@ 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() @@ -68,6 +69,14 @@ 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) @@ -148,19 +157,11 @@ private constructor( fun removeAllQueryParams(keys: Set) = apply { queryParams.removeAll(keys) } - 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 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 = Headers.builder() val queryParams = QueryParams.builder() @@ -171,7 +172,7 @@ private constructor( headers.put("X-Stainless-Package-Version", getPackageVersion()) headers.put("X-Stainless-Runtime", "JRE") headers.put("X-Stainless-Runtime-Version", getJavaVersion()) - apiKey?.let { + apiKey.let { if (!it.isEmpty()) { headers.put("key", it) } @@ -180,10 +181,10 @@ private constructor( queryParams.replaceAll(this.queryParams.build()) return ClientOptions( - httpClient!!, + httpClient, PhantomReachableClosingHttpClient( RetryingHttpClient.builder() - .httpClient(httpClient!!) + .httpClient(httpClient) .clock(clock) .maxRetries(maxRetries) .build() @@ -195,7 +196,7 @@ private constructor( 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/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/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/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 f654c32..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,5 +1,6 @@ package org.onebusaway.core.http +import org.onebusaway.core.checkRequired import org.onebusaway.core.toImmutable class HttpRequest @@ -21,7 +22,7 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + class Builder internal constructor() { private var method: HttpMethod? = null private var url: String? = null @@ -134,7 +135,7 @@ private constructor( fun build(): HttpRequest = HttpRequest( - checkNotNull(method) { "`method` is required but was not set" }, + checkRequired("method", method), url, pathSegments.toImmutable(), headers.build(), 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 fa4ed7a..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 @@ -56,15 +57,17 @@ private constructor( } 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()) } } @@ -112,6 +115,8 @@ 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(requestWithRetryCount, requestOptions) } @@ -223,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() @@ -260,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/OnebusawaySdkError.kt b/onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/OnebusawaySdkError.kt index 2b12984..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 @@ -30,7 +30,8 @@ private constructor( @JvmStatic fun builder() = Builder() } - class Builder { + /** A builder for [OnebusawaySdkError]. */ + class Builder internal constructor() { private var additionalProperties: MutableMap = mutableMapOf() 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 4d859dc..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 @@ -4,22 +4,27 @@ package org.onebusaway.models import java.util.Objects import org.onebusaway.core.NoAutoDetect +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 constructor( private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -28,8 +33,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [AgenciesWithCoverageListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() 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 cff54bc..9b76e48 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 @@ -12,6 +12,7 @@ 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 @@ -41,15 +42,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -66,14 +67,16 @@ private constructor( 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) @@ -83,13 +86,14 @@ 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 @@ -145,11 +149,11 @@ private constructor( 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(), ) } @@ -177,11 +181,15 @@ 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("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing @@ -190,12 +198,14 @@ private constructor( 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) @@ -205,17 +215,18 @@ 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 { limitExceeded = data.limitExceeded - list = data.list + list = data.list.map { it.toMutableList() } references = data.references additionalProperties = data.additionalProperties.toMutableMap() } @@ -228,7 +239,22 @@ private constructor( fun list(list: List) = list(JsonField.of(list)) - 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)) @@ -257,9 +283,9 @@ private constructor( fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -297,15 +323,15 @@ 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 @@ -314,14 +340,16 @@ private constructor( 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) @@ -331,13 +359,14 @@ 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 @@ -394,11 +423,11 @@ private constructor( 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(), ) } 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 9958aee..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 @@ -4,15 +4,18 @@ package org.onebusaway.models import java.util.Objects import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun agencyId(): String = agencyId @@ -20,9 +23,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -38,8 +41,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [AgencyRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var agencyId: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() @@ -154,7 +158,7 @@ constructor( fun build(): AgencyRetrieveParams = AgencyRetrieveParams( - checkNotNull(agencyId) { "`agencyId` is required but was not set" }, + checkRequired("agencyId", agencyId), additionalHeaders.build(), additionalQueryParams.build(), ) 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 599e05e..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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -157,12 +161,12 @@ private constructor( class Data @JsonCreator private constructor( - @JsonProperty("limitExceeded") - @ExcludeMissing - private val limitExceeded: JsonField = JsonMissing.of(), @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(), @@ -170,17 +174,21 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { - fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") - fun entry(): Entry = entry.getRequired("entry") + fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") + 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 @@ -189,12 +197,14 @@ private constructor( 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) @@ -204,31 +214,32 @@ 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 { - limitExceeded = data.limitExceeded 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)) fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } - fun entry(entry: Entry) = entry(JsonField.of(entry)) - - fun entry(entry: JsonField) = apply { this.entry = entry } - fun references(references: References) = references(JsonField.of(references)) fun references(references: JsonField) = apply { @@ -256,9 +267,9 @@ private constructor( fun build(): Data = Data( - limitExceeded, - entry, - references, + checkRequired("entry", entry), + checkRequired("limitExceeded", limitExceeded), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -267,6 +278,18 @@ private constructor( class Entry @JsonCreator private constructor( + @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(), @@ -276,31 +299,27 @@ private constructor( @JsonProperty("fareUrl") @ExcludeMissing private val fareUrl: JsonField = JsonMissing.of(), - @JsonProperty("id") - @ExcludeMissing - private val id: JsonField = JsonMissing.of(), @JsonProperty("lang") @ExcludeMissing private val lang: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), @JsonProperty("phone") @ExcludeMissing private val phone: JsonField = JsonMissing.of(), @JsonProperty("privateService") @ExcludeMissing private val privateService: JsonField = JsonMissing.of(), - @JsonProperty("timezone") - @ExcludeMissing - private val timezone: JsonField = JsonMissing.of(), - @JsonProperty("url") - @ExcludeMissing - private val url: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { + 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")) @@ -308,40 +327,36 @@ 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") + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id - fun url(): String = url.getRequired("url") - - @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 @@ -350,19 +365,21 @@ private constructor( 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) @@ -372,35 +389,52 @@ 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 { + id = entry.id + name = entry.name + timezone = entry.timezone + url = entry.url disclaimer = entry.disclaimer email = entry.email fareUrl = entry.fareUrl - id = entry.id lang = entry.lang - name = entry.name phone = entry.phone privateService = entry.privateService - timezone = entry.timezone - url = entry.url 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)) fun disclaimer(disclaimer: JsonField) = apply { @@ -415,18 +449,10 @@ private constructor( fun fareUrl(fareUrl: JsonField) = apply { this.fareUrl = fareUrl } - fun id(id: String) = id(JsonField.of(id)) - - fun id(id: JsonField) = apply { this.id = id } - fun lang(lang: String) = lang(JsonField.of(lang)) fun lang(lang: JsonField) = apply { this.lang = lang } - fun name(name: String) = name(JsonField.of(name)) - - fun name(name: JsonField) = apply { this.name = name } - fun phone(phone: String) = phone(JsonField.of(phone)) fun phone(phone: JsonField) = apply { this.phone = phone } @@ -438,14 +464,6 @@ private constructor( this.privateService = privateService } - 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 additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -470,16 +488,16 @@ private constructor( 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(), ) } @@ -489,17 +507,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && disclaimer == other.disclaimer && email == other.email && fareUrl == other.fareUrl && id == other.id && lang == other.lang && name == other.name && phone == other.phone && privateService == other.privateService && timezone == other.timezone && url == other.url && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(disclaimer, email, fareUrl, id, lang, name, phone, privateService, timezone, url, additionalProperties) } + 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 = 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 { @@ -507,17 +525,17 @@ private constructor( return true } - return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && entry == other.entry && references == other.references && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(limitExceeded, entry, references, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(entry, limitExceeded, references, additionalProperties) } /* spotless:on */ 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 { 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 f87d6db..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 @@ -7,18 +7,21 @@ import java.time.format.DateTimeFormatter import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun stopId(): String = stopId @@ -35,10 +38,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + 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())) } @@ -63,8 +65,9 @@ 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 @@ -86,13 +89,32 @@ constructor( 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 } + + /** 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. */ - fun minutesBefore(minutesBefore: Long) = apply { this.minutesBefore = minutesBefore } + @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 } /** The specific time for querying the system status. */ - fun time(time: OffsetDateTime) = apply { this.time = time } + fun time(time: Optional) = time(time.orElse(null)) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -194,7 +216,7 @@ constructor( fun build(): ArrivalAndDepartureListParams = ArrivalAndDepartureListParams( - checkNotNull(stopId) { "`stopId` is required but was not set" }, + checkRequired("stopId", stopId), minutesAfter, minutesBefore, time, 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 584beee..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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -146,11 +150,11 @@ private constructor( 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(), ) } @@ -173,9 +177,11 @@ private constructor( 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 @@ -184,11 +190,13 @@ private constructor( 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) @@ -198,10 +206,11 @@ 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 @@ -242,8 +251,8 @@ private constructor( fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -265,7 +274,8 @@ private constructor( @JsonProperty("arrivalsAndDepartures") @ExcludeMissing - fun _arrivalsAndDepartures() = arrivalsAndDepartures + fun _arrivalsAndDepartures(): JsonField> = + arrivalsAndDepartures @JsonAnyGetter @ExcludeMissing @@ -274,10 +284,12 @@ private constructor( 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) @@ -287,15 +299,16 @@ 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 { - arrivalsAndDepartures = entry.arrivalsAndDepartures + arrivalsAndDepartures = entry.arrivalsAndDepartures.map { it.toMutableList() } additionalProperties = entry.additionalProperties.toMutableMap() } @@ -304,7 +317,22 @@ private constructor( 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() @@ -330,7 +358,9 @@ private constructor( fun build(): Entry = Entry( - arrivalsAndDepartures.map { it.toImmutable() }, + checkRequired("arrivalsAndDepartures", arrivalsAndDepartures).map { + it.toImmutable() + }, additionalProperties.toImmutable() ) } @@ -339,9 +369,6 @@ private constructor( class ArrivalsAndDeparture @JsonCreator private constructor( - @JsonProperty("actualTrack") - @ExcludeMissing - private val actualTrack: JsonField = JsonMissing.of(), @JsonProperty("arrivalEnabled") @ExcludeMissing private val arrivalEnabled: JsonField = JsonMissing.of(), @@ -351,6 +378,48 @@ private constructor( @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(), @@ -363,9 +432,6 @@ private constructor( @JsonProperty("lastUpdateTime") @ExcludeMissing private val lastUpdateTime: JsonField = JsonMissing.of(), - @JsonProperty("numberOfStopsAway") - @ExcludeMissing - private val numberOfStopsAway: JsonField = JsonMissing.of(), @JsonProperty("occupancyStatus") @ExcludeMissing private val occupancyStatus: JsonField = JsonMissing.of(), @@ -375,21 +441,12 @@ private constructor( @JsonProperty("predictedArrivalInterval") @ExcludeMissing private val predictedArrivalInterval: JsonField = JsonMissing.of(), - @JsonProperty("predictedArrivalTime") - @ExcludeMissing - private val predictedArrivalTime: JsonField = JsonMissing.of(), @JsonProperty("predictedDepartureInterval") @ExcludeMissing private val predictedDepartureInterval: JsonField = JsonMissing.of(), - @JsonProperty("predictedDepartureTime") - @ExcludeMissing - private val predictedDepartureTime: JsonField = JsonMissing.of(), @JsonProperty("predictedOccupancy") @ExcludeMissing private val predictedOccupancy: JsonField = JsonMissing.of(), - @JsonProperty("routeId") - @ExcludeMissing - private val routeId: JsonField = JsonMissing.of(), @JsonProperty("routeLongName") @ExcludeMissing private val routeLongName: JsonField = JsonMissing.of(), @@ -399,56 +456,25 @@ private constructor( @JsonProperty("scheduledArrivalInterval") @ExcludeMissing private val scheduledArrivalInterval: JsonField = JsonMissing.of(), - @JsonProperty("scheduledArrivalTime") - @ExcludeMissing - private val scheduledArrivalTime: JsonField = JsonMissing.of(), @JsonProperty("scheduledDepartureInterval") @ExcludeMissing private val scheduledDepartureInterval: JsonField = JsonMissing.of(), - @JsonProperty("scheduledDepartureTime") - @ExcludeMissing - private val scheduledDepartureTime: JsonField = JsonMissing.of(), @JsonProperty("scheduledTrack") @ExcludeMissing private val scheduledTrack: 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("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("tripStatus") @ExcludeMissing private val tripStatus: JsonField = JsonMissing.of(), - @JsonProperty("vehicleId") - @ExcludeMissing - private val vehicleId: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - /** 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") @@ -458,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")) @@ -474,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")) @@ -494,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. @@ -541,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")) @@ -572,69 +626,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 + 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 @@ -642,20 +651,7 @@ private constructor( */ @JsonProperty("numberOfStopsAway") @ExcludeMissing - fun _numberOfStopsAway() = numberOfStopsAway - - /** Current occupancy status of the transit vehicle. */ - @JsonProperty("occupancyStatus") - @ExcludeMissing - fun _occupancyStatus() = occupancyStatus - - /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") @ExcludeMissing fun _predicted() = predicted - - /** Interval for predicted arrival time, if available. */ - @JsonProperty("predictedArrivalInterval") - @ExcludeMissing - fun _predictedArrivalInterval() = predictedArrivalInterval + fun _numberOfStopsAway(): JsonField = numberOfStopsAway /** * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time @@ -663,12 +659,7 @@ private constructor( */ @JsonProperty("predictedArrivalTime") @ExcludeMissing - fun _predictedArrivalTime() = predictedArrivalTime - - /** Interval for predicted departure time, if available. */ - @JsonProperty("predictedDepartureInterval") - @ExcludeMissing - fun _predictedDepartureInterval() = predictedDepartureInterval + fun _predictedArrivalTime(): JsonField = predictedArrivalTime /** * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time @@ -676,95 +667,154 @@ private constructor( */ @JsonProperty("predictedDepartureTime") @ExcludeMissing - fun _predictedDepartureTime() = predictedDepartureTime - - /** Predicted occupancy status of the transit vehicle. */ - @JsonProperty("predictedOccupancy") - @ExcludeMissing - fun _predictedOccupancy() = predictedOccupancy + fun _predictedDepartureTime(): JsonField = predictedDepartureTime /** The ID of the route for the arriving vehicle. */ - @JsonProperty("routeId") @ExcludeMissing fun _routeId() = routeId - - /** - * Optional route long name that potentially overrides the route long name in the - * referenced route element. - */ - @JsonProperty("routeLongName") @ExcludeMissing fun _routeLongName() = routeLongName - - /** - * Optional route short name that potentially overrides the route short name in the - * referenced route element. - */ - @JsonProperty("routeShortName") - @ExcludeMissing - fun _routeShortName() = routeShortName - - /** Interval for scheduled arrival time. */ - @JsonProperty("scheduledArrivalInterval") - @ExcludeMissing - fun _scheduledArrivalInterval() = scheduledArrivalInterval + @JsonProperty("routeId") @ExcludeMissing fun _routeId(): JsonField = routeId /** Scheduled arrival time, in milliseconds since Unix epoch. */ @JsonProperty("scheduledArrivalTime") @ExcludeMissing - fun _scheduledArrivalTime() = scheduledArrivalTime - - /** Interval for scheduled departure time. */ - @JsonProperty("scheduledDepartureInterval") - @ExcludeMissing - fun _scheduledDepartureInterval() = scheduledDepartureInterval + fun _scheduledArrivalTime(): JsonField = scheduledArrivalTime /** Scheduled departure time, in milliseconds since Unix epoch. */ @JsonProperty("scheduledDepartureTime") @ExcludeMissing - fun _scheduledDepartureTime() = scheduledDepartureTime - - /** Scheduled track information of the arriving transit vehicle. */ - @JsonProperty("scheduledTrack") - @ExcludeMissing - fun _scheduledTrack() = scheduledTrack + fun _scheduledDepartureTime(): JsonField = scheduledDepartureTime /** * 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 arrival. */ - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds - - /** Current status of the arrival. */ - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate /** The ID of the stop the vehicle is arriving at. */ - @JsonProperty("stopId") @ExcludeMissing fun _stopId() = stopId + @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() = stopSequence + @JsonProperty("stopSequence") + @ExcludeMissing + fun _stopSequence(): JsonField = stopSequence /** Total number of stops visited on the trip for this arrival. */ @JsonProperty("totalStopsInTrip") @ExcludeMissing - fun _totalStopsInTrip() = totalStopsInTrip + fun _totalStopsInTrip(): JsonField = totalStopsInTrip /** * Optional trip headsign that potentially overrides the trip headsign in the * referenced trip element. */ - @JsonProperty("tripHeadsign") @ExcludeMissing fun _tripHeadsign() = tripHeadsign + @JsonProperty("tripHeadsign") + @ExcludeMissing + fun _tripHeadsign(): JsonField = tripHeadsign /** The ID of the trip for the arriving vehicle. */ - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId - - /** Trip-specific status for the arriving transit vehicle. */ - @JsonProperty("tripStatus") @ExcludeMissing fun _tripStatus() = tripStatus + @JsonProperty("tripId") @ExcludeMissing fun _tripId(): JsonField = tripId /** ID of the transit vehicle serving this trip. */ - @JsonProperty("vehicleId") @ExcludeMissing fun _vehicleId() = vehicleId + @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 _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(): JsonField = predictedOccupancy + + /** + * Optional route long name that potentially overrides the route long name in the + * referenced route element. + */ + @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(): JsonField = routeShortName + + /** Interval for scheduled arrival time. */ + @JsonProperty("scheduledArrivalInterval") + @ExcludeMissing + fun _scheduledArrivalInterval(): JsonField = scheduledArrivalInterval + + /** Interval for scheduled departure time. */ + @JsonProperty("scheduledDepartureInterval") + @ExcludeMissing + fun _scheduledDepartureInterval(): JsonField = scheduledDepartureInterval + + /** Scheduled track information of the arriving transit vehicle. */ + @JsonProperty("scheduledTrack") + @ExcludeMissing + fun _scheduledTrack(): JsonField = scheduledTrack + + /** References to situation elements (if any) applicable to this arrival. */ + @JsonProperty("situationIds") + @ExcludeMissing + fun _situationIds(): JsonField> = situationIds + + /** 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(): JsonField = tripStatus @JsonAnyGetter @ExcludeMissing @@ -773,43 +823,45 @@ private constructor( 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) @@ -819,121 +871,263 @@ 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 { - actualTrack = arrivalsAndDeparture.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 - numberOfStopsAway = arrivalsAndDeparture.numberOfStopsAway occupancyStatus = arrivalsAndDeparture.occupancyStatus predicted = arrivalsAndDeparture.predicted predictedArrivalInterval = arrivalsAndDeparture.predictedArrivalInterval - predictedArrivalTime = arrivalsAndDeparture.predictedArrivalTime predictedDepartureInterval = arrivalsAndDeparture.predictedDepartureInterval - predictedDepartureTime = arrivalsAndDeparture.predictedDepartureTime predictedOccupancy = arrivalsAndDeparture.predictedOccupancy - routeId = arrivalsAndDeparture.routeId routeLongName = arrivalsAndDeparture.routeLongName routeShortName = arrivalsAndDeparture.routeShortName scheduledArrivalInterval = arrivalsAndDeparture.scheduledArrivalInterval - scheduledArrivalTime = arrivalsAndDeparture.scheduledArrivalTime scheduledDepartureInterval = arrivalsAndDeparture.scheduledDepartureInterval - scheduledDepartureTime = arrivalsAndDeparture.scheduledDepartureTime scheduledTrack = arrivalsAndDeparture.scheduledTrack - serviceDate = arrivalsAndDeparture.serviceDate - situationIds = arrivalsAndDeparture.situationIds + situationIds = arrivalsAndDeparture.situationIds.map { it.toMutableList() } status = arrivalsAndDeparture.status - stopId = arrivalsAndDeparture.stopId - stopSequence = arrivalsAndDeparture.stopSequence - totalStopsInTrip = arrivalsAndDeparture.totalStopsInTrip - tripHeadsign = arrivalsAndDeparture.tripHeadsign - tripId = arrivalsAndDeparture.tripId tripStatus = arrivalsAndDeparture.tripStatus - vehicleId = arrivalsAndDeparture.vehicleId additionalProperties = arrivalsAndDeparture.additionalProperties.toMutableMap() } - /** The actual track information of the arriving transit vehicle. */ - fun actualTrack(actualTrack: String) = actualTrack(JsonField.of(actualTrack)) + /** Indicates if riders can arrive on this transit vehicle. */ + fun arrivalEnabled(arrivalEnabled: Boolean) = + arrivalEnabled(JsonField.of(arrivalEnabled)) - /** The actual track information of the arriving transit vehicle. */ - fun actualTrack(actualTrack: JsonField) = apply { - this.actualTrack = actualTrack + /** Indicates if riders can arrive on this transit vehicle. */ + fun arrivalEnabled(arrivalEnabled: JsonField) = apply { + this.arrivalEnabled = arrivalEnabled + } + + /** + * Index of this arrival’s trip into the sequence of trips for the active block. + */ + fun blockTripSequence(blockTripSequence: Long) = + blockTripSequence(JsonField.of(blockTripSequence)) + + /** + * Index of this arrival’s trip into the sequence of trips for the active block. + */ + fun blockTripSequence(blockTripSequence: JsonField) = apply { + this.blockTripSequence = blockTripSequence + } + + /** Indicates if riders can depart from this transit vehicle. */ + fun departureEnabled(departureEnabled: Boolean) = + departureEnabled(JsonField.of(departureEnabled)) + + /** Indicates if riders can depart from this transit vehicle. */ + 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 } - /** Indicates if riders can arrive on this transit vehicle. */ - fun arrivalEnabled(arrivalEnabled: Boolean) = - arrivalEnabled(JsonField.of(arrivalEnabled)) + /** Total number of stops visited on the trip for this arrival. */ + fun totalStopsInTrip(totalStopsInTrip: Long) = + totalStopsInTrip(JsonField.of(totalStopsInTrip)) - /** Indicates if riders can arrive on this transit vehicle. */ - fun arrivalEnabled(arrivalEnabled: JsonField) = apply { - this.arrivalEnabled = arrivalEnabled + /** Total number of stops visited on the trip for this arrival. */ + fun totalStopsInTrip(totalStopsInTrip: JsonField) = apply { + this.totalStopsInTrip = totalStopsInTrip } /** - * Index of this arrival’s trip into the sequence of trips for the active block. + * Optional trip headsign that potentially overrides the trip headsign in the + * referenced trip element. */ - fun blockTripSequence(blockTripSequence: Long) = - blockTripSequence(JsonField.of(blockTripSequence)) + fun tripHeadsign(tripHeadsign: String) = + tripHeadsign(JsonField.of(tripHeadsign)) /** - * Index of this arrival’s trip into the sequence of trips for the active block. + * Optional trip headsign that potentially overrides the trip headsign in the + * referenced trip element. */ - fun blockTripSequence(blockTripSequence: JsonField) = apply { - this.blockTripSequence = blockTripSequence + fun tripHeadsign(tripHeadsign: JsonField) = apply { + this.tripHeadsign = tripHeadsign } - /** Indicates if riders can depart from this transit vehicle. */ - fun departureEnabled(departureEnabled: Boolean) = - departureEnabled(JsonField.of(departureEnabled)) + /** The ID of the trip for the arriving vehicle. */ + fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - /** Indicates if riders can depart from this transit vehicle. */ - fun departureEnabled(departureEnabled: JsonField) = apply { - this.departureEnabled = departureEnabled + /** 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. */ @@ -971,21 +1165,6 @@ private constructor( 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). - */ - fun numberOfStopsAway(numberOfStopsAway: JsonField) = apply { - this.numberOfStopsAway = numberOfStopsAway - } - /** Current occupancy status of the transit vehicle. */ fun occupancyStatus(occupancyStatus: String) = occupancyStatus(JsonField.of(occupancyStatus)) @@ -1013,21 +1192,6 @@ private constructor( 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). - */ - fun predictedArrivalTime(predictedArrivalTime: JsonField) = apply { - this.predictedArrivalTime = predictedArrivalTime - } - /** Interval for predicted departure time, if available. */ fun predictedDepartureInterval(predictedDepartureInterval: String) = predictedDepartureInterval(JsonField.of(predictedDepartureInterval)) @@ -1038,21 +1202,6 @@ private constructor( 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). - */ - fun predictedDepartureTime(predictedDepartureTime: JsonField) = apply { - this.predictedDepartureTime = predictedDepartureTime - } - /** Predicted occupancy status of the transit vehicle. */ fun predictedOccupancy(predictedOccupancy: String) = predictedOccupancy(JsonField.of(predictedOccupancy)) @@ -1062,12 +1211,6 @@ private constructor( 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: JsonField) = apply { this.routeId = routeId } - /** * Optional route long name that potentially overrides the route long name in * the referenced route element. @@ -1108,15 +1251,6 @@ private constructor( 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. */ - fun scheduledArrivalTime(scheduledArrivalTime: JsonField) = apply { - this.scheduledArrivalTime = scheduledArrivalTime - } - /** Interval for scheduled departure time. */ fun scheduledDepartureInterval(scheduledDepartureInterval: String) = scheduledDepartureInterval(JsonField.of(scheduledDepartureInterval)) @@ -1127,15 +1261,6 @@ private constructor( 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. */ - fun scheduledDepartureTime(scheduledDepartureTime: JsonField) = apply { - this.scheduledDepartureTime = scheduledDepartureTime - } - /** Scheduled track information of the arriving transit vehicle. */ fun scheduledTrack(scheduledTrack: String) = scheduledTrack(JsonField.of(scheduledTrack)) @@ -1145,27 +1270,27 @@ private constructor( 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. - */ - 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. */ 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. */ @@ -1174,56 +1299,6 @@ private constructor( /** Current status of the arrival. */ 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. */ - 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 } - /** Trip-specific status for the arriving transit vehicle. */ fun tripStatus(tripStatus: TripStatus) = tripStatus(JsonField.of(tripStatus)) @@ -1232,14 +1307,6 @@ private constructor( 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. */ - fun vehicleId(vehicleId: JsonField) = apply { - this.vehicleId = vehicleId - } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1264,40 +1331,40 @@ private constructor( 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(), ) } @@ -1316,36 +1383,18 @@ private constructor( @JsonProperty("closestStop") @ExcludeMissing private val closestStop: JsonField = JsonMissing.of(), - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing - private val closestStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("distanceAlongTrip") @ExcludeMissing private val distanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("frequency") - @ExcludeMissing - private val frequency: JsonField = JsonMissing.of(), @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownLocation") - @ExcludeMissing - private val lastKnownLocation: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - private val lastKnownOrientation: JsonField = JsonMissing.of(), @JsonProperty("lastLocationUpdateTime") @ExcludeMissing private val lastLocationUpdateTime: JsonField = JsonMissing.of(), @JsonProperty("lastUpdateTime") @ExcludeMissing private val lastUpdateTime: JsonField = JsonMissing.of(), - @JsonProperty("nextStop") - @ExcludeMissing - private val nextStop: JsonField = JsonMissing.of(), - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - private val nextStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("occupancyCapacity") @ExcludeMissing private val occupancyCapacity: JsonField = JsonMissing.of(), @@ -1355,36 +1404,54 @@ private constructor( @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("phase") - @ExcludeMissing - private val phase: JsonField = JsonMissing.of(), @JsonProperty("position") @ExcludeMissing private val position: JsonField = JsonMissing.of(), - @JsonProperty("predicted") - @ExcludeMissing - private val predicted: JsonField = JsonMissing.of(), - @JsonProperty("scheduleDeviation") - @ExcludeMissing - private val scheduleDeviation: JsonField = JsonMissing.of(), @JsonProperty("scheduledDistanceAlongTrip") @ExcludeMissing private val scheduledDistanceAlongTrip: 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("vehicleId") @ExcludeMissing private val vehicleId: JsonField = JsonMissing.of(), @@ -1402,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. @@ -1418,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. @@ -1429,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. @@ -1451,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") @@ -1472,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") @@ -1493,25 +1516,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") @@ -1519,28 +1529,81 @@ 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 @@ -1548,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 @@ -1559,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 @@ -1579,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 @@ -1630,35 +1664,92 @@ 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 @@ -1667,36 +1758,38 @@ private constructor( 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) @@ -1706,35 +1799,36 @@ 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() @@ -1744,29 +1838,29 @@ private constructor( activeTripId = tripStatus.activeTripId blockTripSequence = tripStatus.blockTripSequence closestStop = tripStatus.closestStop - closestStopTimeOffset = tripStatus.closestStopTimeOffset distanceAlongTrip = tripStatus.distanceAlongTrip - frequency = tripStatus.frequency lastKnownDistanceAlongTrip = tripStatus.lastKnownDistanceAlongTrip - lastKnownLocation = tripStatus.lastKnownLocation - lastKnownOrientation = tripStatus.lastKnownOrientation lastLocationUpdateTime = tripStatus.lastLocationUpdateTime lastUpdateTime = tripStatus.lastUpdateTime - nextStop = tripStatus.nextStop - nextStopTimeOffset = tripStatus.nextStopTimeOffset occupancyCapacity = tripStatus.occupancyCapacity occupancyCount = tripStatus.occupancyCount occupancyStatus = tripStatus.occupancyStatus - orientation = tripStatus.orientation phase = tripStatus.phase - position = tripStatus.position predicted = tripStatus.predicted scheduleDeviation = tripStatus.scheduleDeviation - scheduledDistanceAlongTrip = tripStatus.scheduledDistanceAlongTrip serviceDate = tripStatus.serviceDate - situationIds = tripStatus.situationIds 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() } @@ -1806,21 +1900,6 @@ private constructor( 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). - */ - fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { - this.closestStopTimeOffset = closestStopTimeOffset - } - /** * Distance, in meters, the transit vehicle has progressed along the active * trip. @@ -1836,18 +1915,6 @@ private constructor( 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. - */ - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1863,31 +1930,6 @@ private constructor( 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. */ - 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 - } - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1917,29 +1959,6 @@ private constructor( 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. */ - 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 - } - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) @@ -1967,33 +1986,12 @@ private constructor( 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. - */ - 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. */ 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. */ - 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)) @@ -2017,21 +2015,6 @@ private constructor( 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. - */ - 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. @@ -2046,15 +2029,6 @@ private constructor( 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. */ - fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds - } - /** Current status modifiers for the trip. */ fun status(status: String) = status(JsonField.of(status)) @@ -2071,6 +2045,140 @@ private constructor( 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)) @@ -2103,32 +2211,35 @@ private constructor( 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(), ) @@ -2157,10 +2268,10 @@ 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 @@ -2169,11 +2280,13 @@ private constructor( 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) @@ -2183,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() @@ -2281,10 +2395,10 @@ 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 @@ -2293,11 +2407,13 @@ private constructor( 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) @@ -2307,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() @@ -2386,17 +2503,17 @@ private constructor( return true } - return /* spotless:off */ other is TripStatus && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && closestStopTimeOffset == other.closestStopTimeOffset && distanceAlongTrip == other.distanceAlongTrip && frequency == other.frequency && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && orientation == other.orientation && phase == other.phase && position == other.position && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && serviceDate == other.serviceDate && situationIds == other.situationIds && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && vehicleId == other.vehicleId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { 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) } + 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 = 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 { @@ -2404,17 +2521,17 @@ private constructor( return true } - return /* spotless:off */ other is ArrivalsAndDeparture && actualTrack == other.actualTrack && arrivalEnabled == other.arrivalEnabled && blockTripSequence == other.blockTripSequence && departureEnabled == other.departureEnabled && distanceFromStop == other.distanceFromStop && frequency == other.frequency && historicalOccupancy == other.historicalOccupancy && lastUpdateTime == other.lastUpdateTime && numberOfStopsAway == other.numberOfStopsAway && occupancyStatus == other.occupancyStatus && predicted == other.predicted && predictedArrivalInterval == other.predictedArrivalInterval && predictedArrivalTime == other.predictedArrivalTime && predictedDepartureInterval == other.predictedDepartureInterval && predictedDepartureTime == other.predictedDepartureTime && predictedOccupancy == other.predictedOccupancy && routeId == other.routeId && routeLongName == other.routeLongName && routeShortName == other.routeShortName && scheduledArrivalInterval == other.scheduledArrivalInterval && scheduledArrivalTime == other.scheduledArrivalTime && scheduledDepartureInterval == other.scheduledDepartureInterval && scheduledDepartureTime == other.scheduledDepartureTime && scheduledTrack == other.scheduledTrack && serviceDate == other.serviceDate && situationIds == other.situationIds && status == other.status && stopId == other.stopId && stopSequence == other.stopSequence && totalStopsInTrip == other.totalStopsInTrip && tripHeadsign == other.tripHeadsign && tripId == other.tripId && tripStatus == other.tripStatus && vehicleId == other.vehicleId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { 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) } + 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 = 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 { 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 427be87..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 @@ -5,11 +5,14 @@ package org.onebusaway.models import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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, @@ -18,7 +21,7 @@ constructor( private val vehicleId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun stopId(): String = stopId @@ -36,10 +39,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + 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())) } @@ -64,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 @@ -96,11 +99,24 @@ 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 time(time: Long) = apply { this.time = time } + fun stopSequence(stopSequence: Long) = stopSequence(stopSequence as Long?) - fun vehicleId(vehicleId: String) = apply { this.vehicleId = vehicleId } + @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) = 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() @@ -202,9 +218,9 @@ constructor( 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, 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 9d491fe..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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -147,11 +151,11 @@ private constructor( 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(), ) } @@ -174,9 +178,11 @@ private constructor( 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 @@ -185,11 +191,13 @@ private constructor( 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) @@ -199,10 +207,11 @@ 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 @@ -243,8 +252,8 @@ private constructor( fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -253,9 +262,6 @@ private constructor( class Entry @JsonCreator private constructor( - @JsonProperty("actualTrack") - @ExcludeMissing - private val actualTrack: JsonField = JsonMissing.of(), @JsonProperty("arrivalEnabled") @ExcludeMissing private val arrivalEnabled: JsonField = JsonMissing.of(), @@ -265,6 +271,48 @@ private constructor( @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(), @@ -277,9 +325,6 @@ private constructor( @JsonProperty("lastUpdateTime") @ExcludeMissing private val lastUpdateTime: JsonField = JsonMissing.of(), - @JsonProperty("numberOfStopsAway") - @ExcludeMissing - private val numberOfStopsAway: JsonField = JsonMissing.of(), @JsonProperty("occupancyStatus") @ExcludeMissing private val occupancyStatus: JsonField = JsonMissing.of(), @@ -289,21 +334,12 @@ private constructor( @JsonProperty("predictedArrivalInterval") @ExcludeMissing private val predictedArrivalInterval: JsonField = JsonMissing.of(), - @JsonProperty("predictedArrivalTime") - @ExcludeMissing - private val predictedArrivalTime: JsonField = JsonMissing.of(), @JsonProperty("predictedDepartureInterval") @ExcludeMissing private val predictedDepartureInterval: JsonField = JsonMissing.of(), - @JsonProperty("predictedDepartureTime") - @ExcludeMissing - private val predictedDepartureTime: JsonField = JsonMissing.of(), @JsonProperty("predictedOccupancy") @ExcludeMissing private val predictedOccupancy: JsonField = JsonMissing.of(), - @JsonProperty("routeId") - @ExcludeMissing - private val routeId: JsonField = JsonMissing.of(), @JsonProperty("routeLongName") @ExcludeMissing private val routeLongName: JsonField = JsonMissing.of(), @@ -313,56 +349,25 @@ private constructor( @JsonProperty("scheduledArrivalInterval") @ExcludeMissing private val scheduledArrivalInterval: JsonField = JsonMissing.of(), - @JsonProperty("scheduledArrivalTime") - @ExcludeMissing - private val scheduledArrivalTime: JsonField = JsonMissing.of(), @JsonProperty("scheduledDepartureInterval") @ExcludeMissing private val scheduledDepartureInterval: JsonField = JsonMissing.of(), - @JsonProperty("scheduledDepartureTime") - @ExcludeMissing - private val scheduledDepartureTime: JsonField = JsonMissing.of(), @JsonProperty("scheduledTrack") @ExcludeMissing private val scheduledTrack: 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("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("tripStatus") @ExcludeMissing private val tripStatus: JsonField = JsonMissing.of(), - @JsonProperty("vehicleId") - @ExcludeMissing - private val vehicleId: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - /** 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") @@ -372,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")) @@ -388,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")) @@ -408,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. @@ -455,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")) @@ -486,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 @@ -551,20 +543,7 @@ private constructor( */ @JsonProperty("numberOfStopsAway") @ExcludeMissing - fun _numberOfStopsAway() = numberOfStopsAway - - /** Current occupancy status of the transit vehicle. */ - @JsonProperty("occupancyStatus") - @ExcludeMissing - fun _occupancyStatus() = occupancyStatus - - /** Indicates if real-time arrival info is available for this trip. */ - @JsonProperty("predicted") @ExcludeMissing fun _predicted() = predicted - - /** Interval for predicted arrival time, if available. */ - @JsonProperty("predictedArrivalInterval") - @ExcludeMissing - fun _predictedArrivalInterval() = predictedArrivalInterval + fun _numberOfStopsAway(): JsonField = numberOfStopsAway /** * Predicted arrival time, in milliseconds since Unix epoch (zero if no real-time @@ -572,12 +551,7 @@ private constructor( */ @JsonProperty("predictedArrivalTime") @ExcludeMissing - fun _predictedArrivalTime() = predictedArrivalTime - - /** Interval for predicted departure time, if available. */ - @JsonProperty("predictedDepartureInterval") - @ExcludeMissing - fun _predictedDepartureInterval() = predictedDepartureInterval + fun _predictedArrivalTime(): JsonField = predictedArrivalTime /** * Predicted departure time, in milliseconds since Unix epoch (zero if no real-time @@ -585,90 +559,153 @@ private constructor( */ @JsonProperty("predictedDepartureTime") @ExcludeMissing - fun _predictedDepartureTime() = predictedDepartureTime - - /** Predicted occupancy status of the transit vehicle. */ - @JsonProperty("predictedOccupancy") - @ExcludeMissing - fun _predictedOccupancy() = predictedOccupancy + fun _predictedDepartureTime(): JsonField = predictedDepartureTime /** The ID of the route for the arriving vehicle. */ - @JsonProperty("routeId") @ExcludeMissing fun _routeId() = routeId - - /** - * Optional route long name that potentially overrides the route long name in the - * referenced route element. - */ - @JsonProperty("routeLongName") @ExcludeMissing fun _routeLongName() = routeLongName - - /** - * Optional route short name that potentially overrides the route short name in the - * referenced route element. - */ - @JsonProperty("routeShortName") @ExcludeMissing fun _routeShortName() = routeShortName - - /** Interval for scheduled arrival time. */ - @JsonProperty("scheduledArrivalInterval") - @ExcludeMissing - fun _scheduledArrivalInterval() = scheduledArrivalInterval + @JsonProperty("routeId") @ExcludeMissing fun _routeId(): JsonField = routeId /** Scheduled arrival time, in milliseconds since Unix epoch. */ @JsonProperty("scheduledArrivalTime") @ExcludeMissing - fun _scheduledArrivalTime() = scheduledArrivalTime - - /** Interval for scheduled departure time. */ - @JsonProperty("scheduledDepartureInterval") - @ExcludeMissing - fun _scheduledDepartureInterval() = scheduledDepartureInterval + fun _scheduledArrivalTime(): JsonField = scheduledArrivalTime /** Scheduled departure time, in milliseconds since Unix epoch. */ @JsonProperty("scheduledDepartureTime") @ExcludeMissing - fun _scheduledDepartureTime() = scheduledDepartureTime - - /** Scheduled track information of the arriving transit vehicle. */ - @JsonProperty("scheduledTrack") @ExcludeMissing fun _scheduledTrack() = scheduledTrack + fun _scheduledDepartureTime(): JsonField = scheduledDepartureTime /** * 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 arrival. */ - @JsonProperty("situationIds") @ExcludeMissing fun _situationIds() = situationIds - - /** Current status of the arrival. */ - @JsonProperty("status") @ExcludeMissing fun _status() = status + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate /** The ID of the stop the vehicle is arriving at. */ - @JsonProperty("stopId") @ExcludeMissing fun _stopId() = stopId + @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() = stopSequence + @JsonProperty("stopSequence") + @ExcludeMissing + fun _stopSequence(): JsonField = stopSequence /** Total number of stops visited on the trip for this arrival. */ @JsonProperty("totalStopsInTrip") @ExcludeMissing - fun _totalStopsInTrip() = totalStopsInTrip + fun _totalStopsInTrip(): JsonField = totalStopsInTrip /** * Optional trip headsign that potentially overrides the trip headsign in the referenced * trip element. */ - @JsonProperty("tripHeadsign") @ExcludeMissing fun _tripHeadsign() = tripHeadsign + @JsonProperty("tripHeadsign") + @ExcludeMissing + fun _tripHeadsign(): JsonField = tripHeadsign /** The ID of the trip for the arriving vehicle. */ - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId - - /** Trip-specific status for the arriving transit vehicle. */ - @JsonProperty("tripStatus") @ExcludeMissing fun _tripStatus() = tripStatus + @JsonProperty("tripId") @ExcludeMissing fun _tripId(): JsonField = tripId /** ID of the transit vehicle serving this trip. */ - @JsonProperty("vehicleId") @ExcludeMissing fun _vehicleId() = vehicleId + @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 _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(): JsonField = predictedOccupancy + + /** + * Optional route long name that potentially overrides the route long name in the + * referenced route element. + */ + @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(): JsonField = routeShortName + + /** Interval for scheduled arrival time. */ + @JsonProperty("scheduledArrivalInterval") + @ExcludeMissing + fun _scheduledArrivalInterval(): JsonField = scheduledArrivalInterval + + /** Interval for scheduled departure time. */ + @JsonProperty("scheduledDepartureInterval") + @ExcludeMissing + fun _scheduledDepartureInterval(): JsonField = scheduledDepartureInterval + + /** Scheduled track information of the arriving transit vehicle. */ + @JsonProperty("scheduledTrack") + @ExcludeMissing + fun _scheduledTrack(): JsonField = scheduledTrack + + /** References to situation elements (if any) applicable to this arrival. */ + @JsonProperty("situationIds") + @ExcludeMissing + fun _situationIds(): JsonField> = situationIds + + /** 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(): JsonField = tripStatus @JsonAnyGetter @ExcludeMissing @@ -677,43 +714,45 @@ private constructor( 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) @@ -723,91 +762,84 @@ 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 { - actualTrack = entry.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 - numberOfStopsAway = entry.numberOfStopsAway occupancyStatus = entry.occupancyStatus predicted = entry.predicted predictedArrivalInterval = entry.predictedArrivalInterval - predictedArrivalTime = entry.predictedArrivalTime predictedDepartureInterval = entry.predictedDepartureInterval - predictedDepartureTime = entry.predictedDepartureTime predictedOccupancy = entry.predictedOccupancy - routeId = entry.routeId routeLongName = entry.routeLongName routeShortName = entry.routeShortName scheduledArrivalInterval = entry.scheduledArrivalInterval - scheduledArrivalTime = entry.scheduledArrivalTime scheduledDepartureInterval = entry.scheduledDepartureInterval - scheduledDepartureTime = entry.scheduledDepartureTime scheduledTrack = entry.scheduledTrack - serviceDate = entry.serviceDate - situationIds = entry.situationIds + situationIds = entry.situationIds.map { it.toMutableList() } status = entry.status - stopId = entry.stopId - stopSequence = entry.stopSequence - totalStopsInTrip = entry.totalStopsInTrip - tripHeadsign = entry.tripHeadsign - tripId = entry.tripId tripStatus = entry.tripStatus - vehicleId = entry.vehicleId additionalProperties = entry.additionalProperties.toMutableMap() } - /** 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 - } - /** Indicates if riders can arrive on this transit vehicle. */ fun arrivalEnabled(arrivalEnabled: Boolean) = arrivalEnabled(JsonField.of(arrivalEnabled)) @@ -835,6 +867,152 @@ private constructor( 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)) @@ -868,21 +1046,6 @@ private constructor( 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). - */ - fun numberOfStopsAway(numberOfStopsAway: JsonField) = apply { - this.numberOfStopsAway = numberOfStopsAway - } - /** Current occupancy status of the transit vehicle. */ fun occupancyStatus(occupancyStatus: String) = occupancyStatus(JsonField.of(occupancyStatus)) @@ -907,21 +1070,6 @@ private constructor( 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). - */ - fun predictedArrivalTime(predictedArrivalTime: JsonField) = apply { - this.predictedArrivalTime = predictedArrivalTime - } - /** Interval for predicted departure time, if available. */ fun predictedDepartureInterval(predictedDepartureInterval: String) = predictedDepartureInterval(JsonField.of(predictedDepartureInterval)) @@ -932,21 +1080,6 @@ private constructor( 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). - */ - fun predictedDepartureTime(predictedDepartureTime: JsonField) = apply { - this.predictedDepartureTime = predictedDepartureTime - } - /** Predicted occupancy status of the transit vehicle. */ fun predictedOccupancy(predictedOccupancy: String) = predictedOccupancy(JsonField.of(predictedOccupancy)) @@ -956,12 +1089,6 @@ private constructor( 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: JsonField) = apply { this.routeId = routeId } - /** * Optional route long name that potentially overrides the route long name in the * referenced route element. @@ -1001,15 +1128,6 @@ private constructor( 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. */ - fun scheduledArrivalTime(scheduledArrivalTime: JsonField) = apply { - this.scheduledArrivalTime = scheduledArrivalTime - } - /** Interval for scheduled departure time. */ fun scheduledDepartureInterval(scheduledDepartureInterval: String) = scheduledDepartureInterval(JsonField.of(scheduledDepartureInterval)) @@ -1020,15 +1138,6 @@ private constructor( 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. */ - fun scheduledDepartureTime(scheduledDepartureTime: JsonField) = apply { - this.scheduledDepartureTime = scheduledDepartureTime - } - /** Scheduled track information of the arriving transit vehicle. */ fun scheduledTrack(scheduledTrack: String) = scheduledTrack(JsonField.of(scheduledTrack)) @@ -1038,27 +1147,27 @@ private constructor( 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. - */ - 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. */ 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. */ @@ -1067,69 +1176,14 @@ private constructor( /** Current status of the arrival. */ 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. */ - 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 } - /** 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 - } - - /** 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 } - + /** Trip-specific status for the arriving transit vehicle. */ + fun tripStatus(tripStatus: JsonField) = apply { + this.tripStatus = tripStatus + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -1154,40 +1208,40 @@ private constructor( 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(), ) } @@ -1206,36 +1260,18 @@ private constructor( @JsonProperty("closestStop") @ExcludeMissing private val closestStop: JsonField = JsonMissing.of(), - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing - private val closestStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("distanceAlongTrip") @ExcludeMissing private val distanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("frequency") - @ExcludeMissing - private val frequency: JsonField = JsonMissing.of(), @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownLocation") - @ExcludeMissing - private val lastKnownLocation: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - private val lastKnownOrientation: JsonField = JsonMissing.of(), @JsonProperty("lastLocationUpdateTime") @ExcludeMissing private val lastLocationUpdateTime: JsonField = JsonMissing.of(), @JsonProperty("lastUpdateTime") @ExcludeMissing private val lastUpdateTime: JsonField = JsonMissing.of(), - @JsonProperty("nextStop") - @ExcludeMissing - private val nextStop: JsonField = JsonMissing.of(), - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - private val nextStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("occupancyCapacity") @ExcludeMissing private val occupancyCapacity: JsonField = JsonMissing.of(), @@ -1245,36 +1281,54 @@ private constructor( @JsonProperty("occupancyStatus") @ExcludeMissing private val occupancyStatus: JsonField = JsonMissing.of(), - @JsonProperty("orientation") - @ExcludeMissing - private val orientation: JsonField = JsonMissing.of(), @JsonProperty("phase") @ExcludeMissing private val phase: JsonField = JsonMissing.of(), - @JsonProperty("position") - @ExcludeMissing - private val position: JsonField = JsonMissing.of(), @JsonProperty("predicted") @ExcludeMissing private val predicted: JsonField = JsonMissing.of(), @JsonProperty("scheduleDeviation") @ExcludeMissing private val scheduleDeviation: JsonField = JsonMissing.of(), - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - private val scheduledDistanceAlongTrip: 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("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), @JsonProperty("vehicleId") @ExcludeMissing private val vehicleId: JsonField = JsonMissing.of(), @@ -1291,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. @@ -1314,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. */ @@ -1331,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") @@ -1351,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") @@ -1370,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") @@ -1396,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 @@ -1435,102 +1482,129 @@ 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 + fun _scheduleDeviation(): JsonField = scheduleDeviation /** - * Distance, in meters, the transit vehicle is scheduled to have progressed along - * the active trip. + * Time, in milliseconds since the Unix epoch, of midnight for the start of the + * service date for the trip. */ - @JsonProperty("scheduledDistanceAlongTrip") + @JsonProperty("serviceDate") + @ExcludeMissing + fun _serviceDate(): JsonField = serviceDate + + /** Current status modifiers for the trip. */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** Total length of the trip, in meters. */ + @JsonProperty("totalDistanceAlongTrip") @ExcludeMissing - fun _scheduledDistanceAlongTrip() = scheduledDistanceAlongTrip + fun _totalDistanceAlongTrip(): JsonField = totalDistanceAlongTrip /** - * Time, in milliseconds since the Unix epoch, of midnight for the start of the - * service date for the trip. + * 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("serviceDate") @ExcludeMissing fun _serviceDate() = serviceDate + @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() = situationIds - - /** Current status modifiers for the trip. */ - @JsonProperty("status") @ExcludeMissing fun _status() = status - - /** Total length of the trip, in meters. */ - @JsonProperty("totalDistanceAlongTrip") + @JsonProperty("situationIds") @ExcludeMissing - fun _totalDistanceAlongTrip() = totalDistanceAlongTrip + 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 @@ -1539,36 +1613,38 @@ private constructor( 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) @@ -1578,34 +1654,35 @@ 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() @@ -1614,29 +1691,29 @@ private constructor( activeTripId = tripStatus.activeTripId blockTripSequence = tripStatus.blockTripSequence closestStop = tripStatus.closestStop - closestStopTimeOffset = tripStatus.closestStopTimeOffset distanceAlongTrip = tripStatus.distanceAlongTrip - frequency = tripStatus.frequency lastKnownDistanceAlongTrip = tripStatus.lastKnownDistanceAlongTrip - lastKnownLocation = tripStatus.lastKnownLocation - lastKnownOrientation = tripStatus.lastKnownOrientation lastLocationUpdateTime = tripStatus.lastLocationUpdateTime lastUpdateTime = tripStatus.lastUpdateTime - nextStop = tripStatus.nextStop - nextStopTimeOffset = tripStatus.nextStopTimeOffset occupancyCapacity = tripStatus.occupancyCapacity occupancyCount = tripStatus.occupancyCount occupancyStatus = tripStatus.occupancyStatus - orientation = tripStatus.orientation phase = tripStatus.phase - position = tripStatus.position predicted = tripStatus.predicted scheduleDeviation = tripStatus.scheduleDeviation - scheduledDistanceAlongTrip = tripStatus.scheduledDistanceAlongTrip serviceDate = tripStatus.serviceDate - situationIds = tripStatus.situationIds 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() } @@ -1667,21 +1744,6 @@ private constructor( 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). - */ - fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { - this.closestStopTimeOffset = closestStopTimeOffset - } - /** * Distance, in meters, the transit vehicle has progressed along the active * trip. @@ -1697,14 +1759,6 @@ private constructor( 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. */ - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1721,28 +1775,6 @@ private constructor( 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. */ - 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 - } - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1767,27 +1799,6 @@ private constructor( 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. */ - 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 - } - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) @@ -1815,26 +1826,12 @@ private constructor( 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. */ - 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. */ 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. */ - 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)) @@ -1858,22 +1855,6 @@ private constructor( 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. - */ - 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. @@ -1888,15 +1869,6 @@ private constructor( 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. */ - fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds - } - /** Current status modifiers for the trip. */ fun status(status: String) = status(JsonField.of(status)) @@ -1912,6 +1884,125 @@ private constructor( 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)) @@ -1944,32 +2035,32 @@ private constructor( 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(), ) @@ -1997,10 +2088,10 @@ 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 @@ -2009,11 +2100,13 @@ private constructor( 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) @@ -2023,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() @@ -2120,10 +2214,10 @@ 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 @@ -2132,11 +2226,13 @@ private constructor( 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) @@ -2146,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() @@ -2225,17 +2322,17 @@ private constructor( return true } - return /* spotless:off */ other is TripStatus && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && closestStopTimeOffset == other.closestStopTimeOffset && distanceAlongTrip == other.distanceAlongTrip && frequency == other.frequency && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && orientation == other.orientation && phase == other.phase && position == other.position && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && serviceDate == other.serviceDate && situationIds == other.situationIds && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && vehicleId == other.vehicleId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { 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) } + 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 = 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 { @@ -2243,17 +2340,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && actualTrack == other.actualTrack && arrivalEnabled == other.arrivalEnabled && blockTripSequence == other.blockTripSequence && departureEnabled == other.departureEnabled && distanceFromStop == other.distanceFromStop && frequency == other.frequency && historicalOccupancy == other.historicalOccupancy && lastUpdateTime == other.lastUpdateTime && numberOfStopsAway == other.numberOfStopsAway && occupancyStatus == other.occupancyStatus && predicted == other.predicted && predictedArrivalInterval == other.predictedArrivalInterval && predictedArrivalTime == other.predictedArrivalTime && predictedDepartureInterval == other.predictedDepartureInterval && predictedDepartureTime == other.predictedDepartureTime && predictedOccupancy == other.predictedOccupancy && routeId == other.routeId && routeLongName == other.routeLongName && routeShortName == other.routeShortName && scheduledArrivalInterval == other.scheduledArrivalInterval && scheduledArrivalTime == other.scheduledArrivalTime && scheduledDepartureInterval == other.scheduledDepartureInterval && scheduledDepartureTime == other.scheduledDepartureTime && scheduledTrack == other.scheduledTrack && serviceDate == other.serviceDate && situationIds == other.situationIds && status == other.status && stopId == other.stopId && stopSequence == other.stopSequence && totalStopsInTrip == other.totalStopsInTrip && tripHeadsign == other.tripHeadsign && tripId == other.tripId && tripStatus == other.tripStatus && vehicleId == other.vehicleId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { 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) } + 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 = 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 { 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 ab76562..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 @@ -4,15 +4,18 @@ package org.onebusaway.models import java.util.Objects import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun blockId(): String = blockId @@ -20,9 +23,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -38,8 +41,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [BlockRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var blockId: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() @@ -154,7 +158,7 @@ constructor( fun build(): BlockRetrieveParams = BlockRetrieveParams( - checkNotNull(blockId) { "`blockId` is required but was not set" }, + checkRequired("blockId", blockId), additionalHeaders.build(), additionalQueryParams.build(), ) 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 cbeff5f..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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -171,9 +175,11 @@ private constructor( 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 @@ -182,11 +188,13 @@ private constructor( 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) @@ -196,10 +204,11 @@ 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 @@ -240,8 +249,8 @@ private constructor( fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -264,9 +273,11 @@ private constructor( 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 @@ -275,11 +286,13 @@ private constructor( 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) @@ -289,16 +302,17 @@ 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 { id = entry.id - configurations = entry.configurations + configurations = entry.configurations.map { it.toMutableList() } additionalProperties = entry.additionalProperties.toMutableMap() } @@ -310,7 +324,20 @@ private constructor( configurations(JsonField.of(configurations)) 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 { @@ -337,8 +364,8 @@ private constructor( fun build(): Entry = Entry( - id, - configurations.map { it.toImmutable() }, + checkRequired("id", id), + checkRequired("configurations", configurations).map { it.toImmutable() }, additionalProperties.toImmutable(), ) } @@ -350,12 +377,12 @@ private constructor( @JsonProperty("activeServiceIds") @ExcludeMissing private val activeServiceIds: JsonField> = JsonMissing.of(), - @JsonProperty("inactiveServiceIds") - @ExcludeMissing - private val inactiveServiceIds: 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(), ) { @@ -363,20 +390,20 @@ private constructor( 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 @@ -385,12 +412,14 @@ private constructor( 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) @@ -400,18 +429,20 @@ 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 { - activeServiceIds = configuration.activeServiceIds - inactiveServiceIds = configuration.inactiveServiceIds - trips = configuration.trips + activeServiceIds = configuration.activeServiceIds.map { it.toMutableList() } + trips = configuration.trips.map { it.toMutableList() } + inactiveServiceIds = + configuration.inactiveServiceIds.map { it.toMutableList() } additionalProperties = configuration.additionalProperties.toMutableMap() } @@ -419,19 +450,60 @@ private constructor( activeServiceIds(JsonField.of(activeServiceIds)) 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)) fun inactiveServiceIds(inactiveServiceIds: JsonField>) = apply { - this.inactiveServiceIds = inactiveServiceIds + this.inactiveServiceIds = inactiveServiceIds.map { it.toMutableList() } } - fun trips(trips: List) = trips(JsonField.of(trips)) - - 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() @@ -457,9 +529,11 @@ private constructor( 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(), ) } @@ -468,46 +542,48 @@ private constructor( class Trip @JsonCreator private constructor( - @JsonProperty("tripId") - @ExcludeMissing - private val tripId: JsonField = JsonMissing.of(), - @JsonProperty("distanceAlongBlock") - @ExcludeMissing - private val distanceAlongBlock: JsonField = JsonMissing.of(), @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(), ) { - 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 @@ -516,13 +592,15 @@ private constructor( 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) @@ -532,36 +610,25 @@ 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 { - tripId = trip.tripId - distanceAlongBlock = trip.distanceAlongBlock accumulatedSlackTime = trip.accumulatedSlackTime - blockStopTimes = trip.blockStopTimes + blockStopTimes = trip.blockStopTimes.map { it.toMutableList() } + distanceAlongBlock = trip.distanceAlongBlock + tripId = trip.tripId additionalProperties = trip.additionalProperties.toMutableMap() } - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - - fun distanceAlongBlock(distanceAlongBlock: Double) = - distanceAlongBlock(JsonField.of(distanceAlongBlock)) - - fun distanceAlongBlock(distanceAlongBlock: JsonField) = apply { - this.distanceAlongBlock = distanceAlongBlock - } - fun accumulatedSlackTime(accumulatedSlackTime: Double) = accumulatedSlackTime(JsonField.of(accumulatedSlackTime)) @@ -573,9 +640,33 @@ private constructor( blockStopTimes(JsonField.of(blockStopTimes)) 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() @@ -600,10 +691,12 @@ private constructor( 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(), ) } @@ -612,15 +705,15 @@ private constructor( class BlockStopTime @JsonCreator private constructor( + @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("accumulatedSlackTime") - @ExcludeMissing - private val accumulatedSlackTime: JsonField = JsonMissing.of(), @JsonProperty("stopTime") @ExcludeMissing private val stopTime: JsonField = JsonMissing.of(), @@ -629,29 +722,31 @@ private constructor( immutableEmptyMap(), ) { + 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 @@ -660,13 +755,15 @@ private constructor( 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) @@ -676,25 +773,34 @@ 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 { + accumulatedSlackTime = blockStopTime.accumulatedSlackTime blockSequence = blockStopTime.blockSequence distanceAlongBlock = blockStopTime.distanceAlongBlock - accumulatedSlackTime = blockStopTime.accumulatedSlackTime 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)) @@ -709,14 +815,6 @@ private constructor( this.distanceAlongBlock = distanceAlongBlock } - fun accumulatedSlackTime(accumulatedSlackTime: Double) = - accumulatedSlackTime(JsonField.of(accumulatedSlackTime)) - - fun accumulatedSlackTime(accumulatedSlackTime: JsonField) = - apply { - this.accumulatedSlackTime = accumulatedSlackTime - } - fun stopTime(stopTime: StopTime) = stopTime(JsonField.of(stopTime)) fun stopTime(stopTime: JsonField) = apply { @@ -747,10 +845,10 @@ private constructor( fun build(): BlockStopTime = BlockStopTime( - blockSequence, - distanceAlongBlock, - accumulatedSlackTime, - stopTime, + checkRequired("accumulatedSlackTime", accumulatedSlackTime), + checkRequired("blockSequence", blockSequence), + checkRequired("distanceAlongBlock", distanceAlongBlock), + checkRequired("stopTime", stopTime), additionalProperties.toImmutable(), ) } @@ -759,55 +857,57 @@ private constructor( class StopTime @JsonCreator private constructor( - @JsonProperty("stopId") - @ExcludeMissing - private val stopId: JsonField = JsonMissing.of(), @JsonProperty("arrivalTime") @ExcludeMissing private val arrivalTime: JsonField = JsonMissing.of(), @JsonProperty("departureTime") @ExcludeMissing private val departureTime: JsonField = JsonMissing.of(), - @JsonProperty("pickupType") + @JsonProperty("stopId") @ExcludeMissing - private val pickupType: JsonField = JsonMissing.of(), + 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(), ) { - 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 @@ -817,14 +917,16 @@ private constructor( 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) @@ -834,33 +936,28 @@ 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 { - stopId = stopTime.stopId arrivalTime = stopTime.arrivalTime departureTime = stopTime.departureTime - pickupType = stopTime.pickupType + stopId = stopTime.stopId dropOffType = stopTime.dropOffType + pickupType = stopTime.pickupType additionalProperties = stopTime.additionalProperties.toMutableMap() } - fun stopId(stopId: String) = stopId(JsonField.of(stopId)) - - fun stopId(stopId: JsonField) = apply { - this.stopId = stopId - } - fun arrivalTime(arrivalTime: Long) = arrivalTime(JsonField.of(arrivalTime)) @@ -875,11 +972,10 @@ private constructor( this.departureTime = departureTime } - fun pickupType(pickupType: Long) = - pickupType(JsonField.of(pickupType)) + fun stopId(stopId: String) = stopId(JsonField.of(stopId)) - fun pickupType(pickupType: JsonField) = apply { - this.pickupType = pickupType + fun stopId(stopId: JsonField) = apply { + this.stopId = stopId } fun dropOffType(dropOffType: Long) = @@ -889,6 +985,13 @@ private constructor( this.dropOffType = dropOffType } + fun pickupType(pickupType: Long) = + pickupType(JsonField.of(pickupType)) + + fun pickupType(pickupType: JsonField) = apply { + this.pickupType = pickupType + } + fun additionalProperties( additionalProperties: Map ) = apply { @@ -914,11 +1017,11 @@ private constructor( fun build(): StopTime = StopTime( - stopId, - arrivalTime, - departureTime, - pickupType, + checkRequired("arrivalTime", arrivalTime), + checkRequired("departureTime", departureTime), + checkRequired("stopId", stopId), dropOffType, + pickupType, additionalProperties.toImmutable(), ) } @@ -928,17 +1031,17 @@ private constructor( return true } - return /* spotless:off */ other is StopTime && stopId == other.stopId && arrivalTime == other.arrivalTime && departureTime == other.departureTime && pickupType == other.pickupType && dropOffType == other.dropOffType && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(stopId, arrivalTime, departureTime, pickupType, dropOffType, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(arrivalTime, departureTime, stopId, dropOffType, pickupType, additionalProperties) } /* spotless:on */ 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 { @@ -946,17 +1049,17 @@ private constructor( return true } - return /* spotless:off */ other is BlockStopTime && blockSequence == other.blockSequence && distanceAlongBlock == other.distanceAlongBlock && accumulatedSlackTime == other.accumulatedSlackTime && stopTime == other.stopTime && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(blockSequence, distanceAlongBlock, accumulatedSlackTime, stopTime, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(accumulatedSlackTime, blockSequence, distanceAlongBlock, stopTime, additionalProperties) } /* spotless:on */ 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 { @@ -964,17 +1067,17 @@ private constructor( return true } - return /* spotless:off */ other is Trip && tripId == other.tripId && distanceAlongBlock == other.distanceAlongBlock && accumulatedSlackTime == other.accumulatedSlackTime && blockStopTimes == other.blockStopTimes && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(tripId, distanceAlongBlock, accumulatedSlackTime, blockStopTimes, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(accumulatedSlackTime, blockStopTimes, distanceAlongBlock, tripId, additionalProperties) } /* spotless:on */ 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 { @@ -982,17 +1085,17 @@ private constructor( return true } - return /* spotless:off */ other is Configuration && activeServiceIds == other.activeServiceIds && inactiveServiceIds == other.inactiveServiceIds && trips == other.trips && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(activeServiceIds, inactiveServiceIds, trips, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(activeServiceIds, trips, inactiveServiceIds, additionalProperties) } /* spotless:on */ 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 { 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 7c58fdd..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 @@ -4,22 +4,24 @@ package org.onebusaway.models import java.util.Objects import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.Params import org.onebusaway.core.http.Headers import org.onebusaway.core.http.QueryParams +/** config */ class ConfigRetrieveParams -constructor( +private constructor( private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -28,8 +30,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [ConfigRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() 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 c103b8d..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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -171,9 +175,11 @@ private constructor( 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 @@ -182,11 +188,13 @@ private constructor( 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) @@ -196,10 +204,11 @@ 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 @@ -240,8 +249,8 @@ private constructor( fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -250,12 +259,12 @@ private constructor( class Entry @JsonCreator private constructor( - @JsonProperty("gitProperties") - @ExcludeMissing - private val gitProperties: JsonField = JsonMissing.of(), @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(), @@ -269,11 +278,11 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { + 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 = @@ -282,17 +291,21 @@ 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 @@ -301,14 +314,16 @@ private constructor( 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) @@ -318,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() @@ -329,14 +345,18 @@ private constructor( @JvmSynthetic internal fun from(entry: Entry) = apply { - gitProperties = entry.gitProperties 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)) @@ -344,10 +364,6 @@ private constructor( this.gitProperties = gitProperties } - 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 } @@ -390,8 +406,8 @@ private constructor( fun build(): Entry = Entry( - gitProperties, id, + gitProperties, name, serviceDateFrom, serviceDateTo, @@ -533,73 +549,85 @@ 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 @@ -608,29 +636,31 @@ private constructor( 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) @@ -640,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() @@ -894,17 +925,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && gitProperties == other.gitProperties && id == other.id && name == other.name && serviceDateFrom == other.serviceDateFrom && serviceDateTo == other.serviceDateTo && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(gitProperties, id, name, serviceDateFrom, serviceDateTo, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(id, gitProperties, name, serviceDateFrom, serviceDateTo, additionalProperties) } /* spotless:on */ 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 { 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 b296308..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 @@ -4,22 +4,24 @@ package org.onebusaway.models import java.util.Objects import org.onebusaway.core.NoAutoDetect +import org.onebusaway.core.Params import org.onebusaway.core.http.Headers import org.onebusaway.core.http.QueryParams +/** current-time */ class CurrentTimeRetrieveParams -constructor( +private constructor( private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun _additionalHeaders(): Headers = additionalHeaders fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = additionalQueryParams fun toBuilder() = Builder().from(this) @@ -28,8 +30,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [CurrentTimeRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() 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 cd1538b..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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -171,9 +175,11 @@ private constructor( 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 @@ -182,11 +188,13 @@ private constructor( 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) @@ -196,10 +204,11 @@ 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 @@ -240,8 +249,8 @@ private constructor( fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -265,9 +274,11 @@ private constructor( 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 @@ -276,11 +287,13 @@ private constructor( 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) @@ -290,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() 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 5bd60d2..3f3b947 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 @@ -14,6 +14,7 @@ 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 @@ -31,12 +32,12 @@ private constructor( @JsonProperty("situations") @ExcludeMissing private val situations: JsonField> = JsonMissing.of(), - @JsonProperty("stopTimes") - @ExcludeMissing - private val stopTimes: 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(), @@ -49,23 +50,27 @@ private constructor( 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 @@ -74,15 +79,17 @@ private constructor( 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) @@ -92,52 +99,141 @@ 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 { - agencies = references.agencies - routes = references.routes - situations = references.situations - stopTimes = references.stopTimes - stops = references.stops - trips = references.trips + 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)) - 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)) - 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)) fun situations(situations: JsonField>) = apply { - this.situations = situations + this.situations = situations.map { it.toMutableList() } } - fun stopTimes(stopTimes: List) = stopTimes(JsonField.of(stopTimes)) - - 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)) - 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)) - 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() @@ -160,12 +256,12 @@ private constructor( 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(), ) } @@ -174,6 +270,14 @@ private constructor( class Agency @JsonCreator private constructor( + @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(), @@ -183,27 +287,27 @@ private constructor( @JsonProperty("fareUrl") @ExcludeMissing private val fareUrl: JsonField = JsonMissing.of(), - @JsonProperty("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), @JsonProperty("lang") @ExcludeMissing private val lang: JsonField = JsonMissing.of(), - @JsonProperty("name") - @ExcludeMissing - private val name: JsonField = JsonMissing.of(), @JsonProperty("phone") @ExcludeMissing private val phone: JsonField = JsonMissing.of(), @JsonProperty("privateService") @ExcludeMissing private val privateService: JsonField = JsonMissing.of(), - @JsonProperty("timezone") - @ExcludeMissing - private val timezone: JsonField = JsonMissing.of(), - @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { + 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")) @@ -211,40 +315,36 @@ 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 @@ -253,19 +353,21 @@ private constructor( 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) @@ -275,35 +377,52 @@ 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 { + id = agency.id + name = agency.name + timezone = agency.timezone + url = agency.url disclaimer = agency.disclaimer email = agency.email fareUrl = agency.fareUrl - id = agency.id lang = agency.lang - name = agency.name phone = agency.phone privateService = agency.privateService - timezone = agency.timezone - url = agency.url 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)) fun disclaimer(disclaimer: JsonField) = apply { this.disclaimer = disclaimer } @@ -316,18 +435,10 @@ private constructor( fun fareUrl(fareUrl: JsonField) = apply { this.fareUrl = fareUrl } - fun id(id: String) = id(JsonField.of(id)) - - fun id(id: JsonField) = apply { this.id = id } - fun lang(lang: String) = lang(JsonField.of(lang)) fun lang(lang: JsonField) = apply { this.lang = lang } - fun name(name: String) = name(JsonField.of(name)) - - fun name(name: JsonField) = apply { this.name = name } - fun phone(phone: String) = phone(JsonField.of(phone)) fun phone(phone: JsonField) = apply { this.phone = phone } @@ -339,14 +450,6 @@ private constructor( this.privateService = privateService } - 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 additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -368,16 +471,16 @@ private constructor( 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(), ) } @@ -387,33 +490,34 @@ private constructor( return true } - return /* spotless:off */ other is Agency && disclaimer == other.disclaimer && email == other.email && fareUrl == other.fareUrl && id == other.id && lang == other.lang && name == other.name && phone == other.phone && privateService == other.privateService && timezone == other.timezone && url == other.url && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(disclaimer, email, fareUrl, id, lang, name, phone, privateService, timezone, url, additionalProperties) } + 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 = 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}" } @NoAutoDetect class Route @JsonCreator private constructor( + @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("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), @JsonProperty("longName") @ExcludeMissing private val longName: JsonField = JsonMissing.of(), @@ -426,21 +530,22 @@ private constructor( @JsonProperty("textColor") @ExcludeMissing private val textColor: JsonField = JsonMissing.of(), - @JsonProperty("type") @ExcludeMissing private val type: JsonField = JsonMissing.of(), @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { + 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 = @@ -450,31 +555,31 @@ 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("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 @@ -483,19 +588,21 @@ private constructor( 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) @@ -505,39 +612,48 @@ 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 { + id = route.id agencyId = route.agencyId + type = route.type color = route.color description = route.description - id = route.id longName = route.longName nullSafeShortName = route.nullSafeShortName shortName = route.shortName textColor = route.textColor - type = route.type 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)) 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)) fun color(color: JsonField) = apply { this.color = color } @@ -548,10 +664,6 @@ private constructor( this.description = description } - fun id(id: String) = id(JsonField.of(id)) - - fun id(id: JsonField) = apply { this.id = id } - fun longName(longName: String) = longName(JsonField.of(longName)) fun longName(longName: JsonField) = apply { this.longName = longName } @@ -571,10 +683,6 @@ private constructor( fun textColor(textColor: JsonField) = apply { this.textColor = textColor } - fun type(type: Long) = type(JsonField.of(type)) - - fun type(type: JsonField) = apply { this.type = type } - fun url(url: String) = url(JsonField.of(url)) fun url(url: JsonField) = apply { this.url = url } @@ -600,15 +708,15 @@ private constructor( 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(), ) @@ -619,17 +727,17 @@ private constructor( return true } - return /* spotless:off */ other is Route && agencyId == other.agencyId && color == other.color && description == other.description && id == other.id && longName == other.longName && nullSafeShortName == other.nullSafeShortName && shortName == other.shortName && textColor == other.textColor && type == other.type && url == other.url && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(agencyId, color, description, id, longName, nullSafeShortName, shortName, textColor, type, url, additionalProperties) } + 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 = 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}" } @NoAutoDetect @@ -640,34 +748,34 @@ private constructor( @JsonProperty("creationTime") @ExcludeMissing private val creationTime: JsonField = JsonMissing.of(), - @JsonProperty("reason") - @ExcludeMissing - private val reason: JsonField = JsonMissing.of(), - @JsonProperty("summary") - @ExcludeMissing - private val summary: JsonField = JsonMissing.of(), - @JsonProperty("description") - @ExcludeMissing - private val description: JsonField = JsonMissing.of(), - @JsonProperty("url") @ExcludeMissing private val url: 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("consequenceMessage") + @JsonProperty("summary") @ExcludeMissing - private val consequenceMessage: JsonField = JsonMissing.of(), + private val summary: JsonField = JsonMissing.of(), + @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { @@ -678,67 +786,77 @@ private constructor( /** 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 @@ -747,21 +865,23 @@ private constructor( 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) @@ -771,36 +891,37 @@ 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 { 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 - description = situation.description url = situation.url - activeWindows = situation.activeWindows - allAffects = situation.allAffects - consequences = situation.consequences - publicationWindows = situation.publicationWindows - severity = situation.severity - consequenceMessage = situation.consequenceMessage additionalProperties = situation.additionalProperties.toMutableMap() } @@ -818,67 +939,119 @@ private constructor( this.creationTime = creationTime } - /** Reason for the service alert, taken from TPEG codes. */ - fun reason(reason: Reason) = reason(JsonField.of(reason)) + fun activeWindows(activeWindows: List) = + activeWindows(JsonField.of(activeWindows)) - /** Reason for the service alert, taken from TPEG codes. */ - fun reason(reason: JsonField) = apply { this.reason = reason } + fun activeWindows(activeWindows: JsonField>) = apply { + this.activeWindows = activeWindows.map { it.toMutableList() } + } - fun summary(summary: Summary) = summary(JsonField.of(summary)) + 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 summary(summary: JsonField) = apply { this.summary = summary } + fun allAffects(allAffects: List) = allAffects(JsonField.of(allAffects)) - fun description(description: Description) = description(JsonField.of(description)) + fun allAffects(allAffects: JsonField>) = apply { + this.allAffects = allAffects.map { it.toMutableList() } + } - fun description(description: JsonField) = apply { - this.description = description + 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) + } } - fun url(url: Url) = url(JsonField.of(url)) + /** Message regarding the consequence of the situation. */ + fun consequenceMessage(consequenceMessage: String) = + consequenceMessage(JsonField.of(consequenceMessage)) - fun url(url: JsonField) = apply { this.url = url } + /** Message regarding the consequence of the situation. */ + fun consequenceMessage(consequenceMessage: JsonField) = apply { + this.consequenceMessage = consequenceMessage + } - fun activeWindows(activeWindows: List) = - activeWindows(JsonField.of(activeWindows)) + fun consequences(consequences: List) = + consequences(JsonField.of(consequences)) - fun activeWindows(activeWindows: JsonField>) = apply { - this.activeWindows = activeWindows + fun consequences(consequences: JsonField>) = apply { + this.consequences = consequences.map { it.toMutableList() } } - fun allAffects(allAffects: List) = allAffects(JsonField.of(allAffects)) - - fun allAffects(allAffects: JsonField>) = apply { - this.allAffects = allAffects + 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 consequences(consequences: List) = - consequences(JsonField.of(consequences)) + fun description(description: Description) = description(JsonField.of(description)) - fun consequences(consequences: JsonField>) = apply { - this.consequences = consequences + fun description(description: JsonField) = apply { + this.description = description } fun publicationWindows(publicationWindows: List) = publicationWindows(JsonField.of(publicationWindows)) 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. */ 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. */ - 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() @@ -901,18 +1074,18 @@ private constructor( 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(), ) } @@ -936,10 +1109,10 @@ 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 @@ -948,11 +1121,13 @@ private constructor( 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) @@ -962,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() @@ -1082,22 +1258,26 @@ 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 @@ -1106,15 +1286,17 @@ private constructor( 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) @@ -1124,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() @@ -1260,11 +1443,13 @@ 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 @@ -1273,11 +1458,13 @@ private constructor( 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) @@ -1287,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() @@ -1363,11 +1551,13 @@ private constructor( 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 @@ -1376,11 +1566,13 @@ private constructor( 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) @@ -1390,16 +1582,18 @@ 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 { diversionPath = conditionDetails.diversionPath - diversionStopIds = conditionDetails.diversionStopIds + diversionStopIds = + conditionDetails.diversionStopIds.map { it.toMutableList() } additionalProperties = conditionDetails.additionalProperties.toMutableMap() } @@ -1414,7 +1608,20 @@ private constructor( diversionStopIds(JsonField.of(diversionStopIds)) 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 { @@ -1442,7 +1649,7 @@ private constructor( fun build(): ConditionDetails = ConditionDetails( diversionPath, - diversionStopIds.map { it.toImmutable() }, + (diversionStopIds ?: JsonMissing.of()).map { it.toImmutable() }, additionalProperties.toImmutable(), ) } @@ -1476,13 +1683,17 @@ 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 @@ -1491,12 +1702,14 @@ private constructor( 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) @@ -1506,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() @@ -1646,10 +1860,10 @@ 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 @@ -1658,11 +1872,13 @@ private constructor( 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) @@ -1672,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() @@ -1764,10 +1981,10 @@ 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 @@ -1776,11 +1993,13 @@ private constructor( 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) @@ -1790,10 +2009,11 @@ 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 @@ -1839,8 +2059,8 @@ private constructor( fun build(): PublicationWindow = PublicationWindow( - from, - to, + checkRequired("from", from), + checkRequired("to", to), additionalProperties.toImmutable(), ) } @@ -1863,12 +2083,21 @@ private constructor( "PublicationWindow{from=$from, to=$to, additionalProperties=$additionalProperties}" } + /** Reason for the service alert, taken from TPEG codes. */ class Reason @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 companion object { @@ -1886,6 +2115,7 @@ private constructor( @JvmStatic fun of(value: String) = Reason(JsonField.of(value)) } + /** An enum containing [Reason]'s known values. */ enum class Known { EQUIPMENT_REASON, ENVIRONMENT_REASON, @@ -1894,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 @@ -1913,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 @@ -1959,10 +2217,10 @@ 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 @@ -1971,11 +2229,13 @@ private constructor( 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) @@ -1985,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() @@ -2079,10 +2340,10 @@ 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 @@ -2091,11 +2352,13 @@ private constructor( 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) @@ -2105,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() @@ -2183,34 +2447,25 @@ private constructor( return true } - return /* spotless:off */ other is Situation && id == other.id && creationTime == other.creationTime && reason == other.reason && summary == other.summary && description == other.description && url == other.url && activeWindows == other.activeWindows && allAffects == other.allAffects && consequences == other.consequences && publicationWindows == other.publicationWindows && severity == other.severity && consequenceMessage == other.consequenceMessage && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(id, creationTime, reason, summary, description, url, activeWindows, allAffects, consequences, publicationWindows, severity, consequenceMessage, additionalProperties) } + 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 = 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}" } @NoAutoDetect class Stop @JsonCreator private constructor( - @JsonProperty("code") - @ExcludeMissing - private val code: JsonField = JsonMissing.of(), - @JsonProperty("direction") - @ExcludeMissing - private val direction: JsonField = JsonMissing.of(), @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 @@ -2224,6 +2479,15 @@ private constructor( @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("locationType") + @ExcludeMissing + private val locationType: JsonField = JsonMissing.of(), @JsonProperty("wheelchairBoarding") @ExcludeMissing private val wheelchairBoarding: JsonField = JsonMissing.of(), @@ -2231,17 +2495,10 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { - 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 lon(): Double = lon.getRequired("lon") fun name(): String = name.getRequired("name") @@ -2252,32 +2509,45 @@ 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 locationType(): Optional = + Optional.ofNullable(locationType.getNullable("locationType")) + 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("lon") @ExcludeMissing fun _lon(): JsonField = lon - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("locationType") @ExcludeMissing fun _locationType() = locationType + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("routeIds") + @ExcludeMissing + fun _routeIds(): JsonField> = routeIds - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("staticRouteIds") + @ExcludeMissing + fun _staticRouteIds(): JsonField> = staticRouteIds - @JsonProperty("parent") @ExcludeMissing fun _parent() = parent + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("routeIds") @ExcludeMissing fun _routeIds() = routeIds + @JsonProperty("direction") @ExcludeMissing fun _direction(): JsonField = direction - @JsonProperty("staticRouteIds") @ExcludeMissing fun _staticRouteIds() = staticRouteIds + @JsonProperty("locationType") + @ExcludeMissing + fun _locationType(): JsonField = locationType @JsonProperty("wheelchairBoarding") @ExcludeMissing - fun _wheelchairBoarding() = wheelchairBoarding + fun _wheelchairBoarding(): JsonField = wheelchairBoarding @JsonAnyGetter @ExcludeMissing @@ -2286,20 +2556,22 @@ private constructor( 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() + lon() + name() + parent() + routeIds() + staticRouteIds() + code() + direction() + locationType() + wheelchairBoarding() + validated = true } fun toBuilder() = Builder().from(this) @@ -2309,45 +2581,38 @@ 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 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 { - code = stop.code - direction = stop.direction id = stop.id lat = stop.lat - locationType = stop.locationType lon = stop.lon name = stop.name parent = stop.parent - routeIds = stop.routeIds - staticRouteIds = stop.staticRouteIds + routeIds = stop.routeIds.map { it.toMutableList() } + staticRouteIds = stop.staticRouteIds.map { it.toMutableList() } + code = stop.code + direction = stop.direction + locationType = stop.locationType wheelchairBoarding = stop.wheelchairBoarding additionalProperties = stop.additionalProperties.toMutableMap() } - 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 id(id: String) = id(JsonField.of(id)) fun id(id: JsonField) = apply { this.id = id } @@ -2356,12 +2621,6 @@ private constructor( fun lat(lat: JsonField) = apply { this.lat = lat } - fun locationType(locationType: Long) = locationType(JsonField.of(locationType)) - - fun locationType(locationType: JsonField) = apply { - this.locationType = locationType - } - fun lon(lon: Double) = lon(JsonField.of(lon)) fun lon(lon: JsonField) = apply { this.lon = lon } @@ -2376,13 +2635,55 @@ private constructor( fun routeIds(routeIds: List) = routeIds(JsonField.of(routeIds)) - 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)) 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 locationType(locationType: Long) = locationType(JsonField.of(locationType)) + + fun locationType(locationType: JsonField) = apply { + this.locationType = locationType } fun wheelchairBoarding(wheelchairBoarding: String) = @@ -2413,16 +2714,16 @@ private constructor( fun build(): Stop = Stop( + checkRequired("id", id), + checkRequired("lat", lat), + 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(), ) @@ -2433,17 +2734,17 @@ private constructor( return true } - return /* spotless:off */ other is Stop && code == other.code && direction == other.direction && id == other.id && lat == other.lat && locationType == other.locationType && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Stop && id == other.id && lat == other.lat && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && code == other.code && direction == other.direction && locationType == other.locationType && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(code, direction, id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, wheelchairBoarding, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(id, lat, lon, name, parent, routeIds, staticRouteIds, code, direction, locationType, wheelchairBoarding, additionalProperties) } /* spotless:on */ 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, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, code=$code, direction=$direction, locationType=$locationType, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" } @NoAutoDetect @@ -2489,21 +2790,27 @@ 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 @@ -2512,15 +2819,17 @@ private constructor( 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) @@ -2530,7 +2839,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() @@ -2638,25 +2948,25 @@ private constructor( class Trip @JsonCreator private constructor( + @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("id") @ExcludeMissing private val id: JsonField = JsonMissing.of(), @JsonProperty("peakOffpeak") @ExcludeMissing private val peakOffpeak: JsonField = JsonMissing.of(), - @JsonProperty("routeId") - @ExcludeMissing - private val routeId: JsonField = JsonMissing.of(), @JsonProperty("routeShortName") @ExcludeMissing private val routeShortName: JsonField = JsonMissing.of(), - @JsonProperty("serviceId") - @ExcludeMissing - private val serviceId: JsonField = JsonMissing.of(), @JsonProperty("shapeId") @ExcludeMissing private val shapeId: JsonField = JsonMissing.of(), @@ -2673,23 +2983,23 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { + 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")) @@ -2700,27 +3010,37 @@ 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 @@ -2729,20 +3049,22 @@ private constructor( 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) @@ -2752,15 +3074,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() @@ -2769,13 +3092,13 @@ private constructor( @JvmSynthetic internal fun from(trip: Trip) = apply { + id = trip.id + routeId = trip.routeId + serviceId = trip.serviceId blockId = trip.blockId directionId = trip.directionId - id = trip.id peakOffpeak = trip.peakOffpeak - routeId = trip.routeId routeShortName = trip.routeShortName - serviceId = trip.serviceId shapeId = trip.shapeId timeZone = trip.timeZone tripHeadsign = trip.tripHeadsign @@ -2783,6 +3106,18 @@ private constructor( 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)) fun blockId(blockId: JsonField) = apply { this.blockId = blockId } @@ -2793,18 +3128,10 @@ private constructor( this.directionId = directionId } - fun id(id: String) = id(JsonField.of(id)) - - fun id(id: JsonField) = apply { this.id = id } - fun peakOffpeak(peakOffpeak: Long) = peakOffpeak(JsonField.of(peakOffpeak)) fun peakOffpeak(peakOffpeak: JsonField) = apply { this.peakOffpeak = peakOffpeak } - fun routeId(routeId: String) = routeId(JsonField.of(routeId)) - - fun routeId(routeId: JsonField) = apply { this.routeId = routeId } - fun routeShortName(routeShortName: String) = routeShortName(JsonField.of(routeShortName)) @@ -2812,10 +3139,6 @@ private constructor( this.routeShortName = routeShortName } - fun serviceId(serviceId: String) = serviceId(JsonField.of(serviceId)) - - fun serviceId(serviceId: JsonField) = apply { this.serviceId = serviceId } - fun shapeId(shapeId: String) = shapeId(JsonField.of(shapeId)) fun shapeId(shapeId: JsonField) = apply { this.shapeId = shapeId } @@ -2857,13 +3180,13 @@ private constructor( fun build(): Trip = Trip( + checkRequired("id", id), + checkRequired("routeId", routeId), + checkRequired("serviceId", serviceId), blockId, directionId, - id, peakOffpeak, - routeId, routeShortName, - serviceId, shapeId, timeZone, tripHeadsign, @@ -2877,17 +3200,17 @@ private constructor( return true } - return /* spotless:off */ other is Trip && blockId == other.blockId && directionId == other.directionId && id == other.id && peakOffpeak == other.peakOffpeak && routeId == other.routeId && routeShortName == other.routeShortName && serviceId == other.serviceId && shapeId == other.shapeId && timeZone == other.timeZone && tripHeadsign == other.tripHeadsign && tripShortName == other.tripShortName && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(blockId, directionId, id, peakOffpeak, routeId, routeShortName, serviceId, shapeId, timeZone, tripHeadsign, tripShortName, additionalProperties) } + 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 = 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 { @@ -2895,15 +3218,15 @@ private constructor( return true } - return /* spotless:off */ other is References && agencies == other.agencies && routes == other.routes && situations == other.situations && stopTimes == other.stopTimes && stops == other.stops && trips == other.trips && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(agencies, routes, situations, stopTimes, stops, trips, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(agencies, routes, situations, stops, stopTimes, trips, additionalProperties) } /* spotless:on */ 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 07dbe77..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 @@ -8,12 +8,15 @@ import java.util.Optional import org.onebusaway.core.Enum import org.onebusaway.core.JsonField import org.onebusaway.core.NoAutoDetect +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 +/** 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?, @@ -22,7 +25,7 @@ constructor( private val userLon: Double?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun stopId(): String = stopId @@ -45,10 +48,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + 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())) } @@ -75,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 @@ -105,21 +108,50 @@ constructor( 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 } + fun userComment(userComment: String?) = apply { this.userComment = userComment } + + /** Additional comment text supplied by the user describing the problem */ + fun userComment(userComment: Optional) = userComment(userComment.orElse(null)) /** The reporting user’s current latitude */ - fun userLat(userLat: Double) = apply { this.userLat = userLat } + 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 */ + @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?) fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() @@ -221,7 +253,7 @@ constructor( fun build(): ReportProblemWithStopRetrieveParams = ReportProblemWithStopRetrieveParams( - checkNotNull(stopId) { "`stopId` is required but was not set" }, + checkRequired("stopId", stopId), code, userComment, userLat, @@ -232,12 +264,21 @@ constructor( ) } + /** 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 companion object { @@ -255,6 +296,7 @@ constructor( @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, @@ -263,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 @@ -282,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 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 6d0e87a..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 @@ -8,12 +8,15 @@ import java.util.Optional import org.onebusaway.core.Enum import org.onebusaway.core.JsonField import org.onebusaway.core.NoAutoDetect +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 +/** 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?, @@ -27,7 +30,7 @@ constructor( private val vehicleId: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun tripId(): String = tripId @@ -65,10 +68,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + 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())) } @@ -100,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 @@ -140,38 +143,93 @@ constructor( 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 } /** A stop ID indicating where the user is experiencing the problem */ - fun stopId(stopId: String) = apply { this.stopId = stopId } + 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 } + fun userComment(userComment: String?) = apply { this.userComment = userComment } + + /** Additional comment text supplied by the user describing the problem */ + 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?) + + /** 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) = apply { this.userOnVehicle = userOnVehicle } + fun userOnVehicle(userOnVehicle: Boolean) = userOnVehicle(userOnVehicle as Boolean?) + + /** Indicator if the user is on the transit vehicle experiencing the problem */ + @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() @@ -273,7 +331,7 @@ constructor( fun build(): ReportProblemWithTripRetrieveParams = ReportProblemWithTripRetrieveParams( - checkNotNull(tripId) { "`tripId` is required but was not set" }, + checkRequired("tripId", tripId), code, serviceDate, stopId, @@ -289,12 +347,21 @@ constructor( ) } + /** 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 companion object { @@ -314,6 +381,7 @@ constructor( @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 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 eb9ea9a..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 @@ -12,6 +12,7 @@ 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 @@ -38,13 +39,13 @@ 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 @@ -53,13 +54,15 @@ private constructor( 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) @@ -69,12 +72,13 @@ 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 @@ -123,10 +127,10 @@ private constructor( fun build(): ResponseWrapper = ResponseWrapper( - code, - currentTime, - text, - version, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), additionalProperties.toImmutable(), ) } 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 cdbc57c..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 @@ -4,15 +4,18 @@ package org.onebusaway.models import java.util.Objects import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun agencyId(): String = agencyId @@ -20,9 +23,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -38,8 +41,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [RouteIdsForAgencyListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var agencyId: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() @@ -154,7 +158,7 @@ constructor( fun build(): RouteIdsForAgencyListParams = RouteIdsForAgencyListParams( - checkNotNull(agencyId) { "`agencyId` is required but was not set" }, + checkRequired("agencyId", agencyId), additionalHeaders.build(), additionalQueryParams.build(), ) 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 d7aa39a..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 @@ -12,6 +12,7 @@ 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 @@ -41,15 +42,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -66,14 +67,16 @@ private constructor( 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) @@ -83,13 +86,14 @@ 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 @@ -143,11 +147,11 @@ private constructor( 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(), ) } @@ -175,11 +179,15 @@ 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("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing @@ -188,12 +196,14 @@ private constructor( 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) @@ -203,17 +213,18 @@ 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 { limitExceeded = data.limitExceeded - list = data.list + list = data.list.map { it.toMutableList() } references = data.references additionalProperties = data.additionalProperties.toMutableMap() } @@ -226,7 +237,22 @@ private constructor( fun list(list: List) = list(JsonField.of(list)) - 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)) @@ -255,9 +281,9 @@ private constructor( fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), additionalProperties.toImmutable(), ) } 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 54c0374..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 @@ -4,15 +4,18 @@ package org.onebusaway.models import java.util.Objects import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun routeId(): String = routeId @@ -20,9 +23,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -38,8 +41,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [RouteRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var routeId: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() @@ -154,7 +158,7 @@ constructor( fun build(): RouteRetrieveParams = RouteRetrieveParams( - checkNotNull(routeId) { "`routeId` is required but was not set" }, + checkRequired("routeId", routeId), additionalHeaders.build(), additionalQueryParams.build(), ) 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 5d65b29..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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -171,9 +175,11 @@ private constructor( 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 @@ -182,11 +188,13 @@ private constructor( 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) @@ -196,10 +204,11 @@ 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 @@ -240,8 +249,8 @@ private constructor( fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -250,18 +259,21 @@ private constructor( class Entry @JsonCreator private constructor( + @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("id") - @ExcludeMissing - private val id: JsonField = JsonMissing.of(), @JsonProperty("longName") @ExcludeMissing private val longName: JsonField = JsonMissing.of(), @@ -274,9 +286,6 @@ private constructor( @JsonProperty("textColor") @ExcludeMissing private val textColor: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), @@ -284,15 +293,17 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { + 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 = @@ -304,31 +315,35 @@ 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 @@ -337,19 +352,21 @@ private constructor( 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) @@ -359,39 +376,48 @@ 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 { + id = entry.id agencyId = entry.agencyId + type = entry.type color = entry.color description = entry.description - id = entry.id longName = entry.longName nullSafeShortName = entry.nullSafeShortName shortName = entry.shortName textColor = entry.textColor - type = entry.type 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)) 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)) fun color(color: JsonField) = apply { this.color = color } @@ -402,10 +428,6 @@ private constructor( this.description = description } - fun id(id: String) = id(JsonField.of(id)) - - fun id(id: JsonField) = apply { this.id = id } - fun longName(longName: String) = longName(JsonField.of(longName)) fun longName(longName: JsonField) = apply { this.longName = longName } @@ -425,10 +447,6 @@ private constructor( fun textColor(textColor: JsonField) = apply { this.textColor = textColor } - fun type(type: Long) = type(JsonField.of(type)) - - fun type(type: JsonField) = apply { this.type = type } - fun url(url: String) = url(JsonField.of(url)) fun url(url: JsonField) = apply { this.url = url } @@ -457,15 +475,15 @@ private constructor( 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(), ) @@ -476,17 +494,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && agencyId == other.agencyId && color == other.color && description == other.description && id == other.id && longName == other.longName && nullSafeShortName == other.nullSafeShortName && shortName == other.shortName && textColor == other.textColor && type == other.type && url == other.url && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(agencyId, color, description, id, longName, nullSafeShortName, shortName, textColor, type, url, additionalProperties) } + 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 = 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 { 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 288f3ee..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 @@ -4,15 +4,18 @@ package org.onebusaway.models import java.util.Objects import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun agencyId(): String = agencyId @@ -20,9 +23,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -38,8 +41,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [RoutesForAgencyListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var agencyId: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() @@ -154,7 +158,7 @@ constructor( fun build(): RoutesForAgencyListParams = RoutesForAgencyListParams( - checkNotNull(agencyId) { "`agencyId` is required but was not set" }, + checkRequired("agencyId", agencyId), additionalHeaders.build(), additionalQueryParams.build(), ) 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 e470d59..38b1edf 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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -176,11 +180,15 @@ 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("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing @@ -189,12 +197,14 @@ private constructor( 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) @@ -204,17 +214,18 @@ 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 { limitExceeded = data.limitExceeded - list = data.list + list = data.list.map { it.toMutableList() } references = data.references additionalProperties = data.additionalProperties.toMutableMap() } @@ -227,7 +238,22 @@ private constructor( fun list(list: List) = list(JsonField.of(list)) - 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)) @@ -256,9 +282,9 @@ private constructor( fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -267,18 +293,21 @@ private constructor( class List @JsonCreator private constructor( + @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("id") - @ExcludeMissing - private val id: JsonField = JsonMissing.of(), @JsonProperty("longName") @ExcludeMissing private val longName: JsonField = JsonMissing.of(), @@ -291,9 +320,6 @@ private constructor( @JsonProperty("textColor") @ExcludeMissing private val textColor: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), @@ -301,15 +327,17 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { + 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 = @@ -321,31 +349,35 @@ 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 + 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 @@ -354,19 +386,21 @@ private constructor( 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) @@ -376,39 +410,48 @@ 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 { + id = list.id agencyId = list.agencyId + type = list.type color = list.color description = list.description - id = list.id longName = list.longName nullSafeShortName = list.nullSafeShortName shortName = list.shortName textColor = list.textColor - type = list.type 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)) 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)) fun color(color: JsonField) = apply { this.color = color } @@ -419,10 +462,6 @@ private constructor( this.description = description } - fun id(id: String) = id(JsonField.of(id)) - - fun id(id: JsonField) = apply { this.id = id } - fun longName(longName: String) = longName(JsonField.of(longName)) fun longName(longName: JsonField) = apply { this.longName = longName } @@ -442,10 +481,6 @@ private constructor( fun textColor(textColor: JsonField) = apply { this.textColor = textColor } - fun type(type: Long) = type(JsonField.of(type)) - - fun type(type: JsonField) = apply { this.type = type } - fun url(url: String) = url(JsonField.of(url)) fun url(url: JsonField) = apply { this.url = url } @@ -474,15 +509,15 @@ private constructor( 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(), ) @@ -493,17 +528,17 @@ private constructor( return true } - return /* spotless:off */ other is List && agencyId == other.agencyId && color == other.color && description == other.description && id == other.id && longName == other.longName && nullSafeShortName == other.nullSafeShortName && shortName == other.shortName && textColor == other.textColor && type == other.type && url == other.url && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(agencyId, color, description, id, longName, nullSafeShortName, shortName, textColor, type, url, additionalProperties) } + 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 = 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 { 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 f934535..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 @@ -5,11 +5,14 @@ package org.onebusaway.models import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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?, @@ -18,7 +21,7 @@ constructor( private val radius: Double?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun lat(): Double = lat @@ -36,10 +39,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + 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())) } @@ -58,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 @@ -86,13 +89,30 @@ constructor( 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 lonSpan(lonSpan: Double) = apply { this.lonSpan = lonSpan } + fun latSpan(latSpan: Double) = latSpan(latSpan as Double?) - fun query(query: String) = apply { this.query = query } + @Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228 + fun latSpan(latSpan: Optional) = latSpan(latSpan.orElse(null) as Double?) - fun radius(radius: Double) = apply { this.radius = radius } + fun lonSpan(lonSpan: Double?) = apply { this.lonSpan = lonSpan } + + 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() @@ -194,8 +214,8 @@ constructor( 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, 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 b3bf871..cfc695d 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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -181,13 +185,19 @@ 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 @@ -196,13 +206,15 @@ private constructor( 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) @@ -212,18 +224,19 @@ 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 { limitExceeded = data.limitExceeded - list = data.list + list = data.list.map { it.toMutableList() } outOfRange = data.outOfRange references = data.references additionalProperties = data.additionalProperties.toMutableMap() @@ -237,7 +250,22 @@ private constructor( fun list(list: List) = list(JsonField.of(list)) - 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)) @@ -270,10 +298,10 @@ private constructor( 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(), ) } @@ -282,18 +310,21 @@ private constructor( class List @JsonCreator private constructor( + @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("id") - @ExcludeMissing - private val id: JsonField = JsonMissing.of(), @JsonProperty("longName") @ExcludeMissing private val longName: JsonField = JsonMissing.of(), @@ -306,9 +337,6 @@ private constructor( @JsonProperty("textColor") @ExcludeMissing private val textColor: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), @@ -316,15 +344,17 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { + 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 = @@ -336,31 +366,35 @@ 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("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 @@ -369,19 +403,21 @@ private constructor( 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) @@ -391,39 +427,48 @@ 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 { + id = list.id agencyId = list.agencyId + type = list.type color = list.color description = list.description - id = list.id longName = list.longName nullSafeShortName = list.nullSafeShortName shortName = list.shortName textColor = list.textColor - type = list.type 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)) 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)) fun color(color: JsonField) = apply { this.color = color } @@ -434,10 +479,6 @@ private constructor( this.description = description } - fun id(id: String) = id(JsonField.of(id)) - - fun id(id: JsonField) = apply { this.id = id } - fun longName(longName: String) = longName(JsonField.of(longName)) fun longName(longName: JsonField) = apply { this.longName = longName } @@ -457,10 +498,6 @@ private constructor( fun textColor(textColor: JsonField) = apply { this.textColor = textColor } - fun type(type: Long) = type(JsonField.of(type)) - - fun type(type: JsonField) = apply { this.type = type } - fun url(url: String) = url(JsonField.of(url)) fun url(url: JsonField) = apply { this.url = url } @@ -489,15 +526,15 @@ private constructor( 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(), ) @@ -508,17 +545,17 @@ private constructor( return true } - return /* spotless:off */ other is List && agencyId == other.agencyId && color == other.color && description == other.description && id == other.id && longName == other.longName && nullSafeShortName == other.nullSafeShortName && shortName == other.shortName && textColor == other.textColor && type == other.type && url == other.url && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(agencyId, color, description, id, longName, nullSafeShortName, shortName, textColor, type, url, additionalProperties) } + 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 = 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 { 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 daacc53..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 @@ -6,16 +6,19 @@ import java.time.LocalDate import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun routeId(): String = routeId @@ -29,10 +32,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + override fun _queryParams(): QueryParams { val queryParams = QueryParams.builder() this.date?.let { queryParams.put("date", listOf(it.toString())) } queryParams.putAll(additionalQueryParams) @@ -53,8 +55,9 @@ 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 @@ -75,7 +78,13 @@ 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() @@ -177,7 +186,7 @@ constructor( fun build(): ScheduleForRouteRetrieveParams = ScheduleForRouteRetrieveParams( - checkNotNull(routeId) { "`routeId` is required but was not set" }, + checkRequired("routeId", routeId), date, additionalHeaders.build(), additionalQueryParams.build(), 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 90e5f08..be77b8a 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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -146,11 +150,11 @@ private constructor( 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(), ) } @@ -168,7 +172,7 @@ private constructor( fun entry(): Entry = entry.getRequired("entry") - @JsonProperty("entry") @ExcludeMissing fun _entry() = entry + @JsonProperty("entry") @ExcludeMissing fun _entry(): JsonField = entry @JsonAnyGetter @ExcludeMissing @@ -177,10 +181,12 @@ private constructor( 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) @@ -190,9 +196,10 @@ 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 @@ -224,7 +231,8 @@ private constructor( keys.forEach(::removeAdditionalProperty) } - fun build(): Data = Data(entry, additionalProperties.toImmutable()) + fun build(): Data = + Data(checkRequired("entry", entry), additionalProperties.toImmutable()) } @NoAutoDetect @@ -240,12 +248,12 @@ private constructor( @JsonProperty("serviceIds") @ExcludeMissing private val serviceIds: JsonField> = JsonMissing.of(), - @JsonProperty("stopTripGroupings") - @ExcludeMissing - private val stopTripGroupings: 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(), @@ -259,26 +267,30 @@ private constructor( 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(): JsonField = scheduleDate - @JsonProperty("scheduleDate") @ExcludeMissing fun _scheduleDate() = scheduleDate + @JsonProperty("serviceIds") + @ExcludeMissing + fun _serviceIds(): JsonField> = serviceIds - @JsonProperty("serviceIds") @ExcludeMissing fun _serviceIds() = 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 @@ -287,15 +299,17 @@ private constructor( 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) @@ -305,24 +319,25 @@ 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 { routeId = entry.routeId scheduleDate = entry.scheduleDate - serviceIds = entry.serviceIds - stopTripGroupings = entry.stopTripGroupings - stops = entry.stops - trips = entry.trips + 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() } @@ -339,7 +354,39 @@ private constructor( fun serviceIds(serviceIds: List) = serviceIds(JsonField.of(serviceIds)) 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) = @@ -347,16 +394,40 @@ private constructor( fun stopTripGroupings(stopTripGroupings: JsonField>) = apply { - this.stopTripGroupings = stopTripGroupings + this.stopTripGroupings = stopTripGroupings.map { it.toMutableList() } } - fun stops(stops: List) = stops(JsonField.of(stops)) - - 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)) - 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() @@ -382,12 +453,14 @@ private constructor( 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(), ) } @@ -396,21 +469,12 @@ private constructor( class Stop @JsonCreator private constructor( - @JsonProperty("code") - @ExcludeMissing - private val code: JsonField = JsonMissing.of(), - @JsonProperty("direction") - @ExcludeMissing - private val direction: JsonField = JsonMissing.of(), @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(), @@ -426,6 +490,15 @@ private constructor( @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("locationType") + @ExcludeMissing + private val locationType: JsonField = JsonMissing.of(), @JsonProperty("wheelchairBoarding") @ExcludeMissing private val wheelchairBoarding: JsonField = JsonMissing.of(), @@ -433,18 +506,10 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { - 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 lon(): Double = lon.getRequired("lon") fun name(): String = name.getRequired("name") @@ -455,34 +520,48 @@ 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 locationType(): Optional = + Optional.ofNullable(locationType.getNullable("locationType")) + 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("lon") @ExcludeMissing fun _lon(): JsonField = lon - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("locationType") @ExcludeMissing fun _locationType() = locationType + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("routeIds") + @ExcludeMissing + fun _routeIds(): JsonField> = routeIds - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("staticRouteIds") + @ExcludeMissing + fun _staticRouteIds(): JsonField> = staticRouteIds - @JsonProperty("parent") @ExcludeMissing fun _parent() = parent + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("routeIds") @ExcludeMissing fun _routeIds() = routeIds + @JsonProperty("direction") + @ExcludeMissing + fun _direction(): JsonField = direction - @JsonProperty("staticRouteIds") + @JsonProperty("locationType") @ExcludeMissing - fun _staticRouteIds() = staticRouteIds + fun _locationType(): JsonField = locationType @JsonProperty("wheelchairBoarding") @ExcludeMissing - fun _wheelchairBoarding() = wheelchairBoarding + fun _wheelchairBoarding(): JsonField = wheelchairBoarding @JsonAnyGetter @ExcludeMissing @@ -491,20 +570,22 @@ private constructor( 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() + lon() + name() + parent() + routeIds() + staticRouteIds() + code() + direction() + locationType() + wheelchairBoarding() + validated = true } fun toBuilder() = Builder().from(this) @@ -514,47 +595,38 @@ 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 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 { - code = stop.code - direction = stop.direction id = stop.id lat = stop.lat - locationType = stop.locationType lon = stop.lon name = stop.name parent = stop.parent - routeIds = stop.routeIds - staticRouteIds = stop.staticRouteIds + routeIds = stop.routeIds.map { it.toMutableList() } + staticRouteIds = stop.staticRouteIds.map { it.toMutableList() } + code = stop.code + direction = stop.direction + locationType = stop.locationType wheelchairBoarding = stop.wheelchairBoarding additionalProperties = stop.additionalProperties.toMutableMap() } - 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 id(id: String) = id(JsonField.of(id)) fun id(id: JsonField) = apply { this.id = id } @@ -563,12 +635,6 @@ private constructor( fun lat(lat: JsonField) = apply { this.lat = lat } - fun locationType(locationType: Long) = locationType(JsonField.of(locationType)) - - fun locationType(locationType: JsonField) = apply { - this.locationType = locationType - } - fun lon(lon: Double) = lon(JsonField.of(lon)) fun lon(lon: JsonField) = apply { this.lon = lon } @@ -584,14 +650,56 @@ private constructor( fun routeIds(routeIds: List) = routeIds(JsonField.of(routeIds)) 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)) 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 locationType(locationType: Long) = locationType(JsonField.of(locationType)) + + fun locationType(locationType: JsonField) = apply { + this.locationType = locationType } fun wheelchairBoarding(wheelchairBoarding: String) = @@ -625,16 +733,18 @@ private constructor( fun build(): Stop = Stop( + checkRequired("id", id), + checkRequired("lat", lat), + 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(), ) @@ -645,17 +755,17 @@ private constructor( return true } - return /* spotless:off */ other is Stop && code == other.code && direction == other.direction && id == other.id && lat == other.lat && locationType == other.locationType && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Stop && id == other.id && lat == other.lat && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && code == other.code && direction == other.direction && locationType == other.locationType && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(code, direction, id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, wheelchairBoarding, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(id, lat, lon, name, parent, routeIds, staticRouteIds, code, direction, locationType, wheelchairBoarding, additionalProperties) } /* spotless:on */ 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, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, code=$code, direction=$direction, locationType=$locationType, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" } @NoAutoDetect @@ -693,17 +803,25 @@ 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 @@ -712,14 +830,16 @@ private constructor( 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) @@ -729,23 +849,25 @@ 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 { directionId = stopTripGrouping.directionId - stopIds = stopTripGrouping.stopIds - tripHeadsigns = stopTripGrouping.tripHeadsigns - tripIds = stopTripGrouping.tripIds - tripsWithStopTimes = stopTripGrouping.tripsWithStopTimes + 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() } @@ -757,27 +879,83 @@ private constructor( fun stopIds(stopIds: List) = stopIds(JsonField.of(stopIds)) - 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)) 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)) - 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)) 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() putAllAdditionalProperties(additionalProperties) @@ -802,11 +980,11 @@ private constructor( 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(), ) } @@ -815,23 +993,27 @@ private constructor( class TripsWithStopTime @JsonCreator private constructor( - @JsonProperty("tripId") - @ExcludeMissing - private val tripId: JsonField = JsonMissing.of(), @JsonProperty("stopTimes") @ExcludeMissing private val stopTimes: JsonField> = JsonMissing.of(), + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - fun tripId(): String = tripId.getRequired("tripId") - fun stopTimes(): List = stopTimes.getRequired("stopTimes") - @JsonProperty("tripId") @ExcludeMissing fun _tripId() = tripId + fun tripId(): String = tripId.getRequired("tripId") - @JsonProperty("stopTimes") @ExcludeMissing fun _stopTimes() = stopTimes + @JsonProperty("stopTimes") + @ExcludeMissing + fun _stopTimes(): JsonField> = stopTimes + + @JsonProperty("tripId") + @ExcludeMissing + fun _tripId(): JsonField = tripId @JsonAnyGetter @ExcludeMissing @@ -840,11 +1022,13 @@ private constructor( 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) @@ -854,32 +1038,46 @@ 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 { + stopTimes = tripsWithStopTime.stopTimes.map { it.toMutableList() } tripId = tripsWithStopTime.tripId - stopTimes = tripsWithStopTime.stopTimes additionalProperties = tripsWithStopTime.additionalProperties.toMutableMap() } - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - fun stopTimes(stopTimes: List) = stopTimes(JsonField.of(stopTimes)) 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() @@ -904,8 +1102,8 @@ private constructor( fun build(): TripsWithStopTime = TripsWithStopTime( - tripId, - stopTimes.map { it.toImmutable() }, + checkRequired("stopTimes", stopTimes).map { it.toImmutable() }, + checkRequired("tripId", tripId), additionalProperties.toImmutable(), ) } @@ -926,18 +1124,18 @@ private constructor( @JsonProperty("departureTime") @ExcludeMissing private val departureTime: JsonField = JsonMissing.of(), - @JsonProperty("serviceId") - @ExcludeMissing - private val serviceId: JsonField = JsonMissing.of(), - @JsonProperty("stopHeadsign") - @ExcludeMissing - private val stopHeadsign: 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(), @@ -952,41 +1150,47 @@ 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 @@ -995,17 +1199,19 @@ private constructor( 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) @@ -1015,16 +1221,17 @@ 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() @@ -1034,10 +1241,10 @@ private constructor( arrivalTime = stopTime.arrivalTime departureEnabled = stopTime.departureEnabled departureTime = stopTime.departureTime - serviceId = stopTime.serviceId - stopHeadsign = stopTime.stopHeadsign stopId = stopTime.stopId tripId = stopTime.tripId + serviceId = stopTime.serviceId + stopHeadsign = stopTime.stopHeadsign additionalProperties = stopTime.additionalProperties.toMutableMap() } @@ -1069,6 +1276,14 @@ private constructor( 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)) fun serviceId(serviceId: JsonField) = apply { @@ -1082,14 +1297,6 @@ private constructor( this.stopHeadsign = stopHeadsign } - 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 additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -1114,14 +1321,14 @@ private constructor( 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(), ) } @@ -1131,17 +1338,17 @@ private constructor( return true } - return /* spotless:off */ other is StopTime && arrivalEnabled == other.arrivalEnabled && arrivalTime == other.arrivalTime && departureEnabled == other.departureEnabled && departureTime == other.departureTime && serviceId == other.serviceId && stopHeadsign == other.stopHeadsign && stopId == other.stopId && tripId == other.tripId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(arrivalEnabled, arrivalTime, departureEnabled, departureTime, serviceId, stopHeadsign, stopId, tripId, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(arrivalEnabled, arrivalTime, departureEnabled, departureTime, stopId, tripId, serviceId, stopHeadsign, additionalProperties) } /* spotless:on */ 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 { @@ -1149,17 +1356,17 @@ private constructor( return true } - return /* spotless:off */ other is TripsWithStopTime && tripId == other.tripId && stopTimes == other.stopTimes && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is TripsWithStopTime && stopTimes == other.stopTimes && tripId == other.tripId && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(tripId, stopTimes, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(stopTimes, tripId, additionalProperties) } /* spotless:on */ 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 { @@ -1184,27 +1391,27 @@ private constructor( class Trip @JsonCreator private constructor( + @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("id") - @ExcludeMissing - private val id: JsonField = JsonMissing.of(), @JsonProperty("peakOffpeak") @ExcludeMissing private val peakOffpeak: JsonField = JsonMissing.of(), - @JsonProperty("routeId") - @ExcludeMissing - private val routeId: JsonField = JsonMissing.of(), @JsonProperty("routeShortName") @ExcludeMissing private val routeShortName: JsonField = JsonMissing.of(), - @JsonProperty("serviceId") - @ExcludeMissing - private val serviceId: JsonField = JsonMissing.of(), @JsonProperty("shapeId") @ExcludeMissing private val shapeId: JsonField = JsonMissing.of(), @@ -1221,24 +1428,24 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { + 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")) @@ -1251,29 +1458,41 @@ 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("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 @@ -1282,20 +1501,22 @@ private constructor( 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) @@ -1305,15 +1526,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() @@ -1322,13 +1544,13 @@ private constructor( @JvmSynthetic internal fun from(trip: Trip) = apply { + id = trip.id + routeId = trip.routeId + serviceId = trip.serviceId blockId = trip.blockId directionId = trip.directionId - id = trip.id peakOffpeak = trip.peakOffpeak - routeId = trip.routeId routeShortName = trip.routeShortName - serviceId = trip.serviceId shapeId = trip.shapeId timeZone = trip.timeZone tripHeadsign = trip.tripHeadsign @@ -1336,6 +1558,20 @@ private constructor( 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)) fun blockId(blockId: JsonField) = apply { this.blockId = blockId } @@ -1346,20 +1582,12 @@ private constructor( this.directionId = directionId } - fun id(id: String) = id(JsonField.of(id)) - - fun id(id: JsonField) = apply { this.id = id } - fun peakOffpeak(peakOffpeak: Long) = peakOffpeak(JsonField.of(peakOffpeak)) fun peakOffpeak(peakOffpeak: JsonField) = apply { this.peakOffpeak = peakOffpeak } - fun routeId(routeId: String) = routeId(JsonField.of(routeId)) - - fun routeId(routeId: JsonField) = apply { this.routeId = routeId } - fun routeShortName(routeShortName: String) = routeShortName(JsonField.of(routeShortName)) @@ -1367,12 +1595,6 @@ private constructor( this.routeShortName = routeShortName } - fun serviceId(serviceId: String) = serviceId(JsonField.of(serviceId)) - - fun serviceId(serviceId: JsonField) = apply { - this.serviceId = serviceId - } - fun shapeId(shapeId: String) = shapeId(JsonField.of(shapeId)) fun shapeId(shapeId: JsonField) = apply { this.shapeId = shapeId } @@ -1419,13 +1641,13 @@ private constructor( fun build(): Trip = Trip( + checkRequired("id", id), + checkRequired("routeId", routeId), + checkRequired("serviceId", serviceId), blockId, directionId, - id, peakOffpeak, - routeId, routeShortName, - serviceId, shapeId, timeZone, tripHeadsign, @@ -1439,17 +1661,17 @@ private constructor( return true } - return /* spotless:off */ other is Trip && blockId == other.blockId && directionId == other.directionId && id == other.id && peakOffpeak == other.peakOffpeak && routeId == other.routeId && routeShortName == other.routeShortName && serviceId == other.serviceId && shapeId == other.shapeId && timeZone == other.timeZone && tripHeadsign == other.tripHeadsign && tripShortName == other.tripShortName && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(blockId, directionId, id, peakOffpeak, routeId, routeShortName, serviceId, shapeId, timeZone, tripHeadsign, tripShortName, additionalProperties) } + 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 = 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 { @@ -1457,17 +1679,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && routeId == other.routeId && scheduleDate == other.scheduleDate && serviceIds == other.serviceIds && stopTripGroupings == other.stopTripGroupings && stops == other.stops && trips == other.trips && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(routeId, scheduleDate, serviceIds, stopTripGroupings, stops, trips, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(routeId, scheduleDate, serviceIds, stops, stopTripGroupings, trips, additionalProperties) } /* spotless:on */ 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 { 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 f33d2c8..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 @@ -6,16 +6,19 @@ import java.time.LocalDate import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun stopId(): String = stopId @@ -29,10 +32,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + override fun _queryParams(): QueryParams { val queryParams = QueryParams.builder() this.date?.let { queryParams.put("date", listOf(it.toString())) } queryParams.putAll(additionalQueryParams) @@ -53,8 +55,9 @@ 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 @@ -75,7 +78,13 @@ 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() @@ -177,7 +186,7 @@ constructor( fun build(): ScheduleForStopRetrieveParams = ScheduleForStopRetrieveParams( - checkNotNull(stopId) { "`stopId` is required but was not set" }, + checkRequired("stopId", stopId), date, additionalHeaders.build(), additionalQueryParams.build(), 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 307813a..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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -146,11 +150,11 @@ private constructor( 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(), ) } @@ -173,9 +177,11 @@ private constructor( 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 @@ -184,11 +190,13 @@ private constructor( 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) @@ -198,10 +206,11 @@ 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 @@ -242,8 +251,8 @@ private constructor( fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -272,13 +281,13 @@ 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 @@ -287,12 +296,14 @@ private constructor( 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) @@ -302,19 +313,19 @@ 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 { date = entry.date stopId = entry.stopId - stopRouteSchedules = entry.stopRouteSchedules + stopRouteSchedules = entry.stopRouteSchedules.map { it.toMutableList() } additionalProperties = entry.additionalProperties.toMutableMap() } @@ -331,9 +342,22 @@ private constructor( 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() putAllAdditionalProperties(additionalProperties) @@ -358,9 +382,11 @@ private constructor( fun build(): Entry = Entry( - date, - stopId, - stopRouteSchedules.map { it.toImmutable() }, + checkRequired("date", date), + checkRequired("stopId", stopId), + checkRequired("stopRouteSchedules", stopRouteSchedules).map { + it.toImmutable() + }, additionalProperties.toImmutable(), ) } @@ -386,11 +412,12 @@ private constructor( 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 @@ -399,11 +426,13 @@ private constructor( 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) @@ -413,18 +442,20 @@ 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 { routeId = stopRouteSchedule.routeId - stopRouteDirectionSchedules = stopRouteSchedule.stopRouteDirectionSchedules + stopRouteDirectionSchedules = + stopRouteSchedule.stopRouteDirectionSchedules.map { it.toMutableList() } additionalProperties = stopRouteSchedule.additionalProperties.toMutableMap() } @@ -438,7 +469,25 @@ private constructor( 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() @@ -464,8 +513,12 @@ private constructor( fun build(): StopRouteSchedule = StopRouteSchedule( - routeId, - stopRouteDirectionSchedules.map { it.toImmutable() }, + checkRequired("routeId", routeId), + checkRequired( + "stopRouteDirectionSchedules", + stopRouteDirectionSchedules + ) + .map { it.toImmutable() }, additionalProperties.toImmutable(), ) } @@ -474,10 +527,6 @@ private constructor( class StopRouteDirectionSchedule @JsonCreator private constructor( - @JsonProperty("scheduleFrequencies") - @ExcludeMissing - private val scheduleFrequencies: JsonField> = - JsonMissing.of(), @JsonProperty("scheduleStopTimes") @ExcludeMissing private val scheduleStopTimes: JsonField> = @@ -485,27 +534,34 @@ private constructor( @JsonProperty("tripHeadsign") @ExcludeMissing private val tripHeadsign: JsonField = JsonMissing.of(), + @JsonProperty("scheduleFrequencies") + @ExcludeMissing + private val scheduleFrequencies: JsonField> = + JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - 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 @@ -514,12 +570,14 @@ private constructor( 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) @@ -529,39 +587,55 @@ 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 { - scheduleFrequencies = stopRouteDirectionSchedule.scheduleFrequencies - scheduleStopTimes = stopRouteDirectionSchedule.scheduleStopTimes + 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)) - - fun scheduleFrequencies( - scheduleFrequencies: JsonField> - ) = apply { this.scheduleFrequencies = scheduleFrequencies } - fun scheduleStopTimes(scheduleStopTimes: List) = scheduleStopTimes(JsonField.of(scheduleStopTimes)) 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)) @@ -570,6 +644,29 @@ private constructor( 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() @@ -594,9 +691,11 @@ private constructor( 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(), ) } @@ -620,12 +719,12 @@ private constructor( @JsonProperty("serviceId") @ExcludeMissing private val serviceId: JsonField = JsonMissing.of(), - @JsonProperty("stopHeadsign") - @ExcludeMissing - private val stopHeadsign: 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(), @@ -642,34 +741,38 @@ 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 @@ -678,16 +781,18 @@ private constructor( 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) @@ -697,15 +802,16 @@ 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() @@ -716,8 +822,8 @@ private constructor( departureEnabled = scheduleStopTime.departureEnabled departureTime = scheduleStopTime.departureTime serviceId = scheduleStopTime.serviceId - stopHeadsign = scheduleStopTime.stopHeadsign tripId = scheduleStopTime.tripId + stopHeadsign = scheduleStopTime.stopHeadsign additionalProperties = scheduleStopTime.additionalProperties.toMutableMap() } @@ -756,6 +862,10 @@ private constructor( 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)) @@ -763,10 +873,6 @@ private constructor( this.stopHeadsign = stopHeadsign } - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -791,13 +897,13 @@ private constructor( 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(), ) } @@ -807,38 +913,38 @@ private constructor( return true } - return /* spotless:off */ other is ScheduleStopTime && arrivalEnabled == other.arrivalEnabled && arrivalTime == other.arrivalTime && departureEnabled == other.departureEnabled && departureTime == other.departureTime && serviceId == other.serviceId && stopHeadsign == other.stopHeadsign && tripId == other.tripId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(arrivalEnabled, arrivalTime, departureEnabled, departureTime, serviceId, stopHeadsign, tripId, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(arrivalEnabled, arrivalTime, departureEnabled, departureTime, serviceId, tripId, stopHeadsign, additionalProperties) } /* spotless:on */ 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}" } @NoAutoDetect class ScheduleFrequency @JsonCreator private constructor( - @JsonProperty("serviceDate") - @ExcludeMissing - private val serviceDate: JsonField = JsonMissing.of(), - @JsonProperty("startTime") - @ExcludeMissing - private val startTime: JsonField = JsonMissing.of(), @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(), @@ -847,31 +953,41 @@ private constructor( immutableEmptyMap(), ) { - 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 @@ -880,15 +996,17 @@ private constructor( 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) @@ -898,42 +1016,30 @@ 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 { - serviceDate = scheduleFrequency.serviceDate - startTime = scheduleFrequency.startTime endTime = scheduleFrequency.endTime headway = scheduleFrequency.headway + serviceDate = scheduleFrequency.serviceDate serviceId = scheduleFrequency.serviceId + startTime = scheduleFrequency.startTime tripId = scheduleFrequency.tripId additionalProperties = scheduleFrequency.additionalProperties.toMutableMap() } - fun serviceDate(serviceDate: Long) = - serviceDate(JsonField.of(serviceDate)) - - fun serviceDate(serviceDate: JsonField) = apply { - this.serviceDate = serviceDate - } - - fun startTime(startTime: Long) = startTime(JsonField.of(startTime)) - - fun startTime(startTime: JsonField) = apply { - this.startTime = startTime - } - fun endTime(endTime: Long) = endTime(JsonField.of(endTime)) fun endTime(endTime: JsonField) = apply { this.endTime = endTime } @@ -942,12 +1048,25 @@ private constructor( 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)) 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)) fun tripId(tripId: JsonField) = apply { this.tripId = tripId } @@ -976,12 +1095,12 @@ private constructor( 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(), ) } @@ -991,17 +1110,17 @@ private constructor( return true } - return /* spotless:off */ other is ScheduleFrequency && serviceDate == other.serviceDate && startTime == other.startTime && endTime == other.endTime && headway == other.headway && serviceId == other.serviceId && tripId == other.tripId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(serviceDate, startTime, endTime, headway, serviceId, tripId, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(endTime, headway, serviceDate, serviceId, startTime, tripId, additionalProperties) } /* spotless:on */ 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 { @@ -1009,17 +1128,17 @@ private constructor( return true } - return /* spotless:off */ other is StopRouteDirectionSchedule && scheduleFrequencies == other.scheduleFrequencies && scheduleStopTimes == other.scheduleStopTimes && tripHeadsign == other.tripHeadsign && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(scheduleFrequencies, scheduleStopTimes, tripHeadsign, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(scheduleStopTimes, tripHeadsign, scheduleFrequencies, additionalProperties) } /* spotless:on */ 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 { 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 e7084d4..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 @@ -5,16 +5,19 @@ package org.onebusaway.models import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { /** The string to search for. */ fun input(): String = input @@ -26,10 +29,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + 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())) } @@ -44,8 +46,9 @@ 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 @@ -64,7 +67,14 @@ constructor( 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() @@ -166,7 +176,7 @@ constructor( fun build(): SearchForRouteListParams = SearchForRouteListParams( - checkNotNull(input) { "`input` is required but was not set" }, + checkRequired("input", input), maxCount, additionalHeaders.build(), additionalQueryParams.build(), 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 01e0c37..22c51b8 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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Optional = Optional.ofNullable(data.getNullable("data")) - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,12 +87,13 @@ 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() @@ -144,10 +148,10 @@ private constructor( fun build(): SearchForRouteListResponse = SearchForRouteListResponse( - code, - currentTime, - text, - version, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), data, additionalProperties.toImmutable(), ) @@ -181,13 +185,19 @@ 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 @@ -196,13 +206,15 @@ private constructor( 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) @@ -212,18 +224,19 @@ 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 { limitExceeded = data.limitExceeded - list = data.list + list = data.list.map { it.toMutableList() } outOfRange = data.outOfRange references = data.references additionalProperties = data.additionalProperties.toMutableMap() @@ -237,7 +250,22 @@ private constructor( fun list(list: List) = list(JsonField.of(list)) - 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)) @@ -270,10 +298,10 @@ private constructor( 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(), ) } @@ -282,18 +310,21 @@ private constructor( class List @JsonCreator private constructor( + @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("id") - @ExcludeMissing - private val id: JsonField = JsonMissing.of(), @JsonProperty("longName") @ExcludeMissing private val longName: JsonField = JsonMissing.of(), @@ -306,9 +337,6 @@ private constructor( @JsonProperty("textColor") @ExcludeMissing private val textColor: JsonField = JsonMissing.of(), - @JsonProperty("type") - @ExcludeMissing - private val type: JsonField = JsonMissing.of(), @JsonProperty("url") @ExcludeMissing private val url: JsonField = JsonMissing.of(), @@ -316,15 +344,17 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { + 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 = @@ -336,31 +366,35 @@ 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("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 @@ -369,19 +403,21 @@ private constructor( 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) @@ -391,39 +427,48 @@ 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 { + id = list.id agencyId = list.agencyId + type = list.type color = list.color description = list.description - id = list.id longName = list.longName nullSafeShortName = list.nullSafeShortName shortName = list.shortName textColor = list.textColor - type = list.type 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)) 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)) fun color(color: JsonField) = apply { this.color = color } @@ -434,10 +479,6 @@ private constructor( this.description = description } - fun id(id: String) = id(JsonField.of(id)) - - fun id(id: JsonField) = apply { this.id = id } - fun longName(longName: String) = longName(JsonField.of(longName)) fun longName(longName: JsonField) = apply { this.longName = longName } @@ -457,10 +498,6 @@ private constructor( fun textColor(textColor: JsonField) = apply { this.textColor = textColor } - fun type(type: Long) = type(JsonField.of(type)) - - fun type(type: JsonField) = apply { this.type = type } - fun url(url: String) = url(JsonField.of(url)) fun url(url: JsonField) = apply { this.url = url } @@ -489,15 +526,15 @@ private constructor( 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(), ) @@ -508,17 +545,17 @@ private constructor( return true } - return /* spotless:off */ other is List && agencyId == other.agencyId && color == other.color && description == other.description && id == other.id && longName == other.longName && nullSafeShortName == other.nullSafeShortName && shortName == other.shortName && textColor == other.textColor && type == other.type && url == other.url && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(agencyId, color, description, id, longName, nullSafeShortName, shortName, textColor, type, url, additionalProperties) } + 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 = 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 { 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 5de1fb8..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 @@ -5,16 +5,19 @@ package org.onebusaway.models import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { /** The string to search for. */ fun input(): String = input @@ -26,10 +29,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + 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())) } @@ -44,8 +46,9 @@ 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 @@ -64,7 +67,14 @@ constructor( 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() @@ -166,7 +176,7 @@ constructor( fun build(): SearchForStopListParams = SearchForStopListParams( - checkNotNull(input) { "`input` is required but was not set" }, + checkRequired("input", input), maxCount, additionalHeaders.build(), additionalQueryParams.build(), 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 a6d50de..fc7340a 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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Optional = Optional.ofNullable(data.getNullable("data")) - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,12 +87,13 @@ 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() @@ -144,10 +148,10 @@ private constructor( fun build(): SearchForStopListResponse = SearchForStopListResponse( - code, - currentTime, - text, - version, + checkRequired("code", code), + checkRequired("currentTime", currentTime), + checkRequired("text", text), + checkRequired("version", version), data, additionalProperties.toImmutable(), ) @@ -181,13 +185,19 @@ 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 @@ -196,13 +206,15 @@ private constructor( 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) @@ -212,18 +224,19 @@ 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 { limitExceeded = data.limitExceeded - list = data.list + list = data.list.map { it.toMutableList() } outOfRange = data.outOfRange references = data.references additionalProperties = data.additionalProperties.toMutableMap() @@ -237,7 +250,22 @@ private constructor( fun list(list: List) = list(JsonField.of(list)) - 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)) @@ -270,10 +298,10 @@ private constructor( 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(), ) } @@ -282,21 +310,12 @@ private constructor( class List @JsonCreator private constructor( - @JsonProperty("code") - @ExcludeMissing - private val code: JsonField = JsonMissing.of(), - @JsonProperty("direction") - @ExcludeMissing - private val direction: JsonField = JsonMissing.of(), @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(), @@ -312,6 +331,15 @@ private constructor( @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("locationType") + @ExcludeMissing + private val locationType: JsonField = JsonMissing.of(), @JsonProperty("wheelchairBoarding") @ExcludeMissing private val wheelchairBoarding: JsonField = JsonMissing.of(), @@ -319,18 +347,10 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { - 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 lon(): Double = lon.getRequired("lon") fun name(): String = name.getRequired("name") @@ -341,32 +361,48 @@ 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 locationType(): Optional = + Optional.ofNullable(locationType.getNullable("locationType")) + 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("lon") @ExcludeMissing fun _lon(): JsonField = lon - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("locationType") @ExcludeMissing fun _locationType() = locationType + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("routeIds") + @ExcludeMissing + fun _routeIds(): JsonField> = routeIds - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("staticRouteIds") + @ExcludeMissing + fun _staticRouteIds(): JsonField> = staticRouteIds - @JsonProperty("parent") @ExcludeMissing fun _parent() = parent + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("routeIds") @ExcludeMissing fun _routeIds() = routeIds + @JsonProperty("direction") + @ExcludeMissing + fun _direction(): JsonField = direction - @JsonProperty("staticRouteIds") @ExcludeMissing fun _staticRouteIds() = staticRouteIds + @JsonProperty("locationType") + @ExcludeMissing + fun _locationType(): JsonField = locationType @JsonProperty("wheelchairBoarding") @ExcludeMissing - fun _wheelchairBoarding() = wheelchairBoarding + fun _wheelchairBoarding(): JsonField = wheelchairBoarding @JsonAnyGetter @ExcludeMissing @@ -375,20 +411,22 @@ private constructor( 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() + lon() + name() + parent() + routeIds() + staticRouteIds() + code() + direction() + locationType() + wheelchairBoarding() + validated = true } fun toBuilder() = Builder().from(this) @@ -398,45 +436,38 @@ 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 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 { - code = list.code - direction = list.direction id = list.id lat = list.lat - locationType = list.locationType lon = list.lon name = list.name parent = list.parent - routeIds = list.routeIds - staticRouteIds = list.staticRouteIds + routeIds = list.routeIds.map { it.toMutableList() } + staticRouteIds = list.staticRouteIds.map { it.toMutableList() } + code = list.code + direction = list.direction + locationType = list.locationType wheelchairBoarding = list.wheelchairBoarding additionalProperties = list.additionalProperties.toMutableMap() } - 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 id(id: String) = id(JsonField.of(id)) fun id(id: JsonField) = apply { this.id = id } @@ -445,12 +476,6 @@ private constructor( fun lat(lat: JsonField) = apply { this.lat = lat } - fun locationType(locationType: Long) = locationType(JsonField.of(locationType)) - - fun locationType(locationType: JsonField) = apply { - this.locationType = locationType - } - fun lon(lon: Double) = lon(JsonField.of(lon)) fun lon(lon: JsonField) = apply { this.lon = lon } @@ -465,13 +490,55 @@ private constructor( fun routeIds(routeIds: List) = routeIds(JsonField.of(routeIds)) - 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)) 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 locationType(locationType: Long) = locationType(JsonField.of(locationType)) + + fun locationType(locationType: JsonField) = apply { + this.locationType = locationType } fun wheelchairBoarding(wheelchairBoarding: String) = @@ -505,16 +572,16 @@ private constructor( fun build(): List = List( + checkRequired("id", id), + checkRequired("lat", lat), + 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(), ) @@ -525,17 +592,17 @@ private constructor( return true } - return /* spotless:off */ other is List && code == other.code && direction == other.direction && id == other.id && lat == other.lat && locationType == other.locationType && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is List && id == other.id && lat == other.lat && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && code == other.code && direction == other.direction && locationType == other.locationType && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(code, direction, id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, wheelchairBoarding, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(id, lat, lon, name, parent, routeIds, staticRouteIds, code, direction, locationType, wheelchairBoarding, additionalProperties) } /* spotless:on */ 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, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, code=$code, direction=$direction, locationType=$locationType, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { 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 d484d52..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 @@ -4,15 +4,18 @@ package org.onebusaway.models import java.util.Objects import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun shapeId(): String = shapeId @@ -20,9 +23,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -38,8 +41,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [ShapeRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var shapeId: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() @@ -154,7 +158,7 @@ constructor( fun build(): ShapeRetrieveParams = ShapeRetrieveParams( - checkNotNull(shapeId) { "`shapeId` is required but was not set" }, + checkRequired("shapeId", shapeId), additionalHeaders.build(), additionalQueryParams.build(), ) 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 cb95187..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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -171,9 +175,11 @@ private constructor( 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 @@ -182,11 +188,13 @@ private constructor( 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) @@ -196,10 +204,11 @@ 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 @@ -240,8 +249,8 @@ private constructor( fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -253,29 +262,29 @@ private constructor( @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(), + @JsonProperty("levels") + @ExcludeMissing + private val levels: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { 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 @@ -284,12 +293,14 @@ private constructor( 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) @@ -299,18 +310,19 @@ 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 { length = entry.length - levels = entry.levels points = entry.points + levels = entry.levels additionalProperties = entry.additionalProperties.toMutableMap() } @@ -318,16 +330,16 @@ private constructor( fun length(length: JsonField) = apply { this.length = length } - fun levels(levels: String) = levels(JsonField.of(levels)) - - 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 */ 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() putAllAdditionalProperties(additionalProperties) @@ -352,9 +364,9 @@ private constructor( fun build(): Entry = Entry( - length, + checkRequired("length", length), + checkRequired("points", points), levels, - points, additionalProperties.toImmutable(), ) } @@ -364,17 +376,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && length == other.length && levels == other.levels && points == other.points && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(length, levels, points, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(length, points, levels, additionalProperties) } /* spotless:on */ 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 { 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 5ed4d90..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 @@ -4,15 +4,18 @@ package org.onebusaway.models import java.util.Objects import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun agencyId(): String = agencyId @@ -20,9 +23,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -38,8 +41,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [StopIdsForAgencyListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var agencyId: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() @@ -154,7 +158,7 @@ constructor( fun build(): StopIdsForAgencyListParams = StopIdsForAgencyListParams( - checkNotNull(agencyId) { "`agencyId` is required but was not set" }, + checkRequired("agencyId", agencyId), additionalHeaders.build(), additionalQueryParams.build(), ) 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 47ff328..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 @@ -12,6 +12,7 @@ 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 @@ -41,15 +42,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -66,14 +67,16 @@ private constructor( 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) @@ -83,13 +86,14 @@ 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 @@ -143,11 +147,11 @@ private constructor( 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(), ) } @@ -175,11 +179,15 @@ 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("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing @@ -188,12 +196,14 @@ private constructor( 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) @@ -203,17 +213,18 @@ 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 { limitExceeded = data.limitExceeded - list = data.list + list = data.list.map { it.toMutableList() } references = data.references additionalProperties = data.additionalProperties.toMutableMap() } @@ -226,7 +237,22 @@ private constructor( fun list(list: List) = list(JsonField.of(list)) - 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)) @@ -255,9 +281,9 @@ private constructor( fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), additionalProperties.toImmutable(), ) } 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 1b46e7b..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 @@ -4,15 +4,18 @@ package org.onebusaway.models import java.util.Objects import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun stopId(): String = stopId @@ -20,9 +23,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -38,8 +41,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [StopRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var stopId: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() @@ -154,7 +158,7 @@ constructor( fun build(): StopRetrieveParams = StopRetrieveParams( - checkNotNull(stopId) { "`stopId` is required but was not set" }, + checkRequired("stopId", stopId), additionalHeaders.build(), additionalQueryParams.build(), ) 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 0888b1b..1650ec1 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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -171,9 +175,11 @@ private constructor( 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 @@ -182,11 +188,13 @@ private constructor( 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) @@ -196,10 +204,11 @@ 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 @@ -240,8 +249,8 @@ private constructor( fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -250,21 +259,12 @@ private constructor( class Entry @JsonCreator private constructor( - @JsonProperty("code") - @ExcludeMissing - private val code: JsonField = JsonMissing.of(), - @JsonProperty("direction") - @ExcludeMissing - private val direction: JsonField = JsonMissing.of(), @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(), @@ -280,6 +280,15 @@ private constructor( @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("locationType") + @ExcludeMissing + private val locationType: JsonField = JsonMissing.of(), @JsonProperty("wheelchairBoarding") @ExcludeMissing private val wheelchairBoarding: JsonField = JsonMissing.of(), @@ -287,18 +296,10 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { - 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 lon(): Double = lon.getRequired("lon") fun name(): String = name.getRequired("name") @@ -309,32 +310,48 @@ 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 locationType(): Optional = + Optional.ofNullable(locationType.getNullable("locationType")) + 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("lon") @ExcludeMissing fun _lon(): JsonField = lon - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("locationType") @ExcludeMissing fun _locationType() = locationType + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("routeIds") + @ExcludeMissing + fun _routeIds(): JsonField> = routeIds - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("staticRouteIds") + @ExcludeMissing + fun _staticRouteIds(): JsonField> = staticRouteIds - @JsonProperty("parent") @ExcludeMissing fun _parent() = parent + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("routeIds") @ExcludeMissing fun _routeIds() = routeIds + @JsonProperty("direction") + @ExcludeMissing + fun _direction(): JsonField = direction - @JsonProperty("staticRouteIds") @ExcludeMissing fun _staticRouteIds() = staticRouteIds + @JsonProperty("locationType") + @ExcludeMissing + fun _locationType(): JsonField = locationType @JsonProperty("wheelchairBoarding") @ExcludeMissing - fun _wheelchairBoarding() = wheelchairBoarding + fun _wheelchairBoarding(): JsonField = wheelchairBoarding @JsonAnyGetter @ExcludeMissing @@ -343,20 +360,22 @@ private constructor( 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() + lon() + name() + parent() + routeIds() + staticRouteIds() + code() + direction() + locationType() + wheelchairBoarding() + validated = true } fun toBuilder() = Builder().from(this) @@ -366,45 +385,38 @@ 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 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 { - code = entry.code - direction = entry.direction id = entry.id lat = entry.lat - locationType = entry.locationType lon = entry.lon name = entry.name parent = entry.parent - routeIds = entry.routeIds - staticRouteIds = entry.staticRouteIds + routeIds = entry.routeIds.map { it.toMutableList() } + staticRouteIds = entry.staticRouteIds.map { it.toMutableList() } + code = entry.code + direction = entry.direction + locationType = entry.locationType wheelchairBoarding = entry.wheelchairBoarding additionalProperties = entry.additionalProperties.toMutableMap() } - 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 id(id: String) = id(JsonField.of(id)) fun id(id: JsonField) = apply { this.id = id } @@ -413,12 +425,6 @@ private constructor( fun lat(lat: JsonField) = apply { this.lat = lat } - fun locationType(locationType: Long) = locationType(JsonField.of(locationType)) - - fun locationType(locationType: JsonField) = apply { - this.locationType = locationType - } - fun lon(lon: Double) = lon(JsonField.of(lon)) fun lon(lon: JsonField) = apply { this.lon = lon } @@ -433,13 +439,55 @@ private constructor( fun routeIds(routeIds: List) = routeIds(JsonField.of(routeIds)) - 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)) 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 locationType(locationType: Long) = locationType(JsonField.of(locationType)) + + fun locationType(locationType: JsonField) = apply { + this.locationType = locationType } fun wheelchairBoarding(wheelchairBoarding: String) = @@ -473,16 +521,16 @@ private constructor( fun build(): Entry = Entry( + checkRequired("id", id), + checkRequired("lat", lat), + 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(), ) @@ -493,17 +541,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && code == other.code && direction == other.direction && id == other.id && lat == other.lat && locationType == other.locationType && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is Entry && id == other.id && lat == other.lat && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && code == other.code && direction == other.direction && locationType == other.locationType && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(code, direction, id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, wheelchairBoarding, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(id, lat, lon, name, parent, routeIds, staticRouteIds, code, direction, locationType, wheelchairBoarding, additionalProperties) } /* spotless:on */ 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, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, code=$code, direction=$direction, locationType=$locationType, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { 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 aa654da..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 @@ -4,15 +4,18 @@ package org.onebusaway.models import java.util.Objects import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun agencyId(): String = agencyId @@ -20,9 +23,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -38,8 +41,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [StopsForAgencyListParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var agencyId: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() @@ -154,7 +158,7 @@ constructor( fun build(): StopsForAgencyListParams = StopsForAgencyListParams( - checkNotNull(agencyId) { "`agencyId` is required but was not set" }, + checkRequired("agencyId", agencyId), additionalHeaders.build(), additionalQueryParams.build(), ) 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 ca78719..10aed87 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 @@ -13,6 +13,7 @@ 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 @@ -31,15 +32,15 @@ private constructor( @JsonProperty("limitExceeded") @ExcludeMissing private val limitExceeded: JsonField = JsonMissing.of(), - @JsonProperty("outOfRange") - @ExcludeMissing - private val outOfRange: 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(), ) { @@ -53,27 +54,31 @@ private constructor( fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") - fun outOfRange(): Optional = Optional.ofNullable(outOfRange.getNullable("outOfRange")) - fun list(): List = list.getRequired("list") fun references(): References = references.getRequired("references") - @JsonProperty("code") @ExcludeMissing fun _code() = code + fun outOfRange(): Optional = Optional.ofNullable(outOfRange.getNullable("outOfRange")) - @JsonProperty("currentTime") @ExcludeMissing fun _currentTime() = currentTime + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("text") @ExcludeMissing fun _text() = text + @JsonProperty("currentTime") @ExcludeMissing fun _currentTime(): JsonField = currentTime - @JsonProperty("version") @ExcludeMissing fun _version() = version + @JsonProperty("text") @ExcludeMissing fun _text(): JsonField = text - @JsonProperty("limitExceeded") @ExcludeMissing fun _limitExceeded() = limitExceeded + @JsonProperty("version") @ExcludeMissing fun _version(): JsonField = version - @JsonProperty("outOfRange") @ExcludeMissing fun _outOfRange() = outOfRange + @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(): JsonField = references - @JsonProperty("references") @ExcludeMissing fun _references() = references + @JsonProperty("outOfRange") @ExcludeMissing fun _outOfRange(): JsonField = outOfRange @JsonAnyGetter @ExcludeMissing @@ -90,17 +95,19 @@ private constructor( 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) @@ -110,16 +117,17 @@ 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 @@ -129,9 +137,9 @@ private constructor( text = stopsForAgencyListResponse.text version = stopsForAgencyListResponse.version limitExceeded = stopsForAgencyListResponse.limitExceeded - outOfRange = stopsForAgencyListResponse.outOfRange - list = stopsForAgencyListResponse.list + list = stopsForAgencyListResponse.list.map { it.toMutableList() } references = stopsForAgencyListResponse.references + outOfRange = stopsForAgencyListResponse.outOfRange additionalProperties = stopsForAgencyListResponse.additionalProperties.toMutableMap() } @@ -157,18 +165,33 @@ private constructor( this.limitExceeded = limitExceeded } - fun outOfRange(outOfRange: Boolean) = outOfRange(JsonField.of(outOfRange)) - - fun outOfRange(outOfRange: JsonField) = apply { this.outOfRange = outOfRange } - fun list(list: List) = list(JsonField.of(list)) - 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)) 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() putAllAdditionalProperties(additionalProperties) @@ -190,14 +213,14 @@ private constructor( 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(), ) } @@ -206,17 +229,8 @@ private constructor( class List @JsonCreator private constructor( - @JsonProperty("code") - @ExcludeMissing - private val code: JsonField = JsonMissing.of(), - @JsonProperty("direction") - @ExcludeMissing - private val direction: JsonField = JsonMissing.of(), @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 @@ -230,6 +244,15 @@ private constructor( @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("locationType") + @ExcludeMissing + private val locationType: JsonField = JsonMissing.of(), @JsonProperty("wheelchairBoarding") @ExcludeMissing private val wheelchairBoarding: JsonField = JsonMissing.of(), @@ -237,17 +260,10 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { - 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 lon(): Double = lon.getRequired("lon") fun name(): String = name.getRequired("name") @@ -258,32 +274,45 @@ 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 locationType(): Optional = + Optional.ofNullable(locationType.getNullable("locationType")) + 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("lon") @ExcludeMissing fun _lon(): JsonField = lon - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("locationType") @ExcludeMissing fun _locationType() = locationType + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("routeIds") + @ExcludeMissing + fun _routeIds(): JsonField> = routeIds - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("staticRouteIds") + @ExcludeMissing + fun _staticRouteIds(): JsonField> = staticRouteIds - @JsonProperty("parent") @ExcludeMissing fun _parent() = parent + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("routeIds") @ExcludeMissing fun _routeIds() = routeIds + @JsonProperty("direction") @ExcludeMissing fun _direction(): JsonField = direction - @JsonProperty("staticRouteIds") @ExcludeMissing fun _staticRouteIds() = staticRouteIds + @JsonProperty("locationType") + @ExcludeMissing + fun _locationType(): JsonField = locationType @JsonProperty("wheelchairBoarding") @ExcludeMissing - fun _wheelchairBoarding() = wheelchairBoarding + fun _wheelchairBoarding(): JsonField = wheelchairBoarding @JsonAnyGetter @ExcludeMissing @@ -292,20 +321,22 @@ private constructor( 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() + lon() + name() + parent() + routeIds() + staticRouteIds() + code() + direction() + locationType() + wheelchairBoarding() + validated = true } fun toBuilder() = Builder().from(this) @@ -315,45 +346,38 @@ 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 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 { - code = list.code - direction = list.direction id = list.id lat = list.lat - locationType = list.locationType lon = list.lon name = list.name parent = list.parent - routeIds = list.routeIds - staticRouteIds = list.staticRouteIds + routeIds = list.routeIds.map { it.toMutableList() } + staticRouteIds = list.staticRouteIds.map { it.toMutableList() } + code = list.code + direction = list.direction + locationType = list.locationType wheelchairBoarding = list.wheelchairBoarding additionalProperties = list.additionalProperties.toMutableMap() } - 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 id(id: String) = id(JsonField.of(id)) fun id(id: JsonField) = apply { this.id = id } @@ -362,12 +386,6 @@ private constructor( fun lat(lat: JsonField) = apply { this.lat = lat } - fun locationType(locationType: Long) = locationType(JsonField.of(locationType)) - - fun locationType(locationType: JsonField) = apply { - this.locationType = locationType - } - fun lon(lon: Double) = lon(JsonField.of(lon)) fun lon(lon: JsonField) = apply { this.lon = lon } @@ -382,13 +400,55 @@ private constructor( fun routeIds(routeIds: List) = routeIds(JsonField.of(routeIds)) - 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)) 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 locationType(locationType: Long) = locationType(JsonField.of(locationType)) + + fun locationType(locationType: JsonField) = apply { + this.locationType = locationType } fun wheelchairBoarding(wheelchairBoarding: String) = @@ -419,16 +479,16 @@ private constructor( fun build(): List = List( + checkRequired("id", id), + checkRequired("lat", lat), + 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(), ) @@ -439,17 +499,17 @@ private constructor( return true } - return /* spotless:off */ other is List && code == other.code && direction == other.direction && id == other.id && lat == other.lat && locationType == other.locationType && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is List && id == other.id && lat == other.lat && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && code == other.code && direction == other.direction && locationType == other.locationType && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(code, direction, id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, wheelchairBoarding, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(id, lat, lon, name, parent, routeIds, staticRouteIds, code, direction, locationType, wheelchairBoarding, additionalProperties) } /* spotless:on */ 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, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, code=$code, direction=$direction, locationType=$locationType, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -457,15 +517,15 @@ private constructor( return true } - return /* spotless:off */ other is StopsForAgencyListResponse && code == other.code && currentTime == other.currentTime && text == other.text && version == other.version && limitExceeded == other.limitExceeded && outOfRange == other.outOfRange && list == other.list && references == other.references && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, limitExceeded, outOfRange, list, references, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(code, currentTime, text, version, limitExceeded, list, references, outOfRange, additionalProperties) } /* spotless:on */ 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 1da3e8f..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 @@ -5,11 +5,14 @@ package org.onebusaway.models import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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?, @@ -18,7 +21,7 @@ constructor( private val radius: Double?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun lat(): Double = lat @@ -40,10 +43,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + 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())) } @@ -62,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 @@ -91,16 +94,40 @@ 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 } + + /** The radius in meters to search within */ + fun radius(radius: Double) = radius(radius as Double?) /** The radius in meters to search within */ - fun radius(radius: Double) = apply { this.radius = radius } + @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() @@ -202,8 +229,8 @@ constructor( 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, 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 37e8d78..9ba8dc7 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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -160,35 +164,41 @@ private constructor( @JsonProperty("limitExceeded") @ExcludeMissing private val limitExceeded: JsonField = JsonMissing.of(), - @JsonProperty("outOfRange") - @ExcludeMissing - private val outOfRange: 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(), ) { fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") - fun outOfRange(): Optional = - Optional.ofNullable(outOfRange.getNullable("outOfRange")) - fun list(): 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 @@ -197,13 +207,15 @@ private constructor( 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) @@ -213,20 +225,21 @@ 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 { limitExceeded = data.limitExceeded - outOfRange = data.outOfRange - list = data.list + list = data.list.map { it.toMutableList() } references = data.references + outOfRange = data.outOfRange additionalProperties = data.additionalProperties.toMutableMap() } @@ -236,13 +249,24 @@ private constructor( this.limitExceeded = limitExceeded } - fun outOfRange(outOfRange: Boolean) = outOfRange(JsonField.of(outOfRange)) - - fun outOfRange(outOfRange: JsonField) = apply { this.outOfRange = outOfRange } - fun list(list: List) = list(JsonField.of(list)) - 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)) @@ -250,6 +274,10 @@ private constructor( 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() putAllAdditionalProperties(additionalProperties) @@ -271,10 +299,10 @@ private constructor( 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(), ) } @@ -283,21 +311,12 @@ private constructor( class List @JsonCreator private constructor( - @JsonProperty("code") - @ExcludeMissing - private val code: JsonField = JsonMissing.of(), - @JsonProperty("direction") - @ExcludeMissing - private val direction: JsonField = JsonMissing.of(), @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(), @@ -313,6 +332,15 @@ private constructor( @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("locationType") + @ExcludeMissing + private val locationType: JsonField = JsonMissing.of(), @JsonProperty("wheelchairBoarding") @ExcludeMissing private val wheelchairBoarding: JsonField = JsonMissing.of(), @@ -320,18 +348,10 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { - 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 lon(): Double = lon.getRequired("lon") fun name(): String = name.getRequired("name") @@ -342,32 +362,48 @@ 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 locationType(): Optional = + Optional.ofNullable(locationType.getNullable("locationType")) + 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("lon") @ExcludeMissing fun _lon(): JsonField = lon - @JsonProperty("lat") @ExcludeMissing fun _lat() = lat + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name - @JsonProperty("locationType") @ExcludeMissing fun _locationType() = locationType + @JsonProperty("parent") @ExcludeMissing fun _parent(): JsonField = parent - @JsonProperty("lon") @ExcludeMissing fun _lon() = lon + @JsonProperty("routeIds") + @ExcludeMissing + fun _routeIds(): JsonField> = routeIds - @JsonProperty("name") @ExcludeMissing fun _name() = name + @JsonProperty("staticRouteIds") + @ExcludeMissing + fun _staticRouteIds(): JsonField> = staticRouteIds - @JsonProperty("parent") @ExcludeMissing fun _parent() = parent + @JsonProperty("code") @ExcludeMissing fun _code(): JsonField = code - @JsonProperty("routeIds") @ExcludeMissing fun _routeIds() = routeIds + @JsonProperty("direction") + @ExcludeMissing + fun _direction(): JsonField = direction - @JsonProperty("staticRouteIds") @ExcludeMissing fun _staticRouteIds() = staticRouteIds + @JsonProperty("locationType") + @ExcludeMissing + fun _locationType(): JsonField = locationType @JsonProperty("wheelchairBoarding") @ExcludeMissing - fun _wheelchairBoarding() = wheelchairBoarding + fun _wheelchairBoarding(): JsonField = wheelchairBoarding @JsonAnyGetter @ExcludeMissing @@ -376,20 +412,22 @@ private constructor( 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() + lon() + name() + parent() + routeIds() + staticRouteIds() + code() + direction() + locationType() + wheelchairBoarding() + validated = true } fun toBuilder() = Builder().from(this) @@ -399,45 +437,38 @@ 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 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 { - code = list.code - direction = list.direction id = list.id lat = list.lat - locationType = list.locationType lon = list.lon name = list.name parent = list.parent - routeIds = list.routeIds - staticRouteIds = list.staticRouteIds + routeIds = list.routeIds.map { it.toMutableList() } + staticRouteIds = list.staticRouteIds.map { it.toMutableList() } + code = list.code + direction = list.direction + locationType = list.locationType wheelchairBoarding = list.wheelchairBoarding additionalProperties = list.additionalProperties.toMutableMap() } - 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 id(id: String) = id(JsonField.of(id)) fun id(id: JsonField) = apply { this.id = id } @@ -446,12 +477,6 @@ private constructor( fun lat(lat: JsonField) = apply { this.lat = lat } - fun locationType(locationType: Long) = locationType(JsonField.of(locationType)) - - fun locationType(locationType: JsonField) = apply { - this.locationType = locationType - } - fun lon(lon: Double) = lon(JsonField.of(lon)) fun lon(lon: JsonField) = apply { this.lon = lon } @@ -466,13 +491,55 @@ private constructor( fun routeIds(routeIds: List) = routeIds(JsonField.of(routeIds)) - 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)) 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 locationType(locationType: Long) = locationType(JsonField.of(locationType)) + + fun locationType(locationType: JsonField) = apply { + this.locationType = locationType } fun wheelchairBoarding(wheelchairBoarding: String) = @@ -506,16 +573,16 @@ private constructor( fun build(): List = List( + checkRequired("id", id), + checkRequired("lat", lat), + 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(), ) @@ -526,17 +593,17 @@ private constructor( return true } - return /* spotless:off */ other is List && code == other.code && direction == other.direction && id == other.id && lat == other.lat && locationType == other.locationType && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ + return /* spotless:off */ other is List && id == other.id && lat == other.lat && lon == other.lon && name == other.name && parent == other.parent && routeIds == other.routeIds && staticRouteIds == other.staticRouteIds && code == other.code && direction == other.direction && locationType == other.locationType && wheelchairBoarding == other.wheelchairBoarding && additionalProperties == other.additionalProperties /* spotless:on */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(code, direction, id, lat, locationType, lon, name, parent, routeIds, staticRouteIds, wheelchairBoarding, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(id, lat, lon, name, parent, routeIds, staticRouteIds, code, direction, locationType, wheelchairBoarding, additionalProperties) } /* spotless:on */ 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, lon=$lon, name=$name, parent=$parent, routeIds=$routeIds, staticRouteIds=$staticRouteIds, code=$code, direction=$direction, locationType=$locationType, wheelchairBoarding=$wheelchairBoarding, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -544,17 +611,17 @@ private constructor( return true } - return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && outOfRange == other.outOfRange && list == other.list && references == other.references && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(limitExceeded, outOfRange, list, references, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, references, outOfRange, additionalProperties) } /* spotless:on */ 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 { 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 7dcf9a4..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 @@ -5,17 +5,20 @@ package org.onebusaway.models import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun routeId(): String = routeId @@ -29,10 +32,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + 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())) } @@ -54,8 +56,9 @@ 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 @@ -75,12 +78,24 @@ constructor( 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() @@ -182,7 +197,7 @@ constructor( fun build(): StopsForRouteListParams = StopsForRouteListParams( - checkNotNull(routeId) { "`routeId` is required but was not set" }, + checkRequired("routeId", routeId), includePolylines, time, additionalHeaders.build(), 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 e42c0f0..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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -171,9 +175,11 @@ private constructor( 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 @@ -182,11 +188,13 @@ private constructor( 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) @@ -196,10 +204,11 @@ 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 @@ -240,8 +249,8 @@ private constructor( fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -277,13 +286,19 @@ 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 @@ -292,13 +307,15 @@ private constructor( 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) @@ -308,27 +325,41 @@ 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 { - polylines = entry.polylines + polylines = entry.polylines.map { it.toMutableList() } routeId = entry.routeId - stopGroupings = entry.stopGroupings - stopIds = entry.stopIds + stopGroupings = entry.stopGroupings.map { it.toMutableList() } + stopIds = entry.stopIds.map { it.toMutableList() } additionalProperties = entry.additionalProperties.toMutableMap() } fun polylines(polylines: List) = polylines(JsonField.of(polylines)) 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)) @@ -339,12 +370,40 @@ private constructor( stopGroupings(JsonField.of(stopGroupings)) 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)) - 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() @@ -370,10 +429,10 @@ private constructor( 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(), ) } @@ -401,11 +460,11 @@ 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 @@ -414,12 +473,14 @@ private constructor( 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) @@ -429,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() @@ -535,13 +597,17 @@ 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 @@ -550,13 +616,15 @@ private constructor( 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) @@ -566,20 +634,21 @@ 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 { id = stopGrouping.id name = stopGrouping.name - polylines = stopGrouping.polylines - stopIds = stopGrouping.stopIds + polylines = stopGrouping.polylines.map { it.toMutableList() } + stopIds = stopGrouping.stopIds.map { it.toMutableList() } additionalProperties = stopGrouping.additionalProperties.toMutableMap() } @@ -594,12 +663,40 @@ private constructor( fun polylines(polylines: List) = polylines(JsonField.of(polylines)) 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)) - 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() @@ -627,8 +724,8 @@ private constructor( 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(), ) } @@ -657,11 +754,13 @@ 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 @@ -670,12 +769,14 @@ private constructor( 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) @@ -685,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() @@ -696,7 +798,7 @@ private constructor( @JvmSynthetic internal fun from(name: Name) = apply { this.name = name.name - names = name.names + names = name.names.map { it.toMutableList() } type = name.type additionalProperties = name.additionalProperties.toMutableMap() } @@ -707,7 +809,22 @@ private constructor( fun names(names: List) = names(JsonField.of(names)) - 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)) @@ -738,7 +855,7 @@ private constructor( fun build(): Name = Name( name, - names.map { it.toImmutable() }, + (names ?: JsonMissing.of()).map { it.toImmutable() }, type, additionalProperties.toImmutable(), ) @@ -787,11 +904,15 @@ 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 @@ -800,12 +921,14 @@ private constructor( 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) @@ -815,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() 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 d51762c..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 @@ -5,11 +5,14 @@ package org.onebusaway.models import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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?, @@ -18,7 +21,7 @@ constructor( private val time: Long?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun tripId(): String = tripId @@ -43,10 +46,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + 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())) } @@ -71,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 @@ -101,25 +104,78 @@ 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 } + + /** + * 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). */ - fun includeTrip(includeTrip: Boolean) = apply { this.includeTrip = includeTrip } + @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 } + fun serviceDate(serviceDate: Long?) = apply { this.serviceDate = serviceDate } + + /** Service date for the trip as Unix time in milliseconds (optional). */ + 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() @@ -221,7 +277,7 @@ constructor( fun build(): TripDetailRetrieveParams = TripDetailRetrieveParams( - checkNotNull(tripId) { "`tripId` is required but was not set" }, + checkRequired("tripId", tripId), includeSchedule, includeStatus, includeTrip, 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 4ffb4c1..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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -171,9 +175,11 @@ private constructor( 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 @@ -182,11 +188,13 @@ private constructor( 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) @@ -196,10 +204,11 @@ 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 @@ -240,8 +249,8 @@ private constructor( fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -250,6 +259,9 @@ private constructor( class Entry @JsonCreator private constructor( + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), @JsonProperty("frequency") @ExcludeMissing private val frequency: JsonField = JsonMissing.of(), @@ -265,13 +277,12 @@ private constructor( @JsonProperty("status") @ExcludeMissing private val status: JsonField = JsonMissing.of(), - @JsonProperty("tripId") - @ExcludeMissing - private val tripId: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { + fun tripId(): String = tripId.getRequired("tripId") + fun frequency(): Optional = Optional.ofNullable(frequency.getNullable("frequency")) @@ -286,19 +297,25 @@ 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 @@ -307,15 +324,17 @@ private constructor( 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) @@ -325,28 +344,35 @@ 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 { + tripId = entry.tripId frequency = entry.frequency schedule = entry.schedule serviceDate = entry.serviceDate - situationIds = entry.situationIds + situationIds = entry.situationIds.map { it.toMutableList() } status = entry.status - tripId = entry.tripId 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)) fun frequency(frequency: JsonField) = apply { this.frequency = frequency } @@ -364,17 +390,26 @@ private constructor( situationIds(JsonField.of(situationIds)) 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)) 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 additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -399,12 +434,12 @@ private constructor( fun build(): Entry = Entry( + checkRequired("tripId", tripId), frequency, schedule, serviceDate, - situationIds.map { it.toImmutable() }, + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, status, - tripId, additionalProperties.toImmutable(), ) } @@ -413,9 +448,6 @@ private constructor( class Schedule @JsonCreator private constructor( - @JsonProperty("frequency") - @ExcludeMissing - private val frequency: JsonField = JsonMissing.of(), @JsonProperty("nextTripId") @ExcludeMissing private val nextTripId: JsonField = JsonMissing.of(), @@ -428,13 +460,13 @@ private constructor( @JsonProperty("timeZone") @ExcludeMissing private val timeZone: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - fun nextTripId(): String = nextTripId.getRequired("nextTripId") fun previousTripId(): String = previousTripId.getRequired("previousTripId") @@ -443,17 +475,28 @@ 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 @@ -462,14 +505,16 @@ private constructor( 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) @@ -479,31 +524,26 @@ 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 { - frequency = schedule.frequency nextTripId = schedule.nextTripId previousTripId = schedule.previousTripId - stopTimes = schedule.stopTimes + stopTimes = schedule.stopTimes.map { it.toMutableList() } timeZone = schedule.timeZone + frequency = schedule.frequency additionalProperties = schedule.additionalProperties.toMutableMap() } - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - fun nextTripId(nextTripId: String) = nextTripId(JsonField.of(nextTripId)) fun nextTripId(nextTripId: JsonField) = apply { @@ -520,13 +560,34 @@ private constructor( fun stopTimes(stopTimes: List) = stopTimes(JsonField.of(stopTimes)) 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)) 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() putAllAdditionalProperties(additionalProperties) @@ -551,11 +612,11 @@ private constructor( 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(), ) } @@ -604,23 +665,29 @@ 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 @@ -629,15 +696,17 @@ private constructor( 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) @@ -647,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() @@ -764,17 +834,17 @@ private constructor( return true } - return /* spotless:off */ other is Schedule && frequency == other.frequency && nextTripId == other.nextTripId && previousTripId == other.previousTripId && stopTimes == other.stopTimes && timeZone == other.timeZone && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(frequency, nextTripId, previousTripId, stopTimes, timeZone, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(nextTripId, previousTripId, stopTimes, timeZone, frequency, additionalProperties) } /* spotless:on */ 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}" } @NoAutoDetect @@ -790,36 +860,18 @@ private constructor( @JsonProperty("closestStop") @ExcludeMissing private val closestStop: JsonField = JsonMissing.of(), - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing - private val closestStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("distanceAlongTrip") @ExcludeMissing private val distanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("frequency") - @ExcludeMissing - private val frequency: JsonField = JsonMissing.of(), @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownLocation") - @ExcludeMissing - private val lastKnownLocation: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - private val lastKnownOrientation: JsonField = JsonMissing.of(), @JsonProperty("lastLocationUpdateTime") @ExcludeMissing private val lastLocationUpdateTime: JsonField = JsonMissing.of(), @JsonProperty("lastUpdateTime") @ExcludeMissing private val lastUpdateTime: JsonField = JsonMissing.of(), - @JsonProperty("nextStop") - @ExcludeMissing - private val nextStop: JsonField = JsonMissing.of(), - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - private val nextStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("occupancyCapacity") @ExcludeMissing private val occupancyCapacity: JsonField = JsonMissing.of(), @@ -829,36 +881,54 @@ private constructor( @JsonProperty("occupancyStatus") @ExcludeMissing private val occupancyStatus: JsonField = JsonMissing.of(), - @JsonProperty("orientation") - @ExcludeMissing - private val orientation: JsonField = JsonMissing.of(), @JsonProperty("phase") @ExcludeMissing private val phase: JsonField = JsonMissing.of(), - @JsonProperty("position") - @ExcludeMissing - private val position: JsonField = JsonMissing.of(), @JsonProperty("predicted") @ExcludeMissing private val predicted: JsonField = JsonMissing.of(), @JsonProperty("scheduleDeviation") @ExcludeMissing private val scheduleDeviation: JsonField = JsonMissing.of(), - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - private val scheduledDistanceAlongTrip: 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("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), @JsonProperty("vehicleId") @ExcludeMissing private val vehicleId: JsonField = JsonMissing.of(), @@ -875,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. @@ -898,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. */ @@ -915,17 +966,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") @@ -935,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") @@ -954,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") @@ -980,141 +999,212 @@ private constructor( 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 - - /** Index of the active trip into the sequence of trips for the active block. */ - @JsonProperty("blockTripSequence") - @ExcludeMissing - fun _blockTripSequence() = 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") - @ExcludeMissing - fun _closestStopTimeOffset() = closestStopTimeOffset - - /** - * Distance, in meters, the transit vehicle has progressed along the active trip. - */ - @JsonProperty("distanceAlongTrip") - @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip + fun closestStopTimeOffset(): Optional = + Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency - - /** - * Last known distance along the trip received in real-time from the transit - * vehicle. - */ - @JsonProperty("lastKnownDistanceAlongTrip") - @ExcludeMissing - fun _lastKnownDistanceAlongTrip() = lastKnownDistanceAlongTrip + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun _lastKnownLocation() = lastKnownLocation + fun lastKnownLocation(): Optional = + Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) /** Last known orientation value received in real-time from the transit vehicle. */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun _lastKnownOrientation() = lastKnownOrientation + 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")) /** - * Timestamp of the last known real-time location update from the transit vehicle. + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). */ - @JsonProperty("lastLocationUpdateTime") - @ExcludeMissing - fun _lastLocationUpdateTime() = lastLocationUpdateTime + fun nextStopTimeOffset(): Optional = + Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) - /** Timestamp of the last known real-time update from the transit vehicle. */ - @JsonProperty("lastUpdateTime") + /** 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 _lastUpdateTime() = lastUpdateTime + fun _activeTripId(): JsonField = activeTripId - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") @ExcludeMissing fun _nextStop() = nextStop + /** Index of the active trip into the sequence of trips for the active block. */ + @JsonProperty("blockTripSequence") + @ExcludeMissing + fun _blockTripSequence(): JsonField = blockTripSequence + + /** ID of the closest stop to the current location of the transit vehicle. */ + @JsonProperty("closestStop") + @ExcludeMissing + fun _closestStop(): JsonField = closestStop /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). + * Distance, in meters, the transit vehicle has progressed along the active trip. */ - @JsonProperty("nextStopTimeOffset") + @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _nextStopTimeOffset() = nextStopTimeOffset + fun _distanceAlongTrip(): JsonField = distanceAlongTrip + + /** + * Last known distance along the trip received in real-time from the transit + * vehicle. + */ + @JsonProperty("lastKnownDistanceAlongTrip") + @ExcludeMissing + fun _lastKnownDistanceAlongTrip(): JsonField = lastKnownDistanceAlongTrip + + /** + * Timestamp of the last known real-time location update from the transit vehicle. + */ + @JsonProperty("lastLocationUpdateTime") + @ExcludeMissing + fun _lastLocationUpdateTime(): JsonField = lastLocationUpdateTime + + /** Timestamp of the last known real-time update from the transit vehicle. */ + @JsonProperty("lastUpdateTime") + @ExcludeMissing + 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 @@ -1123,36 +1213,38 @@ private constructor( 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) @@ -1162,34 +1254,35 @@ 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() @@ -1198,29 +1291,29 @@ private constructor( activeTripId = status.activeTripId blockTripSequence = status.blockTripSequence closestStop = status.closestStop - closestStopTimeOffset = status.closestStopTimeOffset distanceAlongTrip = status.distanceAlongTrip - frequency = status.frequency lastKnownDistanceAlongTrip = status.lastKnownDistanceAlongTrip - lastKnownLocation = status.lastKnownLocation - lastKnownOrientation = status.lastKnownOrientation lastLocationUpdateTime = status.lastLocationUpdateTime lastUpdateTime = status.lastUpdateTime - nextStop = status.nextStop - nextStopTimeOffset = status.nextStopTimeOffset occupancyCapacity = status.occupancyCapacity occupancyCount = status.occupancyCount occupancyStatus = status.occupancyStatus - orientation = status.orientation phase = status.phase - position = status.position predicted = status.predicted scheduleDeviation = status.scheduleDeviation - scheduledDistanceAlongTrip = status.scheduledDistanceAlongTrip serviceDate = status.serviceDate - situationIds = status.situationIds this.status = status.status 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() } @@ -1251,21 +1344,6 @@ private constructor( 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). - */ - fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { - this.closestStopTimeOffset = closestStopTimeOffset - } - /** * Distance, in meters, the transit vehicle has progressed along the active * trip. @@ -1281,14 +1359,6 @@ private constructor( 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. */ - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1305,28 +1375,6 @@ private constructor( 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. */ - 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 - } - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1351,27 +1399,6 @@ private constructor( 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. */ - 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 - } - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) @@ -1399,26 +1426,12 @@ private constructor( 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. */ - 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. */ 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. */ - 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)) @@ -1442,22 +1455,6 @@ private constructor( 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. - */ - 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. @@ -1472,15 +1469,6 @@ private constructor( 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. */ - fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds - } - /** Current status modifiers for the trip. */ fun status(status: String) = status(JsonField.of(status)) @@ -1496,6 +1484,125 @@ private constructor( 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)) @@ -1528,32 +1635,32 @@ private constructor( 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(), ) @@ -1581,10 +1688,10 @@ 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 @@ -1593,11 +1700,13 @@ private constructor( 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) @@ -1607,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() @@ -1704,10 +1814,10 @@ 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 @@ -1716,11 +1826,13 @@ private constructor( 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) @@ -1730,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() @@ -1809,17 +1922,17 @@ private constructor( return true } - return /* spotless:off */ other is Status && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && closestStopTimeOffset == other.closestStopTimeOffset && distanceAlongTrip == other.distanceAlongTrip && frequency == other.frequency && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && orientation == other.orientation && phase == other.phase && position == other.position && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && serviceDate == other.serviceDate && situationIds == other.situationIds && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && vehicleId == other.vehicleId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { 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) } + 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 = 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 { @@ -1827,17 +1940,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && frequency == other.frequency && schedule == other.schedule && serviceDate == other.serviceDate && situationIds == other.situationIds && status == other.status && tripId == other.tripId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(frequency, schedule, serviceDate, situationIds, status, tripId, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(tripId, frequency, schedule, serviceDate, situationIds, status, additionalProperties) } /* spotless:on */ 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 { 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 80e1fe0..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 @@ -5,11 +5,14 @@ package org.onebusaway.models import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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?, @@ -17,7 +20,7 @@ constructor( private val time: Long?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun vehicleId(): String = vehicleId @@ -46,10 +49,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + 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())) } @@ -73,8 +75,9 @@ 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 @@ -101,24 +104,73 @@ 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() @@ -220,7 +272,7 @@ constructor( fun build(): TripForVehicleRetrieveParams = TripForVehicleRetrieveParams( - checkNotNull(vehicleId) { "`vehicleId` is required but was not set" }, + checkRequired("vehicleId", vehicleId), includeSchedule, includeStatus, includeTrip, 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 58341fb..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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -145,11 +149,11 @@ private constructor( 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(), ) } @@ -172,9 +176,11 @@ private constructor( 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 @@ -183,11 +189,13 @@ private constructor( 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) @@ -197,10 +205,11 @@ 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 @@ -241,8 +250,8 @@ private constructor( fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -251,6 +260,9 @@ private constructor( class Entry @JsonCreator private constructor( + @JsonProperty("tripId") + @ExcludeMissing + private val tripId: JsonField = JsonMissing.of(), @JsonProperty("frequency") @ExcludeMissing private val frequency: JsonField = JsonMissing.of(), @@ -266,13 +278,12 @@ private constructor( @JsonProperty("status") @ExcludeMissing private val status: JsonField = JsonMissing.of(), - @JsonProperty("tripId") - @ExcludeMissing - private val tripId: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { + fun tripId(): String = tripId.getRequired("tripId") + fun frequency(): Optional = Optional.ofNullable(frequency.getNullable("frequency")) @@ -287,19 +298,25 @@ 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 @@ -308,15 +325,17 @@ private constructor( 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) @@ -326,28 +345,35 @@ 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 { + tripId = entry.tripId frequency = entry.frequency schedule = entry.schedule serviceDate = entry.serviceDate - situationIds = entry.situationIds + situationIds = entry.situationIds.map { it.toMutableList() } status = entry.status - tripId = entry.tripId 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)) fun frequency(frequency: JsonField) = apply { this.frequency = frequency } @@ -365,17 +391,26 @@ private constructor( situationIds(JsonField.of(situationIds)) 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)) 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 additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -400,12 +435,12 @@ private constructor( fun build(): Entry = Entry( + checkRequired("tripId", tripId), frequency, schedule, serviceDate, - situationIds.map { it.toImmutable() }, + (situationIds ?: JsonMissing.of()).map { it.toImmutable() }, status, - tripId, additionalProperties.toImmutable(), ) } @@ -414,9 +449,6 @@ private constructor( class Schedule @JsonCreator private constructor( - @JsonProperty("frequency") - @ExcludeMissing - private val frequency: JsonField = JsonMissing.of(), @JsonProperty("nextTripId") @ExcludeMissing private val nextTripId: JsonField = JsonMissing.of(), @@ -429,13 +461,13 @@ private constructor( @JsonProperty("timeZone") @ExcludeMissing private val timeZone: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - fun nextTripId(): String = nextTripId.getRequired("nextTripId") fun previousTripId(): String = previousTripId.getRequired("previousTripId") @@ -444,17 +476,28 @@ 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 @@ -463,14 +506,16 @@ private constructor( 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) @@ -480,31 +525,26 @@ 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 { - frequency = schedule.frequency nextTripId = schedule.nextTripId previousTripId = schedule.previousTripId - stopTimes = schedule.stopTimes + stopTimes = schedule.stopTimes.map { it.toMutableList() } timeZone = schedule.timeZone + frequency = schedule.frequency additionalProperties = schedule.additionalProperties.toMutableMap() } - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - fun nextTripId(nextTripId: String) = nextTripId(JsonField.of(nextTripId)) fun nextTripId(nextTripId: JsonField) = apply { @@ -521,13 +561,34 @@ private constructor( fun stopTimes(stopTimes: List) = stopTimes(JsonField.of(stopTimes)) 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)) 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() putAllAdditionalProperties(additionalProperties) @@ -552,11 +613,11 @@ private constructor( 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(), ) } @@ -605,23 +666,29 @@ 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 @@ -630,15 +697,17 @@ private constructor( 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) @@ -648,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() @@ -765,17 +835,17 @@ private constructor( return true } - return /* spotless:off */ other is Schedule && frequency == other.frequency && nextTripId == other.nextTripId && previousTripId == other.previousTripId && stopTimes == other.stopTimes && timeZone == other.timeZone && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(frequency, nextTripId, previousTripId, stopTimes, timeZone, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(nextTripId, previousTripId, stopTimes, timeZone, frequency, additionalProperties) } /* spotless:on */ 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}" } @NoAutoDetect @@ -791,36 +861,18 @@ private constructor( @JsonProperty("closestStop") @ExcludeMissing private val closestStop: JsonField = JsonMissing.of(), - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing - private val closestStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("distanceAlongTrip") @ExcludeMissing private val distanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("frequency") - @ExcludeMissing - private val frequency: JsonField = JsonMissing.of(), @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownLocation") - @ExcludeMissing - private val lastKnownLocation: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - private val lastKnownOrientation: JsonField = JsonMissing.of(), @JsonProperty("lastLocationUpdateTime") @ExcludeMissing private val lastLocationUpdateTime: JsonField = JsonMissing.of(), @JsonProperty("lastUpdateTime") @ExcludeMissing private val lastUpdateTime: JsonField = JsonMissing.of(), - @JsonProperty("nextStop") - @ExcludeMissing - private val nextStop: JsonField = JsonMissing.of(), - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - private val nextStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("occupancyCapacity") @ExcludeMissing private val occupancyCapacity: JsonField = JsonMissing.of(), @@ -830,36 +882,54 @@ private constructor( @JsonProperty("occupancyStatus") @ExcludeMissing private val occupancyStatus: JsonField = JsonMissing.of(), - @JsonProperty("orientation") - @ExcludeMissing - private val orientation: JsonField = JsonMissing.of(), @JsonProperty("phase") @ExcludeMissing private val phase: JsonField = JsonMissing.of(), - @JsonProperty("position") - @ExcludeMissing - private val position: JsonField = JsonMissing.of(), @JsonProperty("predicted") @ExcludeMissing private val predicted: JsonField = JsonMissing.of(), @JsonProperty("scheduleDeviation") @ExcludeMissing private val scheduleDeviation: JsonField = JsonMissing.of(), - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - private val scheduledDistanceAlongTrip: 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("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), @JsonProperty("vehicleId") @ExcludeMissing private val vehicleId: JsonField = JsonMissing.of(), @@ -876,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. @@ -899,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. */ @@ -916,17 +967,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") @@ -936,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") @@ -955,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") @@ -981,141 +1000,212 @@ private constructor( 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 - - /** Index of the active trip into the sequence of trips for the active block. */ - @JsonProperty("blockTripSequence") - @ExcludeMissing - fun _blockTripSequence() = 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") - @ExcludeMissing - fun _closestStopTimeOffset() = closestStopTimeOffset - - /** - * Distance, in meters, the transit vehicle has progressed along the active trip. - */ - @JsonProperty("distanceAlongTrip") - @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip + fun closestStopTimeOffset(): Optional = + Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency - - /** - * Last known distance along the trip received in real-time from the transit - * vehicle. - */ - @JsonProperty("lastKnownDistanceAlongTrip") - @ExcludeMissing - fun _lastKnownDistanceAlongTrip() = lastKnownDistanceAlongTrip + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun _lastKnownLocation() = lastKnownLocation + fun lastKnownLocation(): Optional = + Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) /** Last known orientation value received in real-time from the transit vehicle. */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun _lastKnownOrientation() = lastKnownOrientation + 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")) /** - * Timestamp of the last known real-time location update from the transit vehicle. + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). */ - @JsonProperty("lastLocationUpdateTime") - @ExcludeMissing - fun _lastLocationUpdateTime() = lastLocationUpdateTime + fun nextStopTimeOffset(): Optional = + Optional.ofNullable(nextStopTimeOffset.getNullable("nextStopTimeOffset")) - /** Timestamp of the last known real-time update from the transit vehicle. */ - @JsonProperty("lastUpdateTime") + /** 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 _lastUpdateTime() = lastUpdateTime + fun _activeTripId(): JsonField = activeTripId - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") @ExcludeMissing fun _nextStop() = nextStop + /** Index of the active trip into the sequence of trips for the active block. */ + @JsonProperty("blockTripSequence") + @ExcludeMissing + fun _blockTripSequence(): JsonField = blockTripSequence + + /** ID of the closest stop to the current location of the transit vehicle. */ + @JsonProperty("closestStop") + @ExcludeMissing + fun _closestStop(): JsonField = closestStop /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). + * Distance, in meters, the transit vehicle has progressed along the active trip. */ - @JsonProperty("nextStopTimeOffset") + @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _nextStopTimeOffset() = nextStopTimeOffset + fun _distanceAlongTrip(): JsonField = distanceAlongTrip + + /** + * Last known distance along the trip received in real-time from the transit + * vehicle. + */ + @JsonProperty("lastKnownDistanceAlongTrip") + @ExcludeMissing + fun _lastKnownDistanceAlongTrip(): JsonField = lastKnownDistanceAlongTrip + + /** + * Timestamp of the last known real-time location update from the transit vehicle. + */ + @JsonProperty("lastLocationUpdateTime") + @ExcludeMissing + fun _lastLocationUpdateTime(): JsonField = lastLocationUpdateTime + + /** Timestamp of the last known real-time update from the transit vehicle. */ + @JsonProperty("lastUpdateTime") + @ExcludeMissing + 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 @@ -1124,36 +1214,38 @@ private constructor( 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) @@ -1163,34 +1255,35 @@ 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() @@ -1199,29 +1292,29 @@ private constructor( activeTripId = status.activeTripId blockTripSequence = status.blockTripSequence closestStop = status.closestStop - closestStopTimeOffset = status.closestStopTimeOffset distanceAlongTrip = status.distanceAlongTrip - frequency = status.frequency lastKnownDistanceAlongTrip = status.lastKnownDistanceAlongTrip - lastKnownLocation = status.lastKnownLocation - lastKnownOrientation = status.lastKnownOrientation lastLocationUpdateTime = status.lastLocationUpdateTime lastUpdateTime = status.lastUpdateTime - nextStop = status.nextStop - nextStopTimeOffset = status.nextStopTimeOffset occupancyCapacity = status.occupancyCapacity occupancyCount = status.occupancyCount occupancyStatus = status.occupancyStatus - orientation = status.orientation phase = status.phase - position = status.position predicted = status.predicted scheduleDeviation = status.scheduleDeviation - scheduledDistanceAlongTrip = status.scheduledDistanceAlongTrip serviceDate = status.serviceDate - situationIds = status.situationIds this.status = status.status 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() } @@ -1252,21 +1345,6 @@ private constructor( 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). - */ - fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { - this.closestStopTimeOffset = closestStopTimeOffset - } - /** * Distance, in meters, the transit vehicle has progressed along the active * trip. @@ -1282,14 +1360,6 @@ private constructor( 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. */ - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1306,28 +1376,6 @@ private constructor( 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. */ - 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 - } - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1352,27 +1400,6 @@ private constructor( 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. */ - 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 - } - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) @@ -1400,26 +1427,12 @@ private constructor( 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. */ - 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. */ 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. */ - 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)) @@ -1443,22 +1456,6 @@ private constructor( 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. - */ - 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. @@ -1473,15 +1470,6 @@ private constructor( 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. */ - fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds - } - /** Current status modifiers for the trip. */ fun status(status: String) = status(JsonField.of(status)) @@ -1497,6 +1485,125 @@ private constructor( 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)) @@ -1529,32 +1636,32 @@ private constructor( 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(), ) @@ -1582,10 +1689,10 @@ 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 @@ -1594,11 +1701,13 @@ private constructor( 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) @@ -1608,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() @@ -1705,10 +1815,10 @@ 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 @@ -1717,11 +1827,13 @@ private constructor( 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) @@ -1731,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() @@ -1810,17 +1923,17 @@ private constructor( return true } - return /* spotless:off */ other is Status && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && closestStopTimeOffset == other.closestStopTimeOffset && distanceAlongTrip == other.distanceAlongTrip && frequency == other.frequency && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && orientation == other.orientation && phase == other.phase && position == other.position && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && serviceDate == other.serviceDate && situationIds == other.situationIds && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && vehicleId == other.vehicleId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { 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) } + 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 = 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 { @@ -1828,17 +1941,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && frequency == other.frequency && schedule == other.schedule && serviceDate == other.serviceDate && situationIds == other.situationIds && status == other.status && tripId == other.tripId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(frequency, schedule, serviceDate, situationIds, status, tripId, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(tripId, frequency, schedule, serviceDate, situationIds, status, additionalProperties) } /* spotless:on */ 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 { 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 a2511a5..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 @@ -4,15 +4,18 @@ package org.onebusaway.models import java.util.Objects import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun tripId(): String = tripId @@ -20,9 +23,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic internal fun getQueryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = additionalQueryParams fun getPathParam(index: Int): String { return when (index) { @@ -38,8 +41,9 @@ constructor( @JvmStatic fun builder() = Builder() } + /** A builder for [TripRetrieveParams]. */ @NoAutoDetect - class Builder { + class Builder internal constructor() { private var tripId: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() @@ -154,7 +158,7 @@ constructor( fun build(): TripRetrieveParams = TripRetrieveParams( - checkNotNull(tripId) { "`tripId` is required but was not set" }, + checkRequired("tripId", tripId), additionalHeaders.build(), additionalQueryParams.build(), ) 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 0ab0673..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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -171,9 +175,11 @@ private constructor( 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 @@ -182,11 +188,13 @@ private constructor( 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) @@ -196,10 +204,11 @@ 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 @@ -240,8 +249,8 @@ private constructor( fun build(): Data = Data( - entry, - references, + checkRequired("entry", entry), + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -250,27 +259,27 @@ private constructor( class Entry @JsonCreator private constructor( + @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("id") - @ExcludeMissing - private val id: JsonField = JsonMissing.of(), @JsonProperty("peakOffpeak") @ExcludeMissing private val peakOffpeak: JsonField = JsonMissing.of(), - @JsonProperty("routeId") - @ExcludeMissing - private val routeId: JsonField = JsonMissing.of(), @JsonProperty("routeShortName") @ExcludeMissing private val routeShortName: JsonField = JsonMissing.of(), - @JsonProperty("serviceId") - @ExcludeMissing - private val serviceId: JsonField = JsonMissing.of(), @JsonProperty("shapeId") @ExcludeMissing private val shapeId: JsonField = JsonMissing.of(), @@ -287,23 +296,23 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { + 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")) @@ -314,27 +323,39 @@ 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 @@ -343,20 +364,22 @@ private constructor( 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) @@ -366,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() @@ -383,13 +407,13 @@ private constructor( @JvmSynthetic internal fun from(entry: Entry) = apply { + id = entry.id + routeId = entry.routeId + serviceId = entry.serviceId blockId = entry.blockId directionId = entry.directionId - id = entry.id peakOffpeak = entry.peakOffpeak - routeId = entry.routeId routeShortName = entry.routeShortName - serviceId = entry.serviceId shapeId = entry.shapeId timeZone = entry.timeZone tripHeadsign = entry.tripHeadsign @@ -397,6 +421,18 @@ private constructor( 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)) fun blockId(blockId: JsonField) = apply { this.blockId = blockId } @@ -407,20 +443,12 @@ private constructor( this.directionId = directionId } - fun id(id: String) = id(JsonField.of(id)) - - fun id(id: JsonField) = apply { this.id = id } - fun peakOffpeak(peakOffpeak: Long) = peakOffpeak(JsonField.of(peakOffpeak)) fun peakOffpeak(peakOffpeak: JsonField) = apply { this.peakOffpeak = peakOffpeak } - fun routeId(routeId: String) = routeId(JsonField.of(routeId)) - - fun routeId(routeId: JsonField) = apply { this.routeId = routeId } - fun routeShortName(routeShortName: String) = routeShortName(JsonField.of(routeShortName)) @@ -428,10 +456,6 @@ private constructor( this.routeShortName = routeShortName } - fun serviceId(serviceId: String) = serviceId(JsonField.of(serviceId)) - - fun serviceId(serviceId: JsonField) = apply { this.serviceId = serviceId } - fun shapeId(shapeId: String) = shapeId(JsonField.of(shapeId)) fun shapeId(shapeId: JsonField) = apply { this.shapeId = shapeId } @@ -477,13 +501,13 @@ private constructor( fun build(): Entry = Entry( + checkRequired("id", id), + checkRequired("routeId", routeId), + checkRequired("serviceId", serviceId), blockId, directionId, - id, peakOffpeak, - routeId, routeShortName, - serviceId, shapeId, timeZone, tripHeadsign, @@ -497,17 +521,17 @@ private constructor( return true } - return /* spotless:off */ other is Entry && blockId == other.blockId && directionId == other.directionId && id == other.id && peakOffpeak == other.peakOffpeak && routeId == other.routeId && routeShortName == other.routeShortName && serviceId == other.serviceId && shapeId == other.shapeId && timeZone == other.timeZone && tripHeadsign == other.tripHeadsign && tripShortName == other.tripShortName && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(blockId, directionId, id, peakOffpeak, routeId, routeShortName, serviceId, shapeId, timeZone, tripHeadsign, tripShortName, additionalProperties) } + 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 = 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 { 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 90ed900..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 @@ -5,11 +5,14 @@ package org.onebusaway.models import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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,7 +22,7 @@ constructor( private val time: Long?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { /** The latitude coordinate of the search center */ fun lat(): Double = lat @@ -46,10 +49,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + 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())) } @@ -69,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 @@ -110,15 +113,42 @@ 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 } + 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) = 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) = time(time as Long?) /** Specific time for the query. Defaults to the current time. */ - 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() @@ -220,10 +250,10 @@ constructor( 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, 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 b727efe..dd918cf 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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -163,12 +167,12 @@ private constructor( @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(), + @JsonProperty("outOfRange") + @ExcludeMissing + private val outOfRange: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { @@ -178,21 +182,27 @@ private constructor( fun list(): 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 @@ -201,13 +211,15 @@ private constructor( 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) @@ -217,20 +229,21 @@ 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 { limitExceeded = data.limitExceeded - list = data.list - outOfRange = data.outOfRange + list = data.list.map { it.toMutableList() } references = data.references + outOfRange = data.outOfRange additionalProperties = data.additionalProperties.toMutableMap() } @@ -244,13 +257,22 @@ private constructor( fun list(list: List) = list(JsonField.of(list)) - 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 */ - 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)) @@ -258,6 +280,12 @@ private constructor( 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() putAllAdditionalProperties(additionalProperties) @@ -279,10 +307,10 @@ private constructor( 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(), ) } @@ -291,6 +319,15 @@ private constructor( class List @JsonCreator private constructor( + @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(), @@ -300,19 +337,16 @@ private constructor( @JsonProperty("situationIds") @ExcludeMissing private val situationIds: JsonField> = JsonMissing.of(), - @JsonProperty("tripId") - @ExcludeMissing - private val tripId: JsonField = JsonMissing.of(), - @JsonProperty("schedule") - @ExcludeMissing - private val schedule: JsonField = JsonMissing.of(), - @JsonProperty("status") - @ExcludeMissing - private val status: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { + 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")) @@ -322,23 +356,25 @@ 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 @@ -347,15 +383,17 @@ private constructor( 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) @@ -365,28 +403,43 @@ 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 { - frequency = list.frequency - serviceDate = list.serviceDate - situationIds = list.situationIds - tripId = list.tripId 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)) fun frequency(frequency: JsonField) = apply { this.frequency = frequency } @@ -400,20 +453,21 @@ private constructor( situationIds(JsonField.of(situationIds)) fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds + this.situationIds = situationIds.map { it.toMutableList() } } - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - - 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 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() @@ -439,12 +493,12 @@ private constructor( 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(), ) } @@ -453,9 +507,6 @@ private constructor( class Schedule @JsonCreator private constructor( - @JsonProperty("frequency") - @ExcludeMissing - private val frequency: JsonField = JsonMissing.of(), @JsonProperty("nextTripId") @ExcludeMissing private val nextTripId: JsonField = JsonMissing.of(), @@ -468,13 +519,13 @@ private constructor( @JsonProperty("timeZone") @ExcludeMissing private val timeZone: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - fun nextTripId(): String = nextTripId.getRequired("nextTripId") fun previousTripId(): String = previousTripId.getRequired("previousTripId") @@ -483,17 +534,28 @@ 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 @@ -502,14 +564,16 @@ private constructor( 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) @@ -519,31 +583,26 @@ 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 { - frequency = schedule.frequency nextTripId = schedule.nextTripId previousTripId = schedule.previousTripId - stopTimes = schedule.stopTimes + stopTimes = schedule.stopTimes.map { it.toMutableList() } timeZone = schedule.timeZone + frequency = schedule.frequency additionalProperties = schedule.additionalProperties.toMutableMap() } - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - fun nextTripId(nextTripId: String) = nextTripId(JsonField.of(nextTripId)) fun nextTripId(nextTripId: JsonField) = apply { @@ -560,13 +619,34 @@ private constructor( fun stopTimes(stopTimes: List) = stopTimes(JsonField.of(stopTimes)) 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)) 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() putAllAdditionalProperties(additionalProperties) @@ -591,11 +671,11 @@ private constructor( 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(), ) } @@ -644,23 +724,29 @@ 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 @@ -669,15 +755,17 @@ private constructor( 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) @@ -687,7 +775,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() @@ -804,17 +893,17 @@ private constructor( return true } - return /* spotless:off */ other is Schedule && frequency == other.frequency && nextTripId == other.nextTripId && previousTripId == other.previousTripId && stopTimes == other.stopTimes && timeZone == other.timeZone && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(frequency, nextTripId, previousTripId, stopTimes, timeZone, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(nextTripId, previousTripId, stopTimes, timeZone, frequency, additionalProperties) } /* spotless:on */ 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}" } @NoAutoDetect @@ -830,36 +919,18 @@ private constructor( @JsonProperty("closestStop") @ExcludeMissing private val closestStop: JsonField = JsonMissing.of(), - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing - private val closestStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("distanceAlongTrip") @ExcludeMissing private val distanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("frequency") - @ExcludeMissing - private val frequency: JsonField = JsonMissing.of(), @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownLocation") - @ExcludeMissing - private val lastKnownLocation: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - private val lastKnownOrientation: JsonField = JsonMissing.of(), @JsonProperty("lastLocationUpdateTime") @ExcludeMissing private val lastLocationUpdateTime: JsonField = JsonMissing.of(), @JsonProperty("lastUpdateTime") @ExcludeMissing private val lastUpdateTime: JsonField = JsonMissing.of(), - @JsonProperty("nextStop") - @ExcludeMissing - private val nextStop: JsonField = JsonMissing.of(), - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - private val nextStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("occupancyCapacity") @ExcludeMissing private val occupancyCapacity: JsonField = JsonMissing.of(), @@ -869,36 +940,54 @@ private constructor( @JsonProperty("occupancyStatus") @ExcludeMissing private val occupancyStatus: JsonField = JsonMissing.of(), - @JsonProperty("orientation") - @ExcludeMissing - private val orientation: JsonField = JsonMissing.of(), @JsonProperty("phase") @ExcludeMissing private val phase: JsonField = JsonMissing.of(), - @JsonProperty("position") - @ExcludeMissing - private val position: JsonField = JsonMissing.of(), @JsonProperty("predicted") @ExcludeMissing private val predicted: JsonField = JsonMissing.of(), @JsonProperty("scheduleDeviation") @ExcludeMissing private val scheduleDeviation: JsonField = JsonMissing.of(), - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - private val scheduledDistanceAlongTrip: 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("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), @JsonProperty("vehicleId") @ExcludeMissing private val vehicleId: JsonField = JsonMissing.of(), @@ -915,22 +1004,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. @@ -938,14 +1016,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. */ @@ -955,17 +1025,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") @@ -975,17 +1034,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") @@ -994,25 +1045,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") @@ -1020,38 +1058,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 @@ -1059,102 +1141,129 @@ 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 @@ -1163,36 +1272,38 @@ private constructor( 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) @@ -1202,34 +1313,35 @@ 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() @@ -1238,29 +1350,29 @@ private constructor( activeTripId = status.activeTripId blockTripSequence = status.blockTripSequence closestStop = status.closestStop - closestStopTimeOffset = status.closestStopTimeOffset distanceAlongTrip = status.distanceAlongTrip - frequency = status.frequency lastKnownDistanceAlongTrip = status.lastKnownDistanceAlongTrip - lastKnownLocation = status.lastKnownLocation - lastKnownOrientation = status.lastKnownOrientation lastLocationUpdateTime = status.lastLocationUpdateTime lastUpdateTime = status.lastUpdateTime - nextStop = status.nextStop - nextStopTimeOffset = status.nextStopTimeOffset occupancyCapacity = status.occupancyCapacity occupancyCount = status.occupancyCount occupancyStatus = status.occupancyStatus - orientation = status.orientation phase = status.phase - position = status.position predicted = status.predicted scheduleDeviation = status.scheduleDeviation - scheduledDistanceAlongTrip = status.scheduledDistanceAlongTrip serviceDate = status.serviceDate - situationIds = status.situationIds this.status = status.status 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() } @@ -1291,21 +1403,6 @@ private constructor( 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). - */ - fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { - this.closestStopTimeOffset = closestStopTimeOffset - } - /** * Distance, in meters, the transit vehicle has progressed along the active * trip. @@ -1321,14 +1418,6 @@ private constructor( 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. */ - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1345,28 +1434,6 @@ private constructor( 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. */ - 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 - } - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1391,27 +1458,6 @@ private constructor( 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. */ - 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 - } - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) @@ -1439,26 +1485,12 @@ private constructor( 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. */ - 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. */ 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. */ - 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)) @@ -1482,22 +1514,6 @@ private constructor( 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. - */ - 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. @@ -1512,15 +1528,6 @@ private constructor( 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. */ - fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds - } - /** Current status modifiers for the trip. */ fun status(status: String) = status(JsonField.of(status)) @@ -1536,6 +1543,125 @@ private constructor( 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)) @@ -1568,32 +1694,32 @@ private constructor( 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(), ) @@ -1621,10 +1747,10 @@ 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 @@ -1633,11 +1759,13 @@ private constructor( 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) @@ -1647,7 +1775,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() @@ -1744,10 +1873,10 @@ 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 @@ -1756,11 +1885,13 @@ private constructor( 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) @@ -1770,7 +1901,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() @@ -1849,17 +1981,17 @@ private constructor( return true } - return /* spotless:off */ other is Status && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && closestStopTimeOffset == other.closestStopTimeOffset && distanceAlongTrip == other.distanceAlongTrip && frequency == other.frequency && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && orientation == other.orientation && phase == other.phase && position == other.position && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && serviceDate == other.serviceDate && situationIds == other.situationIds && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && vehicleId == other.vehicleId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { 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) } + 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 = 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 { @@ -1867,17 +1999,17 @@ private constructor( return true } - return /* spotless:off */ other is List && frequency == other.frequency && serviceDate == other.serviceDate && situationIds == other.situationIds && tripId == other.tripId && schedule == other.schedule && status == other.status && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(frequency, serviceDate, situationIds, tripId, schedule, status, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(schedule, status, tripId, frequency, serviceDate, situationIds, additionalProperties) } /* spotless:on */ 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 { @@ -1885,17 +2017,17 @@ private constructor( return true } - return /* spotless:off */ other is Data && limitExceeded == other.limitExceeded && list == other.list && outOfRange == other.outOfRange && references == other.references && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, outOfRange, references, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(limitExceeded, list, references, outOfRange, additionalProperties) } /* spotless:on */ 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 { 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 12d2d35..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 @@ -5,18 +5,21 @@ package org.onebusaway.models import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun routeId(): String = routeId @@ -36,10 +39,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + 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())) } @@ -62,8 +64,9 @@ 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 @@ -85,18 +88,47 @@ constructor( 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 } + /** * 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) = 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() @@ -198,7 +230,7 @@ constructor( fun build(): TripsForRouteListParams = TripsForRouteListParams( - checkNotNull(routeId) { "`routeId` is required but was not set" }, + checkRequired("routeId", routeId), includeSchedule, includeStatus, time, 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 ddf7dfb..c72b061 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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -176,11 +180,15 @@ 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("references") @ExcludeMissing fun _references() = references + @JsonProperty("references") + @ExcludeMissing + fun _references(): JsonField = references @JsonAnyGetter @ExcludeMissing @@ -189,12 +197,14 @@ private constructor( 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) @@ -204,17 +214,18 @@ 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 { limitExceeded = data.limitExceeded - list = data.list + list = data.list.map { it.toMutableList() } references = data.references additionalProperties = data.additionalProperties.toMutableMap() } @@ -227,7 +238,22 @@ private constructor( fun list(list: List) = list(JsonField.of(list)) - 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)) @@ -256,9 +282,9 @@ private constructor( fun build(): Data = Data( - limitExceeded, - list.map { it.toImmutable() }, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -267,6 +293,15 @@ private constructor( class List @JsonCreator private constructor( + @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(), @@ -276,19 +311,16 @@ private constructor( @JsonProperty("situationIds") @ExcludeMissing private val situationIds: JsonField> = JsonMissing.of(), - @JsonProperty("tripId") - @ExcludeMissing - private val tripId: JsonField = JsonMissing.of(), - @JsonProperty("schedule") - @ExcludeMissing - private val schedule: JsonField = JsonMissing.of(), - @JsonProperty("status") - @ExcludeMissing - private val status: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { + 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")) @@ -298,23 +330,25 @@ 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 @@ -323,15 +357,17 @@ private constructor( 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) @@ -341,28 +377,43 @@ 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 { - frequency = list.frequency - serviceDate = list.serviceDate - situationIds = list.situationIds - tripId = list.tripId 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)) fun frequency(frequency: JsonField) = apply { this.frequency = frequency } @@ -376,20 +427,21 @@ private constructor( situationIds(JsonField.of(situationIds)) fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds + this.situationIds = situationIds.map { it.toMutableList() } } - fun tripId(tripId: String) = tripId(JsonField.of(tripId)) - - fun tripId(tripId: JsonField) = apply { this.tripId = tripId } - - 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 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() @@ -415,12 +467,12 @@ private constructor( 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(), ) } @@ -429,9 +481,6 @@ private constructor( class Schedule @JsonCreator private constructor( - @JsonProperty("frequency") - @ExcludeMissing - private val frequency: JsonField = JsonMissing.of(), @JsonProperty("nextTripId") @ExcludeMissing private val nextTripId: JsonField = JsonMissing.of(), @@ -444,13 +493,13 @@ private constructor( @JsonProperty("timeZone") @ExcludeMissing private val timeZone: JsonField = JsonMissing.of(), + @JsonProperty("frequency") + @ExcludeMissing + private val frequency: JsonField = JsonMissing.of(), @JsonAnySetter private val additionalProperties: Map = immutableEmptyMap(), ) { - fun frequency(): Optional = - Optional.ofNullable(frequency.getNullable("frequency")) - fun nextTripId(): String = nextTripId.getRequired("nextTripId") fun previousTripId(): String = previousTripId.getRequired("previousTripId") @@ -459,17 +508,28 @@ 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 @@ -478,14 +538,16 @@ private constructor( 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) @@ -495,31 +557,26 @@ 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 { - frequency = schedule.frequency nextTripId = schedule.nextTripId previousTripId = schedule.previousTripId - stopTimes = schedule.stopTimes + stopTimes = schedule.stopTimes.map { it.toMutableList() } timeZone = schedule.timeZone + frequency = schedule.frequency additionalProperties = schedule.additionalProperties.toMutableMap() } - fun frequency(frequency: String) = frequency(JsonField.of(frequency)) - - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - fun nextTripId(nextTripId: String) = nextTripId(JsonField.of(nextTripId)) fun nextTripId(nextTripId: JsonField) = apply { @@ -536,13 +593,34 @@ private constructor( fun stopTimes(stopTimes: List) = stopTimes(JsonField.of(stopTimes)) 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)) 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() putAllAdditionalProperties(additionalProperties) @@ -567,11 +645,11 @@ private constructor( 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(), ) } @@ -620,23 +698,29 @@ 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 @@ -645,15 +729,17 @@ private constructor( 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) @@ -663,7 +749,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() @@ -780,17 +867,17 @@ private constructor( return true } - return /* spotless:off */ other is Schedule && frequency == other.frequency && nextTripId == other.nextTripId && previousTripId == other.previousTripId && stopTimes == other.stopTimes && timeZone == other.timeZone && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(frequency, nextTripId, previousTripId, stopTimes, timeZone, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(nextTripId, previousTripId, stopTimes, timeZone, frequency, additionalProperties) } /* spotless:on */ 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}" } @NoAutoDetect @@ -806,36 +893,18 @@ private constructor( @JsonProperty("closestStop") @ExcludeMissing private val closestStop: JsonField = JsonMissing.of(), - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing - private val closestStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("distanceAlongTrip") @ExcludeMissing private val distanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("frequency") - @ExcludeMissing - private val frequency: JsonField = JsonMissing.of(), @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownLocation") - @ExcludeMissing - private val lastKnownLocation: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - private val lastKnownOrientation: JsonField = JsonMissing.of(), @JsonProperty("lastLocationUpdateTime") @ExcludeMissing private val lastLocationUpdateTime: JsonField = JsonMissing.of(), @JsonProperty("lastUpdateTime") @ExcludeMissing private val lastUpdateTime: JsonField = JsonMissing.of(), - @JsonProperty("nextStop") - @ExcludeMissing - private val nextStop: JsonField = JsonMissing.of(), - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - private val nextStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("occupancyCapacity") @ExcludeMissing private val occupancyCapacity: JsonField = JsonMissing.of(), @@ -845,36 +914,54 @@ private constructor( @JsonProperty("occupancyStatus") @ExcludeMissing private val occupancyStatus: JsonField = JsonMissing.of(), - @JsonProperty("orientation") - @ExcludeMissing - private val orientation: JsonField = JsonMissing.of(), @JsonProperty("phase") @ExcludeMissing private val phase: JsonField = JsonMissing.of(), - @JsonProperty("position") - @ExcludeMissing - private val position: JsonField = JsonMissing.of(), @JsonProperty("predicted") @ExcludeMissing private val predicted: JsonField = JsonMissing.of(), @JsonProperty("scheduleDeviation") @ExcludeMissing private val scheduleDeviation: JsonField = JsonMissing.of(), - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - private val scheduledDistanceAlongTrip: 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("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), @JsonProperty("vehicleId") @ExcludeMissing private val vehicleId: JsonField = JsonMissing.of(), @@ -891,22 +978,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. @@ -914,14 +990,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. */ @@ -931,17 +999,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") @@ -951,17 +1008,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") @@ -970,25 +1019,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") @@ -996,38 +1032,82 @@ private constructor( 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 + /** + * 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(): 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 @@ -1035,102 +1115,129 @@ 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 @@ -1139,36 +1246,38 @@ private constructor( 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) @@ -1178,34 +1287,35 @@ 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() @@ -1214,29 +1324,29 @@ private constructor( activeTripId = status.activeTripId blockTripSequence = status.blockTripSequence closestStop = status.closestStop - closestStopTimeOffset = status.closestStopTimeOffset distanceAlongTrip = status.distanceAlongTrip - frequency = status.frequency lastKnownDistanceAlongTrip = status.lastKnownDistanceAlongTrip - lastKnownLocation = status.lastKnownLocation - lastKnownOrientation = status.lastKnownOrientation lastLocationUpdateTime = status.lastLocationUpdateTime lastUpdateTime = status.lastUpdateTime - nextStop = status.nextStop - nextStopTimeOffset = status.nextStopTimeOffset occupancyCapacity = status.occupancyCapacity occupancyCount = status.occupancyCount occupancyStatus = status.occupancyStatus - orientation = status.orientation phase = status.phase - position = status.position predicted = status.predicted scheduleDeviation = status.scheduleDeviation - scheduledDistanceAlongTrip = status.scheduledDistanceAlongTrip serviceDate = status.serviceDate - situationIds = status.situationIds this.status = status.status 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() } @@ -1267,21 +1377,6 @@ private constructor( 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). - */ - fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { - this.closestStopTimeOffset = closestStopTimeOffset - } - /** * Distance, in meters, the transit vehicle has progressed along the active * trip. @@ -1297,14 +1392,6 @@ private constructor( 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. */ - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1321,28 +1408,6 @@ private constructor( 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. */ - 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 - } - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1367,27 +1432,6 @@ private constructor( 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. */ - 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 - } - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) @@ -1415,26 +1459,12 @@ private constructor( 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. */ - 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. */ 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. */ - 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)) @@ -1458,22 +1488,6 @@ private constructor( 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. - */ - 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. @@ -1488,15 +1502,6 @@ private constructor( 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. */ - fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds - } - /** Current status modifiers for the trip. */ fun status(status: String) = status(JsonField.of(status)) @@ -1512,6 +1517,125 @@ private constructor( 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)) @@ -1544,32 +1668,32 @@ private constructor( 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(), ) @@ -1597,10 +1721,10 @@ 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 @@ -1609,11 +1733,13 @@ private constructor( 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) @@ -1623,7 +1749,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() @@ -1720,10 +1847,10 @@ 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 @@ -1732,11 +1859,13 @@ private constructor( 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) @@ -1746,7 +1875,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() @@ -1825,17 +1955,17 @@ private constructor( return true } - return /* spotless:off */ other is Status && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && closestStopTimeOffset == other.closestStopTimeOffset && distanceAlongTrip == other.distanceAlongTrip && frequency == other.frequency && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && orientation == other.orientation && phase == other.phase && position == other.position && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && serviceDate == other.serviceDate && situationIds == other.situationIds && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && vehicleId == other.vehicleId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { 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) } + 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 = 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 { @@ -1843,17 +1973,17 @@ private constructor( return true } - return /* spotless:off */ other is List && frequency == other.frequency && serviceDate == other.serviceDate && situationIds == other.situationIds && tripId == other.tripId && schedule == other.schedule && status == other.status && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(frequency, serviceDate, situationIds, tripId, schedule, status, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(schedule, status, tripId, frequency, serviceDate, situationIds, additionalProperties) } /* spotless:on */ 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 { 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 959a68a..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 @@ -5,16 +5,19 @@ package org.onebusaway.models import java.util.Objects import java.util.Optional import org.onebusaway.core.NoAutoDetect +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: Headers, private val additionalQueryParams: QueryParams, -) { +) : Params { fun agencyId(): String = agencyId @@ -25,10 +28,9 @@ constructor( fun _additionalQueryParams(): QueryParams = additionalQueryParams - @JvmSynthetic internal fun getHeaders(): Headers = additionalHeaders + override fun _headers(): Headers = additionalHeaders - @JvmSynthetic - internal fun getQueryParams(): QueryParams { + override fun _queryParams(): QueryParams { val queryParams = QueryParams.builder() this.time?.let { queryParams.put("time", listOf(it.toString())) } queryParams.putAll(additionalQueryParams) @@ -49,8 +51,9 @@ 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 @@ -68,7 +71,10 @@ constructor( 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() @@ -170,7 +176,7 @@ constructor( fun build(): VehiclesForAgencyListParams = VehiclesForAgencyListParams( - checkNotNull(agencyId) { "`agencyId` is required but was not set" }, + checkRequired("agencyId", agencyId), time, additionalHeaders.build(), additionalQueryParams.build(), 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 2420506..eacc19e 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 @@ -13,6 +13,7 @@ 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 @@ -42,15 +43,15 @@ private constructor( fun data(): Data = data.getRequired("data") - @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 @@ -67,14 +68,16 @@ private constructor( 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) @@ -84,13 +87,14 @@ 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 @@ -144,11 +148,11 @@ private constructor( 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(), ) } @@ -157,12 +161,12 @@ private constructor( class Data @JsonCreator private constructor( - @JsonProperty("list") - @ExcludeMissing - private val list: 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(), @@ -170,17 +174,21 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { - fun list(): List = list.getRequired("list") - fun limitExceeded(): Boolean = limitExceeded.getRequired("limitExceeded") + fun list(): List = list.getRequired("list") + 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 @@ -189,12 +197,14 @@ private constructor( 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) @@ -204,31 +214,47 @@ 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 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 { - list = data.list limitExceeded = data.limitExceeded + list = data.list.map { it.toMutableList() } references = data.references additionalProperties = data.additionalProperties.toMutableMap() } - fun list(list: List) = list(JsonField.of(list)) - - fun list(list: JsonField>) = apply { this.list = list } - fun limitExceeded(limitExceeded: Boolean) = limitExceeded(JsonField.of(limitExceeded)) fun limitExceeded(limitExceeded: JsonField) = apply { this.limitExceeded = limitExceeded } + fun list(list: List) = list(JsonField.of(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)) fun references(references: JsonField) = apply { @@ -256,9 +282,9 @@ private constructor( fun build(): Data = Data( - list.map { it.toImmutable() }, - limitExceeded, - references, + checkRequired("limitExceeded", limitExceeded), + checkRequired("list", list).map { it.toImmutable() }, + checkRequired("references", references), additionalProperties.toImmutable(), ) } @@ -267,15 +293,12 @@ private constructor( class List @JsonCreator private constructor( - @JsonProperty("vehicleId") + @JsonProperty("lastLocationUpdateTime") @ExcludeMissing - private val vehicleId: JsonField = JsonMissing.of(), + private val lastLocationUpdateTime: JsonField = JsonMissing.of(), @JsonProperty("lastUpdateTime") @ExcludeMissing private val lastUpdateTime: JsonField = JsonMissing.of(), - @JsonProperty("lastLocationUpdateTime") - @ExcludeMissing - private val lastLocationUpdateTime: JsonField = JsonMissing.of(), @JsonProperty("location") @ExcludeMissing private val location: JsonField = JsonMissing.of(), @@ -285,6 +308,9 @@ private constructor( @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(), @@ -304,19 +330,19 @@ private constructor( private val additionalProperties: Map = immutableEmptyMap(), ) { - 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")) @@ -330,33 +356,43 @@ 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 @@ -365,20 +401,22 @@ private constructor( 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) @@ -388,14 +426,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() @@ -405,12 +444,12 @@ private constructor( @JvmSynthetic internal fun from(list: List) = apply { - vehicleId = list.vehicleId - lastUpdateTime = list.lastUpdateTime 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 @@ -419,9 +458,12 @@ private constructor( additionalProperties = list.additionalProperties.toMutableMap() } - fun vehicleId(vehicleId: String) = vehicleId(JsonField.of(vehicleId)) + fun lastLocationUpdateTime(lastLocationUpdateTime: Long) = + lastLocationUpdateTime(JsonField.of(lastLocationUpdateTime)) - fun vehicleId(vehicleId: JsonField) = apply { this.vehicleId = vehicleId } + fun lastLocationUpdateTime(lastLocationUpdateTime: JsonField) = apply { + this.lastLocationUpdateTime = lastLocationUpdateTime + } fun lastUpdateTime(lastUpdateTime: Long) = lastUpdateTime(JsonField.of(lastUpdateTime)) @@ -430,13 +472,6 @@ private constructor( this.lastUpdateTime = lastUpdateTime } - fun lastLocationUpdateTime(lastLocationUpdateTime: Long) = - lastLocationUpdateTime(JsonField.of(lastLocationUpdateTime)) - - fun lastLocationUpdateTime(lastLocationUpdateTime: JsonField) = apply { - this.lastLocationUpdateTime = lastLocationUpdateTime - } - fun location(location: Location) = location(JsonField.of(location)) fun location(location: JsonField) = apply { this.location = location } @@ -451,6 +486,10 @@ private constructor( 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)) @@ -504,12 +543,12 @@ private constructor( 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, @@ -537,9 +576,9 @@ private constructor( 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 @@ -548,11 +587,13 @@ private constructor( 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) @@ -562,7 +603,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() @@ -644,36 +686,18 @@ private constructor( @JsonProperty("closestStop") @ExcludeMissing private val closestStop: JsonField = JsonMissing.of(), - @JsonProperty("closestStopTimeOffset") - @ExcludeMissing - private val closestStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("distanceAlongTrip") @ExcludeMissing private val distanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("frequency") - @ExcludeMissing - private val frequency: JsonField = JsonMissing.of(), @JsonProperty("lastKnownDistanceAlongTrip") @ExcludeMissing private val lastKnownDistanceAlongTrip: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownLocation") - @ExcludeMissing - private val lastKnownLocation: JsonField = JsonMissing.of(), - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - private val lastKnownOrientation: JsonField = JsonMissing.of(), @JsonProperty("lastLocationUpdateTime") @ExcludeMissing private val lastLocationUpdateTime: JsonField = JsonMissing.of(), @JsonProperty("lastUpdateTime") @ExcludeMissing private val lastUpdateTime: JsonField = JsonMissing.of(), - @JsonProperty("nextStop") - @ExcludeMissing - private val nextStop: JsonField = JsonMissing.of(), - @JsonProperty("nextStopTimeOffset") - @ExcludeMissing - private val nextStopTimeOffset: JsonField = JsonMissing.of(), @JsonProperty("occupancyCapacity") @ExcludeMissing private val occupancyCapacity: JsonField = JsonMissing.of(), @@ -683,36 +707,54 @@ private constructor( @JsonProperty("occupancyStatus") @ExcludeMissing private val occupancyStatus: JsonField = JsonMissing.of(), - @JsonProperty("orientation") - @ExcludeMissing - private val orientation: JsonField = JsonMissing.of(), @JsonProperty("phase") @ExcludeMissing private val phase: JsonField = JsonMissing.of(), - @JsonProperty("position") - @ExcludeMissing - private val position: JsonField = JsonMissing.of(), @JsonProperty("predicted") @ExcludeMissing private val predicted: JsonField = JsonMissing.of(), @JsonProperty("scheduleDeviation") @ExcludeMissing private val scheduleDeviation: JsonField = JsonMissing.of(), - @JsonProperty("scheduledDistanceAlongTrip") - @ExcludeMissing - private val scheduledDistanceAlongTrip: 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("situationIds") + @ExcludeMissing + private val situationIds: JsonField> = JsonMissing.of(), @JsonProperty("vehicleId") @ExcludeMissing private val vehicleId: JsonField = JsonMissing.of(), @@ -729,22 +771,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. @@ -752,14 +783,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. */ @@ -769,17 +792,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") @@ -789,17 +801,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") @@ -808,25 +812,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") @@ -834,141 +825,212 @@ private constructor( 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 - - /** Index of the active trip into the sequence of trips for the active block. */ - @JsonProperty("blockTripSequence") - @ExcludeMissing - fun _blockTripSequence() = 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") - @ExcludeMissing - fun _closestStopTimeOffset() = closestStopTimeOffset - - /** - * Distance, in meters, the transit vehicle has progressed along the active trip. - */ - @JsonProperty("distanceAlongTrip") - @ExcludeMissing - fun _distanceAlongTrip() = distanceAlongTrip + fun closestStopTimeOffset(): Optional = + Optional.ofNullable(closestStopTimeOffset.getNullable("closestStopTimeOffset")) /** Information about frequency-based scheduling, if applicable to the trip. */ - @JsonProperty("frequency") @ExcludeMissing fun _frequency() = frequency - - /** - * Last known distance along the trip received in real-time from the transit - * vehicle. - */ - @JsonProperty("lastKnownDistanceAlongTrip") - @ExcludeMissing - fun _lastKnownDistanceAlongTrip() = lastKnownDistanceAlongTrip + fun frequency(): Optional = + Optional.ofNullable(frequency.getNullable("frequency")) /** Last known location of the transit vehicle. */ - @JsonProperty("lastKnownLocation") - @ExcludeMissing - fun _lastKnownLocation() = lastKnownLocation + fun lastKnownLocation(): Optional = + Optional.ofNullable(lastKnownLocation.getNullable("lastKnownLocation")) /** Last known orientation value received in real-time from the transit vehicle. */ - @JsonProperty("lastKnownOrientation") - @ExcludeMissing - fun _lastKnownOrientation() = lastKnownOrientation + 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")) /** - * Timestamp of the last known real-time location update from the transit vehicle. + * Time offset from the next stop to the current position of the transit vehicle (in + * seconds). */ - @JsonProperty("lastLocationUpdateTime") + 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 _lastLocationUpdateTime() = lastLocationUpdateTime + fun _activeTripId(): JsonField = activeTripId - /** Timestamp of the last known real-time update from the transit vehicle. */ - @JsonProperty("lastUpdateTime") + /** Index of the active trip into the sequence of trips for the active block. */ + @JsonProperty("blockTripSequence") @ExcludeMissing - fun _lastUpdateTime() = lastUpdateTime + fun _blockTripSequence(): JsonField = blockTripSequence - /** ID of the next stop the transit vehicle is scheduled to arrive at. */ - @JsonProperty("nextStop") @ExcludeMissing fun _nextStop() = nextStop + /** ID of the closest stop to the current location of the transit vehicle. */ + @JsonProperty("closestStop") + @ExcludeMissing + fun _closestStop(): JsonField = closestStop /** - * Time offset from the next stop to the current position of the transit vehicle (in - * seconds). + * Distance, in meters, the transit vehicle has progressed along the active trip. */ - @JsonProperty("nextStopTimeOffset") + @JsonProperty("distanceAlongTrip") @ExcludeMissing - fun _nextStopTimeOffset() = nextStopTimeOffset + fun _distanceAlongTrip(): JsonField = distanceAlongTrip + + /** + * Last known distance along the trip received in real-time from the transit + * vehicle. + */ + @JsonProperty("lastKnownDistanceAlongTrip") + @ExcludeMissing + fun _lastKnownDistanceAlongTrip(): JsonField = lastKnownDistanceAlongTrip + + /** + * Timestamp of the last known real-time location update from the transit vehicle. + */ + @JsonProperty("lastLocationUpdateTime") + @ExcludeMissing + fun _lastLocationUpdateTime(): JsonField = lastLocationUpdateTime + + /** Timestamp of the last known real-time update from the transit vehicle. */ + @JsonProperty("lastUpdateTime") + @ExcludeMissing + 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 @@ -977,36 +1039,38 @@ private constructor( 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) @@ -1016,34 +1080,35 @@ 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() @@ -1052,29 +1117,29 @@ private constructor( activeTripId = tripStatus.activeTripId blockTripSequence = tripStatus.blockTripSequence closestStop = tripStatus.closestStop - closestStopTimeOffset = tripStatus.closestStopTimeOffset distanceAlongTrip = tripStatus.distanceAlongTrip - frequency = tripStatus.frequency lastKnownDistanceAlongTrip = tripStatus.lastKnownDistanceAlongTrip - lastKnownLocation = tripStatus.lastKnownLocation - lastKnownOrientation = tripStatus.lastKnownOrientation lastLocationUpdateTime = tripStatus.lastLocationUpdateTime lastUpdateTime = tripStatus.lastUpdateTime - nextStop = tripStatus.nextStop - nextStopTimeOffset = tripStatus.nextStopTimeOffset occupancyCapacity = tripStatus.occupancyCapacity occupancyCount = tripStatus.occupancyCount occupancyStatus = tripStatus.occupancyStatus - orientation = tripStatus.orientation phase = tripStatus.phase - position = tripStatus.position predicted = tripStatus.predicted scheduleDeviation = tripStatus.scheduleDeviation - scheduledDistanceAlongTrip = tripStatus.scheduledDistanceAlongTrip serviceDate = tripStatus.serviceDate - situationIds = tripStatus.situationIds 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() } @@ -1105,21 +1170,6 @@ private constructor( 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). - */ - fun closestStopTimeOffset(closestStopTimeOffset: JsonField) = apply { - this.closestStopTimeOffset = closestStopTimeOffset - } - /** * Distance, in meters, the transit vehicle has progressed along the active * trip. @@ -1135,14 +1185,6 @@ private constructor( 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. */ - fun frequency(frequency: JsonField) = apply { - this.frequency = frequency - } - /** * Last known distance along the trip received in real-time from the transit * vehicle. @@ -1159,28 +1201,6 @@ private constructor( 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. */ - 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 - } - /** * Timestamp of the last known real-time location update from the transit * vehicle. @@ -1205,27 +1225,6 @@ private constructor( 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. */ - 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 - } - /** Capacity of the transit vehicle in terms of occupancy. */ fun occupancyCapacity(occupancyCapacity: Long) = occupancyCapacity(JsonField.of(occupancyCapacity)) @@ -1253,26 +1252,12 @@ private constructor( 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. */ - 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. */ 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. */ - 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)) @@ -1296,22 +1281,6 @@ private constructor( 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. - */ - 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. @@ -1326,15 +1295,6 @@ private constructor( 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. */ - fun situationIds(situationIds: JsonField>) = apply { - this.situationIds = situationIds - } - /** Current status modifiers for the trip. */ fun status(status: String) = status(JsonField.of(status)) @@ -1350,6 +1310,125 @@ private constructor( 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)) @@ -1382,32 +1461,32 @@ private constructor( 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(), ) @@ -1435,10 +1514,10 @@ 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 @@ -1447,11 +1526,13 @@ private constructor( 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) @@ -1461,7 +1542,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() @@ -1558,10 +1640,10 @@ 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 @@ -1570,11 +1652,13 @@ private constructor( 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) @@ -1584,7 +1668,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() @@ -1663,17 +1748,17 @@ private constructor( return true } - return /* spotless:off */ other is TripStatus && activeTripId == other.activeTripId && blockTripSequence == other.blockTripSequence && closestStop == other.closestStop && closestStopTimeOffset == other.closestStopTimeOffset && distanceAlongTrip == other.distanceAlongTrip && frequency == other.frequency && lastKnownDistanceAlongTrip == other.lastKnownDistanceAlongTrip && lastKnownLocation == other.lastKnownLocation && lastKnownOrientation == other.lastKnownOrientation && lastLocationUpdateTime == other.lastLocationUpdateTime && lastUpdateTime == other.lastUpdateTime && nextStop == other.nextStop && nextStopTimeOffset == other.nextStopTimeOffset && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && orientation == other.orientation && phase == other.phase && position == other.position && predicted == other.predicted && scheduleDeviation == other.scheduleDeviation && scheduledDistanceAlongTrip == other.scheduledDistanceAlongTrip && serviceDate == other.serviceDate && situationIds == other.situationIds && status == other.status && totalDistanceAlongTrip == other.totalDistanceAlongTrip && vehicleId == other.vehicleId && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { 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) } + 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 = 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 { @@ -1681,17 +1766,17 @@ private constructor( return true } - return /* spotless:off */ other is List && vehicleId == other.vehicleId && lastUpdateTime == other.lastUpdateTime && lastLocationUpdateTime == other.lastLocationUpdateTime && location == other.location && tripId == other.tripId && tripStatus == other.tripStatus && occupancyCapacity == other.occupancyCapacity && occupancyCount == other.occupancyCount && occupancyStatus == other.occupancyStatus && phase == other.phase && status == other.status && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(vehicleId, lastUpdateTime, lastLocationUpdateTime, location, tripId, tripStatus, occupancyCapacity, occupancyCount, occupancyStatus, phase, status, additionalProperties) } + 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 = 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 { @@ -1699,17 +1784,17 @@ private constructor( return true } - return /* spotless:off */ other is Data && list == other.list && limitExceeded == other.limitExceeded && references == other.references && 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 */ } /* spotless:off */ - private val hashCode: Int by lazy { Objects.hash(list, limitExceeded, references, additionalProperties) } + 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 { 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 d71c3ec..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 f60ba45..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 204abfe..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 9f096ec..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 a5fca9d..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 9ce90d7..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 faffec9..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 5f05c95..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 5eff280..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 aefd043..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 e224551..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 c064084..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 8becc41..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 2e7d2db..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 31e79fa..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 548d135..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 62212c7..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 ac255ef..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 224c85b..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 2014540..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 e8c9059..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 37dfda5..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 7327ed8..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 3fcabfc..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 d0b805c..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 d94a02c..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 56fa6a6..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 8041ee4..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 96e220f..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 601f734..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 a2b5c2b..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 e548168..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 559ee0e..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 4c2fbb3..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 96cc31f..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 58edddb..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 f8bc0a8..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 34b2b54..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 635e3ec..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 224ef56..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 e8258ab..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 d3e5860..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 7f891ca..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 1d11851..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 688e7f9..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 44057c5..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 408115e..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 5c47981..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 c372642..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 747794f..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 6715731..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 e70fa50..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 91e1972..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 7505571..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 029f847..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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 5bcd201..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) - .replaceAllQueryParams(params.getQueryParams()) - .putAllHeaders(clientOptions.headers) - .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/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 7fea7da..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 @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test 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 56d8a08..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 @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test 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 15676cb..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 @@ -10,7 +10,7 @@ import org.onebusaway.core.http.QueryParams class ArrivalAndDepartureListParamsTest { @Test - fun createArrivalAndDepartureListParams() { + fun create() { ArrivalAndDepartureListParams.builder() .stopId("1_75403") .minutesAfter(0L) @@ -20,7 +20,7 @@ class ArrivalAndDepartureListParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = ArrivalAndDepartureListParams.builder() .stopId("1_75403") @@ -32,14 +32,14 @@ class ArrivalAndDepartureListParamsTest { expected.put("minutesAfter", "0") expected.put("minutesBefore", "0") expected.put("time", "2019-12-27T18:11:19.117Z") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = ArrivalAndDepartureListParams.builder().stopId("1_75403").build() val expected = QueryParams.builder() - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test 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 af85193..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 @@ -9,7 +9,7 @@ import org.onebusaway.core.http.QueryParams class ArrivalAndDepartureRetrieveParamsTest { @Test - fun createArrivalAndDepartureRetrieveParams() { + fun create() { ArrivalAndDepartureRetrieveParams.builder() .stopId("1_75403") .serviceDate(0L) @@ -21,7 +21,7 @@ class ArrivalAndDepartureRetrieveParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = ArrivalAndDepartureRetrieveParams.builder() .stopId("1_75403") @@ -37,11 +37,11 @@ class ArrivalAndDepartureRetrieveParamsTest { expected.put("stopSequence", "0") expected.put("time", "0") expected.put("vehicleId", "vehicleId") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = ArrivalAndDepartureRetrieveParams.builder() .stopId("1_75403") @@ -51,7 +51,7 @@ class ArrivalAndDepartureRetrieveParamsTest { val expected = QueryParams.builder() expected.put("serviceDate", "0") expected.put("tripId", "tripId") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test 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 feb2888..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 @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test 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 7d6183d..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 @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test 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 d8f5418..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 @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Test 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 f21fd6b..2eb893a 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(0L) - .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(0L) - .activeWindows( - listOf( - 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() - ) - ) - .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(0L) - .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(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() - ) + .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(0.0) - .lon(0.0) - .name("name") - .parent("parent") - .routeIds(listOf("string")) - .staticRouteIds(listOf("string")) - .code("code") - .direction("direction") - .locationType(0L) - .wheelchairBoarding("wheelchairBoarding") - .build() - ) + .addStop( + References.Stop.builder() + .id("id") + .lat(0.0) + .lon(0.0) + .name("name") + .parent("parent") + .addRouteId("string") + .addStaticRouteId("string") + .code("code") + .direction("direction") + .locationType(0L) + .wheelchairBoarding("wheelchairBoarding") + .build() ) - .stopTimes( - listOf( - References.StopTime.builder() - .arrivalTime(0L) - .departureTime(0L) - .distanceAlongTrip(0.0) - .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(0L) - .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 @@ -206,42 +173,38 @@ class ReferencesTest { References.Situation.builder() .id("id") .creationTime(0L) - .activeWindows( - listOf(References.Situation.ActiveWindow.builder().from(0L).to(0L).build()) + .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(0L) - .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() @@ -249,10 +212,8 @@ class ReferencesTest { .value("value") .build() ) - .publicationWindows( - listOf( - References.Situation.PublicationWindow.builder().from(0L).to(0L).build() - ) + .addPublicationWindow( + References.Situation.PublicationWindow.builder().from(0L).to(0L).build() ) .reason(References.Situation.Reason.EQUIPMENT_REASON) .severity("severity") @@ -270,8 +231,8 @@ class ReferencesTest { .lon(0.0) .name("name") .parent("parent") - .routeIds(listOf("string")) - .staticRouteIds(listOf("string")) + .addRouteId("string") + .addStaticRouteId("string") .code("code") .direction("direction") .locationType(0L) 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 9715973..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 @@ -9,7 +9,7 @@ import org.onebusaway.core.http.QueryParams class ReportProblemWithStopRetrieveParamsTest { @Test - fun createReportProblemWithStopRetrieveParams() { + fun create() { ReportProblemWithStopRetrieveParams.builder() .stopId("stopID") .code(ReportProblemWithStopRetrieveParams.Code.STOP_NAME_WRONG) @@ -21,7 +21,7 @@ class ReportProblemWithStopRetrieveParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = ReportProblemWithStopRetrieveParams.builder() .stopId("stopID") @@ -37,14 +37,14 @@ class ReportProblemWithStopRetrieveParamsTest { expected.put("userLat", "0.0") expected.put("userLocationAccuracy", "0.0") expected.put("userLon", "0.0") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = ReportProblemWithStopRetrieveParams.builder().stopId("stopID").build() val expected = QueryParams.builder() - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + 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 6c00abc..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 @@ -9,7 +9,7 @@ import org.onebusaway.core.http.QueryParams class ReportProblemWithTripRetrieveParamsTest { @Test - fun createReportProblemWithTripRetrieveParams() { + fun create() { ReportProblemWithTripRetrieveParams.builder() .tripId("tripID") .code(ReportProblemWithTripRetrieveParams.Code.VEHICLE_NEVER_CAME) @@ -26,7 +26,7 @@ class ReportProblemWithTripRetrieveParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = ReportProblemWithTripRetrieveParams.builder() .tripId("tripID") @@ -52,14 +52,14 @@ class ReportProblemWithTripRetrieveParamsTest { expected.put("userOnVehicle", "true") expected.put("userVehicleNumber", "userVehicleNumber") expected.put("vehicleID", "vehicleID") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = ReportProblemWithTripRetrieveParams.builder().tripId("tripID").build() val expected = QueryParams.builder() - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test 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 27815d0..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 @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test 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 2648eee..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 @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test 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 25e5db1..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 @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test class RoutesForAgencyListParamsTest { @Test - fun createRoutesForAgencyListParams() { + fun create() { RoutesForAgencyListParams.builder().agencyId("40").build() } 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 7ae2da5..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 @@ -9,7 +9,7 @@ import org.onebusaway.core.http.QueryParams class RoutesForLocationListParamsTest { @Test - fun createRoutesForLocationListParams() { + fun create() { RoutesForLocationListParams.builder() .lat(0.0) .lon(0.0) @@ -21,7 +21,7 @@ class RoutesForLocationListParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = RoutesForLocationListParams.builder() .lat(0.0) @@ -38,15 +38,15 @@ class RoutesForLocationListParamsTest { expected.put("lonSpan", "0.0") expected.put("query", "query") expected.put("radius", "0.0") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + 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.getQueryParams()).isEqualTo(expected.build()) + 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 ad74668..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 @@ -10,7 +10,7 @@ import org.onebusaway.core.http.QueryParams class ScheduleForRouteRetrieveParamsTest { @Test - fun createScheduleForRouteRetrieveParams() { + fun create() { ScheduleForRouteRetrieveParams.builder() .routeId("1_100223") .date(LocalDate.parse("2019-12-27")) @@ -18,7 +18,7 @@ class ScheduleForRouteRetrieveParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = ScheduleForRouteRetrieveParams.builder() .routeId("1_100223") @@ -26,14 +26,14 @@ class ScheduleForRouteRetrieveParamsTest { .build() val expected = QueryParams.builder() expected.put("date", "2019-12-27") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = ScheduleForRouteRetrieveParams.builder().routeId("1_100223").build() val expected = QueryParams.builder() - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test 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 b70616d..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 @@ -10,7 +10,7 @@ import org.onebusaway.core.http.QueryParams class ScheduleForStopRetrieveParamsTest { @Test - fun createScheduleForStopRetrieveParams() { + fun create() { ScheduleForStopRetrieveParams.builder() .stopId("stopID") .date(LocalDate.parse("2019-12-27")) @@ -18,7 +18,7 @@ class ScheduleForStopRetrieveParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = ScheduleForStopRetrieveParams.builder() .stopId("stopID") @@ -26,14 +26,14 @@ class ScheduleForStopRetrieveParamsTest { .build() val expected = QueryParams.builder() expected.put("date", "2019-12-27") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = ScheduleForStopRetrieveParams.builder().stopId("stopID").build() val expected = QueryParams.builder() - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + 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 d75e481..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 @@ -9,24 +9,24 @@ import org.onebusaway.core.http.QueryParams class SearchForRouteListParamsTest { @Test - fun createSearchForRouteListParams() { + fun create() { SearchForRouteListParams.builder().input("input").maxCount(0L).build() } @Test - fun getQueryParams() { + 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.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = SearchForRouteListParams.builder().input("input").build() val expected = QueryParams.builder() expected.put("input", "input") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + 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 368c33b..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 @@ -9,24 +9,24 @@ import org.onebusaway.core.http.QueryParams class SearchForStopListParamsTest { @Test - fun createSearchForStopListParams() { + fun create() { SearchForStopListParams.builder().input("input").maxCount(0L).build() } @Test - fun getQueryParams() { + 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.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = SearchForStopListParams.builder().input("input").build() val expected = QueryParams.builder() expected.put("input", "input") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + 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 be4ffff..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 @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test 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 67d9e2b..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 @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test 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 1c0577b..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 @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test 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 9a74b02..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 @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test 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 e0f8bf1..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 @@ -9,7 +9,7 @@ import org.onebusaway.core.http.QueryParams class StopsForLocationListParamsTest { @Test - fun createStopsForLocationListParams() { + fun create() { StopsForLocationListParams.builder() .lat(0.0) .lon(0.0) @@ -21,7 +21,7 @@ class StopsForLocationListParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = StopsForLocationListParams.builder() .lat(0.0) @@ -38,15 +38,15 @@ class StopsForLocationListParamsTest { expected.put("lonSpan", "0.0") expected.put("query", "query") expected.put("radius", "0.0") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + 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.getQueryParams()).isEqualTo(expected.build()) + 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 14c60aa..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 @@ -9,7 +9,7 @@ import org.onebusaway.core.http.QueryParams class StopsForRouteListParamsTest { @Test - fun createStopsForRouteListParams() { + fun create() { StopsForRouteListParams.builder() .routeId("routeID") .includePolylines(true) @@ -18,7 +18,7 @@ class StopsForRouteListParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = StopsForRouteListParams.builder() .routeId("routeID") @@ -28,14 +28,14 @@ class StopsForRouteListParamsTest { val expected = QueryParams.builder() expected.put("includePolylines", "true") expected.put("time", "time") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = StopsForRouteListParams.builder().routeId("routeID").build() val expected = QueryParams.builder() - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + 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 e8d54bc..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 @@ -9,7 +9,7 @@ import org.onebusaway.core.http.QueryParams class TripDetailRetrieveParamsTest { @Test - fun createTripDetailRetrieveParams() { + fun create() { TripDetailRetrieveParams.builder() .tripId("tripID") .includeSchedule(true) @@ -21,7 +21,7 @@ class TripDetailRetrieveParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = TripDetailRetrieveParams.builder() .tripId("tripID") @@ -37,14 +37,14 @@ class TripDetailRetrieveParamsTest { expected.put("includeTrip", "true") expected.put("serviceDate", "0") expected.put("time", "0") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = TripDetailRetrieveParams.builder().tripId("tripID").build() val expected = QueryParams.builder() - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + 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 7ffc796..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 @@ -9,7 +9,7 @@ import org.onebusaway.core.http.QueryParams class TripForVehicleRetrieveParamsTest { @Test - fun createTripForVehicleRetrieveParams() { + fun create() { TripForVehicleRetrieveParams.builder() .vehicleId("vehicleID") .includeSchedule(true) @@ -20,7 +20,7 @@ class TripForVehicleRetrieveParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = TripForVehicleRetrieveParams.builder() .vehicleId("vehicleID") @@ -34,14 +34,14 @@ class TripForVehicleRetrieveParamsTest { expected.put("includeStatus", "true") expected.put("includeTrip", "true") expected.put("time", "0") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = TripForVehicleRetrieveParams.builder().vehicleId("vehicleID").build() val expected = QueryParams.builder() - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + 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 0bc7f7f..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 @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test 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 c4eb862..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 @@ -9,7 +9,7 @@ import org.onebusaway.core.http.QueryParams class TripsForLocationListParamsTest { @Test - fun createTripsForLocationListParams() { + fun create() { TripsForLocationListParams.builder() .lat(0.0) .latSpan(0.0) @@ -22,7 +22,7 @@ class TripsForLocationListParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = TripsForLocationListParams.builder() .lat(0.0) @@ -41,11 +41,11 @@ class TripsForLocationListParamsTest { expected.put("includeSchedule", "true") expected.put("includeTrip", "true") expected.put("time", "0") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = TripsForLocationListParams.builder().lat(0.0).latSpan(0.0).lon(0.0).lonSpan(0.0).build() val expected = QueryParams.builder() @@ -53,6 +53,6 @@ class TripsForLocationListParamsTest { expected.put("latSpan", "0.0") expected.put("lon", "0.0") expected.put("lonSpan", "0.0") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + 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 43f6c77..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 @@ -9,7 +9,7 @@ import org.onebusaway.core.http.QueryParams class TripsForRouteListParamsTest { @Test - fun createTripsForRouteListParams() { + fun create() { TripsForRouteListParams.builder() .routeId("routeID") .includeSchedule(true) @@ -19,7 +19,7 @@ class TripsForRouteListParamsTest { } @Test - fun getQueryParams() { + fun queryParams() { val params = TripsForRouteListParams.builder() .routeId("routeID") @@ -31,14 +31,14 @@ class TripsForRouteListParamsTest { expected.put("includeSchedule", "true") expected.put("includeStatus", "true") expected.put("time", "0") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = TripsForRouteListParams.builder().routeId("routeID").build() val expected = QueryParams.builder() - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + 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 4797643..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 @@ -9,23 +9,23 @@ 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 = QueryParams.builder() expected.put("time", "time") - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + assertThat(params._queryParams()).isEqualTo(expected.build()) } @Test - fun getQueryParamsWithoutOptionalFields() { + fun queryParamsWithoutOptionalFields() { val params = VehiclesForAgencyListParams.builder().agencyId("agencyID").build() val expected = QueryParams.builder() - assertThat(params.getQueryParams()).isEqualTo(expected.build()) + 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 1162b3b..b97cc0b 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 @@ -73,164 +73,144 @@ class ErrorHandlingTest { ) .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(0L) - .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(0L) - .activeWindows( - listOf( - 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() - ) - ) - .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(0L) - .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(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() - ) + .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(0.0) - .lon(0.0) - .name("name") - .parent("parent") - .routeIds(listOf("string")) - .staticRouteIds(listOf("string")) - .code("code") - .direction("direction") - .locationType(0L) - .wheelchairBoarding("wheelchairBoarding") - .build() - ) + .addStop( + References.Stop.builder() + .id("id") + .lat(0.0) + .lon(0.0) + .name("name") + .parent("parent") + .addRouteId("string") + .addStaticRouteId("string") + .code("code") + .direction("direction") + .locationType(0L) + .wheelchairBoarding("wheelchairBoarding") + .build() ) - .stopTimes( - listOf( - References.StopTime.builder() - .arrivalTime(0L) - .departureTime(0L) - .distanceAlongTrip(0.0) - .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(0L) - .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() ) 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 34c128c..44bf670 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 @@ -69,164 +69,144 @@ class ServiceParamsTest { ) .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(0L) - .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(0L) - .activeWindows( - listOf( - 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() - ) - ) - .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(0L) - .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(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() - ) + .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(0.0) - .lon(0.0) - .name("name") - .parent("parent") - .routeIds(listOf("string")) - .staticRouteIds(listOf("string")) - .code("code") - .direction("direction") - .locationType(0L) - .wheelchairBoarding("wheelchairBoarding") - .build() - ) + .addStop( + References.Stop.builder() + .id("id") + .lat(0.0) + .lon(0.0) + .name("name") + .parent("parent") + .addRouteId("string") + .addStaticRouteId("string") + .code("code") + .direction("direction") + .locationType(0L) + .wheelchairBoarding("wheelchairBoarding") + .build() ) - .stopTimes( - listOf( - References.StopTime.builder() - .arrivalTime(0L) - .departureTime(0L) - .distanceAlongTrip(0.0) - .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(0L) - .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() )