Mercurial > hg > Members > nobuyasu > jungle-network
comparison src/main/java/alice/jungle/datasegment/container/DefaultNodePathContainer.java @ 105:f9e29a52efd3
Move some files
author | one |
---|---|
date | Tue, 26 Nov 2013 06:43:10 +0900 |
parents | src/alice/jungle/datasegment/store/container/DefaultNodePathContainer.java@87ec5dd0dc27 |
children |
comparison
equal
deleted
inserted
replaced
104:03bf62bb699e | 105:f9e29a52efd3 |
---|---|
1 package alice.jungle.datasegment.container; | |
2 | |
3 import java.io.IOException; | |
4 import java.util.LinkedList; | |
5 import java.util.List; | |
6 | |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; | |
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; | |
12 import org.msgpack.template.IntegerTemplate; | |
13 import org.msgpack.template.ListTemplate; | |
14 import org.msgpack.type.Value; | |
15 | |
16 @Message | |
17 public class DefaultNodePathContainer { | |
18 | |
19 public Value pathValue; | |
20 | |
21 public static void main(String[] args) throws IOException { | |
22 DefaultNodePath p = new DefaultNodePath(); | |
23 p = p.add(1).add(2).add(3); | |
24 DefaultNodePathContainer pathContainer = new DefaultNodePathContainer(); | |
25 pathContainer.unconvert(p); | |
26 NodePath convertedPath = pathContainer.convert(); | |
27 for (int i : convertedPath) { | |
28 System.out.println(i); | |
29 } | |
30 } | |
31 | |
32 public DefaultNodePathContainer() { | |
33 | |
34 } | |
35 | |
36 public void unconvert(NodePath path) throws IOException { | |
37 MessagePack msgpack = new MessagePack(); | |
38 List<Integer> list = new LinkedList<Integer>(); | |
39 for(Integer i : path) { | |
40 list.add(i); | |
41 } | |
42 /* Remove first Element(-1). */ | |
43 list.remove(0); | |
44 Value v = msgpack.unconvert(list); | |
45 pathValue = v; | |
46 } | |
47 | |
48 public DefaultNodePath convert() throws IOException { | |
49 MessagePack msgpack = new MessagePack(); | |
50 msgpack.register(List.class, new ListTemplate(IntegerTemplate.getInstance())); | |
51 List<Integer> convertedList = (List<Integer>)msgpack.convert(pathValue, List.class); | |
52 DefaultNodePath path = new DefaultNodePath(); | |
53 for (int i: convertedList) { | |
54 path = path.add(i); | |
55 } | |
56 return path; | |
57 } | |
58 } |