Skip to content

Commit 70033bd

Browse files
chore(internal): swap from getNullable to getOptional (#528)
1 parent b5a2343 commit 70033bd

File tree

101 files changed

+953
-1332
lines changed

Some content is hidden

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

101 files changed

+953
-1332
lines changed

finch-java-core/src/main/kotlin/com/tryfinch/api/core/Values.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ sealed class JsonField<out T : Any> {
132132
}
133133

134134
@JvmSynthetic
135-
internal fun getNullable(name: String): T? =
135+
internal fun getOptional(name: String): Optional<@UnsafeVariance T> =
136136
when (this) {
137-
is KnownValue -> value
138-
is JsonMissing -> null
139-
is JsonNull -> null
137+
is KnownValue -> Optional.of(value)
138+
is JsonMissing,
139+
is JsonNull -> Optional.empty()
140140
else -> throw FinchInvalidDataException("`$name` is invalid, received $this")
141141
}
142142

finch-java-core/src/main/kotlin/com/tryfinch/api/models/AccessTokenCreateParams.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,19 @@ private constructor(
346346
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
347347
* server responded with an unexpected value).
348348
*/
349-
fun clientId(): Optional<String> = Optional.ofNullable(clientId.getNullable("client_id"))
349+
fun clientId(): Optional<String> = clientId.getOptional("client_id")
350350

351351
/**
352352
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
353353
* server responded with an unexpected value).
354354
*/
355-
fun clientSecret(): Optional<String> =
356-
Optional.ofNullable(clientSecret.getNullable("client_secret"))
355+
fun clientSecret(): Optional<String> = clientSecret.getOptional("client_secret")
357356

358357
/**
359358
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
360359
* server responded with an unexpected value).
361360
*/
362-
fun redirectUri(): Optional<String> =
363-
Optional.ofNullable(redirectUri.getNullable("redirect_uri"))
361+
fun redirectUri(): Optional<String> = redirectUri.getOptional("redirect_uri")
364362

365363
/**
366364
* Returns the raw JSON value of [code].

finch-java-core/src/main/kotlin/com/tryfinch/api/models/AccountUpdateEvent.kt

Lines changed: 150 additions & 254 deletions
Large diffs are not rendered by default.

finch-java-core/src/main/kotlin/com/tryfinch/api/models/AccountUpdateResponse.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ private constructor(
100100
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
101101
* server responded with an unexpected value).
102102
*/
103-
fun connectionId(): Optional<String> =
104-
Optional.ofNullable(connectionId.getNullable("connection_id"))
103+
fun connectionId(): Optional<String> = connectionId.getOptional("connection_id")
105104

106105
/**
107106
* Returns the raw JSON value of [accountId].

finch-java-core/src/main/kotlin/com/tryfinch/api/models/AutomatedAsyncJob.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ private constructor(
7171
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
7272
* server responded with an unexpected value).
7373
*/
74-
fun completedAt(): Optional<OffsetDateTime> =
75-
Optional.ofNullable(completedAt.getNullable("completed_at"))
74+
fun completedAt(): Optional<OffsetDateTime> = completedAt.getOptional("completed_at")
7675

7776
/**
7877
* The datetime when the job was created. for scheduled jobs, this will be the initial
@@ -105,7 +104,7 @@ private constructor(
105104
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
106105
* server responded with an unexpected value).
107106
*/
108-
fun params(): Optional<Params> = Optional.ofNullable(params.getNullable("params"))
107+
fun params(): Optional<Params> = params.getOptional("params")
109108

110109
/**
111110
* The datetime a job is scheduled to be run. For scheduled jobs, this datetime can be in the
@@ -114,17 +113,15 @@ private constructor(
114113
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
115114
* server responded with an unexpected value).
116115
*/
117-
fun scheduledAt(): Optional<OffsetDateTime> =
118-
Optional.ofNullable(scheduledAt.getNullable("scheduled_at"))
116+
fun scheduledAt(): Optional<OffsetDateTime> = scheduledAt.getOptional("scheduled_at")
119117

120118
/**
121119
* The datetime a job entered into the job queue.
122120
*
123121
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
124122
* server responded with an unexpected value).
125123
*/
126-
fun startedAt(): Optional<OffsetDateTime> =
127-
Optional.ofNullable(startedAt.getNullable("started_at"))
124+
fun startedAt(): Optional<OffsetDateTime> = startedAt.getOptional("started_at")
128125

129126
/**
130127
* @throws FinchInvalidDataException if the JSON field has an unexpected type or is unexpectedly
@@ -520,8 +517,7 @@ private constructor(
520517
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
521518
* server responded with an unexpected value).
522519
*/
523-
fun individualId(): Optional<String> =
524-
Optional.ofNullable(individualId.getNullable("individual_id"))
520+
fun individualId(): Optional<String> = individualId.getOptional("individual_id")
525521

526522
/**
527523
* Returns the raw JSON value of [individualId].

finch-java-core/src/main/kotlin/com/tryfinch/api/models/AutomatedListResponse.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private constructor(
224224
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
225225
* server responded with an unexpected value).
226226
*/
227-
fun quotas(): Optional<Quotas> = Optional.ofNullable(quotas.getNullable("quotas"))
227+
fun quotas(): Optional<Quotas> = quotas.getOptional("quotas")
228228

229229
/**
230230
* Returns the raw JSON value of [quotas].
@@ -355,8 +355,7 @@ private constructor(
355355
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if
356356
* the server responded with an unexpected value).
357357
*/
358-
fun dataSyncAll(): Optional<DataSyncAll> =
359-
Optional.ofNullable(dataSyncAll.getNullable("data_sync_all"))
358+
fun dataSyncAll(): Optional<DataSyncAll> = dataSyncAll.getOptional("data_sync_all")
360359

361360
/**
362361
* Returns the raw JSON value of [dataSyncAll].
@@ -491,14 +490,14 @@ private constructor(
491490
* if the server responded with an unexpected value).
492491
*/
493492
fun allowedRefreshes(): Optional<Long> =
494-
Optional.ofNullable(allowedRefreshes.getNullable("allowed_refreshes"))
493+
allowedRefreshes.getOptional("allowed_refreshes")
495494

496495
/**
497496
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g.
498497
* if the server responded with an unexpected value).
499498
*/
500499
fun remainingRefreshes(): Optional<Long> =
501-
Optional.ofNullable(remainingRefreshes.getNullable("remaining_refreshes"))
500+
remainingRefreshes.getOptional("remaining_refreshes")
502501

503502
/**
504503
* Returns the raw JSON value of [allowedRefreshes].

finch-java-core/src/main/kotlin/com/tryfinch/api/models/BaseWebhookEvent.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ private constructor(
5757
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
5858
* server responded with an unexpected value).
5959
*/
60-
fun connectionId(): Optional<String> =
61-
Optional.ofNullable(connectionId.getNullable("connection_id"))
60+
fun connectionId(): Optional<String> = connectionId.getOptional("connection_id")
6261

6362
/**
6463
* Returns the raw JSON value of [accountId].

finch-java-core/src/main/kotlin/com/tryfinch/api/models/BenefitContribution.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ private constructor(
3636
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
3737
* server responded with an unexpected value).
3838
*/
39-
fun amount(): Optional<Long> = Optional.ofNullable(amount.getNullable("amount"))
39+
fun amount(): Optional<Long> = amount.getOptional("amount")
4040

4141
/**
4242
* Contribution type.
4343
*
4444
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
4545
* server responded with an unexpected value).
4646
*/
47-
fun type(): Optional<Type> = Optional.ofNullable(type.getNullable("type"))
47+
fun type(): Optional<Type> = type.getOptional("type")
4848

4949
/**
5050
* Returns the raw JSON value of [amount].

finch-java-core/src/main/kotlin/com/tryfinch/api/models/BenefitFeaturesAndOperations.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ private constructor(
4141
* server responded with an unexpected value).
4242
*/
4343
fun supportedFeatures(): Optional<BenefitFeature> =
44-
Optional.ofNullable(supportedFeatures.getNullable("supported_features"))
44+
supportedFeatures.getOptional("supported_features")
4545

4646
/**
4747
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
4848
* server responded with an unexpected value).
4949
*/
5050
fun supportedOperations(): Optional<SupportPerBenefitType> =
51-
Optional.ofNullable(supportedOperations.getNullable("supported_operations"))
51+
supportedOperations.getOptional("supported_operations")
5252

5353
/**
5454
* Returns the raw JSON value of [supportedFeatures].
@@ -246,8 +246,7 @@ private constructor(
246246
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
247247
* server responded with an unexpected value).
248248
*/
249-
fun annualMaximum(): Optional<Boolean> =
250-
Optional.ofNullable(annualMaximum.getNullable("annual_maximum"))
249+
fun annualMaximum(): Optional<Boolean> = annualMaximum.getOptional("annual_maximum")
251250

252251
/**
253252
* Whether the provider supports catch up for this benefit. This field will only be true for
@@ -256,7 +255,7 @@ private constructor(
256255
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
257256
* server responded with an unexpected value).
258257
*/
259-
fun catchUp(): Optional<Boolean> = Optional.ofNullable(catchUp.getNullable("catch_up"))
258+
fun catchUp(): Optional<Boolean> = catchUp.getOptional("catch_up")
260259

261260
/**
262261
* Supported contribution types. An empty array indicates contributions are not supported.
@@ -265,14 +264,13 @@ private constructor(
265264
* server responded with an unexpected value).
266265
*/
267266
fun companyContribution(): Optional<List<CompanyContribution?>> =
268-
Optional.ofNullable(companyContribution.getNullable("company_contribution"))
267+
companyContribution.getOptional("company_contribution")
269268

270269
/**
271270
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
272271
* server responded with an unexpected value).
273272
*/
274-
fun description(): Optional<String> =
275-
Optional.ofNullable(description.getNullable("description"))
273+
fun description(): Optional<String> = description.getOptional("description")
276274

277275
/**
278276
* Supported deduction types. An empty array indicates deductions are not supported.
@@ -281,7 +279,7 @@ private constructor(
281279
* server responded with an unexpected value).
282280
*/
283281
fun employeeDeduction(): Optional<List<EmployeeDeduction?>> =
284-
Optional.ofNullable(employeeDeduction.getNullable("employee_deduction"))
282+
employeeDeduction.getOptional("employee_deduction")
285283

286284
/**
287285
* The list of frequencies supported by the provider for this benefit
@@ -290,7 +288,7 @@ private constructor(
290288
* server responded with an unexpected value).
291289
*/
292290
fun frequencies(): Optional<List<BenefitFrequency?>> =
293-
Optional.ofNullable(frequencies.getNullable("frequencies"))
291+
frequencies.getOptional("frequencies")
294292

295293
/**
296294
* Whether the provider supports HSA contribution limits. Empty if this feature is not
@@ -300,7 +298,7 @@ private constructor(
300298
* server responded with an unexpected value).
301299
*/
302300
fun hsaContributionLimit(): Optional<List<HsaContributionLimit?>> =
303-
Optional.ofNullable(hsaContributionLimit.getNullable("hsa_contribution_limit"))
301+
hsaContributionLimit.getOptional("hsa_contribution_limit")
304302

305303
/**
306304
* Returns the raw JSON value of [annualMaximum].

finch-java-core/src/main/kotlin/com/tryfinch/api/models/BenefitsSupport.kt

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,85 +95,77 @@ private constructor(
9595
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
9696
* server responded with an unexpected value).
9797
*/
98-
fun commuter(): Optional<BenefitFeaturesAndOperations> =
99-
Optional.ofNullable(commuter.getNullable("commuter"))
98+
fun commuter(): Optional<BenefitFeaturesAndOperations> = commuter.getOptional("commuter")
10099

101100
/**
102101
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
103102
* server responded with an unexpected value).
104103
*/
105104
fun customPostTax(): Optional<BenefitFeaturesAndOperations> =
106-
Optional.ofNullable(customPostTax.getNullable("custom_post_tax"))
105+
customPostTax.getOptional("custom_post_tax")
107106

108107
/**
109108
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
110109
* server responded with an unexpected value).
111110
*/
112111
fun customPreTax(): Optional<BenefitFeaturesAndOperations> =
113-
Optional.ofNullable(customPreTax.getNullable("custom_pre_tax"))
112+
customPreTax.getOptional("custom_pre_tax")
114113

115114
/**
116115
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
117116
* server responded with an unexpected value).
118117
*/
119118
fun fsaDependentCare(): Optional<BenefitFeaturesAndOperations> =
120-
Optional.ofNullable(fsaDependentCare.getNullable("fsa_dependent_care"))
119+
fsaDependentCare.getOptional("fsa_dependent_care")
121120

122121
/**
123122
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
124123
* server responded with an unexpected value).
125124
*/
126-
fun fsaMedical(): Optional<BenefitFeaturesAndOperations> =
127-
Optional.ofNullable(fsaMedical.getNullable("fsa_medical"))
125+
fun fsaMedical(): Optional<BenefitFeaturesAndOperations> = fsaMedical.getOptional("fsa_medical")
128126

129127
/**
130128
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
131129
* server responded with an unexpected value).
132130
*/
133-
fun hsaPost(): Optional<BenefitFeaturesAndOperations> =
134-
Optional.ofNullable(hsaPost.getNullable("hsa_post"))
131+
fun hsaPost(): Optional<BenefitFeaturesAndOperations> = hsaPost.getOptional("hsa_post")
135132

136133
/**
137134
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
138135
* server responded with an unexpected value).
139136
*/
140-
fun hsaPre(): Optional<BenefitFeaturesAndOperations> =
141-
Optional.ofNullable(hsaPre.getNullable("hsa_pre"))
137+
fun hsaPre(): Optional<BenefitFeaturesAndOperations> = hsaPre.getOptional("hsa_pre")
142138

143139
/**
144140
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
145141
* server responded with an unexpected value).
146142
*/
147-
fun s125Dental(): Optional<BenefitFeaturesAndOperations> =
148-
Optional.ofNullable(s125Dental.getNullable("s125_dental"))
143+
fun s125Dental(): Optional<BenefitFeaturesAndOperations> = s125Dental.getOptional("s125_dental")
149144

150145
/**
151146
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
152147
* server responded with an unexpected value).
153148
*/
154149
fun s125Medical(): Optional<BenefitFeaturesAndOperations> =
155-
Optional.ofNullable(s125Medical.getNullable("s125_medical"))
150+
s125Medical.getOptional("s125_medical")
156151

157152
/**
158153
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
159154
* server responded with an unexpected value).
160155
*/
161-
fun s125Vision(): Optional<BenefitFeaturesAndOperations> =
162-
Optional.ofNullable(s125Vision.getNullable("s125_vision"))
156+
fun s125Vision(): Optional<BenefitFeaturesAndOperations> = s125Vision.getOptional("s125_vision")
163157

164158
/**
165159
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
166160
* server responded with an unexpected value).
167161
*/
168-
fun simple(): Optional<BenefitFeaturesAndOperations> =
169-
Optional.ofNullable(simple.getNullable("simple"))
162+
fun simple(): Optional<BenefitFeaturesAndOperations> = simple.getOptional("simple")
170163

171164
/**
172165
* @throws FinchInvalidDataException if the JSON field has an unexpected type (e.g. if the
173166
* server responded with an unexpected value).
174167
*/
175-
fun simpleIra(): Optional<BenefitFeaturesAndOperations> =
176-
Optional.ofNullable(simpleIra.getNullable("simple_ira"))
168+
fun simpleIra(): Optional<BenefitFeaturesAndOperations> = simpleIra.getOptional("simple_ira")
177169

178170
/**
179171
* Returns the raw JSON value of [commuter].

0 commit comments

Comments
 (0)