Advertisement
UriSteiff

thrhrthrth

Jun 10th, 2021
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. public static Map<Officer, Spaceship> getHighestRankingOfficerPerShip(Collection<Spaceship> fleet) {
  2.         Map<Officer, Spaceship> officersMap = new HashMap<Officer, Spaceship>();
  3.         for (Spaceship ship: fleet) {
  4.             Stream<Officer> officers = ship.getCrewMembers().stream().filter(member -> member instanceof Officer).map(member -> (Officer) member);
  5.             Officer seniorOfficer = officers.max((officer1, officer2) -> officer1.getRank().compareTo(officer2.getRank())).get();
  6.             officersMap.put(seniorOfficer, ship);
  7.         }
  8.         return officersMap;
  9.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement