diff src/jungle/test/operations/NetworkNodePath.java @ 1:8ee02d1a2b12

add jungle.test.operations
author one
date Fri, 07 Jun 2013 19:26:08 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jungle/test/operations/NetworkNodePath.java	Fri Jun 07 19:26:08 2013 +0900
@@ -0,0 +1,59 @@
+package jungle.test.operations;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair;
+
+public class NetworkNodePath implements NodePath
+{
+	LinkedList<Integer> path;
+	
+	public NetworkNodePath() {
+		path = new LinkedList<Integer>();
+	}
+	
+	private NetworkNodePath(LinkedList<Integer> _path) {
+		path = _path;
+	}
+	
+	@Override
+	public Iterator<Integer> iterator() {
+		return path.iterator();
+	}
+
+	@Override
+	public NetworkNodePath add(int _pos) {
+		LinkedList<Integer> newPath = copyPath();
+		newPath.add(_pos);
+		return new NetworkNodePath(newPath);
+	}
+
+	@Override
+	public Pair<Integer, NodePath> pop() {
+		LinkedList<Integer> cPath = copyPath();
+		int e = cPath.getFirst();
+		cPath.remove();
+		return new Pair<Integer, NodePath>(e, new NetworkNodePath(cPath));
+	}
+
+	@Override
+	public int size() {
+		return path.size();
+	}
+
+	private LinkedList<Integer> copyPath() {
+		LinkedList<Integer> newPath = new LinkedList<Integer>();
+		for (Integer i : path) {
+			newPath.add(i);
+		}
+		return newPath;
+	}
+	
+	@Override
+	public String toString() {
+		return path.toString();
+	}
+	
+}