diff --git a/src/ch/zhaw/ads/Competitor.java b/src/ch/zhaw/ads/Competitor.java index 9ebe5a7..3536c6b 100644 --- a/src/ch/zhaw/ads/Competitor.java +++ b/src/ch/zhaw/ads/Competitor.java @@ -77,7 +77,7 @@ class AlphaComparatorCompetitor implements Comparator { @Override public int compare(Competitor o1, Competitor o2) { // TODO Implement - int c = 0; + int c = o1.compareTo(o2); return c; } } diff --git a/src/ch/zhaw/ads/RankingListServer.java b/src/ch/zhaw/ads/RankingListServer.java index 3d70c0d..7828dba 100644 --- a/src/ch/zhaw/ads/RankingListServer.java +++ b/src/ch/zhaw/ads/RankingListServer.java @@ -1,17 +1,34 @@ package ch.zhaw.ads; +import java.util.LinkedList; import java.util.List; public class RankingListServer implements CommandExecutor { public List createList(String rankingText) { - // TODO Implement - return null; + List competitorList = new LinkedList<>(); + for(String listEntry : rankingText.split("\\n")){ + String[] entry = listEntry.split(";"); + competitorList.add(new Competitor(0, entry[0], entry[1])); + } + competitorList.sort(new AlphaComparatorCompetitor()); + int rank = 1; + for(Competitor competitor : competitorList){ + competitor.setRank(rank); + rank++; + } + return competitorList; } public String createSortedText(List competitorList) { // TODO Implement - return ""; + StringBuilder stringBuilder = new StringBuilder(); + int rank = 1; + for (Competitor competitor : competitorList) { + stringBuilder.append(rank).append(" ").append(competitor.getName()).append(" ").append(competitor.getTime()).append("\n"); + rank++; + } + return stringBuilder.toString(); } public String createNameList(List competitorList) {