view src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/oldTree/Index.java @ 11:cc219065cea3

error fix
author one
date Tue, 25 Nov 2014 12:07:55 +0900
parents 2af5af044947
children 33b15ef21dcd
line wrap: on
line source

package jp.ac.u_ryukyu.ie.cr.tatsuki.oldTree;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import java.util.Random;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import fj.data.List;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser;
import ac.jp.u_ryukyu.cr.ie.tatsuki.xmlReader.LoadXml;

public class Index {

  public static void main(String args[]) throws FileNotFoundException, SAXException, IOException,
      ParserConfigurationException {

    LoadXml reader = new LoadXml();
    JungleTree personTree = reader.loadTestData("test.xml");
    InterfaceTraverser traverser = personTree.getTraverser();
    search(traverser, "Normal");
    System.out.println("test");

  }

  public static void search(InterfaceTraverser traverser, String type) {

    Random rnd = new Random();
    List<String> str = List.nil();
    System.out.println("start");
    str = str.cons(String.valueOf(rnd.nextInt(1000)));

    long t1 = System.currentTimeMillis();

    for (String attribute : str) {

      Iterator<TreeNode> targetNode = traverser.find((TreeNode node) -> {
        String element = node.getAttributes().getString("element");
        if (element == null)
          return false;
        if (!element.equals("element"))
          return false;

        String id = node.getAttributes().getString("element-id");
        if (id == null)
          return false;
        if (id.equals(attribute))
          return true;
        return false;
      }, "element-id", attribute);

      for (; targetNode.hasNext();) {
        targetNode.next();
      }
    }
    long t2 = System.currentTimeMillis();
    System.out.println(type + " : time = " + (t2 - t1));
  }

}