31
|
1 package alice.jungle.datasegment.store.operations;
|
2
|
2
|
|
3 import java.io.IOException;
|
3
|
4 import java.util.LinkedList;
|
2
|
5 import java.util.List;
|
|
6
|
3
|
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
|
2
|
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
|
|
9
|
|
10 import org.msgpack.MessagePack;
|
|
11 import org.msgpack.annotation.Message;
|
3
|
12 import org.msgpack.template.IntegerTemplate;
|
|
13 import org.msgpack.template.ListTemplate;
|
2
|
14 import org.msgpack.type.Value;
|
|
15
|
62
|
16 import alice.codesegment.SingletonMessage;
|
|
17
|
2
|
18 @Message
|
|
19 public class DefaultNodePathContainer {
|
|
20
|
|
21 public Value pathValue;
|
|
22
|
3
|
23 public static void main(String[] args) throws IOException {
|
|
24 DefaultNodePath p = new DefaultNodePath();
|
|
25 p = p.add(1).add(2).add(3);
|
|
26 DefaultNodePathContainer pathContainer = new DefaultNodePathContainer();
|
|
27 pathContainer.unconvert(p);
|
|
28 NodePath convertedPath = pathContainer.convert();
|
|
29 for (int i : convertedPath) {
|
|
30 System.out.println(i);
|
|
31 }
|
|
32 }
|
|
33
|
2
|
34 public DefaultNodePathContainer() {
|
|
35
|
|
36 }
|
|
37
|
6
|
38 public void unconvert(NodePath path) throws IOException {
|
2
|
39 MessagePack msgpack = new MessagePack();
|
3
|
40 List<Integer> list = new LinkedList<Integer>();
|
2
|
41 for(Integer i : path) {
|
|
42 list.add(i);
|
|
43 }
|
3
|
44 /* Remove first Element(-1). */
|
|
45 list.remove(0);
|
2
|
46 Value v = msgpack.unconvert(list);
|
|
47 pathValue = v;
|
|
48 }
|
|
49
|
|
50 public DefaultNodePath convert() throws IOException {
|
|
51 MessagePack msgpack = new MessagePack();
|
3
|
52 msgpack.register(List.class, new ListTemplate(IntegerTemplate.getInstance()));
|
|
53 List<Integer> convertedList = (List<Integer>)msgpack.convert(pathValue, List.class);
|
|
54 DefaultNodePath path = new DefaultNodePath();
|
|
55 for (int i: convertedList) {
|
|
56 path = path.add(i);
|
|
57 }
|
|
58 return path;
|
2
|
59 }
|
|
60 }
|