Skip to content

Shouldn't this method return List<Player> instead of Map<Player, Integer>? #4

@ntalbs

Description

@ntalbs

public Map<Player, Integer> getTopPlayers() {
return playerRatings.entrySet()
.stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.map(Map.Entry::getKey)
.collect(Collectors.toMap(player -> player, player -> playerRatings.get(player)));
}

Inside the method, it sorts the players by their ratings in descending order, then collects them into a map. As it returns HashMap, the sorted order is not preserved. I think it should collect players into a list, so it can keep the sorted order. What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions