changeset 12:33b15ef21dcd

time measurementjuGrix and extendsXmlTree
author one
date Wed, 26 Nov 2014 06:24:25 +0900
parents cc219065cea3
children 7c544969d4c9
files src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/oldTree/CreateXML.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/oldTree/Index.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/xml/CreateXML.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/xml/TimeMeasurementJuGrix.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/xml/extendXmlTree.java
diffstat 5 files changed, 358 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/oldTree/CreateXML.java	Tue Nov 25 12:07:55 2014 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-package jp.ac.u_ryukyu.ie.cr.tatsuki.oldTree;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-
-public class CreateXML {
-
-  public static void main(String args[]) {
-
-    try {
-      File file = new File("./XML/test.xml");
-      PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
-      pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
-      int nodeCount = put(pw, 0, "", 0);
-      pw.close();
-      System.out.println(nodeCount);
-    } catch (IOException e) {
-      System.out.println(e);
-    }
-  }
-
-  public static int put(PrintWriter pw, int deep, String str, int nodeCount) {
-    nodeCount++;
-    pw.println(str + "<element id = \"" + deep + "\">");
-    String newStr = str + "  ";
-    System.out.println("deep = " + deep);
-    deep++;
-    if (deep < 17) {
-      nodeCount = put(pw, deep, newStr, nodeCount);
-      nodeCount = put(pw, deep, newStr, nodeCount);
-    }
-    pw.println(str + "</element>");
-    return nodeCount;
-  }
-}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/oldTree/Index.java	Tue Nov 25 12:07:55 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/oldTree/Index.java	Wed Nov 26 06:24:25 2014 +0900
@@ -22,7 +22,7 @@
 
     LoadXml reader = new LoadXml();
     JungleTree personTree = reader.loadTestData("test.xml");
-    InterfaceTraverser traverser = personTree.getTraverser();
+    InterfaceTraverser traverser = personTree.getTraverser(true);
     search(traverser, "Normal");
     System.out.println("test");
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/xml/CreateXML.java	Wed Nov 26 06:24:25 2014 +0900
@@ -0,0 +1,38 @@
+package jp.ac.u_ryukyu.ie.cr.tatsuki.xml;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+public class CreateXML {
+
+  public static void main(String args[]) {
+
+    try {
+      File file = new File("./XML/test.xml");
+      PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
+      pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+      int nodeCount = put(pw, 0, "", 0);
+      pw.close();
+      System.out.println(nodeCount);
+    } catch (IOException e) {
+      System.out.println(e);
+    }
+  }
+
+  public static int put(PrintWriter pw, int deep, String str, int nodeCount) {
+    nodeCount++;
+    pw.println(str + "<element id = \"" + deep + "\">");
+    String newStr = str + "  ";
+    System.out.println("deep = " + deep);
+    deep++;
+    if (deep < 17) {
+      nodeCount = put(pw, deep, newStr, nodeCount);
+      nodeCount = put(pw, deep, newStr, nodeCount);
+    }
+    pw.println(str + "</element>");
+    return nodeCount;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/xml/TimeMeasurementJuGrix.java	Wed Nov 26 06:24:25 2014 +0900
@@ -0,0 +1,73 @@
+package jp.ac.u_ryukyu.ie.cr.tatsuki.xml;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.Random;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.xml.sax.SAXException;
+
+import jp.ac.u_ryukyu.cr.ie.tatsuki.bbs.JuGrix;
+
+public class TimeMeasurementJuGrix {
+
+  static int roopCount = 10;
+  static boolean useIndex = false;
+  
+  public static void main(String args[]) throws FileNotFoundException, ParserConfigurationException, SAXException, IOException {
+
+    System.out.println("start : ");
+
+    String orgId = "o:2";
+    String personId = "p:1";
+    LinkedList<String> filterIds = new LinkedList<String>();
+    filterIds.add("r:5");
+    long t2;
+    long t1; 
+    t1 = System.currentTimeMillis();
+    JuGrix jugrix = extendXmlTree.createJuGrix(useIndex);
+    t2 = System.currentTimeMillis();
+    System.out.println("create tree =" + (t2 - t1) + "s");
+    Random random = new Random();
+
+    t1 = System.currentTimeMillis();
+    functions(jugrix, orgId, personId, filterIds);
+    t2 = System.currentTimeMillis();
+    System.out.println("1回目=" + (t2 - t1) + "s");
+
+    long sumTime = 0;
+    for (int count = 0; count < roopCount; count++) {
+
+      int ran = random.nextInt(30);
+      orgId = "o:" + String.valueOf(ran);
+      personId = "p:" + String.valueOf(ran);
+      t1 = System.currentTimeMillis();
+      functions(jugrix, orgId, personId, filterIds);
+      t2 = System.currentTimeMillis();
+      sumTime = (t2 - t1); 
+      System.out.println(count + "回目=" +sumTime + "s");
+    }
+    System.out.println("平均 = " + sumTime + "s");
+    System.out.println("end");
+  }
+
+  private static void functions(JuGrix jugrix, String orgId, String personId, LinkedList<String> filterIds) {
+    jugrix.childOrganizationIds(orgId, filterIds);
+    jugrix.competentRoleId(personId);
+    jugrix.concurrentRoleIds(personId);
+    jugrix.deepChildOrganizationIds(orgId, filterIds);
+    jugrix.deepChildOrganizationIdsPlus(orgId, filterIds);
+    jugrix.deepParentOrganizationIds(orgId, filterIds);
+    jugrix.deepParentOrganizationIdsPlus(orgId, filterIds);
+    jugrix.deepPersonIds(orgId, filterIds);
+    jugrix.isActive(personId);
+    jugrix.parentOrganizationIds(orgId, filterIds);
+    jugrix.personIds(orgId, filterIds);
+    jugrix.roleDescriptionElementIds(orgId, filterIds);
+    jugrix.roleIds(orgId, filterIds);
+    jugrix.rolePriority(personId, "r:34");
+    jugrix.stringPathToId("r:path:エスアールエルテクノシステム/臨検システム部/業務システムグループ");
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/xml/extendXmlTree.java	Wed Nov 26 06:24:25 2014 +0900
@@ -0,0 +1,246 @@
+package jp.ac.u_ryukyu.ie.cr.tatsuki.xml;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Iterator;
+import java.util.Random;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.SAXException;
+
+import jp.ac.u_ryukyu.cr.ie.tatsuki.bbs.JuGrix;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser;
+import ac.jp.u_ryukyu.cr.ie.tatsuki.xmlReader.ReadXmlHandler;
+
+public class extendXmlTree {
+
+  private extendXmlTree() {
+
+  }
+
+  static int personCount = 10;
+
+  public static JuGrix createJuGrix(boolean useIndex) throws ParserConfigurationException, SAXException,
+      FileNotFoundException, IOException {
+    Jungle jungle = new DefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser()));
+    JungleTree readXmlTree = jungle.createNewTree("Person");
+    // JungleTree readXmlTree = readXml("Person", jungle);
+    JungleTree orgTree = readXml("Organization", jungle);
+    JungleTree roleTree = readXml("Role", jungle);
+    JungleTreeEditor editor = readXmlTree.getTreeEditor();
+    NodePath path = new DefaultNodePath();
+    editor = editor.addNewChildAt(path, 0).b();
+    editor = editor.putAttribute(path.add(0), "element", ByteBuffer.wrap("Persons".getBytes())).b();
+    for (int count = 0; count < personCount; ++count) {
+      editor = extendsTree(editor, orgTree, roleTree, count);
+      System.out.println("Count = " + count);
+    }
+    editor.success();
+    int PersonCount = readXmlTree.getRootNode().getChildren().at(0).b().getChildren().size();
+    System.out.println("PersonCount = " + PersonCount);
+    JuGrix jugrix = new JuGrix(useIndex, readXmlTree, orgTree, roleTree);
+    return jugrix;
+  }
+
+  private static JungleTreeEditor extendsTree(JungleTreeEditor editor, JungleTree orgTree, JungleTree roleTree,
+      int count) {
+    Random rdm = new Random();
+    int orgNum = rdm.nextInt(30);
+    String orgId = "o:" + String.valueOf(orgNum);
+    String orgRoleId = searchOrgRole(orgTree, orgId);
+    String roleId = searchRole(roleTree, orgRoleId);
+    orgNum = rdm.nextInt(30);
+
+    String orgId2 = "o:" + String.valueOf(orgNum);
+    String orgRoleId2 = searchOrgRole(orgTree, orgId2);
+    String roleId2 = searchRole(roleTree, orgRoleId2);
+
+    NodePath path = new DefaultNodePath().add(0);
+    editor = editor.addNewChildAt(path, count).b();
+    path = path.add(count);
+    editor = editor.putAttribute(path, "element", ByteBuffer.wrap("Person".getBytes())).b();
+    String personId = String.valueOf(count);
+    editor = editor.putAttribute(path, "Person-id", ByteBuffer.wrap(("p:" + personId).getBytes())).b();
+    editor = editor.putAttribute(path, "Person-type", ByteBuffer.wrap("Person".getBytes())).b();
+
+    editor = editor.addNewChildAt(path, 0).b();
+    editor = editor.putAttribute(path.add(0), "element", ByteBuffer.wrap(("accountId").getBytes())).b();
+    editor = editor.putAttribute(path.add(0), "text-accountId", ByteBuffer.wrap(("a:" + personId).getBytes())).b();
+
+    editor = editor.addNewChildAt(path, 1).b();
+    editor = editor.putAttribute(path.add(1), "element", ByteBuffer.wrap(("lastName").getBytes())).b();
+    editor = editor.putAttribute(path.add(1), "text-lastName", ByteBuffer.wrap(("金川").getBytes())).b();
+
+    editor = editor.addNewChildAt(path, 2).b();
+    editor = editor.putAttribute(path.add(2), "element", ByteBuffer.wrap(("name").getBytes())).b();
+    editor = editor.putAttribute(path.add(2), "text-name", ByteBuffer.wrap(("竜己").getBytes())).b();
+
+    editor = editor.addNewChildAt(path, 3).b();
+    editor = editor.putAttribute(path.add(3), "element", ByteBuffer.wrap(("nameReading").getBytes())).b();
+    editor = editor.putAttribute(path.add(3), "text-nameReading", ByteBuffer.wrap(("かながわたつき").getBytes())).b();
+
+    editor = editor.addNewChildAt(path, 4).b();
+    editor = editor.putAttribute(path.add(4), "element", ByteBuffer.wrap(("roleRefIds").getBytes())).b();
+
+    editor = editor.addNewChildAt(path.add(4), 0).b();
+    editor = editor.putAttribute(path.add(4).add(0), "element", ByteBuffer.wrap(("roleRefId").getBytes())).b();
+    editor = editor.putAttribute(path.add(4).add(0), "text-roleRefId", ByteBuffer.wrap((roleId).getBytes())).b();
+    editor = editor.addNewChildAt(path.add(4), 1).b();
+    editor = editor.putAttribute(path.add(4).add(1), "element", ByteBuffer.wrap(("roleRefId").getBytes())).b();
+    editor = editor.putAttribute(path.add(4).add(1), "text-roleRefId", ByteBuffer.wrap((roleId2).getBytes())).b();
+
+    editor = editor.addNewChildAt(path, 5).b();
+    editor = editor.putAttribute(path.add(5), "element", ByteBuffer.wrap(("parentOrganizations").getBytes())).b();
+    editor = editor.putAttribute(path.add(5), "parentOrganizations-type",
+        ByteBuffer.wrap(("OrganizationMappedByRole").getBytes())).b();
+
+    NodePath parentOrgPath = path.add(5);
+    editor = editor.addNewChildAt(parentOrgPath, 0).b();
+    editor = editor.putAttribute(parentOrgPath.add(0), "element",
+        ByteBuffer.wrap(("OrganizationMappedByRole").getBytes())).b();
+    editor = editor.putAttribute(parentOrgPath.add(0), "OrganizationMappedByRole-type",
+        ByteBuffer.wrap(("OrganizationMappedByRole").getBytes())).b();
+
+    editor = editor.addNewChildAt(parentOrgPath.add(0), 0).b();
+    editor = editor.putAttribute(parentOrgPath.add(0).add(0), "element",
+        ByteBuffer.wrap(("organizationRefId").getBytes())).b();
+    editor = editor.putAttribute(parentOrgPath.add(0).add(0), "text-organizationRefId",
+        ByteBuffer.wrap((orgId).getBytes())).b();
+
+    editor = editor.addNewChildAt(parentOrgPath.add(0), 1).b();
+    editor = editor.putAttribute(parentOrgPath.add(0).add(1), "element", ByteBuffer.wrap(("roleRefId").getBytes())).b();
+    editor = editor.putAttribute(parentOrgPath.add(0).add(1), "text-roleRefId", ByteBuffer.wrap((roleId).getBytes()))
+        .b();
+
+    editor = editor.addNewChildAt(parentOrgPath, 1).b();
+    editor = editor.putAttribute(parentOrgPath.add(1), "element",
+        ByteBuffer.wrap(("OrganizationMappedByRole").getBytes())).b();
+    editor = editor.putAttribute(parentOrgPath.add(1), "OrganizationMappedByRole-type",
+        ByteBuffer.wrap(("OrganizationMappedByRole").getBytes())).b();
+
+    editor = editor.addNewChildAt(parentOrgPath.add(1), 0).b();
+    editor = editor.putAttribute(parentOrgPath.add(1).add(0), "element",
+        ByteBuffer.wrap(("organizationRefId").getBytes())).b();
+    editor = editor.putAttribute(parentOrgPath.add(1).add(0), "text-organizationRefId",
+        ByteBuffer.wrap((orgId2).getBytes())).b();
+
+    editor = editor.addNewChildAt(parentOrgPath.add(1), 1).b();
+    editor = editor.putAttribute(parentOrgPath.add(1).add(1), "element", ByteBuffer.wrap(("roleRefId").getBytes())).b();
+    editor = editor.putAttribute(parentOrgPath.add(1).add(1), "text-roleRefId", ByteBuffer.wrap((roleId2).getBytes()))
+        .b();
+
+    editor = editor.addNewChildAt(path, 6).b();
+    editor = editor.putAttribute(path.add(6), "element", ByteBuffer.wrap(("priorities").getBytes())).b();
+    editor = editor.putAttribute(path.add(6), "priorities-type",
+        ByteBuffer.wrap(("OrganizationMappedByRole").getBytes())).b();
+
+    //
+    editor = editor.addNewChildAt(path.add(6), 0).b();
+    editor = editor.putAttribute(path.add(6).add(0), "element", ByteBuffer.wrap(("PriorityMappedByRole").getBytes()))
+        .b();
+    editor = editor.putAttribute(path.add(6).add(0), "PriorityMappedByRole-type",
+        ByteBuffer.wrap(("PriorityMappedByRole").getBytes())).b();
+
+    editor = editor.addNewChildAt(path.add(6).add(0), 0).b();
+    editor = editor.putAttribute(path.add(6).add(0).add(0), "element", ByteBuffer.wrap(("priority").getBytes())).b();
+    editor = editor.putAttribute(path.add(6).add(0).add(0), "text-priority", ByteBuffer.wrap(("0").getBytes())).b();
+    editor = editor.addNewChildAt(path.add(6).add(0), 1).b();
+    editor = editor.putAttribute(path.add(6).add(0).add(1), "element", ByteBuffer.wrap(("roleRefId").getBytes())).b();
+    editor = editor.putAttribute(path.add(6).add(0).add(1), "text-roleRefId", ByteBuffer.wrap((roleId).getBytes())).b();
+
+    editor = editor.addNewChildAt(path.add(6), 1).b();
+    editor = editor.putAttribute(path.add(6).add(1), "element", ByteBuffer.wrap(("PriorityMappedByRole").getBytes()))
+        .b();
+    editor = editor.putAttribute(path.add(6).add(1), "PriorityMappedByRole-type",
+        ByteBuffer.wrap(("PriorityMappedByRole").getBytes())).b();
+
+    editor = editor.addNewChildAt(path.add(6).add(1), 0).b();
+    editor = editor.putAttribute(path.add(6).add(1).add(0), "element", ByteBuffer.wrap(("priority").getBytes())).b();
+    editor = editor.putAttribute(path.add(6).add(1).add(0), "text-priority", ByteBuffer.wrap(("1").getBytes())).b();
+    editor = editor.addNewChildAt(path.add(6).add(1), 1).b();
+    editor = editor.putAttribute(path.add(6).add(1).add(1), "element", ByteBuffer.wrap(("roleRefId").getBytes())).b();
+    editor = editor.putAttribute(path.add(6).add(1).add(1), "text-roleRefId", ByteBuffer.wrap((roleId2).getBytes()))
+        .b();
+    return editor;
+
+  }
+
+  private static String searchRole(JungleTree roleTree, String orgRoleId) {
+    InterfaceTraverser traverser = roleTree.getTraverser(false);
+    Iterator<TreeNode> roleIdIterator = traverser.find((TreeNode node) -> {
+      String element = node.getAttributes().getString("element");
+      if (element == null)
+        return false;
+      if (!element.equals("Role"))
+        return false;
+      String compareRoleId = node.getAttributes().getString("Role-id");
+      if (compareRoleId == null)
+        return false;
+      if (compareRoleId.equals(orgRoleId))
+        return true;
+      return false;
+    }, "Role-id", orgRoleId);
+
+    if (!roleIdIterator.hasNext())
+      return orgRoleId;
+
+    TreeNode orgIdNode = roleIdIterator.next();
+    TreeNode roleRefIdNode = orgIdNode.getChildren().at(0).b().getChildren().at(0).b();
+    if (roleRefIdNode == null)
+      return orgRoleId;
+    String roleId = roleRefIdNode.getAttributes().getString("text-childrenRoleRefId");
+
+    return roleId;
+  }
+
+  private static String searchOrgRole(JungleTree orgTree, String orgId) {
+    InterfaceTraverser traverser = orgTree.getTraverser(false);
+    Iterator<TreeNode> orgIdIterator = traverser.find((TreeNode node) -> {
+      String element = node.getAttributes().getString("element");
+      if (element == null)
+        return false;
+      if (!element.equals("Organization"))
+        return false;
+      String compareRoleId = node.getAttributes().getString("Organization-id");
+      if (compareRoleId == null)
+        return false;
+      if (compareRoleId.equals(orgId))
+        return true;
+      return false;
+    }, "Organization-id", orgId);
+
+    if (!orgIdIterator.hasNext())
+      return "";
+
+    TreeNode orgIdNode = orgIdIterator.next();
+    TreeNode roleRefIdNode = orgIdNode.getChildren().at(2).b().getChildren().at(0).b();
+    String roleId = roleRefIdNode.getAttributes().getString("text-roleRefId");
+    return roleId;
+  }
+
+  private static JungleTree readXml(String xml, Jungle jungle) throws ParserConfigurationException, SAXException,
+      IOException, FileNotFoundException {
+    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
+    SAXParser saxParser = saxParserFactory.newSAXParser();
+    JungleTree tree = jungle.createNewTree(xml);
+    ReadXmlHandler readXmlHandler = new ReadXmlHandler(tree);
+    saxParser
+        .parse(new FileInputStream("/Users/e115731/workspace/JungleXmlReader/xml/" + xml + ".xml"), readXmlHandler);
+    return readXmlHandler.getTree();
+  }
+
+}