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