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 4e43b6a..da17614 100644 --- a/app/src/main/java/ch/nuth/zhaw/exbox/RankingListServer.java +++ b/app/src/main/java/ch/nuth/zhaw/exbox/RankingListServer.java @@ -1,11 +1,40 @@ package ch.nuth.zhaw.exbox; +import java.io.BufferedReader; +import java.io.StringReader; +import java.util.ArrayList; import java.util.List; public class RankingListServer implements CommandExecutor { + /** + * The delimiter of the data. + */ + private static final String Delimiter = ";"; public List createList(String rankingText) { - // TODO Implement + String currentLine; + + try { + try (BufferedReader reader = new BufferedReader(new StringReader(rankingText))) { + List result = new ArrayList<>(); + + while ((currentLine = reader.readLine()) != null) { + String[] fields = currentLine.split(Delimiter); + + result.add( + new Competitor( + 0, + fields[0], + fields[1])); + } + + return result; + } + } catch (Exception e) { + System.out.println("An error occurred"); + System.out.println(e); + } + return null; }