Skip to content

Commit efecaec

Browse files
Duncan McGregordmcg
authored andcommitted
encapsulated-collections.4 : convert withJourneyAt to extension
1 parent 45d07c3 commit efecaec

File tree

1 file changed

+7
-6
lines changed
  • src/main/java/travelator/itinerary

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.time.Duration
55
import java.util.*
66

77
class Route(
8-
private val journeys: List<Journey>
8+
val journeys: List<Journey>
99
) {
1010
fun size(): Int = journeys.size
1111

@@ -20,11 +20,12 @@ class Route(
2020
get(size() - 1).arrivalTime
2121
)
2222

23-
fun withJourneyAt(index: Int, replacedBy: Journey): Route {
24-
val newJourneys = ArrayList(journeys)
25-
newJourneys[index] = replacedBy
26-
return Route(newJourneys)
27-
}
23+
}
24+
25+
fun Route.withJourneyAt(index: Int, replacedBy: Journey): Route {
26+
val newJourneys = ArrayList(journeys)
27+
newJourneys[index] = replacedBy
28+
return Route(newJourneys)
2829
}
2930

3031
val Route.departsFrom: Location

0 commit comments

Comments
 (0)