Mercurial > hg > Members > nobuyasu > jungle-network
changeset 78:0055d917c796
Modified NetworkNodeOperation
author | one |
---|---|
date | Wed, 16 Oct 2013 17:24:15 +0900 |
parents | 2dba7e1cf9fa |
children | 5b9708d9febc |
files | src/alice/jungle/operations/NetworkAppendChildAtOperation.java src/alice/jungle/operations/NetworkNodeOperation.java src/alice/jungle/operations/NetworkPutAttributeOperation.java src/test/alice/jungle/core/operations/NetworkAppendChildOperationTest.java src/test/alice/jungle/core/operations/NetworkNodeOperationTest.java src/test/alice/jungle/core/operations/NetworkPutAttributeOperationTest.java src/test/alice/jungle/core/operations/NetworknodeOperationTest.java |
diffstat | 7 files changed, 66 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/jungle/operations/NetworkAppendChildAtOperation.java Tue Oct 15 16:01:11 2013 +0900 +++ b/src/alice/jungle/operations/NetworkAppendChildAtOperation.java Wed Oct 16 17:24:15 2013 +0900 @@ -16,8 +16,8 @@ @Message public class NetworkAppendChildAtOperation implements NodeOperation { + /* MessagePack cannot handle final.*/ // private final int pos; - /* MessagePack cannot handle final.*/ private int pos; /* Position -1 represent root position. */
--- a/src/alice/jungle/operations/NetworkNodeOperation.java Tue Oct 15 16:01:11 2013 +0900 +++ b/src/alice/jungle/operations/NetworkNodeOperation.java Wed Oct 16 17:24:15 2013 +0900 @@ -7,47 +7,64 @@ import org.msgpack.annotation.Message; - @Message public class NetworkNodeOperation { public int pos; - public String key = null; - public ByteBuffer value = null; - public Command command = null; + public String key; + public ByteBuffer value; + public int commandType; public NetworkNodeOperation() { pos = -2; + key = null; + value = null; + commandType = 0; } public NetworkNodeOperation(NodeOperation _op) { pos = _op.getPosition(); key = _op.getKey(); value = _op.getValue(); - command= _op.getCommand(); - + commandType = getCommandType(_op.getCommand()); } - public NetworkNodeOperation(int _pos, Command _command) { - pos = _pos; - command = _command; + public static int getCommandType(Command c) { + switch(c) { + case PUT_ATTRIBUTE: + return 1; + case APPEND_CHILD: + return 2; + case DELETE_CHILD: + return 3; + case DELETE_ATTRIBUTE: + return 4; + default: + break; + } + return 0; } - public NetworkNodeOperation(String _key, Command _command) { - key = _key; - command = _command; + public static Command getCommand(int num) { + switch(num) { + case 1: + return Command.PUT_ATTRIBUTE; + case 2: + return Command.APPEND_CHILD; + case 3: + return Command.DELETE_CHILD; + case 4: + return Command.DELETE_ATTRIBUTE; + default: + break; + } + return null; } - public NetworkNodeOperation(String _key, ByteBuffer _value, Command _command) { - key = _key; - value = _value; - command = _command; + public Command getCommand() { + return getCommand(commandType); } - public NetworkNodeOperation(Command _command) { - command = _command; - } - public int getPosition() { return pos; } @@ -60,7 +77,4 @@ return value; } - public Command getCommand() { - return command; - } }
--- a/src/alice/jungle/operations/NetworkPutAttributeOperation.java Tue Oct 15 16:01:11 2013 +0900 +++ b/src/alice/jungle/operations/NetworkPutAttributeOperation.java Wed Oct 16 17:24:15 2013 +0900 @@ -13,8 +13,9 @@ @Message public class NetworkPutAttributeOperation implements NodeOperation { - /* MessagePack cannot handle final.*/ -/* + +/* MessagePack cannot handle final. + * * private final String key; * private final ByteBuffer value; */
--- a/src/test/alice/jungle/core/operations/NetworkAppendChildOperationTest.java Tue Oct 15 16:01:11 2013 +0900 +++ b/src/test/alice/jungle/core/operations/NetworkAppendChildOperationTest.java Wed Oct 16 17:24:15 2013 +0900 @@ -19,6 +19,5 @@ 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/NetworkNodeOperationTest.java Wed Oct 16 17:24:15 2013 +0900 @@ -0,0 +1,25 @@ +package test.alice.jungle.core.operations; + +import java.io.IOException; + +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import alice.jungle.operations.NetworkAppendChildAtOperation; +import alice.jungle.operations.NetworkNodeOperation; +import junit.framework.TestCase; + +public class NetworkNodeOperationTest extends TestCase { + + public void testMsgpackConvert() throws IOException { + NetworkAppendChildAtOperation op = new NetworkAppendChildAtOperation(1); + NetworkNodeOperation nOp = new NetworkNodeOperation(op); + MessagePack msgpack = new MessagePack(); + Value v = msgpack.unconvert(nOp); + NetworkNodeOperation mOp = msgpack.convert(v, NetworkNodeOperation.class); + assertEquals(op.getCommand(), mOp.getCommand()); + assertEquals(op.getPosition(), 1); + assertEquals(op.getPosition(), mOp.getPosition()); + } + +}
--- a/src/test/alice/jungle/core/operations/NetworkPutAttributeOperationTest.java Tue Oct 15 16:01:11 2013 +0900 +++ b/src/test/alice/jungle/core/operations/NetworkPutAttributeOperationTest.java Wed Oct 16 17:24:15 2013 +0900 @@ -6,7 +6,6 @@ import org.msgpack.MessagePack; import org.msgpack.type.Value; -import alice.jungle.operations.NetworkAppendChildAtOperation; import alice.jungle.operations.NetworkPutAttributeOperation; import junit.framework.TestCase;
--- a/src/test/alice/jungle/core/operations/NetworknodeOperationTest.java Tue Oct 15 16:01:11 2013 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -package test.alice.jungle.core.operations; - -import java.io.IOException; - -import org.msgpack.MessagePack; -import org.msgpack.type.Value; - -import alice.jungle.operations.NetworkAppendChildAtOperation; -import alice.jungle.operations.NetworkNodeOperation; -import junit.framework.TestCase; - -public class NetworknodeOperationTest extends TestCase { - - public void testMsgpackConvert() throws IOException { - NetworkAppendChildAtOperation op = new NetworkAppendChildAtOperation(1); - NetworkNodeOperation nOp = new NetworkNodeOperation(op); - MessagePack msgpack = new MessagePack(); - Value v = msgpack.unconvert(nOp); - NetworkNodeOperation mOp = msgpack.convert(v, NetworkNodeOperation.class); - assertEquals(op.getCommand(), mOp.getCommand()); - assertEquals(op.getPosition(), 1); - assertEquals(op.getPosition(), mOp.getPosition()); - - } - -}