10
|
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.oldTree;
|
|
2
|
|
3 import java.io.FileNotFoundException;
|
|
4 import java.io.IOException;
|
|
5 import java.util.Iterator;
|
|
6 import java.util.Random;
|
|
7
|
|
8 import javax.xml.parsers.ParserConfigurationException;
|
|
9
|
|
10 import org.xml.sax.SAXException;
|
|
11
|
|
12 import fj.data.List;
|
|
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
|
|
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
|
|
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser;
|
|
16 import ac.jp.u_ryukyu.cr.ie.tatsuki.xmlReader.LoadXml;
|
|
17
|
|
18 public class Index {
|
|
19
|
|
20 public static void main(String args[]) throws FileNotFoundException, SAXException, IOException,
|
|
21 ParserConfigurationException {
|
|
22
|
11
|
23 LoadXml reader = new LoadXml();
|
|
24 JungleTree personTree = reader.loadTestData("test.xml");
|
12
|
25 InterfaceTraverser traverser = personTree.getTraverser(true);
|
11
|
26 search(traverser, "Normal");
|
10
|
27 System.out.println("test");
|
|
28
|
|
29 }
|
|
30
|
|
31 public static void search(InterfaceTraverser traverser, String type) {
|
|
32
|
|
33 Random rnd = new Random();
|
|
34 List<String> str = List.nil();
|
|
35 System.out.println("start");
|
|
36 str = str.cons(String.valueOf(rnd.nextInt(1000)));
|
|
37
|
|
38 long t1 = System.currentTimeMillis();
|
|
39
|
|
40 for (String attribute : str) {
|
|
41
|
11
|
42 Iterator<TreeNode> targetNode = traverser.find((TreeNode node) -> {
|
|
43 String element = node.getAttributes().getString("element");
|
|
44 if (element == null)
|
10
|
45 return false;
|
11
|
46 if (!element.equals("element"))
|
10
|
47 return false;
|
|
48
|
11
|
49 String id = node.getAttributes().getString("element-id");
|
|
50 if (id == null)
|
10
|
51 return false;
|
11
|
52 if (id.equals(attribute))
|
10
|
53 return true;
|
|
54 return false;
|
|
55 }, "element-id", attribute);
|
|
56
|
11
|
57 for (; targetNode.hasNext();) {
|
|
58 targetNode.next();
|
10
|
59 }
|
|
60 }
|
|
61 long t2 = System.currentTimeMillis();
|
|
62 System.out.println(type + " : time = " + (t2 - t1));
|
|
63 }
|
|
64
|
|
65 }
|