Skip to content

Commit 61e40f0

Browse files
Duncan McGregordmcg
authored andcommitted
single-expressions.11 : toss it
1 parent 14be125 commit 61e40f0

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/main/java/travelator/EmailAddress.kt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@ data class EmailAddress(
99

1010
companion object {
1111
@JvmStatic
12-
fun parse(value: String) =
13-
emailAddress(value, value.lastIndexOf('@'))
14-
15-
private fun emailAddress(value: String, atIndex: Int): EmailAddress =
16-
when {
17-
atIndex < 1 || atIndex == value.length - 1 ->
18-
throw IllegalArgumentException(
19-
"EmailAddress must be two parts separated by @"
20-
)
21-
else -> EmailAddress(
22-
value.substring(0, atIndex),
23-
value.substring(atIndex + 1)
24-
)
12+
fun parse(value: String): EmailAddress {
13+
val atIndex = value.lastIndexOf('@')
14+
require(!(atIndex < 1 || atIndex == value.length - 1)) {
15+
"EmailAddress must be two parts separated by @"
2516
}
17+
return EmailAddress(
18+
value.substring(0, atIndex),
19+
value.substring(atIndex + 1)
20+
)
21+
}
2622
}
2723
}

0 commit comments

Comments
 (0)