Mercurial > hg > Database > jungle-network
annotate src/alice/jungle/datasegment/store/container/DefaultNodePathContainer.java @ 75:87ec5dd0dc27
Rename from alice.jungle.datasegment.store.operation to alice.jungle.datasegment.store.container
author | one |
---|---|
date | Tue, 15 Oct 2013 14:43:29 +0900 |
parents | src/alice/jungle/datasegment/store/operations/DefaultNodePathContainer.java@89e39301ccaa |
children |
rev | line source |
---|---|
75
87ec5dd0dc27
Rename from alice.jungle.datasegment.store.operation to alice.jungle.datasegment.store.container
one
parents:
67
diff
changeset
|
1 package alice.jungle.datasegment.store.container; |
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 | |
16 @Message | |
17 public class DefaultNodePathContainer { | |
18 | |
19 public Value pathValue; | |
20 | |
3 | 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 | |
2 | 32 public DefaultNodePathContainer() { |
33 | |
34 } | |
35 | |
6 | 36 public void unconvert(NodePath path) throws IOException { |
2 | 37 MessagePack msgpack = new MessagePack(); |
3 | 38 List<Integer> list = new LinkedList<Integer>(); |
2 | 39 for(Integer i : path) { |
40 list.add(i); | |
41 } | |
3 | 42 /* Remove first Element(-1). */ |
43 list.remove(0); | |
2 | 44 Value v = msgpack.unconvert(list); |
45 pathValue = v; | |
46 } | |
47 | |
48 public DefaultNodePath convert() throws IOException { | |
49 MessagePack msgpack = new MessagePack(); | |
3 | 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; | |
2 | 57 } |
58 } |