8000 exceptions-to-values.3 : return null for other failure · java-to-kotlin/code@799d81d · GitHub
[go: up one dir, main page]

Skip to content

Commit 799d81d

Browse files
Duncan McGregordmcg
authored andcommitted
exceptions-to-values.3 : return null for other failure
1 parent 135ad70 commit 799d81d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/main/java/travelator/marketing/HighValueCustomersReport.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ private fun Sequence<String>.withoutHeader() = drop(1)
2323
internal fun String.toCustomerData(): CustomerData? =
2424
split("\t").let { parts ->
2525
if (parts.size < 4)
26-
null
27-
else
28-
CustomerData(
29-
id = parts[0],
30-
givenName = parts[1],
31-
familyName = parts[2],
32-
score = parts[3].toInt(),
33-
spend = if (parts.size == 4) 0.0 else parts[4].toDouble()
34-
)
26+
return null
27+
val score = parts[3].toIntOrNull() ?:
28+
return null
29+
val spend = if (parts.size == 4) 0.0 else parts[4].toDoubleOrNull() ?:
30+
return null
31+
CustomerData(
32+
id = parts[0],
33+
givenName = parts[1],
34+
familyName = parts[2],
35+
score = score,
36+
spend = spend
37+
)
3538
}
3639

3740
private val CustomerData.outputLine: String

0 commit comments

Comments
 (0)
0