annotate src/jungle/test/codesegment/practice/ShowAttribute.java @ 21:1abbfc8f11f2

add ShowAttribute
author one
date Sun, 30 Jun 2013 04:18:12 +0900
parents
children 2232263d449b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
1 package jungle.test.codesegment.practice;
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
2
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
3 import java.nio.ByteBuffer;
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
4
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle;
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children;
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node;
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
13 import alice.codesegment.CodeSegment;
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
14 import alice.datasegment.CommandType;
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
15 import alice.datasegment.Receiver;
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
16
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
17 public class ShowAttribute extends CodeSegment {
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
18
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
19 Receiver arg1 = ids.create(CommandType.TAKE);
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
20
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
21 public ShowAttribute() {
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
22 arg1.setKey("show");
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
23 }
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
24
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
25 public void run() {
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
26 System.out.println("--ShowAttribute--");
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
27
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
28 Jungle jungle = new JungleManager().getJungle();
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
29 JungleTree tree = jungle.getTreeByName("tree");
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
30 JungleTreeEditor editor = tree.getTreeEditor();
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
31 DefaultNodePath root = new DefaultNodePath();
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
32 Either<Error,JungleTreeEditor> either = editor.addNewChildAt(root, 0);
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
33 if(either.isA()) {
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
34 throw new IllegalStateException();
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
35 }
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
36 editor = either.b();
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
37 either = editor.putAttribute(root.add(0), "key1", ByteBuffer.wrap("message".getBytes()));
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
38 if(either.isA()) {
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
39 throw new IllegalStateException();
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
40 }
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
41 editor = either.b();
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
42 Either<Error,JungleTreeEditor> result = editor.success();
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
43 if(result.isA()) {
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
44 throw new IllegalStateException();
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
45 }
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
46
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
47 Node node = tree.getRootNode();
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
48 Children<Node> chs = node.getChildren();
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
49 for(Node n : chs) {
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
50 System.out.println(n.getAttributes().get("key1"));
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
51 }
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
52
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
53 System.exit(0);
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
54
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
55
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
56 }
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
57
1abbfc8f11f2 add ShowAttribute
one
parents:
diff changeset
58 }