comparison src/jungle/test/datasegment/store/operations/DefaultTreeOperationLogContainer.java @ 8:ee93e16d5a3f

implement unconvert and convert method in DefaultTreeOperationLog class
author one
date Tue, 11 Jun 2013 05:41:07 +0900
parents b7396f848d78
children 49c0eaa4dce2
comparison
equal deleted inserted replaced
7:b7396f848d78 8:ee93e16d5a3f
30 String key = "hoge"; 30 String key = "hoge";
31 ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes()); 31 ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes());
32 PutAttributeOperation putOp = new PutAttributeOperation(key, b); 32 PutAttributeOperation putOp = new PutAttributeOperation(key, b);
33 DefaultNodePath nodePath = new DefaultNodePath(); 33 DefaultNodePath nodePath = new DefaultNodePath();
34 nodePath = nodePath.add(1).add(2).add(3); 34 nodePath = nodePath.add(1).add(2).add(3);
35
36 TreeOperation op = new DefaultTreeOperation(nodePath, putOp); 35 TreeOperation op = new DefaultTreeOperation(nodePath, putOp);
36 List<TreeOperation> list = new LinkedList<TreeOperation>();
37 list.add(op);
38 list.add(op);
39 list.add(op);
40 DefaultTreeOperationLog log = new DefaultTreeOperationLog(list, list.size());
37 41
42 DefaultTreeOperationLogContainer logContainer = new DefaultTreeOperationLogContainer();
43 logContainer.unconvert(log);
44
45 TreeOperationLog convertedLog = logContainer.convert();
46 for (TreeOperation treeOp : convertedLog) {
47 NodePath path = treeOp.getNodePath();
48 NodeOperation nodeOp = treeOp.getNodeOperation();
49 Command c = nodeOp.getCommand();
50 String str = "";
51 switch (c) {
52 case PUT_ATTRIBUTE:
53 String k = nodeOp.getKey();
54 ByteBuffer value = nodeOp.getValue();
55 if (value.limit() < 100) {
56 str = String.format("key:%s,value:%s", k,
57 new String(value.array()));
58 } else {
59 str = String.format("key:%s,value:%d", k, value.limit());
60 }
61 break;
62 case DELETE_ATTRIBUTE:
63 str = String.format("key:%s", nodeOp.getKey());
64 break;
65 case APPEND_CHILD:
66 str = String.format("pos:%d", nodeOp.getPosition());
67 break;
68 case DELETE_CHILD:
69 str = String.format("pos:%d", nodeOp.getPosition());
70 break;
71 }
72 System.out.println(String.format("[%s:%s:%s]", c, nodePath, str));
73 for (int i: nodePath ) {
74 System.out.println(i);
75 }
76
77 }
38 78
39 79
40 } 80 }
41 81
42 public DefaultTreeOperationLogContainer() { 82 public DefaultTreeOperationLogContainer() {
47 MessagePack msgpack = new MessagePack(); 87 MessagePack msgpack = new MessagePack();
48 List<Value> list = new LinkedList<Value>(); 88 List<Value> list = new LinkedList<Value>();
49 for(TreeOperation op : _log) { 89 for(TreeOperation op : _log) {
50 NodeOperation nOp = op.getNodeOperation(); 90 NodeOperation nOp = op.getNodeOperation();
51 NodePath nodePath = op.getNodePath(); 91 NodePath nodePath = op.getNodePath();
52 DefaultNodeOperationContainer nodeOpContainer = new DefaultNodeOperationContainer(); 92 DefaultTreeOperation treeOp = new DefaultTreeOperation(nodePath, nOp);
53 nodeOpContainer.unconvert(nOp);
54 DefaultNodePathContainer nodePathContainer = new DefaultNodePathContainer();
55 nodePathContainer.unconvert(nodePath);
56 DefaultTreeOperationContainer container = new DefaultTreeOperationContainer(); 93 DefaultTreeOperationContainer container = new DefaultTreeOperationContainer();
57 container.unconvert(nodeOpContainer, nodePathContainer); 94 container.unconvert(treeOp);
58 Value v = msgpack.unconvert(container); 95 Value v = msgpack.unconvert(container);
59 list.add(v); 96 list.add(v);
60 } 97 }
61 /* */ 98 /* */
62 msgpack.register(List.class, new ListTemplate(ValueTemplate.getInstance())); 99 msgpack.register(List.class, new ListTemplate(ValueTemplate.getInstance()));