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>();
|
|
18 }
|
|
19
|
76
|
20 public NetworkNodePath(NodePath _p) {
|
|
21 path = new LinkedList<Integer>();
|
|
22 for(Integer pos: _p) {
|
|
23 path.add(pos);
|
|
24 }
|
|
25 }
|
|
26
|
1
|
27 private NetworkNodePath(LinkedList<Integer> _path) {
|
|
28 path = _path;
|
|
29 }
|
|
30
|
|
31 @Override
|
|
32 public Iterator<Integer> iterator() {
|
|
33 return path.iterator();
|
|
34 }
|
|
35
|
|
36 @Override
|
|
37 public NetworkNodePath add(int _pos) {
|
|
38 LinkedList<Integer> newPath = copyPath();
|
|
39 newPath.add(_pos);
|
|
40 return new NetworkNodePath(newPath);
|
|
41 }
|
|
42
|
|
43 @Override
|
|
44 public Pair<Integer, NodePath> pop() {
|
|
45 LinkedList<Integer> cPath = copyPath();
|
|
46 int e = cPath.getFirst();
|
|
47 cPath.remove();
|
|
48 return new Pair<Integer, NodePath>(e, new NetworkNodePath(cPath));
|
|
49 }
|
|
50
|
|
51 @Override
|
|
52 public int size() {
|
|
53 return path.size();
|
|
54 }
|
|
55
|
|
56 private LinkedList<Integer> copyPath() {
|
|
57 LinkedList<Integer> newPath = new LinkedList<Integer>();
|
|
58 for (Integer i : path) {
|
|
59 newPath.add(i);
|
|
60 }
|
|
61 return newPath;
|
|
62 }
|
|
63
|
|
64 @Override
|
|
65 public String toString() {
|
|
66 return path.toString();
|
|
67 }
|
|
68
|
|
69 }
|