diff src/main/java/alice/jungle/operations/NetworkNodePath.java @ 105:f9e29a52efd3

Move some files
author one
date Tue, 26 Nov 2013 06:43:10 +0900
parents src/alice/jungle/operations/NetworkNodePath.java@b3ccefdf2b43
children 2828205bdc3a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/alice/jungle/operations/NetworkNodePath.java	Tue Nov 26 06:43:10 2013 +0900
@@ -0,0 +1,70 @@
+package alice.jungle.operations;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.msgpack.annotation.Message;
+
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair;
+
+@Message
+public class NetworkNodePath implements NodePath
+{
+	LinkedList<Integer> path;
+	
+	public NetworkNodePath() {
+		path = new LinkedList<Integer>();
+		path.add(-1);
+	}
+	
+	public NetworkNodePath(NodePath _p) {
+		path = new LinkedList<Integer>();
+		for(Integer pos: _p) {
+			path.add(pos);
+		}
+	}
+	
+	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();
+	}
+	
+}