-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTravelMapService.java
More file actions
47 lines (36 loc) · 1.35 KB
/
TravelMapService.java
File metadata and controls
47 lines (36 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package service;
import graph.Node;
import interfaces.Payable;
import interfaces.Visitable;
import model.LocationWithBusinessHours;
import model.TravelMap;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
public class TravelMapService {
private TravelMap travelMap;
public TravelMapService(TravelMap travelMap) {
this.travelMap = travelMap;
}
public TravelMap getTravelMap() {
return travelMap;
}
public void setTravelMap(TravelMap travelMap) {
this.travelMap = travelMap;
}
public void printVisitableButNotPlayableLocations() {
travelMap.getNodes().stream()
.filter(node -> node instanceof Visitable)
.filter(node -> !(node instanceof Payable))
.sorted(Comparator.comparing(node -> ((Visitable) node).getOpeningTimes().stream().findFirst().get().getFrom()
.compareTo(((Visitable) node).getOpeningTimes().stream().findFirst().get().getFrom())))
.forEach(System.out::println);
}
public void printAveragePriceOfPayableLocations(){
travelMap.getNodes().stream()
.filter(node -> node instanceof Payable)
.mapToInt(node -> ((Payable) node).getFee())
.average()
.ifPresent(System.out::println);
}
}