8000 open-to-sealed.5 : get compiling again · java-to-kotlin/code@c6e7346 · GitHub
[go: up one dir, main page]

Skip to content

Commit c6e7346

Browse files
nprycedmcg
authored andcommitted
open-to-sealed.5 : get compiling again
- remove the now incorrect override modifiers - implement ItineraryItem.mapOverlay as an exhaustive with expr that calls the mapOverlay method of subclasses. Highlighted as smart-casts.
1 parent bf772ed commit c6e7346

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/main/java/travelator/itinerary/ItineraryItem.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ import java.time.ZonedDateTime
1111
sealed class ItineraryItem {
1212
abstract val id: Id<ItineraryItem>
1313
abstract val description: String
14-
abstract val costs: List<Money> // <1>
14+
abstract val costs: List<Money>
1515
}
1616

17-
val ItineraryItem.mapOverlay: MapOverlay // <2>
18-
get() = TODO("Not yet implemented")
17+
val ItineraryItem.mapOverlay: MapOverlay get() = when (this) {
18+
is Accommodation -> mapOverlay
19+
is Attraction -> mapOverlay
20+
is Journey -> mapOverlay
21+
is RestaurantBooking -> mapOverlay
22+
}
1923

2024
data class Accommodation(
2125
override val id: Id<Accommodation>,
@@ -34,7 +38,7 @@ data class Accommodation(
3438
get() = "$nights nights at ${location.userReadableName}"
3539
override val costs
3640
get() = listOf(totalPrice)
37-
override val mapOverlay // <3>
41+
val mapOverlay
3842
get() = PointOverlay(
3943
id = id,
4044
position = location.position,
@@ -55,7 +59,7 @@ data class Attraction(
5559
override val costs get() =
5660
emptyList<Money>()
5761

58-
override val mapOverlay get() =
62+
val mapOverlay get() =
5963
PointOverlay(
6064
position = location.position,
6165
text = description,
@@ -83,7 +87,7 @@ data class Journey(
8387
override val costs
8488
get() = listOf(price)
8589

86-
override val mapOverlay
90+
val mapOverlay
8791
get() = OverlayGroup(
8892
id = id,
8993
elements = listOf(
@@ -104,7 +108,7 @@ data class RestaurantBooking(
104108

105109
override val costs get() = emptyList<Money>()
106110

107-
override val mapOverlay get() =
111+
val mapOverlay get() =
108112
PointOverlay(
109113
id = id,
110114
position = location.position,

0 commit comments

Comments
 (0)
0