Skip to content

Commit 09c4f45

Browse files
chore(internal): use getOrNull instead of orElse(null) (#524)
1 parent 5bd8973 commit 09c4f45

100 files changed

Lines changed: 495 additions & 450 deletions

File tree

Some content is hidden

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

lithic-java-client-okhttp/src/main/kotlin/com/lithic/api/client/okhttp/LithicOkHttpClient.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 LithicOkHttpClient private constructor() {
1819

@@ -152,7 +153,7 @@ class LithicOkHttpClient private constructor() {
152153
}
153154

154155
fun webhookSecret(webhookSecret: Optional<String>) =
155-
webhookSecret(webhookSecret.orElse(null))
156+
webhookSecret(webhookSecret.getOrNull())
156157

157158
fun fromEnv() = apply { clientOptions.fromEnv() }
158159

lithic-java-client-okhttp/src/main/kotlin/com/lithic/api/client/okhttp/LithicOkHttpClientAsync.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 LithicOkHttpClientAsync private constructor() {
1819

@@ -152,7 +153,7 @@ class LithicOkHttpClientAsync private constructor() {
152153
}
153154

154155
fun webhookSecret(webhookSecret: Optional<String>) =
155-
webhookSecret(webhookSecret.orElse(null))
156+
webhookSecret(webhookSecret.getOrNull())
156157

157158
fun fromEnv() = apply { clientOptions.fromEnv() }
158159

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.lithic.api.core.http.QueryParams
1010
import com.lithic.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(
@@ -102,7 +103,7 @@ private constructor(
102103
fun webhookSecret(webhookSecret: String?) = apply { this.webhookSecret = webhookSecret }
103104

104105
fun webhookSecret(webhookSecret: Optional<String>) =
105-
webhookSecret(webhookSecret.orElse(null))
106+
webhookSecret(webhookSecret.getOrNull())
106107

107108
fun headers(headers: Headers) = apply {
108109
this.headers.clear()

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package com.lithic.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
}

lithic-java-core/src/main/kotlin/com/lithic/api/models/Account.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.lithic.api.errors.LithicInvalidDataException
2020
import java.time.OffsetDateTime
2121
import java.util.Objects
2222
import java.util.Optional
23+
import kotlin.jvm.optionals.getOrNull
2324

2425
@NoAutoDetect
2526
class Account
@@ -248,7 +249,7 @@ private constructor(
248249
* Timestamp of when the account was created. For accounts created before 2023-05-11, this
249250
* field will be null.
250251
*/
251-
fun created(created: Optional<OffsetDateTime>) = created(created.orElse(null))
252+
fun created(created: Optional<OffsetDateTime>) = created(created.getOrNull())
252253

253254
/**
254255
* Timestamp of when the account was created. For accounts created before 2023-05-11, this

lithic-java-core/src/main/kotlin/com/lithic/api/models/AccountHolderListPage.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import java.util.Objects
1818
import java.util.Optional
1919
import java.util.stream.Stream
2020
import java.util.stream.StreamSupport
21+
import kotlin.jvm.optionals.getOrNull
2122

2223
/** Get a list of individual or business account holders and their KYC or KYB evaluation status. */
2324
class AccountHolderListPage
@@ -167,7 +168,7 @@ private constructor(
167168
while (index < page.data().size) {
168169
yield(page.data()[index++])
169170
}
170-
page = page.getNextPage().orElse(null) ?: break
171+
page = page.getNextPage().getOrNull() ?: break
171172
index = 0
172173
}
173174
}

lithic-java-core/src/main/kotlin/com/lithic/api/models/AccountHolderListParams.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import java.time.OffsetDateTime
1010
import java.time.format.DateTimeFormatter
1111
import java.util.Objects
1212
import java.util.Optional
13+
import kotlin.jvm.optionals.getOrNull
1314

1415
/** Get a list of individual or business account holders and their KYC or KYB evaluation status. */
1516
class AccountHolderListParams
@@ -167,7 +168,7 @@ private constructor(
167168
* Date string in RFC 3339 format. Only entries created after the specified time will be
168169
* included. UTC time zone.
169170
*/
170-
fun begin(begin: Optional<OffsetDateTime>) = begin(begin.orElse(null))
171+
fun begin(begin: Optional<OffsetDateTime>) = begin(begin.getOrNull())
171172

172173
/**
173174
* Email address of the account holder. The query must be an exact match, case insensitive.
@@ -177,7 +178,7 @@ private constructor(
177178
/**
178179
* Email address of the account holder. The query must be an exact match, case insensitive.
179180
*/
180-
fun email(email: Optional<String>) = email(email.orElse(null))
181+
fun email(email: Optional<String>) = email(email.getOrNull())
181182

182183
/**
183184
* Date string in RFC 3339 format. Only entries created before the specified time will be
@@ -189,7 +190,7 @@ private constructor(
189190
* Date string in RFC 3339 format. Only entries created before the specified time will be
190191
* included. UTC time zone.
191192
*/
192-
fun end(end: Optional<OffsetDateTime>) = end(end.orElse(null))
193+
fun end(end: Optional<OffsetDateTime>) = end(end.getOrNull())
193194

194195
/**
195196
* A cursor representing an item's token before which a page of results should end. Used to
@@ -201,13 +202,13 @@ private constructor(
201202
* A cursor representing an item's token before which a page of results should end. Used to
202203
* retrieve the previous page of results before this item.
203204
*/
204-
fun endingBefore(endingBefore: Optional<String>) = endingBefore(endingBefore.orElse(null))
205+
fun endingBefore(endingBefore: Optional<String>) = endingBefore(endingBefore.getOrNull())
205206

206207
/** If applicable, represents the external_id associated with the account_holder. */
207208
fun externalId(externalId: String?) = apply { this.externalId = externalId }
208209

209210
/** If applicable, represents the external_id associated with the account_holder. */
210-
fun externalId(externalId: Optional<String>) = externalId(externalId.orElse(null))
211+
fun externalId(externalId: Optional<String>) = externalId(externalId.getOrNull())
211212

212213
/**
213214
* (Individual Account Holders only) The first name of the account holder. The query is case
@@ -219,7 +220,7 @@ private constructor(
219220
* (Individual Account Holders only) The first name of the account holder. The query is case
220221
* insensitive and supports partial matches.
221222
*/
222-
fun firstName(firstName: Optional<String>) = firstName(firstName.orElse(null))
223+
fun firstName(firstName: Optional<String>) = firstName(firstName.getOrNull())
223224

224225
/**
225226
* (Individual Account Holders only) The last name of the account holder. The query is case
@@ -231,7 +232,7 @@ private constructor(
231232
* (Individual Account Holders only) The last name of the account holder. The query is case
232233
* insensitive and supports partial matches.
233234
*/
234-
fun lastName(lastName: Optional<String>) = lastName(lastName.orElse(null))
235+
fun lastName(lastName: Optional<String>) = lastName(lastName.getOrNull())
235236

236237
/**
237238
* (Business Account Holders only) The legal business name of the account holder. The query
@@ -246,7 +247,7 @@ private constructor(
246247
* is case insensitive and supports partial matches.
247248
*/
248249
fun legalBusinessName(legalBusinessName: Optional<String>) =
249-
legalBusinessName(legalBusinessName.orElse(null))
250+
legalBusinessName(legalBusinessName.getOrNull())
250251

251252
/** The number of account_holders to limit the response to. */
252253
fun limit(limit: Long?) = apply { this.limit = limit }
@@ -255,14 +256,13 @@ private constructor(
255256
fun limit(limit: Long) = limit(limit as Long?)
256257

257258
/** The number of account_holders to limit the response to. */
258-
@Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228
259-
fun limit(limit: Optional<Long>) = limit(limit.orElse(null) as Long?)
259+
fun limit(limit: Optional<Long>) = limit(limit.getOrNull())
260260

261261
/** Phone number of the account holder. The query must be an exact match. */
262262
fun phoneNumber(phoneNumber: String?) = apply { this.phoneNumber = phoneNumber }
263263

264264
/** Phone number of the account holder. The query must be an exact match. */
265-
fun phoneNumber(phoneNumber: Optional<String>) = phoneNumber(phoneNumber.orElse(null))
265+
fun phoneNumber(phoneNumber: Optional<String>) = phoneNumber(phoneNumber.getOrNull())
266266

267267
/**
268268
* A cursor representing an item's token after which a page of results should begin. Used to
@@ -275,7 +275,7 @@ private constructor(
275275
* retrieve the next page of results after this item.
276276
*/
277277
fun startingAfter(startingAfter: Optional<String>) =
278-
startingAfter(startingAfter.orElse(null))
278+
startingAfter(startingAfter.getOrNull())
279279

280280
fun additionalHeaders(additionalHeaders: Headers) = apply {
281281
this.additionalHeaders.clear()

lithic-java-core/src/main/kotlin/com/lithic/api/models/AccountListPage.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import java.util.Objects
1818
import java.util.Optional
1919
import java.util.stream.Stream
2020
import java.util.stream.StreamSupport
21+
import kotlin.jvm.optionals.getOrNull
2122

2223
/** List account configurations. */
2324
class AccountListPage
@@ -180,7 +181,7 @@ private constructor(
180181
while (index < page.data().size) {
181182
yield(page.data()[index++])
182183
}
183-
page = page.getNextPage().orElse(null) ?: break
184+
page = page.getNextPage().getOrNull() ?: break
184185
index = 0
185186
}
186187
}

lithic-java-core/src/main/kotlin/com/lithic/api/models/AccountListParams.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import java.time.OffsetDateTime
1010
import java.time.format.DateTimeFormatter
1111
import java.util.Objects
1212
import java.util.Optional
13+
import kotlin.jvm.optionals.getOrNull
1314

1415
/** List account configurations. */
1516
class AccountListParams
@@ -114,7 +115,7 @@ private constructor(
114115
* Date string in RFC 3339 format. Only entries created after the specified time will be
115116
* included. UTC time zone.
116117
*/
117-
fun begin(begin: Optional<OffsetDateTime>) = begin(begin.orElse(null))
118+
fun begin(begin: Optional<OffsetDateTime>) = begin(begin.getOrNull())
118119

119120
/**
120121
* Date string in RFC 3339 format. Only entries created before the specified time will be
@@ -126,7 +127,7 @@ private constructor(
126127
* Date string in RFC 3339 format. Only entries created before the specified time will be
127128
* included. UTC time zone.
128129
*/
129-
fun end(end: Optional<OffsetDateTime>) = end(end.orElse(null))
130+
fun end(end: Optional<OffsetDateTime>) = end(end.getOrNull())
130131

131132
/**
132133
* A cursor representing an item's token before which a page of results should end. Used to
@@ -138,7 +139,7 @@ private constructor(
138139
* A cursor representing an item's token before which a page of results should end. Used to
139140
* retrieve the previous page of results before this item.
140141
*/
141-
fun endingBefore(endingBefore: Optional<String>) = endingBefore(endingBefore.orElse(null))
142+
fun endingBefore(endingBefore: Optional<String>) = endingBefore(endingBefore.getOrNull())
142143

143144
/** Page size (for pagination). */
144145
fun pageSize(pageSize: Long?) = apply { this.pageSize = pageSize }
@@ -147,8 +148,7 @@ private constructor(
147148
fun pageSize(pageSize: Long) = pageSize(pageSize as Long?)
148149

149150
/** Page size (for pagination). */
150-
@Suppress("USELESS_CAST") // See https://youtrack.jetbrains.com/issue/KT-74228
151-
fun pageSize(pageSize: Optional<Long>) = pageSize(pageSize.orElse(null) as Long?)
151+
fun pageSize(pageSize: Optional<Long>) = pageSize(pageSize.getOrNull())
152152

153153
/**
154154
* A cursor representing an item's token after which a page of results should begin. Used to
@@ -161,7 +161,7 @@ private constructor(
161161
* retrieve the next page of results after this item.
162162
*/
163163
fun startingAfter(startingAfter: Optional<String>) =
164-
startingAfter(startingAfter.orElse(null))
164+
startingAfter(startingAfter.getOrNull())
165165

166166
fun additionalHeaders(additionalHeaders: Headers) = apply {
167167
this.additionalHeaders.clear()

lithic-java-core/src/main/kotlin/com/lithic/api/models/AggregateBalanceListPage.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import java.util.Objects
1818
import java.util.Optional
1919
import java.util.stream.Stream
2020
import java.util.stream.StreamSupport
21+
import kotlin.jvm.optionals.getOrNull
2122

2223
/** Get the aggregated balance across all end-user accounts by financial account type */
2324
class AggregateBalanceListPage
@@ -168,7 +169,7 @@ private constructor(
168169
while (index < page.data().size) {
169170
yield(page.data()[index++])
170171
}
171-
page = page.getNextPage().orElse(null) ?: break
172+
page = page.getNextPage().getOrNull() ?: break
172173
index = 0
173174
}
174175
}

0 commit comments

Comments
 (0)