I have two classes Meeting and Guest.
The relation looks like this:
class Meeting {
private LocalDate date;
private List<Guest> guests;
}
I need to get one Meeting by date and where guests are from the USA using stream.
I have List and I have done the next one:
List<Meeting> meetings = new ArrayList<>();
public Meeting getByDay(LocalDate date) {
List<Guest> guests = getGuestsByDate(date).stream()
.filter(guest-> guest.getCountry().equals("USA"))
.collect(Collectors.toList());
return new Meeting(date, guests);
}
but now I need to refactor my code with custom Collector, which returns Meeting. I read it needs to implement the Collector interface or Collector.of() method but how it must look in my case? I would be grateful for any advice.
getGuestsByDate(date)would be more fun to know the implementation of..collect(Collectors.toList())→.collect(Collectors.collectingAndThen(Collectors.toList(), l->new Meeting(date,l)))