@@ -8,11 +8,11 @@ import java.time.Duration
8
8
import java.time.Period
9
9
import java.time.ZonedDateTime
10
10
11
- interface ItineraryItem {
12
- val id: Id <ItineraryItem >
13
- val description: String
14
- val costs: List <Money >
15
- val mapOverlay: MapOverlay
11
+ sealed class ItineraryItem { // <1>
12
+ abstract val id: Id <ItineraryItem > // <2 >
13
+ abstract val description: String
14
+ abstract val costs: List <Money >
15
+ abstract val mapOverlay: MapOverlay
16
16
}
17
17
18
18
data class Accommodation (
@@ -21,8 +21,11 @@ data class Accommodation(
21
21
val checkInFrom : ZonedDateTime ,
22
22
val checkOutBefore : ZonedDateTime ,
23
23
val pricePerNight : Money
24
- ) : ItineraryItem {
25
- val nights = Period .between(checkInFrom.toLocalDate(), checkOutBefore.toLocalDate()).days
24
+ ) : ItineraryItem() { // <3>
25
+ val nights = Period .between(
26
+ checkInFrom.toLocalDate(),
27
+ checkOutBefore.toLocalDate()
28
+ ).days
26
29
val totalPrice: Money = pricePerNight * nights
27
30
28
31
override val description
@@ -39,24 +42,28 @@ data class Accommodation(
39
42
40
43
}
41
44
45
+
42
46
data class Attraction (
43
47
override val id : Id <Attraction >,
44
48
val location : Location ,
45
49
val notes : String
46
- ) : ItineraryItem {
47
- override val description get() =
48
- location.userReadableName
50
+ ) : ItineraryItem() {
51
+ override val description
52
+ get() =
53
+ location.userReadableName
49
54
50
- override val costs get() =
51
- emptyList<Money >()
55
+ override val costs
56
+ get() =
57
+ emptyList<Money >()
52
58
53
- override val mapOverlay get() =
54
- PointOverlay (
55
- position = location.position,
56
- text = description,
57
- icon = StandardIcons .ATTRACTION ,
58
- id = id
59
- )
59
+ override val mapOverlay
60
+ get() =
61
+ PointOverlay (
62
+ position = location.position,
63
+ text = description,
64
+ icon = StandardIcons .ATTRACTION ,
65
+ id = id
66
+ )
60
67
61
68
}
62
69
@@ -69,7 +76,7 @@ data class Journey(
69
76
val arrivalTime : ZonedDateTime ,
70
77
val price : Money ,
71
78
val path : List <Position > = listOf(departsFrom.position, arrivesAt.position),
72
- ) : ItineraryItem {
79
+ ) : ItineraryItem() {
73
80
override val description
74
81
get() = " ${departsFrom.userReadableName} " +
75
82
" to ${arrivesAt.userReadableName} " +
@@ -94,16 +101,17 @@ data class RestaurantBooking(
94
101
override val id : Id <RestaurantBooking >,
95
102
val location : Location ,
96
103
val time : ZonedDateTime
97
- ) : ItineraryItem {
104
+ ) : ItineraryItem() {
98
105
override val description get() = location.userReadableName
99
106
100
107
override val costs get() = emptyList<Money >()
101
108
102
- override val mapOverlay get() =
103
- PointOverlay (
104
- id = id,
105
- position = location.position,
106
- text = location.userReadableName,
107
- icon = StandardIcons .RESTAURANT
108
- )
109
+ override val mapOverlay
110
+ get() =
111
+ PointOverlay (
112
+ id = id,
113
+ position = location.position,
114
+ text = location.userReadableName,
115
+ icon = StandardIcons .RESTAURANT
116
+ )
109
117
}
0 commit comments