Add logic for sorting competitors
This commit is contained in:
parent
bca09ae2d1
commit
1ed56f10da
1 changed files with 18 additions and 2 deletions
|
@ -39,8 +39,24 @@ public class RankingListServer implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createSortedText(List<Competitor> competitorList) {
|
public String createSortedText(List<Competitor> competitorList) {
|
||||||
// TODO Implement
|
List<Competitor> competitors = competitorList.stream().sorted().toList();
|
||||||
return "";
|
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) {
|
public String createNameList(List<Competitor> competitorList) {
|
||||||
|
|
Loading…
Reference in a new issue