There are multiple options to achieve this. It matters in which case you want to check that. E.g. if you only want to check if all players have two locations you can use Java Stream for that:
boolean allTwoLocations = who.values().stream().allMatch(locations -> locations.size() == 2);
If you want to check only a single player it matters if you already have the reference to that player or only an id or username of it. If you have an object of the player you want to check its as simple as this: who.get(player)
. Remember to check if the player exists in the map to prevent a NullPointerException
. You then can access the locations of that player:
if (who.containsKey(player) && who.get(player).size() ==2) {
// do whatever you want
}
If you only have a property of that player (id, username, etc.) I also would recommend to use a Stream for that:
boolean userExistsAndTwoLocations = who.entrySet().stream()
.filter(p -> p.getKey().getId() == id).findFirst()
.map(Map.Entry::getValue)
.filter(locations -> locations.size() == 2)
.isPresent();