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