Mercurial > hg > Database > jungle-network
comparison src/jungle/test/datasegment/store/operations/DefaultNodePathContainer.java @ 3:3770d2be3e73
modified DfaultNodePathContainer
author | one |
---|---|
date | Mon, 10 Jun 2013 01:18:45 +0900 |
parents | 20498c88a70d |
children | 2900e0b1d7e6 |
comparison
equal
deleted
inserted
replaced
2:20498c88a70d | 3:3770d2be3e73 |
---|---|
1 package jungle.test.datasegment.store.operations; | 1 package jungle.test.datasegment.store.operations; |
2 | 2 |
3 import java.io.IOException; | 3 import java.io.IOException; |
4 import java.util.Arrays; | 4 import java.util.LinkedList; |
5 import java.util.List; | 5 import java.util.List; |
6 | 6 |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; | |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; | 8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; |
8 | 9 |
9 import org.msgpack.MessagePack; | 10 import org.msgpack.MessagePack; |
10 import org.msgpack.annotation.Message; | 11 import org.msgpack.annotation.Message; |
12 import org.msgpack.template.IntegerTemplate; | |
13 import org.msgpack.template.ListTemplate; | |
14 import org.msgpack.template.ValueTemplate; | |
11 import org.msgpack.type.Value; | 15 import org.msgpack.type.Value; |
12 | 16 |
13 @Message | 17 @Message |
14 public class DefaultNodePathContainer { | 18 public class DefaultNodePathContainer { |
15 | 19 |
16 public Value pathValue; | 20 public Value pathValue; |
17 | 21 |
22 public static void main(String[] args) throws IOException { | |
23 DefaultNodePath p = new DefaultNodePath(); | |
24 p = p.add(1).add(2).add(3); | |
25 DefaultNodePathContainer pathContainer = new DefaultNodePathContainer(); | |
26 pathContainer.unconvert(p); | |
27 NodePath convertedPath = pathContainer.convert(); | |
28 for (int i : convertedPath) { | |
29 System.out.println(i); | |
30 } | |
31 } | |
32 | |
18 public DefaultNodePathContainer() { | 33 public DefaultNodePathContainer() { |
19 | 34 |
20 } | 35 } |
21 | 36 |
22 public void unconvert(DefaultNodePath path) throws IOException { | 37 public void unconvert(DefaultNodePath path) throws IOException { |
23 MessagePack msgpack = new MessagePack(); | 38 MessagePack msgpack = new MessagePack(); |
24 List<Integer> list = Arrays.asList(); | 39 List<Integer> list = new LinkedList<Integer>(); |
25 for(Integer i : path) { | 40 for(Integer i : path) { |
26 list.add(i); | 41 list.add(i); |
27 } | 42 } |
43 /* Remove first Element(-1). */ | |
44 list.remove(0); | |
45 msgpack.register(List.class, new ListTemplate(IntegerTemplate.getInstance())); | |
28 Value v = msgpack.unconvert(list); | 46 Value v = msgpack.unconvert(list); |
29 pathValue = v; | 47 pathValue = v; |
30 } | 48 } |
31 | 49 |
32 public DefaultNodePath convert() throws IOException { | 50 public DefaultNodePath convert() throws IOException { |
33 MessagePack msgpack = new MessagePack(); | 51 MessagePack msgpack = new MessagePack(); |
34 return msgpack.convert(pathValue, DefaultNodePath.class); | 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; | |
35 } | 59 } |
36 | |
37 | |
38 } | 60 } |