I have this CasaDeBurrito class:
public class CasaDeBurritoImpl implements OOP.Provided.CasaDeBurrito {
private Integer id;
private String name;
private Integer dist;
private Set<String> menu;
private Map<Integer, Integer> ratings;
...
}
and this profesor class: (it should be with one s)
public class ProfessorImpl implements OOP.Provided.Profesor {
private Integer id;
private String name;
private List<CasaDeBurrito> favorites;
private Set<Profesor> friends;
private Comparator<CasaDeBurrito> ratingComparator = (CasaDeBurrito c1, CasaDeBurrito c2) ->
{
if (c1.averageRating() == c2.averageRating()) {
if (c1.distance() == c2.distance()) {
return Integer.compare(c1.getId(), c2.getId());
}
return Integer.compare(c1.distance(), c2.distance());
}
return Double.compare(c2.averageRating(), c1.averageRating());
};
private Predicate<CasaDeBurrito> isAvgRatingAbove(int rLimit) {
return c -> c.averageRating() >= rLimit;
};
public Collection<CasaDeBurrito>
filterAndSortFavorites(Comparator<CasaDeBurrito> comp, Predicate<CasaDeBurrito> p) {
return favorites.stream().filter(p).sorted(comp).collect(Collectors.toList());
}
public Collection<CasaDeBurrito> favoritesByRating(int rLimit) {
return filterAndSortFavorites(ratingComparator, isAvgRatingAbove(rLimit));
}
}
I want to implement a function which gets a Profesor prof
, and unifies all the sets of favorites
of all prof
's friends, sorted by ID, with stream.
as a result I want a collection of all favorite CasaDeBurrito
restaurants by rating (with favoritesByRating).
for example:
public Collection<CasaDeBurrito> favoritesByRating(Profesor p) {
Stream ret = p.getFriends().stream()
.<*some Intermediate Operations*>.
.forEach(y->y.concat(y.favoritesByRating(0))
.<*some Intermediate Operations*>.
.collect(toList());
return ret;
}