31
|
1 package alice.jungle.operations;
|
1
|
2
|
68
|
3 import java.io.IOException;
|
1
|
4 import java.util.Iterator;
|
|
5 import java.util.LinkedList;
|
|
6
|
68
|
7 import org.msgpack.MessagePack;
|
|
8 import org.msgpack.annotation.Message;
|
|
9 import org.msgpack.type.Value;
|
|
10
|
1
|
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
|
|
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair;
|
|
13
|
67
|
14 @Message
|
1
|
15 public class NetworkNodePath implements NodePath
|
|
16 {
|
|
17 LinkedList<Integer> path;
|
|
18
|
68
|
19 public static void main(String[] args) throws IOException {
|
|
20 NetworkNodePath path = new NetworkNodePath();
|
|
21 path = path.add(1).add(2).add(3);
|
|
22 MessagePack msgpack = new MessagePack();
|
|
23 Value value = msgpack.unconvert(path);
|
|
24 NetworkNodePath mPath = msgpack.convert(value, NetworkNodePath.class);
|
|
25 for (Integer i : mPath) {
|
|
26 System.out.println(i);
|
|
27 }
|
|
28 }
|
|
29
|
1
|
30 public NetworkNodePath() {
|
|
31 path = new LinkedList<Integer>();
|
|
32 }
|
|
33
|
|
34 private NetworkNodePath(LinkedList<Integer> _path) {
|
|
35 path = _path;
|
|
36 }
|
|
37
|
|
38 @Override
|
|
39 public Iterator<Integer> iterator() {
|
|
40 return path.iterator();
|
|
41 }
|
|
42
|
|
43 @Override
|
|
44 public NetworkNodePath add(int _pos) {
|
|
45 LinkedList<Integer> newPath = copyPath();
|
|
46 newPath.add(_pos);
|
|
47 return new NetworkNodePath(newPath);
|
|
48 }
|
|
49
|
|
50 @Override
|
|
51 public Pair<Integer, NodePath> pop() {
|
|
52 LinkedList<Integer> cPath = copyPath();
|
|
53 int e = cPath.getFirst();
|
|
54 cPath.remove();
|
|
55 return new Pair<Integer, NodePath>(e, new NetworkNodePath(cPath));
|
|
56 }
|
|
57
|
|
58 @Override
|
|
59 public int size() {
|
|
60 return path.size();
|
|
61 }
|
|
62
|
|
63 private LinkedList<Integer> copyPath() {
|
|
64 LinkedList<Integer> newPath = new LinkedList<Integer>();
|
|
65 for (Integer i : path) {
|
|
66 newPath.add(i);
|
|
67 }
|
|
68 return newPath;
|
|
69 }
|
|
70
|
|
71 @Override
|
|
72 public String toString() {
|
|
73 return path.toString();
|
|
74 }
|
|
75
|
|
76 }
|