changeset 73:9ab7d515e076

Added NetworkDeleteChildAtOpration and Test
author one
date Tue, 15 Oct 2013 14:26:25 +0900
parents 2520a5bd3dac
children 19e278488b42
files src/alice/jungle/operations/NetworkDeleteChildAtOperation.java src/test/alice/jungle/core/operations/NetworkAppendChildOperationTest.java src/test/alice/jungle/core/operations/NetworkDeleteChildAtOperationTest.java
diffstat 3 files changed, 83 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/jungle/operations/NetworkDeleteChildAtOperation.java	Tue Oct 15 14:26:25 2013 +0900
@@ -0,0 +1,58 @@
+package alice.jungle.operations;
+
+import java.nio.ByteBuffer;
+
+import org.msgpack.annotation.Message;
+
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteChildAt;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
+
+@Message
+public class NetworkDeleteChildAtOperation implements NodeOperation
+{
+	//private final int pos;
+	/* MessagePack can not handle final.*/
+	private int pos;
+	
+	
+	/* Position -1 represent root position. */	
+	public NetworkDeleteChildAtOperation(int _pos)
+	{
+		pos = _pos;
+	}
+	
+	@Override
+	public Command getCommand()
+	{
+		return Command.DELETE_CHILD;
+	}
+	
+	@Override
+	public <T extends EditableNode<T>> Either<Error, T> invoke(T _target)
+	{
+		DeleteChildAt deleteChildAt = new DeleteChildAt(pos);
+		return deleteChildAt.edit(_target);
+	}
+
+	@Override
+	public int getPosition()
+	{
+		return pos;
+	}
+
+	@Override
+	public String getKey()
+	{
+		return null;
+	}
+
+	@Override
+	public ByteBuffer getValue()
+	{
+		return null;
+	}
+}
--- a/src/test/alice/jungle/core/operations/NetworkAppendChildOperationTest.java	Tue Oct 15 09:13:18 2013 +0900
+++ b/src/test/alice/jungle/core/operations/NetworkAppendChildOperationTest.java	Tue Oct 15 14:26:25 2013 +0900
@@ -15,6 +15,7 @@
 		MessagePack msgpack = new MessagePack();
 		Value v = msgpack.unconvert(op);
 		NetworkAppendChildAtOperation mOp = msgpack.convert(v, NetworkAppendChildAtOperation.class);
+//		NodeOperation mOp = msgpack.convert(v, NodeOperation.class);
 		assertEquals(op.getCommand(), mOp.getCommand());
 		assertEquals(op.getPosition(), 1);
 		assertEquals(op.getPosition(), mOp.getPosition());
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/alice/jungle/core/operations/NetworkDeleteChildAtOperationTest.java	Tue Oct 15 14:26:25 2013 +0900
@@ -0,0 +1,24 @@
+package test.alice.jungle.core.operations;
+
+import java.io.IOException;
+
+import org.msgpack.MessagePack;
+import org.msgpack.type.Value;
+
+import alice.jungle.operations.NetworkDeleteChildAtOperation;
+import junit.framework.TestCase;
+
+public class NetworkDeleteChildAtOperationTest extends TestCase {
+
+
+	public void testMsgpackConvert() throws IOException {
+		NetworkDeleteChildAtOperation op = new NetworkDeleteChildAtOperation(1);
+		MessagePack msgpack = new MessagePack();
+		Value v = msgpack.unconvert(op);
+		NetworkDeleteChildAtOperation mOp = msgpack.convert(v, NetworkDeleteChildAtOperation.class);
+		assertEquals(op.getCommand(), mOp.getCommand());
+		assertEquals(op.getPosition(), mOp.getPosition());
+
+	}	
+	
+}