Implement RankingTreeServer
This commit is contained in:
parent
e47818c3fa
commit
13b54d1e88
|
@ -1,18 +1,32 @@
|
||||||
package ch.nuth.zhaw.exbox;
|
package ch.nuth.zhaw.exbox;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class RankingTreeServer implements CommandExecutor {
|
public class RankingTreeServer implements CommandExecutor {
|
||||||
|
|
||||||
public Tree<Competitor> createTree(String rankingText) {
|
public Tree<Competitor> createTree(String rankingText) {
|
||||||
// TODO Implement
|
SortedBinaryTree<Competitor> result = new SortedBinaryTree<>();
|
||||||
return null;
|
List<Competitor> competitors = new RankingListServer().createList(rankingText);
|
||||||
|
|
||||||
|
for (Competitor competitor : competitors) {
|
||||||
|
result.add(competitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String createSortedText(Tree<Competitor> competitorTree) {
|
public String createSortedText(Tree<Competitor> competitorTree) {
|
||||||
AtomicInteger rank = new AtomicInteger(1);
|
AtomicInteger rank = new AtomicInteger(1);
|
||||||
StringBuilder sb = new StringBuilder();
|
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();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,19 +34,4 @@ public class RankingTreeServer implements CommandExecutor {
|
||||||
Tree<Competitor> competitorTree = createTree(rankingList);
|
Tree<Competitor> competitorTree = createTree(rankingList);
|
||||||
return "Rangliste (Tree)\n" + createSortedText(competitorTree);
|
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue