changeset 4:a7cd9a10033b

add PracticeEnum
author one
date Sun, 09 Jun 2013 13:13:02 +0900
parents 5b77974d641b
children 6fbdb09fb0e6
files src/ie/oshiro/messagepack/enumpractice/Command.java src/ie/oshiro/messagepack/enumpractice/Operation.java src/ie/oshiro/messagepack/enumpractice/OperationA.java src/ie/oshiro/messagepack/enumpractice/OperationB.java src/ie/oshiro/messagepack/enumpractice/PracticeEnum.java src/ie/oshiro/messagepack/jungle/containvalue/ListValue.java src/ie/oshiro/messagepack/jungle/containvalue/ListValueValue.java src/ie/oshiro/messagepack/jungle/containvalue/ListValueValueValue.java src/ie/oshiro/messagepack/jungle/practice/ImplClassA.java src/ie/oshiro/messagepack/jungle/practice/ImplClassB.java src/ie/oshiro/messagepack/jungle/practice/ListValue.java src/ie/oshiro/messagepack/jungle/practice/PracticeImplement.java src/ie/oshiro/messagepack/jungle/practice/PracticeInterface.java
diffstat 13 files changed, 311 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ie/oshiro/messagepack/enumpractice/Command.java	Sun Jun 09 13:13:02 2013 +0900
@@ -0,0 +1,6 @@
+package ie.oshiro.messagepack.enumpractice;
+
+public enum Command {
+	COMMAND_A,
+	COMMAND_B;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ie/oshiro/messagepack/enumpractice/Operation.java	Sun Jun 09 13:13:02 2013 +0900
@@ -0,0 +1,5 @@
+package ie.oshiro.messagepack.enumpractice;
+
+public interface Operation {
+	public Command getCommand();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ie/oshiro/messagepack/enumpractice/OperationA.java	Sun Jun 09 13:13:02 2013 +0900
@@ -0,0 +1,11 @@
+package ie.oshiro.messagepack.enumpractice;
+
+import org.msgpack.annotation.Message;
+
+@Message
+public class OperationA implements Operation {
+	public OperationA() {}
+	public Command getCommand() {
+		return Command.COMMAND_A;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ie/oshiro/messagepack/enumpractice/OperationB.java	Sun Jun 09 13:13:02 2013 +0900
@@ -0,0 +1,11 @@
+package ie.oshiro.messagepack.enumpractice;
+
+import org.msgpack.annotation.Message;
+
+@Message
+public class OperationB implements Operation {
+	public OperationB() {}
+	public Command getCommand() {
+		return Command.COMMAND_B;
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ie/oshiro/messagepack/enumpractice/PracticeEnum.java	Sun Jun 09 13:13:02 2013 +0900
@@ -0,0 +1,25 @@
+package ie.oshiro.messagepack.enumpractice;
+
+import java.io.IOException;
+
+import org.msgpack.MessagePack;
+import org.msgpack.annotation.Message;
+import org.msgpack.type.Value;
+
+public class PracticeEnum {
+	public static void main(String[] args) throws IOException {
+		MessagePack msgpack = new MessagePack();
+		OperationA opA = new OperationA();
+		OperationB opB = new OperationB();
+		
+		Value vA = msgpack.unconvert(opA);
+		Value vB = msgpack.unconvert(opB);
+		
+		OperationA convertedOpA =  msgpack.convert(vA, OperationA.class);
+		OperationB convertedOpB =  msgpack.convert(vB, OperationB.class);
+
+		System.out.println("opA :"+convertedOpA.getCommand());
+		System.out.println("opB :"+convertedOpB.getCommand());
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ie/oshiro/messagepack/jungle/containvalue/ListValue.java	Sun Jun 09 13:13:02 2013 +0900
@@ -0,0 +1,53 @@
+package ie.oshiro.messagepack.jungle.containvalue;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.msgpack.MessagePack;
+import org.msgpack.annotation.Message;
+import org.msgpack.template.ListTemplate;
+import org.msgpack.template.ValueTemplate;
+import org.msgpack.type.Value;
+
+@Message
+public class ListValue {
+	
+	public Value iterValue;
+	
+	public ListValue() {
+		iterValue = null;
+	}
+	
+	public void setList(List<Integer> list) throws IOException {
+		MessagePack msgpack = new MessagePack();
+		Value v = msgpack.unconvert(list);
+		iterValue = v;
+	}
+	
+	public List<Value> getList() throws IOException {
+		MessagePack msgpack = new MessagePack();
+		msgpack.register(List.class, new ListTemplate(ValueTemplate.getInstance()));
+		return (List<Value>)msgpack.convert(iterValue, List.class);
+	}
+	
+	public void setIterValue(Value iter) {
+		iterValue = iter;
+	}
+	
+	public Value getIterValue() {
+		return iterValue;
+	}
+	
+	public static void main(String[] args) throws IOException {
+		List<Integer> list = Arrays.asList(1,2,3,4);
+		ListValue lv = new ListValue();
+		lv.setList(list);
+		
+		List<Value> convertedList = lv.getList();
+		for (Value v: convertedList) {
+			System.out.println(v.asIntegerValue());
+		}
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ie/oshiro/messagepack/jungle/containvalue/ListValueValue.java	Sun Jun 09 13:13:02 2013 +0900
@@ -0,0 +1,60 @@
+package ie.oshiro.messagepack.jungle.containvalue;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.msgpack.MessagePack;
+import org.msgpack.annotation.Message;
+import org.msgpack.type.Value;
+
+@Message
+public class ListValueValue {
+
+	public Value lv;
+	
+	public ListValueValue() {
+		lv = null;
+	}
+	
+	public ListValueValue(Value v) {
+		lv = v;
+	}
+	
+	public void setlv(Value v) {
+		lv = v;
+	}
+	
+	public Value getlv() {
+		return lv;
+	}
+	
+	public ListValue getListValue() throws IOException {
+		MessagePack msgpack = new MessagePack();
+		return msgpack.convert(lv, ListValue.class);
+	}
+
+	public void setListValue(ListValue listValue) throws IOException {
+		MessagePack msgpack = new MessagePack();
+		Value v = msgpack.unconvert(listValue);
+		lv = v;
+	}
+
+	public static void main(String[] args) throws IOException {
+		/* serialize */
+		List<Integer> list = Arrays.asList(8,9,10,11);
+		ListValue listValue = new ListValue();
+		listValue.setList(list);
+		ListValueValue lvv = new ListValueValue();
+		lvv.setListValue(listValue);
+		
+		/* deserialize */
+		ListValue lv = lvv.getListValue();
+		List<Value> convertedList = lv.getList();
+		for (Value v: convertedList) {
+			System.out.println(v.asIntegerValue());
+		}
+		
+	}
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ie/oshiro/messagepack/jungle/containvalue/ListValueValueValue.java	Sun Jun 09 13:13:02 2013 +0900
@@ -0,0 +1,56 @@
+package ie.oshiro.messagepack.jungle.containvalue;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.msgpack.MessagePack;
+import org.msgpack.type.Value;
+
+public class ListValueValueValue {
+
+	public Value lvv;
+	
+	public ListValueValueValue() {
+		lvv = null;
+	}
+	
+	public void setlvv(Value v) {
+		lvv = v;
+	}
+	
+	public Value getlvv() {
+		return lvv;
+	}
+	
+	public ListValueValue getLVV() throws IOException {
+		MessagePack msgpack = new MessagePack();
+		return msgpack.convert(lvv, ListValueValue.class);
+	}
+	
+	public void setLVV(ListValueValue _lvv) throws IOException {
+		MessagePack msgpack = new MessagePack();
+		Value v = msgpack.unconvert(_lvv);
+		lvv = v;
+	}
+	
+	public static void main(String[] args) throws IOException {
+		/* serialize */
+		List<Integer> list = Arrays.asList(20,21,22,23);
+		ListValue listValue = new ListValue();
+		listValue.setList(list);
+		ListValueValue lvv = new ListValueValue();
+		lvv.setListValue(listValue);
+		ListValueValueValue lvvv = new ListValueValueValue();
+		lvvv.setLVV(lvv);
+		
+		/* deserialize */
+		ListValueValue convertedLVV = lvvv.getLVV();
+		ListValue convertedLV = convertedLVV.getListValue();
+		List<Value> convertedList = convertedLV.getList();
+		for (Value v: convertedList) {
+			System.out.println(v.asIntegerValue());
+		}
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ie/oshiro/messagepack/jungle/practice/ImplClassA.java	Sun Jun 09 13:13:02 2013 +0900
@@ -0,0 +1,22 @@
+package ie.oshiro.messagepack.jungle.practice;
+
+import org.msgpack.annotation.Message;
+
+@Message
+public class ImplClassA implements PracticeInterface {
+
+	private String message;
+	
+	public ImplClassA() {
+		message = "classA";
+	}
+	
+	public void setMessage(String m) {
+		message = m;
+	}
+	
+	@Override
+	public void print() {
+		System.out.println(message);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ie/oshiro/messagepack/jungle/practice/ImplClassB.java	Sun Jun 09 13:13:02 2013 +0900
@@ -0,0 +1,23 @@
+package ie.oshiro.messagepack.jungle.practice;
+
+import org.msgpack.annotation.Message;
+
+@Message
+public class ImplClassB implements PracticeInterface {
+
+	private  String message;
+	
+	public ImplClassB() {
+		message = "classB";
+	}
+	
+	public void setMessage(String m) {
+		message = m;
+	}
+
+	@Override
+	public void print() {
+		System.out.println(message);
+	}
+
+}
--- a/src/ie/oshiro/messagepack/jungle/practice/ListValue.java	Sat Jun 08 20:43:52 2013 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-package ie.oshiro.messagepack.jungle.practice;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-
-import org.msgpack.MessagePack;
-import org.msgpack.template.ListTemplate;
-import org.msgpack.template.ValueTemplate;
-import org.msgpack.type.Value;
-
-public class ListValue {
-	
-	public Value iterValue;
-	
-	public ListValue() {
-		iterValue = null;
-	}
-	
-	public void setList(List<Integer> list) throws IOException {
-		MessagePack msgpack = new MessagePack();
-		Value v = msgpack.unconvert(list);
-		iterValue = v;
-	}
-	
-	public List<Value> getList() throws IOException {
-		MessagePack msgpack = new MessagePack();
-		msgpack.register(List.class, new ListTemplate(ValueTemplate.getInstance()));
-		return (List<Value>)msgpack.convert(iterValue, List.class);
-	}
-	
-	public void setIterValue(Value iter) {
-		iterValue = iter;
-	}
-	
-	public Value getIterValue() {
-		return iterValue;
-	}
-	
-	public static void main(String[] args) throws IOException {
-		List<Integer> list = Arrays.asList(1,2,3,4);
-		ListValue lv = new ListValue();
-		lv.setList(list);
-		
-		List<Value> convertedList = lv.getList();
-		for (Value v: convertedList) {
-			System.out.println(v.asIntegerValue());
-		}
-	}
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ie/oshiro/messagepack/jungle/practice/PracticeImplement.java	Sun Jun 09 13:13:02 2013 +0900
@@ -0,0 +1,30 @@
+package ie.oshiro.messagepack.jungle.practice;
+
+import java.io.IOException;
+
+import org.msgpack.MessagePack;
+import org.msgpack.annotation.Message;
+import org.msgpack.type.Value;
+
+@Message
+public class PracticeImplement{
+
+	public static void main(String[] args) throws IOException {
+		ImplClassA a = new ImplClassA();
+		ImplClassB b = new ImplClassB();
+		a.setMessage("set message classA");
+		MessagePack msgpack = new MessagePack();
+		
+		Value aValue = msgpack.unconvert(a);
+		Value bValue = msgpack.unconvert(b);
+		
+		MessagePack msgpack2 = new MessagePack();
+		PracticeInterface convertedA = msgpack2.convert(aValue, ImplClassA.class);
+		PracticeInterface convertedB = msgpack2.convert(bValue, ImplClassB.class);
+		
+		convertedA.print();
+		convertedB.print();
+		
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ie/oshiro/messagepack/jungle/practice/PracticeInterface.java	Sun Jun 09 13:13:02 2013 +0900
@@ -0,0 +1,9 @@
+package ie.oshiro.messagepack.jungle.practice;
+
+import org.msgpack.annotation.Message;
+
+
+@Message
+public interface PracticeInterface {
+	public void print();
+}