source: src/main/java/agents/anac/y2013/MetaAgent/parser/cart/TreeParser.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 1.2 KB
Line 
1package agents.anac.y2013.MetaAgent.parser.cart;
2
3import java.util.HashMap;
4
5import agents.anac.y2013.MetaAgent.Parser.Type;
6import agents.anac.y2013.MetaAgent.agentsData.AgentData;
7import agents.anac.y2013.MetaAgent.parser.cart.tree.MeanNode;
8import agents.anac.y2013.MetaAgent.parser.cart.tree.Node;
9
10public class TreeParser {
11
12 /**
13 * @param args
14 */
15 String text="";
16 Type type;
17 AgentData data;
18 public TreeParser(AgentData data){
19 this.data=data;
20 }
21 public Node Parse(){
22 text=data.getText();
23 text=text.trim();
24 String []nodesText=text.split("Node number ");
25 return parseNodes(nodesText);
26
27 }
28
29 private Node parseNodes(String[] nodesText) {
30 HashMap<Integer,Node> nodes= new HashMap<Integer,Node>();
31 for (int i = 0; i < nodesText.length; i++) {
32 if(!nodesText[i].equals("")){
33 Node n=MeanNode.factory(nodesText[i]);
34 nodes.put(new Integer(n.get_id()),n);
35 }
36 }
37
38 for (Node node : nodes.values()) {
39 int id=node.get_leftId();
40 if(id!=-1){
41 Node other=nodes.get(new Integer(id));
42 node.set_left(other);
43 }
44 id=node.get_rightId();
45 if(id!=-1){
46 Node other=nodes.get(new Integer(id));
47 node.set_right(other);
48 }
49 }
50
51 return nodes.get(new Integer(1));
52 }
53}
Note: See TracBrowser for help on using the repository browser.