Mercurial > hg > Members > nobuyasu > jungle-network
comparison src/alice/jungle/datasegment/store/operations/DefaultNodePathContainer.java @ 31:190f6a3bdab2
rename some packages
author | one |
---|---|
date | Mon, 01 Jul 2013 20:34:03 +0900 |
parents | src/jungle/test/datasegment/store/operations/DefaultNodePathContainer.java@02bdf23edf5a |
children | 85bc7416ae02 |
comparison
equal
deleted
inserted
replaced
30:8593c2525aa7 | 31:190f6a3bdab2 |
---|---|
1 package alice.jungle.datasegment.store.operations; | |
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 msgpack.register(List.class, new ListTemplate(IntegerTemplate.getInstance())); | |
45 Value v = msgpack.unconvert(list); | |
46 pathValue = v; | |
47 } | |
48 | |
49 public DefaultNodePath convert() throws IOException { | |
50 MessagePack msgpack = new MessagePack(); | |
51 msgpack.register(List.class, new ListTemplate(IntegerTemplate.getInstance())); | |
52 List<Integer> convertedList = (List<Integer>)msgpack.convert(pathValue, List.class); | |
53 DefaultNodePath path = new DefaultNodePath(); | |
54 for (int i: convertedList) { | |
55 path = path.add(i); | |
56 } | |
57 return path; | |
58 } | |
59 } |