Mercurial > hg > Members > tatsuki > jungle-bench
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/xml/extendXmlTree.java @ 17:917ecf2c7350
function Measurement
author | one |
---|---|
date | Wed, 24 Dec 2014 15:48:32 +0900 |
parents | eed6235830c9 |
children | 190890be73e4 |
comparison
equal
deleted
inserted
replaced
16:eed6235830c9 | 17:917ecf2c7350 |
---|---|
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.xml; | 1 package jp.ac.u_ryukyu.ie.cr.tatsuki.xml; |
2 | 2 |
3 import java.io.BufferedWriter; | |
4 import java.io.File; | |
3 import java.io.FileInputStream; | 5 import java.io.FileInputStream; |
4 import java.io.FileNotFoundException; | 6 import java.io.FileNotFoundException; |
7 import java.io.FileWriter; | |
5 import java.io.IOException; | 8 import java.io.IOException; |
9 import java.io.PrintWriter; | |
6 import java.nio.ByteBuffer; | 10 import java.nio.ByteBuffer; |
7 import java.util.Iterator; | 11 import java.util.Iterator; |
8 import java.util.Random; | 12 import java.util.Random; |
9 | 13 |
10 import javax.xml.parsers.ParserConfigurationException; | 14 import javax.xml.parsers.ParserConfigurationException; |
26 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; | 30 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; |
27 import ac.jp.u_ryukyu.cr.ie.tatsuki.xmlReader.ReadXmlHandler; | 31 import ac.jp.u_ryukyu.cr.ie.tatsuki.xmlReader.ReadXmlHandler; |
28 | 32 |
29 public class extendXmlTree { | 33 public class extendXmlTree { |
30 | 34 |
31 private extendXmlTree() { | 35 public static void main(String args[]) throws FileNotFoundException, ParserConfigurationException, SAXException, |
32 | 36 IOException { |
33 } | 37 |
34 | 38 if (args.length != 2) { |
35 | 39 System.out.println("Arguments are two necessary , first person count, second use Index"); |
36 public static JuGrix createJuGrix(boolean useIndex,int personCount ) throws ParserConfigurationException, SAXException, | 40 return; |
37 FileNotFoundException, IOException { | 41 } |
42 | |
43 int maxPersonCount = Integer.parseInt(args[0]); | |
44 | |
45 boolean useIndex = false; | |
46 if (args[1].equals("true")) | |
47 useIndex = true; | |
48 | |
49 for (int personCount = 10; personCount <= maxPersonCount; personCount = personCount + 10) { | |
50 createJuGrix(useIndex, personCount); | |
51 } | |
52 | |
53 } | |
54 | |
55 public static JuGrix createJuGrix(boolean useIndex, int personCount) throws ParserConfigurationException, | |
56 SAXException, FileNotFoundException, IOException { | |
38 Jungle jungle = new DefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser())); | 57 Jungle jungle = new DefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser())); |
39 JungleTree readXmlTree = jungle.createNewTree("Person"); | 58 JungleTree readXmlTree = jungle.createNewTree("Person"); |
40 //JungleTree readXmlTree = readXml("Person", jungle); | 59 // JungleTree readXmlTree = readXml("Person", jungle); |
41 JungleTree orgTree = readXml("Organization", jungle); | 60 JungleTree orgTree = readXml("Organization", jungle); |
42 JungleTree roleTree = readXml("Role", jungle); | 61 JungleTree roleTree = readXml("Role", jungle); |
43 JungleTreeEditor editor = readXmlTree.getTreeEditor(); | 62 JungleTreeEditor editor = readXmlTree.getTreeEditor(); |
44 NodePath path = new DefaultNodePath(); | 63 NodePath path = new DefaultNodePath(); |
45 editor = editor.addNewChildAt(path, 0).b(); | 64 editor = editor.addNewChildAt(path, 0).b(); |
46 editor = editor.putAttribute(path.add(0), "element", ByteBuffer.wrap("Persons".getBytes())).b(); | 65 editor = editor.putAttribute(path.add(0), "element", ByteBuffer.wrap("Persons".getBytes())).b(); |
47 System.out.println("Create Tree-------------------------------"); | 66 |
67 long start = System.currentTimeMillis(); | |
68 | |
48 for (int count = 0; count < personCount; ++count) { | 69 for (int count = 0; count < personCount; ++count) { |
49 editor = extendsTree(editor, orgTree, roleTree, count); | 70 editor = extendsTree(editor, orgTree, roleTree, count); |
50 } | 71 } |
72 | |
73 long stop = System.currentTimeMillis(); | |
74 File file = new File("./time/createPersonTime"); | |
75 PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file,true))); | |
76 pw.println(personCount + " " + (stop - start)); | |
77 pw.close(); | |
78 System.out.println("create person time = " + (stop - start)); | |
79 System.out.println("person count = " + personCount); | |
51 editor.success(); | 80 editor.success(); |
52 | |
53 int PersonCount = readXmlTree.getRootNode().getChildren().at(0).b().getChildren().size(); | |
54 System.out.println("PersonCount = " + PersonCount); | |
55 System.out.println("end-------------------------------"); | |
56 JuGrix jugrix = new JuGrix(useIndex, readXmlTree, orgTree, roleTree); | 81 JuGrix jugrix = new JuGrix(useIndex, readXmlTree, orgTree, roleTree); |
57 return jugrix; | 82 return jugrix; |
58 } | 83 } |
59 | 84 |
60 public static JungleTreeEditor extendsTree(JungleTreeEditor editor, JungleTree orgTree, JungleTree roleTree, | 85 public static JungleTreeEditor extendsTree(JungleTreeEditor editor, JungleTree orgTree, JungleTree roleTree, int count) { |
61 int count) { | |
62 Random rdm = new Random(); | 86 Random rdm = new Random(); |
63 int orgNum = rdm.nextInt(30); | 87 int orgNum = rdm.nextInt(30); |
64 String orgId = "o:" + String.valueOf(orgNum); | 88 String orgId = "o:" + String.valueOf(orgNum); |
65 String orgRoleId = searchOrgRole(orgTree, orgId); | 89 String orgRoleId = searchOrgRole(orgTree, orgId); |
66 String roleId = searchRole(roleTree, orgRoleId); | 90 String roleId = searchRole(roleTree, orgRoleId); |
237 IOException, FileNotFoundException { | 261 IOException, FileNotFoundException { |
238 SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); | 262 SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); |
239 SAXParser saxParser = saxParserFactory.newSAXParser(); | 263 SAXParser saxParser = saxParserFactory.newSAXParser(); |
240 JungleTree tree = jungle.createNewTree(xml); | 264 JungleTree tree = jungle.createNewTree(xml); |
241 ReadXmlHandler readXmlHandler = new ReadXmlHandler(tree); | 265 ReadXmlHandler readXmlHandler = new ReadXmlHandler(tree); |
242 saxParser | 266 String currentPath = System.getProperty("user.dir"); |
243 .parse(new FileInputStream("/Users/one/Documents/workspace/JungleXMLReader/xml/" + xml + ".xml"), readXmlHandler); | 267 saxParser.parse(new FileInputStream(currentPath + "/xml/" + xml + ".xml"), readXmlHandler); |
244 return readXmlHandler.getTree(); | 268 return readXmlHandler.getTree(); |
245 } | 269 } |
246 | 270 |
247 } | 271 } |