8000 collections.6 : Implement with stream · java-to-kotlin/code@589c6b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 589c6b0

Browse files
Duncan McGregordmcg
authored andcommitted
collections.6 : Implement with stream
1 parent a705882 commit 589c6b0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/main/java/travelator/Suffering.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import java.util.List;
44

55
import static java.util.Comparator.comparing;
6-
import static travelator.Collections.sorted;
6+
import static java.util.stream.Collectors.toUnmodifiableList;
77
import static travelator.Other.SOME_COMPLICATED_RESULT;
8+
import static travelator.Collections.sorted;
89
import static travelator.Other.routesFor;
910
import static travelator.Routes.getDepartsFrom;
1011

@@ -29,15 +30,16 @@ static List<Journey> longestJourneysIn(
2930

3031
public static List<List<Journey>> routesToShowFor(String itineraryId) {
3132
var routes = routesFor(itineraryId);
32-
routes = removeUnbearableRoutes(routes);
33+
routes = bearable(routes);
3334
return routes;
3435
}
3536

36-
private static List<List<Journey>> removeUnbearableRoutes
37+
private static List<List<Journey>> bearable
3738
(List<List<Journey>> routes
3839
) {
39-
routes.removeIf(route -> sufferScoreFor(route) > 10);
40-
return routes;
40+
return routes.stream()
41+
.filter(route -> sufferScoreFor(route) <= 10)
42+
.collect(toUnmodifiableList());
4143
}
4244

4345
private static int sufferScore(

0 commit comments

Comments
 (0)
0