Skip to content

Commit 02fd429

Browse files
chore(internal): use getOrNull instead of orElse(null) (#324)
1 parent 8c1f105 commit 02fd429

File tree

142 files changed

+3902
-4736
lines changed

Some content is hidden

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

142 files changed

+3902
-4736
lines changed

orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import java.net.Proxy
1313
import java.time.Clock
1414
import java.time.Duration
1515
import java.util.Optional
16+
import kotlin.jvm.optionals.getOrNull
1617

1718
class OrbOkHttpClient private constructor() {
1819

@@ -150,7 +151,7 @@ class OrbOkHttpClient private constructor() {
150151
}
151152

152153
fun webhookSecret(webhookSecret: Optional<String>) =
153-
webhookSecret(webhookSecret.orElse(null))
154+
webhookSecret(webhookSecret.getOrNull())
154155

155156
fun fromEnv() = apply { clientOptions.fromEnv() }
156157

orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import java.net.Proxy
1313
import java.time.Clock
1414
import java.time.Duration
1515
import java.util.Optional
16+
import kotlin.jvm.optionals.getOrNull
1617

1718
class OrbOkHttpClientAsync private constructor() {
1819

@@ -150,7 +151,7 @@ class OrbOkHttpClientAsync private constructor() {
150151
}
151152

152153
fun webhookSecret(webhookSecret: Optional<String>) =
153-
webhookSecret(webhookSecret.orElse(null))
154+
webhookSecret(webhookSecret.getOrNull())
154155

155156
fun fromEnv() = apply { clientOptions.fromEnv() }
156157

orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.withorb.api.core.http.QueryParams
1010
import com.withorb.api.core.http.RetryingHttpClient
1111
import java.time.Clock
1212
import java.util.Optional
13+
import kotlin.jvm.optionals.getOrNull
1314

1415
class ClientOptions
1516
private constructor(
@@ -100,7 +101,7 @@ private constructor(
100101
fun webhookSecret(webhookSecret: String?) = apply { this.webhookSecret = webhookSecret }
101102

102103
fun webhookSecret(webhookSecret: Optional<String>) =
103-
webhookSecret(webhookSecret.orElse(null))
104+
webhookSecret(webhookSecret.getOrNull())
104105

105106
fun headers(headers: Headers) = apply {
106107
this.headers.clear()

orb-java-core/src/main/kotlin/com/withorb/api/core/Timeout.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package com.withorb.api.core
55
import java.time.Duration
66
import java.util.Objects
77
import java.util.Optional
8+
import kotlin.jvm.optionals.getOrNull
89

910
/** A class containing timeouts for various processing phases of a request. */
1011
class Timeout
@@ -96,7 +97,7 @@ private constructor(
9697
*
9798
* Defaults to `Duration.ofMinutes(1)`.
9899
*/
99-
fun connect(connect: Optional<Duration>) = connect(connect.orElse(null))
100+
fun connect(connect: Optional<Duration>) = connect(connect.getOrNull())
100101

101102
/**
102103
* The maximum time allowed between two data packets when waiting for the server’s response.
@@ -114,7 +115,7 @@ private constructor(
114115
*
115116
* Defaults to `request()`.
116117
*/
117-
fun read(read: Optional<Duration>) = read(read.orElse(null))
118+
fun read(read: Optional<Duration>) = read(read.getOrNull())
118119

119120
/**
120121
* The maximum time allowed between two data packets when sending the request to the server.
@@ -132,7 +133,7 @@ private constructor(
132133
*
133134
* Defaults to `request()`.
134135
*/
135-
fun write(write: Optional<Duration>) = write(write.orElse(null))
136+
fun write(write: Optional<Duration>) = write(write.getOrNull())
136137

137138
/**
138139
* The maximum time allowed for a complete HTTP call, not including retries.
@@ -156,7 +157,7 @@ private constructor(
156157
*
157158
* Defaults to `Duration.ofMinutes(1)`.
158159
*/
159-
fun request(request: Optional<Duration>) = request(request.orElse(null))
160+
fun request(request: Optional<Duration>) = request(request.getOrNull())
160161

161162
fun build(): Timeout = Timeout(connect, read, write, request)
162163
}

orb-java-core/src/main/kotlin/com/withorb/api/models/Alert.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.withorb.api.errors.OrbInvalidDataException
2020
import java.time.OffsetDateTime
2121
import java.util.Objects
2222
import java.util.Optional
23+
import kotlin.jvm.optionals.getOrNull
2324

2425
/**
2526
* [Alerts within Orb](/product-catalog/configuring-alerts) monitor spending, usage, or credit
@@ -220,7 +221,7 @@ private constructor(
220221
fun currency(currency: String?) = currency(JsonField.ofNullable(currency))
221222

222223
/** The name of the currency the credit balance or invoice cost is denominated in. */
223-
fun currency(currency: Optional<String>) = currency(currency.orElse(null))
224+
fun currency(currency: Optional<String>) = currency(currency.getOrNull())
224225

225226
/** The name of the currency the credit balance or invoice cost is denominated in. */
226227
fun currency(currency: JsonField<String>) = apply { this.currency = currency }
@@ -229,7 +230,7 @@ private constructor(
229230
fun customer(customer: Customer?) = customer(JsonField.ofNullable(customer))
230231

231232
/** The customer the alert applies to. */
232-
fun customer(customer: Optional<Customer>) = customer(customer.orElse(null))
233+
fun customer(customer: Optional<Customer>) = customer(customer.getOrNull())
233234

234235
/** The customer the alert applies to. */
235236
fun customer(customer: JsonField<Customer>) = apply { this.customer = customer }
@@ -244,7 +245,7 @@ private constructor(
244245
fun metric(metric: Metric?) = metric(JsonField.ofNullable(metric))
245246

246247
/** The metric the alert applies to. */
247-
fun metric(metric: Optional<Metric>) = metric(metric.orElse(null))
248+
fun metric(metric: Optional<Metric>) = metric(metric.getOrNull())
248249

249250
/** The metric the alert applies to. */
250251
fun metric(metric: JsonField<Metric>) = apply { this.metric = metric }
@@ -253,7 +254,7 @@ private constructor(
253254
fun plan(plan: Plan?) = plan(JsonField.ofNullable(plan))
254255

255256
/** The plan the alert applies to. */
256-
fun plan(plan: Optional<Plan>) = plan(plan.orElse(null))
257+
fun plan(plan: Optional<Plan>) = plan(plan.getOrNull())
257258

258259
/** The plan the alert applies to. */
259260
fun plan(plan: JsonField<Plan>) = apply { this.plan = plan }
@@ -264,7 +265,7 @@ private constructor(
264265

265266
/** The subscription the alert applies to. */
266267
fun subscription(subscription: Optional<Subscription>) =
267-
subscription(subscription.orElse(null))
268+
subscription(subscription.getOrNull())
268269

269270
/** The subscription the alert applies to. */
270271
fun subscription(subscription: JsonField<Subscription>) = apply {
@@ -275,7 +276,7 @@ private constructor(
275276
fun thresholds(thresholds: List<Threshold>?) = thresholds(JsonField.ofNullable(thresholds))
276277

277278
/** The thresholds that define the conditions under which the alert will be triggered. */
278-
fun thresholds(thresholds: Optional<List<Threshold>>) = thresholds(thresholds.orElse(null))
279+
fun thresholds(thresholds: Optional<List<Threshold>>) = thresholds(thresholds.getOrNull())
279280

280281
/** The thresholds that define the conditions under which the alert will be triggered. */
281282
fun thresholds(thresholds: JsonField<List<Threshold>>) = apply {
@@ -409,7 +410,7 @@ private constructor(
409410
externalCustomerId(JsonField.ofNullable(externalCustomerId))
410411

411412
fun externalCustomerId(externalCustomerId: Optional<String>) =
412-
externalCustomerId(externalCustomerId.orElse(null))
413+
externalCustomerId(externalCustomerId.getOrNull())
413414

414415
fun externalCustomerId(externalCustomerId: JsonField<String>) = apply {
415416
this.externalCustomerId = externalCustomerId
@@ -666,7 +667,7 @@ private constructor(
666667

667668
fun id(id: String?) = id(JsonField.ofNullable(id))
668669

669-
fun id(id: Optional<String>) = id(id.orElse(null))
670+
fun id(id: Optional<String>) = id(id.getOrNull())
670671

671672
fun id(id: JsonField<String>) = apply { this.id = id }
672673

@@ -684,7 +685,7 @@ private constructor(
684685
* your system.
685686
*/
686687
fun externalPlanId(externalPlanId: Optional<String>) =
687-
externalPlanId(externalPlanId.orElse(null))
688+
externalPlanId(externalPlanId.getOrNull())
688689

689690
/**
690691
* An optional user-defined ID for this plan resource, used throughout the system as an
@@ -697,7 +698,7 @@ private constructor(
697698

698699
fun name(name: String?) = name(JsonField.ofNullable(name))
699700

700-
fun name(name: Optional<String>) = name(name.orElse(null))
701+
fun name(name: Optional<String>) = name(name.getOrNull())
701702

702703
fun name(name: JsonField<String>) = apply { this.name = name }
703704

orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForCustomerParams.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.withorb.api.core.toImmutable
2222
import com.withorb.api.errors.OrbInvalidDataException
2323
import java.util.Objects
2424
import java.util.Optional
25+
import kotlin.jvm.optionals.getOrNull
2526

2627
/**
2728
* This endpoint creates a new alert to monitor a customer's credit balance. There are three types
@@ -181,7 +182,7 @@ private constructor(
181182

182183
/** The thresholds that define the values at which the alert will be triggered. */
183184
fun thresholds(thresholds: Optional<List<Threshold>>) =
184-
thresholds(thresholds.orElse(null))
185+
thresholds(thresholds.getOrNull())
185186

186187
/** The thresholds that define the values at which the alert will be triggered. */
187188
fun thresholds(thresholds: JsonField<List<Threshold>>) = apply {
@@ -294,7 +295,7 @@ private constructor(
294295
fun thresholds(thresholds: List<Threshold>?) = apply { body.thresholds(thresholds) }
295296

296297
/** The thresholds that define the values at which the alert will be triggered. */
297-
fun thresholds(thresholds: Optional<List<Threshold>>) = thresholds(thresholds.orElse(null))
298+
fun thresholds(thresholds: Optional<List<Threshold>>) = thresholds(thresholds.getOrNull())
298299

299300
/** The thresholds that define the values at which the alert will be triggered. */
300301
fun thresholds(thresholds: JsonField<List<Threshold>>) = apply {

orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForExternalCustomerParams.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.withorb.api.core.toImmutable
2222
import com.withorb.api.errors.OrbInvalidDataException
2323
import java.util.Objects
2424
import java.util.Optional
25+
import kotlin.jvm.optionals.getOrNull
2526

2627
/**
2728
* This endpoint creates a new alert to monitor a customer's credit balance. There are three types
@@ -181,7 +182,7 @@ private constructor(
181182

182183
/** The thresholds that define the values at which the alert will be triggered. */
183184
fun thresholds(thresholds: Optional<List<Threshold>>) =
184-
thresholds(thresholds.orElse(null))
185+
thresholds(thresholds.getOrNull())
185186

186187
/** The thresholds that define the values at which the alert will be triggered. */
187188
fun thresholds(thresholds: JsonField<List<Threshold>>) = apply {
@@ -300,7 +301,7 @@ private constructor(
300301
fun thresholds(thresholds: List<Threshold>?) = apply { body.thresholds(thresholds) }
301302

302303
/** The thresholds that define the values at which the alert will be triggered. */
303-
fun thresholds(thresholds: Optional<List<Threshold>>) = thresholds(thresholds.orElse(null))
304+
fun thresholds(thresholds: Optional<List<Threshold>>) = thresholds(thresholds.getOrNull())
304305

305306
/** The thresholds that define the values at which the alert will be triggered. */
306307
fun thresholds(thresholds: JsonField<List<Threshold>>) = apply {

orb-java-core/src/main/kotlin/com/withorb/api/models/AlertCreateForSubscriptionParams.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.withorb.api.core.toImmutable
2222
import com.withorb.api.errors.OrbInvalidDataException
2323
import java.util.Objects
2424
import java.util.Optional
25+
import kotlin.jvm.optionals.getOrNull
2526

2627
/**
2728
* This endpoint is used to create alerts at the subscription level.
@@ -192,7 +193,7 @@ private constructor(
192193
fun metricId(metricId: String?) = metricId(JsonField.ofNullable(metricId))
193194

194195
/** The metric to track usage for. */
195-
fun metricId(metricId: Optional<String>) = metricId(metricId.orElse(null))
196+
fun metricId(metricId: Optional<String>) = metricId(metricId.getOrNull())
196197

197198
/** The metric to track usage for. */
198199
fun metricId(metricId: JsonField<String>) = apply { this.metricId = metricId }
@@ -303,7 +304,7 @@ private constructor(
303304
fun metricId(metricId: String?) = apply { body.metricId(metricId) }
304305

305306
/** The metric to track usage for. */
306-
fun metricId(metricId: Optional<String>) = metricId(metricId.orElse(null))
307+
fun metricId(metricId: Optional<String>) = metricId(metricId.getOrNull())
307308

308309
/** The metric to track usage for. */
309310
fun metricId(metricId: JsonField<String>) = apply { body.metricId(metricId) }

orb-java-core/src/main/kotlin/com/withorb/api/models/AlertDisableParams.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.withorb.api.core.http.QueryParams
1111
import com.withorb.api.core.toImmutable
1212
import java.util.Objects
1313
import java.util.Optional
14+
import kotlin.jvm.optionals.getOrNull
1415

1516
/**
1617
* This endpoint allows you to disable an alert. To disable a plan-level alert for a specific
@@ -100,7 +101,7 @@ private constructor(
100101

101102
/** Used to update the status of a plan alert scoped to this subscription_id */
102103
fun subscriptionId(subscriptionId: Optional<String>) =
103-
subscriptionId(subscriptionId.orElse(null))
104+
subscriptionId(subscriptionId.getOrNull())
104105

105106
fun additionalHeaders(additionalHeaders: Headers) = apply {
106107
this.additionalHeaders.clear()

orb-java-core/src/main/kotlin/com/withorb/api/models/AlertEnableParams.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.withorb.api.core.http.QueryParams
1111
import com.withorb.api.core.toImmutable
1212
import java.util.Objects
1313
import java.util.Optional
14+
import kotlin.jvm.optionals.getOrNull
1415

1516
/**
1617
* This endpoint allows you to enable an alert. To enable a plan-level alert for a specific
@@ -100,7 +101,7 @@ private constructor(
100101

101102
/** Used to update the status of a plan alert scoped to this subscription_id */
102103
fun subscriptionId(subscriptionId: Optional<String>) =
103-
subscriptionId(subscriptionId.orElse(null))
104+
subscriptionId(subscriptionId.getOrNull())
104105

105106
fun additionalHeaders(additionalHeaders: Headers) = apply {
106107
this.additionalHeaders.clear()

0 commit comments

Comments
 (0)