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