Skip to content

Commit

Permalink
chore: rebuild project due to codegen change (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Nov 1, 2024
1 parent f446746 commit fc6c26f
Show file tree
Hide file tree
Showing 67 changed files with 746 additions and 716 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ private constructor(
val jsonMapper: JsonMapper,
val clock: Clock,
val baseUrl: String,
val apiKey: String,
val headers: ListMultimap<String, String>,
val queryParams: ListMultimap<String, String>,
val responseValidation: Boolean,
val maxRetries: Int,
val apiKey: String,
) {

fun toBuilder() = Builder().from(this)
Expand All @@ -38,11 +38,11 @@ private constructor(
class Builder {

private var httpClient: HttpClient? = null
private var jsonMapper: JsonMapper? = null
private var jsonMapper: JsonMapper = jsonMapper()
private var clock: Clock = Clock.systemUTC()
private var baseUrl: String = PRODUCTION_URL
private var headers: MutableMap<String, MutableList<String>> = mutableMapOf()
private var queryParams: MutableMap<String, MutableList<String>> = mutableMapOf()
private var headers: ListMultimap<String, String> = ArrayListMultimap.create()
private var queryParams: ListMultimap<String, String> = ArrayListMultimap.create()
private var responseValidation: Boolean = false
private var maxRetries: Int = 2
private var apiKey: String? = null
Expand All @@ -52,14 +52,8 @@ private constructor(
jsonMapper = clientOptions.jsonMapper
clock = clientOptions.clock
baseUrl = clientOptions.baseUrl
headers =
clientOptions.headers.asMap().mapValuesTo(mutableMapOf()) { (_, value) ->
value.toMutableList()
}
queryParams =
clientOptions.queryParams.asMap().mapValuesTo(mutableMapOf()) { (_, value) ->
value.toMutableList()
}
headers = ArrayListMultimap.create(clientOptions.headers)
queryParams = ArrayListMultimap.create(clientOptions.queryParams)
responseValidation = clientOptions.responseValidation
maxRetries = clientOptions.maxRetries
apiKey = clientOptions.apiKey
Expand All @@ -69,47 +63,43 @@ private constructor(

fun jsonMapper(jsonMapper: JsonMapper) = apply { this.jsonMapper = jsonMapper }

fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl }

fun clock(clock: Clock) = apply { this.clock = clock }

fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl }

fun headers(headers: Map<String, Iterable<String>>) = apply {
this.headers.clear()
putAllHeaders(headers)
}

fun putHeader(name: String, value: String) = apply {
this.headers.getOrPut(name) { mutableListOf() }.add(value)
}
fun putHeader(name: String, value: String) = apply { headers.put(name, value) }

fun putHeaders(name: String, values: Iterable<String>) = apply {
this.headers.getOrPut(name) { mutableListOf() }.addAll(values)
headers.putAll(name, values)
}

fun putAllHeaders(headers: Map<String, Iterable<String>>) = apply {
headers.forEach(this::putHeaders)
headers.forEach(::putHeaders)
}

fun removeHeader(name: String) = apply { this.headers.put(name, mutableListOf()) }
fun removeHeader(name: String) = apply { headers.removeAll(name) }

fun queryParams(queryParams: Map<String, Iterable<String>>) = apply {
this.queryParams.clear()
putAllQueryParams(queryParams)
}

fun putQueryParam(name: String, value: String) = apply {
this.queryParams.getOrPut(name) { mutableListOf() }.add(value)
}
fun putQueryParam(name: String, value: String) = apply { queryParams.put(name, value) }

fun putQueryParams(name: String, values: Iterable<String>) = apply {
this.queryParams.getOrPut(name) { mutableListOf() }.addAll(values)
queryParams.putAll(name, values)
}

fun putAllQueryParams(queryParams: Map<String, Iterable<String>>) = apply {
queryParams.forEach(this::putQueryParams)
queryParams.forEach(::putQueryParams)
}

fun removeQueryParam(name: String) = apply { this.queryParams.put(name, mutableListOf()) }
fun removeQueryParam(name: String) = apply { queryParams.removeAll(name) }

fun responseValidation(responseValidation: Boolean) = apply {
this.responseValidation = responseValidation
Expand Down Expand Up @@ -137,8 +127,8 @@ private constructor(
if (!apiKey.isNullOrEmpty()) {
queryParams.put("key", apiKey)
}
this.headers.forEach(headers::replaceValues)
this.queryParams.forEach(queryParams::replaceValues)
this.headers.asMap().forEach(headers::replaceValues)
this.queryParams.asMap().forEach(queryParams::replaceValues)

return ClientOptions(
httpClient!!,
Expand All @@ -149,14 +139,14 @@ private constructor(
.maxRetries(maxRetries)
.build()
),
jsonMapper ?: jsonMapper(),
jsonMapper,
clock,
baseUrl,
apiKey!!,
headers.toUnmodifiable(),
queryParams.toUnmodifiable(),
headers.toImmutable(),
queryParams.toImmutable(),
responseValidation,
maxRetries,
apiKey!!,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,24 @@ package org.onebusaway.core

import com.google.common.collect.ImmutableListMultimap
import com.google.common.collect.ListMultimap
import com.google.common.collect.Multimaps
import java.util.Collections
import java.util.SortedMap
import org.onebusaway.errors.OnebusawaySdkInvalidDataException

internal fun <T : Any> T?.getOrThrow(name: String): T =
this ?: throw OnebusawaySdkInvalidDataException("`${name}` is not present")

internal fun <T> List<T>.toUnmodifiable(): List<T> {
if (isEmpty()) {
return Collections.emptyList()
}
internal fun <T> List<T>.toImmutable(): List<T> =
if (isEmpty()) Collections.emptyList() else Collections.unmodifiableList(toList())

return Collections.unmodifiableList(this)
}
internal fun <K, V> Map<K, V>.toImmutable(): Map<K, V> =
if (isEmpty()) Collections.emptyMap() else Collections.unmodifiableMap(toMap())

internal fun <K, V> Map<K, V>.toUnmodifiable(): Map<K, V> {
if (isEmpty()) {
return Collections.emptyMap()
}
internal fun <K : Comparable<K>, V> SortedMap<K, V>.toImmutable(): SortedMap<K, V> =
if (isEmpty()) Collections.emptySortedMap()
else Collections.unmodifiableSortedMap(toSortedMap(comparator()))

return Collections.unmodifiableMap(this)
}

internal fun <K, V> ListMultimap<K, V>.toUnmodifiable(): ListMultimap<K, V> {
if (isEmpty()) {
return ImmutableListMultimap.of()
}

return Multimaps.unmodifiableListMultimap(this)
}
internal fun <K, V> ListMultimap<K, V>.toImmutable(): ListMultimap<K, V> =
ImmutableListMultimap.copyOf(this)

internal interface Enum
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ private constructor(
override fun toString() = values.toString()

companion object {
@JsonCreator fun of(values: List<JsonValue>) = JsonArray(values.toUnmodifiable())
@JsonCreator fun of(values: List<JsonValue>) = JsonArray(values.toImmutable())
}
}

Expand All @@ -411,7 +411,7 @@ private constructor(
override fun toString() = values.toString()

companion object {
@JsonCreator fun of(values: Map<String, JsonValue>) = JsonObject(values.toUnmodifiable())
@JsonCreator fun of(values: Map<String, JsonValue>) = JsonObject(values.toImmutable())
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.onebusaway.core.http

import java.util.TreeMap
import org.onebusaway.core.toImmutable

class Headers private constructor(private val map: Map<String, List<String>>, val size: Int) {

fun isEmpty(): Boolean = map.isEmpty()

fun names(): Set<String> = map.keys

fun values(name: String): List<String> = map[name].orEmpty()

fun toBuilder(): Builder = Builder().putAll(map)

companion object {

fun builder() = Builder()
}

class Builder {

private val map: MutableMap<String, MutableList<String>> =
TreeMap(String.CASE_INSENSITIVE_ORDER)
private var size: Int = 0

fun put(name: String, value: String) = apply {
map.getOrPut(name) { mutableListOf() }.add(value)
size++
}

fun put(name: String, values: Iterable<String>) = apply { values.forEach { put(name, it) } }

fun putAll(headers: Map<String, Iterable<String>>) = apply { headers.forEach(::put) }

fun putAll(headers: Headers) = apply {
headers.names().forEach { put(it, headers.values(it)) }
}

fun replace(name: String, value: String) = apply {
remove(name)
put(name, value)
}

fun replace(name: String, values: Iterable<String>) = apply {
remove(name)
put(name, values)
}

fun replaceAll(headers: Map<String, Iterable<String>>) = apply {
headers.forEach(::replace)
}

fun replaceAll(headers: Headers) = apply {
headers.names().forEach { replace(it, headers.values(it)) }
}

fun remove(name: String) = apply { size -= map.remove(name).orEmpty().size }

fun removeAll(names: Set<String>) = apply { names.forEach(::remove) }

fun clear() = apply {
map.clear()
size = 0
}

fun build() =
Headers(
map.mapValuesTo(TreeMap(String.CASE_INSENSITIVE_ORDER)) { (_, values) ->
values.toImmutable()
}
.toImmutable(),
size
)
}

override fun hashCode(): Int = map.hashCode()

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}

return other is Headers && map == other.map
}

override fun toString(): String = "Headers{map=$map}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.google.common.collect.ArrayListMultimap
import com.google.common.collect.ListMultimap
import com.google.common.collect.Multimap
import com.google.common.collect.MultimapBuilder
import org.onebusaway.core.toUnmodifiable
import org.onebusaway.core.toImmutable

class HttpRequest
private constructor(
Expand Down Expand Up @@ -83,8 +83,8 @@ private constructor(
HttpRequest(
checkNotNull(method) { "`method` is required but was not set" },
url,
pathSegments.toUnmodifiable(),
queryParams.toUnmodifiable(),
pathSegments.toImmutable(),
queryParams.toImmutable(),
headers,
body,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import java.util.Objects
import org.onebusaway.core.JsonValue
import org.onebusaway.core.NoAutoDetect
import org.onebusaway.core.toUnmodifiable
import org.onebusaway.core.toImmutable

@JsonDeserialize(builder = OnebusawaySdkError.Builder::class)
@NoAutoDetect
Expand Down Expand Up @@ -62,6 +62,6 @@ constructor(
this.additionalProperties.putAll(additionalProperties)
}

fun build(): OnebusawaySdkError = OnebusawaySdkError(additionalProperties.toUnmodifiable())
fun build(): OnebusawaySdkError = OnebusawaySdkError(additionalProperties.toImmutable())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package org.onebusaway.models

import java.util.Objects
import org.onebusaway.core.NoAutoDetect
import org.onebusaway.core.toUnmodifiable
import org.onebusaway.core.toImmutable
import org.onebusaway.models.*

class AgenciesWithCoverageListParams
Expand Down Expand Up @@ -96,8 +96,8 @@ constructor(

fun build(): AgenciesWithCoverageListParams =
AgenciesWithCoverageListParams(
additionalQueryParams.mapValues { it.value.toUnmodifiable() }.toUnmodifiable(),
additionalHeaders.mapValues { it.value.toUnmodifiable() }.toUnmodifiable()
additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(),
additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +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.toUnmodifiable
import org.onebusaway.core.toImmutable

@JsonDeserialize(builder = AgenciesWithCoverageListResponse.Builder::class)
@NoAutoDetect
Expand Down Expand Up @@ -148,7 +148,7 @@ private constructor(
text,
version,
data,
additionalProperties.toUnmodifiable(),
additionalProperties.toImmutable(),
)
}

Expand Down Expand Up @@ -249,9 +249,9 @@ private constructor(
fun build(): Data =
Data(
limitExceeded,
list.map { it.toUnmodifiable() },
list.map { it.toImmutable() },
references,
additionalProperties.toUnmodifiable(),
additionalProperties.toImmutable(),
)
}

Expand Down Expand Up @@ -381,7 +381,7 @@ private constructor(
latSpan,
lon,
lonSpan,
additionalProperties.toUnmodifiable(),
additionalProperties.toImmutable(),
)
}

Expand Down
Loading

0 comments on commit fc6c26f

Please sign in to comment.