8000 open-to-sealed.7 : move mapOverlay extension to geo package · java-to-kotlin/code@c043831 · GitHub
[go: up one dir, main page]

Skip to content

Commit c043831

Browse files
nprycedmcg
authored andcommitted
open-to-sealed.7 : move mapOverlay extension to geo package
1 parent 6eae26a commit c043831

File tree

3 files changed

+48
-45
lines changed

3 files changed

+48
-45
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package travelator.geo
2+
3+
import travelator.itinerary.*
4+
5+
val ItineraryItem.mapOverlay: MapOverlay get() = when (this) {
6+
is Accommodation -> mapOverlay
7+
is Attraction -> mapOverlay
8+
is Journey -> mapOverlay
9+
is RestaurantBooking -> mapOverlay
10+
}
11+
12+
private val Accommodation.mapOverlay
13+
get() = PointOverlay(
14+
id = id,
15+
position = location.position,
16+
text = location.userReadableName,
17+
icon = StandardIcons.HOTEL
18+
)
19+
20+
private val Attraction.mapOverlay get() =
21+
PointOverlay(
22+
position = location.position,
23+
text = description,
24+
icon = StandardIcons.ATTRACTION,
25+
id = id
26+
)
27+
28+
private val Journey.mapOverlay
29+
get() = OverlayGroup(
30+
id = id,
31+
elements = listOf(
32+
PathOverlay(path, travelMethod.userReadableName),
33+
PointOverlay(departsFrom.position, departsFrom.userReadableName, StandardIcons.START),
34+
PointOverlay(arrivesAt.position, arrivesAt.userReadableName, StandardIcons.END)
35+
)
36+
)
37+
38+
private val RestaurantBooking.mapOverlay get() =
39+
PointOverlay(
40+
id = id,
41+
position = location.position,
42+
text = location.userReadableName,
43+
icon = StandardIcons.RESTAURANT
44+
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package travelator.itinerary
22

33
import travelator.Id
44
import travelator.geo.OverlayGroup
5+
import travelator.geo.mapOverlay
56

67
data class Itinerary(
78
val id: Id<Itinerary>,

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

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ sealed class ItineraryItem {
1414
abstract val costs: List<Money>
1515
}
1616

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-
}
2317

2418
data class Accommodation(
2519
override val id: Id<Accommodation>,
@@ -28,25 +22,15 @@ data class Accommodation(
2822
val checkOutBefore: ZonedDateTime,
2923
val pricePerNight: Money
3024
) : ItineraryItem() {
31-
val nights = Period.between(
32-
checkInFrom.toLocalDate(),
33-
checkOutBefore.toLocalDate()
34-
).days
25+
val nights = Period.between(checkInFrom.toLocalDate(), checkOutBefore.toLocalDate()).days
3526
val totalPrice: Money = pricePerNight * nights
3627

3728
override val description
3829
get() = "$nights nights at ${location.userReadableName}"
3930
override val costs
4031
get() = listOf(totalPrice)
41-
}
4232

43-
val Accommodation.mapOverlay
44-
get() = PointOverlay(
45-
id = id,
46-
position = location.position,
47-
text = location.userReadableName,
48-
icon = StandardIcons.HOTEL
49-
)
33+
}
5034

5135
data class Attraction(
5236
override val id: Id<Attraction>,
@@ -61,14 +45,6 @@ data class Attraction(
6145

6246
}
6347

64-
val Attraction.mapOverlay get() =
65-
PointOverlay(
66-
position = location.position,
67-
text = description,
68-
icon = StandardIcons.ATTRACTION,
69-
id = id
70-
)
71-
7248
data class Journey(
7349
override val id: Id<Journey>,
7450
val travelMethod: TravelMethod,
@@ -89,16 +65,6 @@ data class Journey(
8965

9066
}
9167

92-
val Journey.mapOverlay
93-
get() = OverlayGroup(
94-
id = id,
95-
elements = listOf(
96-
PathOverlay(path, travelMethod.userReadableName),
97-
PointOverlay(departsFrom.position, departsFrom.userReadableName, StandardIcons.START),
98-
PointOverlay(arrivesAt.position, arrivesAt.userReadableName, StandardIcons.END)
99-
)
100-
)
101-
10268
data class RestaurantBooking(
10369
override val id: Id<RestaurantBooking>,
10470
val location: Location,
@@ -107,12 +73,4 @@ data class RestaurantBooking(
10773
override val description get() = location.userReadableName
10874

10975
override val costs get() = emptyList<Money>()
110-
}
111-
112-
val RestaurantBooking.mapOverlay get() =
113-
PointOverlay(
114-
id = id,
115-
position = location.position,
116-
text = location.userReadableName,
117-
icon = StandardIcons.RESTAURANT
118-
)
76+
}

0 commit comments

Comments
 (0)
0