Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Map<Officer, Spaceship> getHighestRankingOfficerPerShip(Collection<Spaceship> fleet) {
- Map<Officer, Spaceship> officersMap = new HashMap<Officer, Spaceship>();
- for (Spaceship ship: fleet) {
- Stream<Officer> officers = ship.getCrewMembers().stream().filter(member -> member instanceof Officer).map(member -> (Officer) member);
- Officer seniorOfficer = officers.max((officer1, officer2) -> officer1.getRank().compareTo(officer2.getRank())).get();
- officersMap.put(seniorOfficer, ship);
- }
- return officersMap;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement