ADS-Praktika/06/src/main/java/ch/zhaw/ads/RankingTreeServer.java
navid.sassan 603a4fabe3 dos2unix
2020-11-01 22:36:42 +01:00

38 lines
1.2 KiB
Java

import java.util.*;
import java.text.*;
public class RankingTreeServer implements CommandExecutor {
private final static int STARTNR = 0;
private final static int NAME = 1;
private final static int JG = 2;
private final static int COUNTRY = 3;
private final static int TIME = 4;
Tree<Competitor> tree = new AVLSearchTree<>();
public void load(Tree<Competitor> tree, String list) throws Exception {
String[] lines = list.split("\n");
for (int i = 0; i < lines.length; i++) {
String[] items = lines[i].split(";");
Competitor c = new Competitor(Integer.parseInt(items[STARTNR]), // startNr
items[NAME], // name
Integer.parseInt(items[JG]), // jg
items[COUNTRY], // country
items[TIME]); // time
tree.add(c);
}
}
public String execute(String command) throws Exception {
// list of all Competitors
//read values from String
load(tree,command);
StringBuilder buf = new StringBuilder();
Traversal<Competitor> trav = tree.traversal();
Visitor<Competitor> vis = new MyRankingVisitor(buf);
trav.inorder(vis);
return buf.toString();
}
}