Add logic for sorting competitors

This commit is contained in:
Manuel Thalmann 2022-10-04 21:26:05 +02:00
parent bca09ae2d1
commit 1ed56f10da

View file

@ -39,8 +39,24 @@ public class RankingListServer implements CommandExecutor {
}
public String createSortedText(List<Competitor> competitorList) {
// TODO Implement
return "";
List<Competitor> 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<Competitor> competitorList) {