comparison src/main/java/example/SimpleJungle.java @ 3:37aab24020a0

thread test
author Kanagawa TATSUKI <tatsuki@ie.u-ryukyu.ac.jp>
date Thu, 06 Mar 2014 04:17:40 +0900
parents f716298e440a
children
comparison
equal deleted inserted replaced
2:f716298e440a 3:37aab24020a0
22 public static final String valueString = "kanagawa"; 22 public static final String valueString = "kanagawa";
23 public static final ByteBuffer value = ByteBuffer.wrap(valueString.getBytes()); 23 public static final ByteBuffer value = ByteBuffer.wrap(valueString.getBytes());
24 24
25 public static void main(String[] args) { 25 public static void main(String[] args) {
26 Jungle j = new DefaultJungle(null,"hogehoge",new DefaultTreeEditor(new DefaultTraverser())); 26 Jungle j = new DefaultJungle(null,"hogehoge",new DefaultTreeEditor(new DefaultTraverser()));
27 j.createNewTree("tree"); 27 j.createNewTree("tree");//木を作った
28 JungleTree tree = j.getTreeByName("tree"); 28 JungleTree tree = j.getTreeByName("tree");//名前を取得
29 JungleTreeEditor editor1 = tree.getTreeEditor(); 29 JungleTreeEditor editor1 = tree.getTreeEditor();//editorの取得
30 DefaultNodePath root = new DefaultNodePath(); 30 DefaultNodePath root = new DefaultNodePath();//パスの取得
31 31
32 //eitherに値を入れる
32 Either<Error,JungleTreeEditor> either = editor1.putAttribute(root,key,value); 33 Either<Error,JungleTreeEditor> either = editor1.putAttribute(root,key,value);
33 if(either.isA()){ 34 if(either.isA()){//失敗した場合Aが出てくる
34 Assert.fail(); 35 Assert.fail();
35 } 36 }
36 editor1 = either.b(); 37 editor1 = either.b();
37 editor1.success(); 38 editor1.success();
39 //ここで初めてSUCCESS
38 40
39 Node node = tree.getRootNode(); 41 Node node = tree.getRootNode();
40 ByteBuffer v = node.getAttributes().get(key); 42 ByteBuffer v = node.getAttributes().get(key);
41 System.out.println(new String(v.array())); 43 System.out.println(new String(v.array()));
42 44
43 editor1 = tree.getTreeEditor(); 45 editor1 = tree.getTreeEditor();//Treeのeditorを作成
44 either = editor1.addNewChildAt(root,0); 46 either = editor1.addNewChildAt(root,0);//新しく入れるところへのパス
45 if(either.isA()){ 47 if(either.isA()){//ちゃんとパスを指定できたかチェック
46 Assert.fail(); 48 Assert.fail();
47 } 49 }
48 editor1 = either.b(); 50 editor1 = either.b();//成功した場合パスを入れる
49 DefaultNodePath childPath = root.add(0); 51 DefaultNodePath childPath = root.add(0);
50 either = editor1.putAttribute(childPath,key,value); 52 //そしてここで子ノードに値を入れる
51 if(either.isA()){ 53 for(int count = 0 ; count < 1000 ; count++){
54 either = editor1.putAttribute(childPath,key,value);
55 if(either.isA()){
52 Assert.fail(); 56 Assert.fail();
53 } 57 }
54 editor1 = either.b(); 58 editor1 = either.b();
55 either = editor1.success(); 59 either = editor1.success();
56 if(either.isA()){
57 Assert.fail();
58 } 60 }
59 61
60 62
61 node = tree.getRootNode(); 63 node = tree.getRootNode();
62 Children<Node> children = node.getChildren(); 64 Children<Node> children = node.getChildren();