From 7e46399a4a25081a59f52f00256030cd400d64d0 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 4 Oct 2022 21:23:21 +0200 Subject: [PATCH] Add logic for creating competitor lists --- .../ch/nuth/zhaw/exbox/RankingListServer.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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; }