diff --git a/app/src/main/java/ch/nuth/zhaw/exbox/RankingListServer.java b/app/src/main/java/ch/nuth/zhaw/exbox/RankingListServer.java index da17614..9801b24 100644 --- a/app/src/main/java/ch/nuth/zhaw/exbox/RankingListServer.java +++ b/app/src/main/java/ch/nuth/zhaw/exbox/RankingListServer.java @@ -39,8 +39,24 @@ public class RankingListServer implements CommandExecutor { } public String createSortedText(List competitorList) { - // TODO Implement - return ""; + List competitors = competitorList.stream().sorted().toList(); + String previousTime = null; + int previousRank = 1; + + for (int i = 0; i < competitors.size(); i++) { + Competitor competitor = competitors.get(i); + + if (competitor.getTime() != previousTime) { + previousRank = i + 1; + previousTime = competitor.getTime(); + } + + competitor.setRank(previousRank); + } + + return String.join( + System.lineSeparator(), + competitors.stream().map((competitor) -> competitor.toString()).toList()); } public String createNameList(List competitorList) {