Add logic for creating competitor lists
This commit is contained in:
parent
29adffee18
commit
7e46399a4a
1 changed files with 30 additions and 1 deletions
|
@ -1,11 +1,40 @@
|
||||||
package ch.nuth.zhaw.exbox;
|
package ch.nuth.zhaw.exbox;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RankingListServer implements CommandExecutor {
|
public class RankingListServer implements CommandExecutor {
|
||||||
|
/**
|
||||||
|
* The delimiter of the data.
|
||||||
|
*/
|
||||||
|
private static final String Delimiter = ";";
|
||||||
|
|
||||||
public List<Competitor> createList(String rankingText) {
|
public List<Competitor> createList(String rankingText) {
|
||||||
// TODO Implement
|
String currentLine;
|
||||||
|
|
||||||
|
try {
|
||||||
|
try (BufferedReader reader = new BufferedReader(new StringReader(rankingText))) {
|
||||||
|
List<Competitor> 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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue