diff src/alice/jungle/datasegment/store/container/DefaultTreeOperationContainer.java @ 75:87ec5dd0dc27

Rename from alice.jungle.datasegment.store.operation to alice.jungle.datasegment.store.container
author one
date Tue, 15 Oct 2013 14:43:29 +0900
parents src/alice/jungle/datasegment/store/operations/DefaultTreeOperationContainer.java@85bc7416ae02
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/jungle/datasegment/store/container/DefaultTreeOperationContainer.java	Tue Oct 15 14:43:29 2013 +0900
@@ -0,0 +1,100 @@
+package alice.jungle.datasegment.store.container;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command;
+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.operations.DefaultTreeOperation;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation;
+
+import org.msgpack.MessagePack;
+import org.msgpack.annotation.Message;
+import org.msgpack.type.Value;
+
+import alice.codesegment.SingletonMessage;
+
+@Message
+public class DefaultTreeOperationContainer {
+
+	Value pathValue;
+	Value opValue;
+
+	public static void main(String[] args) throws IOException {
+		String key = "hoge";
+		ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes());
+		PutAttributeOperation op = new PutAttributeOperation(key, b);
+
+		DefaultNodePath p = new DefaultNodePath();
+		p = p.add(1).add(2).add(3);
+		DefaultTreeOperation treeOp = new DefaultTreeOperation(p, op);
+		
+		DefaultTreeOperationContainer treeOperationContainer = new DefaultTreeOperationContainer();
+		treeOperationContainer.unconvert(treeOp);
+
+		TreeOperation treeOperation = treeOperationContainer.convert();
+		NodePath nodePath = treeOperation.getNodePath();
+		NodeOperation nodeOp = treeOperation.getNodeOperation();
+		Command c = nodeOp.getCommand();
+		String str = "";
+		switch (c) {
+		case PUT_ATTRIBUTE:
+			String k = nodeOp.getKey();
+			ByteBuffer value = nodeOp.getValue();
+			if (value.limit() < 100) {
+				str = String.format("key:%s,value:%s", k,
+						new String(value.array()));
+			} else {
+				str = String.format("key:%s,value:%d", k, value.limit());
+			}
+			break;
+		case DELETE_ATTRIBUTE:
+			str = String.format("key:%s", nodeOp.getKey());
+			break;
+		case APPEND_CHILD:
+			str = String.format("pos:%d", nodeOp.getPosition());
+			break;
+		case DELETE_CHILD:
+			str = String.format("pos:%d", nodeOp.getPosition());
+			break;
+		}
+		System.out.println(String.format("[%s:%s:%s]", c, nodePath, str));
+		for (int i: nodePath ) {
+			System.out.println(i);
+		}
+	}
+
+	public DefaultTreeOperationContainer() {
+
+	}
+	
+	public void unconvert(DefaultTreeOperation _op) throws IOException {
+		NodeOperation nodeOp = _op.getNodeOperation();
+		NodePath nodePath = _op.getNodePath();
+		DefaultNodeOperationContainer opContainer = new DefaultNodeOperationContainer();
+		opContainer.unconvert(nodeOp);
+		DefaultNodePathContainer pathContainer = new DefaultNodePathContainer();
+		pathContainer.unconvert(nodePath);
+		unconvert(opContainer, pathContainer);
+	}
+
+	public void unconvert(DefaultNodeOperationContainer _op,
+			DefaultNodePathContainer _path) throws IOException {
+//		MessagePack msgpack = new MessagePack();
+		MessagePack msgpack = SingletonMessage.getInstance();
+		pathValue = msgpack.unconvert(_path);
+		opValue = msgpack.unconvert(_op);
+	}
+
+	public TreeOperation convert() throws IOException {
+//		MessagePack msgpack = new MessagePack();
+		MessagePack msgpack = SingletonMessage.getInstance();
+		DefaultNodePathContainer pathContainer = msgpack.convert(pathValue, DefaultNodePathContainer.class);
+		DefaultNodeOperationContainer opContainer = msgpack.convert(opValue, DefaultNodeOperationContainer.class);
+		return new DefaultTreeOperation(pathContainer.convert(), opContainer.convert());
+	}
+
+}