Skip to content

Commit a90f9f4

Browse files
chore: rebuild project due to codegen change (#48)
1 parent 8e5a228 commit a90f9f4

File tree

67 files changed

+751
-723
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+751
-723
lines changed

onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/ClientOptions.kt

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ private constructor(
1717
@get:JvmName("jsonMapper") val jsonMapper: JsonMapper,
1818
@get:JvmName("clock") val clock: Clock,
1919
@get:JvmName("baseUrl") val baseUrl: String,
20-
@get:JvmName("apiKey") val apiKey: String,
2120
@get:JvmName("headers") val headers: ListMultimap<String, String>,
2221
@get:JvmName("queryParams") val queryParams: ListMultimap<String, String>,
2322
@get:JvmName("responseValidation") val responseValidation: Boolean,
2423
@get:JvmName("maxRetries") val maxRetries: Int,
24+
@get:JvmName("apiKey") val apiKey: String,
2525
) {
2626

2727
fun toBuilder() = Builder().from(this)
@@ -38,11 +38,11 @@ private constructor(
3838
class Builder {
3939

4040
private var httpClient: HttpClient? = null
41-
private var jsonMapper: JsonMapper? = null
41+
private var jsonMapper: JsonMapper = jsonMapper()
4242
private var clock: Clock = Clock.systemUTC()
4343
private var baseUrl: String = PRODUCTION_URL
44-
private var headers: MutableMap<String, MutableList<String>> = mutableMapOf()
45-
private var queryParams: MutableMap<String, MutableList<String>> = mutableMapOf()
44+
private var headers: ListMultimap<String, String> = ArrayListMultimap.create()
45+
private var queryParams: ListMultimap<String, String> = ArrayListMultimap.create()
4646
private var responseValidation: Boolean = false
4747
private var maxRetries: Int = 2
4848
private var apiKey: String? = null
@@ -53,14 +53,8 @@ private constructor(
5353
jsonMapper = clientOptions.jsonMapper
5454
clock = clientOptions.clock
5555
baseUrl = clientOptions.baseUrl
56-
headers =
57-
clientOptions.headers.asMap().mapValuesTo(mutableMapOf()) { (_, value) ->
58-
value.toMutableList()
59-
}
60-
queryParams =
61-
clientOptions.queryParams.asMap().mapValuesTo(mutableMapOf()) { (_, value) ->
62-
value.toMutableList()
63-
}
56+
headers = ArrayListMultimap.create(clientOptions.headers)
57+
queryParams = ArrayListMultimap.create(clientOptions.queryParams)
6458
responseValidation = clientOptions.responseValidation
6559
maxRetries = clientOptions.maxRetries
6660
apiKey = clientOptions.apiKey
@@ -70,47 +64,43 @@ private constructor(
7064

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

73-
fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl }
74-
7567
fun clock(clock: Clock) = apply { this.clock = clock }
7668

69+
fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl }
70+
7771
fun headers(headers: Map<String, Iterable<String>>) = apply {
7872
this.headers.clear()
7973
putAllHeaders(headers)
8074
}
8175

82-
fun putHeader(name: String, value: String) = apply {
83-
this.headers.getOrPut(name) { mutableListOf() }.add(value)
84-
}
76+
fun putHeader(name: String, value: String) = apply { headers.put(name, value) }
8577

8678
fun putHeaders(name: String, values: Iterable<String>) = apply {
87-
this.headers.getOrPut(name) { mutableListOf() }.addAll(values)
79+
headers.putAll(name, values)
8880
}
8981

9082
fun putAllHeaders(headers: Map<String, Iterable<String>>) = apply {
91-
headers.forEach(this::putHeaders)
83+
headers.forEach(::putHeaders)
9284
}
9385

94-
fun removeHeader(name: String) = apply { this.headers.put(name, mutableListOf()) }
86+
fun removeHeader(name: String) = apply { headers.removeAll(name) }
9587

9688
fun queryParams(queryParams: Map<String, Iterable<String>>) = apply {
9789
this.queryParams.clear()
9890
putAllQueryParams(queryParams)
9991
}
10092

101-
fun putQueryParam(name: String, value: String) = apply {
102-
this.queryParams.getOrPut(name) { mutableListOf() }.add(value)
103-
}
93+
fun putQueryParam(name: String, value: String) = apply { queryParams.put(name, value) }
10494

10595
fun putQueryParams(name: String, values: Iterable<String>) = apply {
106-
this.queryParams.getOrPut(name) { mutableListOf() }.addAll(values)
96+
queryParams.putAll(name, values)
10797
}
10898

10999
fun putAllQueryParams(queryParams: Map<String, Iterable<String>>) = apply {
110-
queryParams.forEach(this::putQueryParams)
100+
queryParams.forEach(::putQueryParams)
111101
}
112102

113-
fun removeQueryParam(name: String) = apply { this.queryParams.put(name, mutableListOf()) }
103+
fun removeQueryParam(name: String) = apply { queryParams.removeAll(name) }
114104

115105
fun responseValidation(responseValidation: Boolean) = apply {
116106
this.responseValidation = responseValidation
@@ -138,8 +128,8 @@ private constructor(
138128
if (!apiKey.isNullOrEmpty()) {
139129
queryParams.put("key", apiKey)
140130
}
141-
this.headers.forEach(headers::replaceValues)
142-
this.queryParams.forEach(queryParams::replaceValues)
131+
this.headers.asMap().forEach(headers::replaceValues)
132+
this.queryParams.asMap().forEach(queryParams::replaceValues)
143133

144134
return ClientOptions(
145135
httpClient!!,
@@ -150,14 +140,14 @@ private constructor(
150140
.maxRetries(maxRetries)
151141
.build()
152142
),
153-
jsonMapper ?: jsonMapper(),
143+
jsonMapper,
154144
clock,
155145
baseUrl,
156-
apiKey!!,
157-
headers.toUnmodifiable(),
158-
queryParams.toUnmodifiable(),
146+
headers.toImmutable(),
147+
queryParams.toImmutable(),
159148
responseValidation,
160149
maxRetries,
150+
apiKey!!,
161151
)
162152
}
163153
}

onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Utils.kt

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,29 @@ package org.onebusaway.core
44

55
import com.google.common.collect.ImmutableListMultimap
66
import com.google.common.collect.ListMultimap
7-
import com.google.common.collect.Multimaps
87
import java.util.Collections
8+
import java.util.SortedMap
99
import org.onebusaway.errors.OnebusawaySdkInvalidDataException
1010

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

1515
@JvmSynthetic
16-
internal fun <T> List<T>.toUnmodifiable(): List<T> {
17-
if (isEmpty()) {
18-
return Collections.emptyList()
19-
}
20-
21-
return Collections.unmodifiableList(this)
22-
}
16+
internal fun <T> List<T>.toImmutable(): List<T> =
17+
if (isEmpty()) Collections.emptyList() else Collections.unmodifiableList(toList())
2318

2419
@JvmSynthetic
25-
internal fun <K, V> Map<K, V>.toUnmodifiable(): Map<K, V> {
26-
if (isEmpty()) {
27-
return Collections.emptyMap()
28-
}
29-
30-
return Collections.unmodifiableMap(this)
31-
}
20+
internal fun <K, V> Map<K, V>.toImmutable(): Map<K, V> =
21+
if (isEmpty()) Collections.emptyMap() else Collections.unmodifiableMap(toMap())
3222

3323
@JvmSynthetic
34-
internal fun <K, V> ListMultimap<K, V>.toUnmodifiable(): ListMultimap<K, V> {
35-
if (isEmpty()) {
36-
return ImmutableListMultimap.of()
37-
}
24+
internal fun <K : Comparable<K>, V> SortedMap<K, V>.toImmutable(): SortedMap<K, V> =
25+
if (isEmpty()) Collections.emptySortedMap()
26+
else Collections.unmodifiableSortedMap(toSortedMap(comparator()))
3827

39-
return Multimaps.unmodifiableListMultimap(this)
40-
}
28+
@JvmSynthetic
29+
internal fun <K, V> ListMultimap<K, V>.toImmutable(): ListMultimap<K, V> =
30+
ImmutableListMultimap.copyOf(this)
4131

4232
internal interface Enum

onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/Values.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private constructor(
391391
override fun toString() = values.toString()
392392

393393
companion object {
394-
@JsonCreator @JvmStatic fun of(values: List<JsonValue>) = JsonArray(values.toUnmodifiable())
394+
@JsonCreator @JvmStatic fun of(values: List<JsonValue>) = JsonArray(values.toImmutable())
395395
}
396396
}
397397

@@ -417,7 +417,7 @@ private constructor(
417417
companion object {
418418
@JsonCreator
419419
@JvmStatic
420-
fun of(values: Map<String, JsonValue>) = JsonObject(values.toUnmodifiable())
420+
fun of(values: Map<String, JsonValue>) = JsonObject(values.toImmutable())
421421
}
422422
}
423423

onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/BinaryResponseContent.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package org.onebusaway.core.http
2+
3+
import java.util.TreeMap
4+
import org.onebusaway.core.toImmutable
5+
6+
class Headers
7+
private constructor(
8+
private val map: Map<String, List<String>>,
9+
@get:JvmName("size") val size: Int
10+
) {
11+
12+
fun isEmpty(): Boolean = map.isEmpty()
13+
14+
fun names(): Set<String> = map.keys
15+
16+
fun values(name: String): List<String> = map[name].orEmpty()
17+
18+
fun toBuilder(): Builder = Builder().putAll(map)
19+
20+
companion object {
21+
22+
@JvmStatic fun builder() = Builder()
23+
}
24+
25+
class Builder {
26+
27+
private val map: MutableMap<String, MutableList<String>> =
28+
TreeMap(String.CASE_INSENSITIVE_ORDER)
29+
private var size: Int = 0
30+
31+
fun put(name: String, value: String) = apply {
32+
map.getOrPut(name) { mutableListOf() }.add(value)
33+
size++
34+
}
35+
36+
fun put(name: String, values: Iterable<String>) = apply { values.forEach { put(name, it) } }
37+
38+
fun putAll(headers: Map<String, Iterable<String>>) = apply { headers.forEach(::put) }
39+
40+
fun putAll(headers: Headers) = apply {
41+
headers.names().forEach { put(it, headers.values(it)) }
42+
}
43+
44+
fun remove(name: String) = apply { size -= map.remove(name).orEmpty().size }
45+
46+
fun removeAll(names: Set<String>) = apply { names.forEach(::remove) }
47+
48+
fun clear() = apply {
49+
map.clear()
50+
size = 0
51+
}
52+
53+
fun replace(name: String, value: String) = apply {
54+
remove(name)
55+
put(name, value)
56+
}
57+
58+
fun replace(name: String, values: Iterable<String>) = apply {
59+
remove(name)
60+
put(name, values)
61+
}
62+
63+
fun replaceAll(headers: Map<String, Iterable<String>>) = apply {
64+
headers.forEach(::replace)
65+
}
66+
67+
fun replaceAll(headers: Headers) = apply {
68+
headers.names().forEach { replace(it, headers.values(it)) }
69+
}
70+
71+
fun build() =
72+
Headers(
73+
map.mapValuesTo(TreeMap(String.CASE_INSENSITIVE_ORDER)) { (_, values) ->
74+
values.toImmutable()
75+
}
76+
.toImmutable(),
77+
size
78+
)
79+
}
80+
81+
override fun hashCode(): Int = map.hashCode()
82+
83+
override fun equals(other: Any?): Boolean {
84+
if (this === other) {
85+
return true
86+
}
87+
88+
return other is Headers && map == other.map
89+
}
90+
91+
override fun toString(): String = "Headers{map=$map}"
92+
}

onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/core/http/HttpRequest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.google.common.collect.ArrayListMultimap
44
import com.google.common.collect.ListMultimap
55
import com.google.common.collect.Multimap
66
import com.google.common.collect.MultimapBuilder
7-
import org.onebusaway.core.toUnmodifiable
7+
import org.onebusaway.core.toImmutable
88

99
class HttpRequest
1010
private constructor(
@@ -83,8 +83,8 @@ private constructor(
8383
HttpRequest(
8484
checkNotNull(method) { "`method` is required but was not set" },
8585
url,
86-
pathSegments.toUnmodifiable(),
87-
queryParams.toUnmodifiable(),
86+
pathSegments.toImmutable(),
87+
queryParams.toImmutable(),
8888
headers,
8989
body,
9090
)

onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/errors/OnebusawaySdkError.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
88
import java.util.Objects
99
import org.onebusaway.core.JsonValue
1010
import org.onebusaway.core.NoAutoDetect
11-
import org.onebusaway.core.toUnmodifiable
11+
import org.onebusaway.core.toImmutable
1212

1313
@JsonDeserialize(builder = OnebusawaySdkError.Builder::class)
1414
@NoAutoDetect
@@ -62,6 +62,6 @@ constructor(
6262
this.additionalProperties.putAll(additionalProperties)
6363
}
6464

65-
fun build(): OnebusawaySdkError = OnebusawaySdkError(additionalProperties.toUnmodifiable())
65+
fun build(): OnebusawaySdkError = OnebusawaySdkError(additionalProperties.toImmutable())
6666
}
6767
}

onebusaway-sdk-java-core/src/main/kotlin/org/onebusaway/models/AgenciesWithCoverageListParams.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package org.onebusaway.models
44

55
import java.util.Objects
66
import org.onebusaway.core.NoAutoDetect
7-
import org.onebusaway.core.toUnmodifiable
7+
import org.onebusaway.core.toImmutable
88
import org.onebusaway.models.*
99

1010
class AgenciesWithCoverageListParams
@@ -97,8 +97,8 @@ constructor(
9797

9898
fun build(): AgenciesWithCoverageListParams =
9999
AgenciesWithCoverageListParams(
100-
additionalQueryParams.mapValues { it.value.toUnmodifiable() }.toUnmodifiable(),
101-
additionalHeaders.mapValues { it.value.toUnmodifiable() }.toUnmodifiable()
100+
additionalQueryParams.mapValues { it.value.toImmutable() }.toImmutable(),
101+
additionalHeaders.mapValues { it.value.toImmutable() }.toImmutable()
102102
)
103103
}
104104
}

0 commit comments

Comments
 (0)