changeset 235:faa9fa06ead1 Implementation_of_communication

log export bug fix
author tatsuki
date Sun, 24 Jan 2016 18:51:47 +0900
parents 3c2f7afc4931
children 9befc64affeb
files src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/JungleUpdater.java
diffstat 1 files changed, 59 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/JungleUpdater.java	Sun Jan 24 16:25:49 2016 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/JungleUpdater.java	Sun Jan 24 18:51:47 2016 +0900
@@ -13,62 +13,64 @@
 
 public class JungleUpdater {
 
-	public JungleUpdater() {
-		
-	}
-	
-	public static Either<Error, JungleTreeEditor> edit(JungleTreeEditor _editor ,Iterable<TreeOperation> _log) {
-		JungleTreeEditor editor = _editor;
-		Either<Error, JungleTreeEditor> either = null;
-		for (TreeOperation op : _log) { 
-			NodePath path = op.getNodePath();
-			NodeOperation nodeOp = op.getNodeOperation();
-			either = _edit(editor, path, nodeOp, nodeOp.getPosition());
-			if(either.isA()) {
-				return either;
-			}
-			editor = either.b();
-		}
-		return either;
-	}
-	
-	/* 
-	 * This method decide node position by param. 
-	 */
-	public static Either<Error, JungleTreeEditor> edit(JungleTreeEditor _editor ,Iterable<TreeOperation> _log, int pos) {
-		JungleTreeEditor editor = _editor;
-		Either<Error, JungleTreeEditor> either = null;
-		for (TreeOperation op : _log) { 
-			NodePath path = op.getNodePath();
-			NodeOperation nodeOp = op.getNodeOperation();
-			either = _edit(editor, path, nodeOp, pos);
-			if(either.isA()) {
-				return either;
-			}
-			editor = either.b();
-		}
-		return either;
-	}
-	
-	
-	private static Either<Error, JungleTreeEditor> _edit(JungleTreeEditor editor, NodePath path, 
-				NodeOperation nodeOp, int pos) {
-			String key = "";
-			Command c = nodeOp.getCommand();
-		switch (c) {
-		case PUT_ATTRIBUTE:
-			key = nodeOp.getKey();
-			ByteBuffer value = nodeOp.getValue();
-			return editor.putAttribute(path, key, value);
-		case DELETE_ATTRIBUTE:
-			key = nodeOp.getKey();
-			return editor.deleteAttribute(path, key);
-		case APPEND_CHILD:
-			return editor.addNewChildAt(path, pos);
-		case DELETE_CHILD:
-			return editor.deleteChildAt(path, 0);
-		}
-		return null;
-	}
+    public JungleUpdater() {
+
+    }
+
+    public static Either<Error, JungleTreeEditor> edit(JungleTreeEditor _editor, Iterable<TreeOperation> _log) {
+        JungleTreeEditor editor = _editor;
+        Either<Error, JungleTreeEditor> either = null;
+        for (TreeOperation op : _log) {
+            NodePath path = op.getNodePath();
+            NodeOperation nodeOp = op.getNodeOperation();
+            either = _edit(editor, path, nodeOp, nodeOp.getPosition());
+            if (either.isA()) {
+                return either;
+            }
+            editor = either.b();
+        }
+        return either;
+    }
+
+    /*
+     * This method decide node position by param.
+     */
+    public static Either<Error, JungleTreeEditor> edit(JungleTreeEditor _editor, Iterable<TreeOperation> _log, int pos) {
+        JungleTreeEditor editor = _editor;
+        Either<Error, JungleTreeEditor> either = null;
+        for (TreeOperation op : _log) {
+            NodePath path = op.getNodePath();
+            NodeOperation nodeOp = op.getNodeOperation();
+            either = _edit(editor, path, nodeOp, pos);
+            if (either.isA()) {
+                return either;
+            }
+            editor = either.b();
+        }
+        return either;
+    }
+
+
+    private static Either<Error, JungleTreeEditor> _edit(JungleTreeEditor editor, NodePath path, NodeOperation nodeOp, int pos) {//posはmergeの時に使う?
+        String key = "";
+        Command c = nodeOp.getCommand();
+        int num;
+        switch (c) {
+            case PUT_ATTRIBUTE:
+                key = nodeOp.getKey();
+                ByteBuffer value = nodeOp.getValue();
+                return editor.putAttribute(path, key, value);
+            case DELETE_ATTRIBUTE:
+                key = nodeOp.getKey();
+                return editor.deleteAttribute(path, key);
+            case APPEND_CHILD:
+                num = nodeOp.getPosition();
+                return editor.addNewChildAt(path, num);
+            case DELETE_CHILD:
+                num = nodeOp.getPosition();
+                return editor.deleteChildAt(path, num);
+        }
+        return null;
+    }
 
 }