Implement RankingTreeServer

This commit is contained in:
Manuel Thalmann 2022-10-18 13:48:27 +02:00
parent e47818c3fa
commit 13b54d1e88

View file

@ -1,18 +1,32 @@
package ch.nuth.zhaw.exbox;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public class RankingTreeServer implements CommandExecutor {
public Tree<Competitor> createTree(String rankingText) {
// TODO Implement
return null;
SortedBinaryTree<Competitor> result = new SortedBinaryTree<>();
List<Competitor> competitors = new RankingListServer().createList(rankingText);
for (Competitor competitor : competitors) {
result.add(competitor);
}
return result;
}
public String createSortedText(Tree<Competitor> competitorTree) {
AtomicInteger rank = new AtomicInteger(1);
StringBuilder sb = new StringBuilder();
competitorTree.traversal(); // TODO Implement
competitorTree.traversal().inorder(
(competitor) -> {
competitor.setRank(rank.getAndIncrement());
sb.append(competitor);
sb.append(System.lineSeparator());
});
return sb.toString();
}
@ -20,19 +34,4 @@ public class RankingTreeServer implements CommandExecutor {
Tree<Competitor> competitorTree = createTree(rankingList);
return "Rangliste (Tree)\n" + createSortedText(competitorTree);
}
public static void main(String[] args) {
String rangliste = "Mueller Stefan;02:31:14\n" +
"Marti Adrian;02:30:09\n" +
"Kiptum Daniel;02:11:31\n" +
"Ancay Tarcis;02:20:02\n" +
"Kreibuhl Christian;02:21:47\n" +
"Ott Michael;02:33:48\n" +
"Menzi Christoph;02:27:26\n" +
"Oliver Ruben;02:32:12\n" +
"Elmer Beat;02:33:53\n" +
"Kuehni Martin;02:33:36\n";
RankingTreeServer server = new RankingTreeServer();
System.out.println(server.execute(rangliste));
}
}