# HG changeset patch # User tatsuki # Date 1481621029 -32400 # Node ID 80bdcdef07536390bd91f459a43965c87ad9e0f9 # Parent c62462c28807ba9c3682a840a5235ffea799bc39 merge traverse and edit diff -r c62462c28807 -r 80bdcdef0753 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DefaultJungleTreeEditor.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DefaultJungleTreeEditor.java Tue Dec 13 16:48:23 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DefaultJungleTreeEditor.java Tue Dec 13 18:23:49 2016 +0900 @@ -1,19 +1,18 @@ package jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; -import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.DefaultTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.OperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.DefaultTreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.*; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.manager.TransactionManager; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.Traversal; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; @@ -45,13 +44,7 @@ private Either _edit(final NodePath _path,NodeEditor _e) { - Either traverseEither = editor.traverse(root,_path); - if (traverseEither.isA()) { - return DefaultEither.newA(traverseEither.a()); - } - Traversal traversal = traverseEither.b(); - - Either editEither = editor.edit(root, traversal, _e); + Either editEither = editor.edit(root, _path, _e); if(editEither.isA()){ return DefaultEither.newA(editEither.a()); diff -r c62462c28807 -r 80bdcdef0753 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DifferenceJungleTreeEditor.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DifferenceJungleTreeEditor.java Tue Dec 13 16:48:23 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DifferenceJungleTreeEditor.java Tue Dec 13 18:23:49 2016 +0900 @@ -13,7 +13,6 @@ import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.manager.TransactionManager; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.Traversal; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; @@ -44,13 +43,7 @@ } private Either _edit(final NodePath _path, NodeEditor _e) { - Either traverseEither = editor.traverse(root,_path); - if (traverseEither.isA()) { - return DefaultEither.newA(traverseEither.a()); - } - Traversal traversal = traverseEither.b(); - - Either editEither = editor.edit(root, traversal, _e); + Either editEither = editor.edit(root, _path, _e); if(editEither.isA()){ return DefaultEither.newA(editEither.a()); diff -r c62462c28807 -r 80bdcdef0753 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/treeEditor/DefaultTreeEditor.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/treeEditor/DefaultTreeEditor.java Tue Dec 13 16:48:23 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/treeEditor/DefaultTreeEditor.java Tue Dec 13 18:23:49 2016 +0900 @@ -24,8 +24,13 @@ @Override - public Either edit(TreeNode root, Traversal traversal, NodeEditor editor) { - // target + public Either edit(TreeNode root, NodePath path, NodeEditor editor) { + DefaultEvaluator e = new DefaultEvaluator(path); + Either traverseEither = traverser.traverse(root,e); + if (traverseEither.isA()) { + return DefaultEither.newA(traverseEither.a()); + } + Traversal traversal = traverseEither.b(); TreeNode target = traversal.destination(); Either either = editor.edit(target); if (either.isA()) { @@ -36,12 +41,6 @@ return clone(newWrap, traversal, editor); } - @Override - public Either traverse(TreeNode root, NodePath path) { - DefaultEvaluator e = new DefaultEvaluator(path); - return traverser.traverse(root, e); - } - private Either clone(LoggingNode newWrap, Traversal traversal, NodeEditor editor) { // copying nodes from bottom to root List> path = new List<>(); diff -r c62462c28807 -r 80bdcdef0753 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/treeEditor/DifferenceTreeEditor.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/treeEditor/DifferenceTreeEditor.java Tue Dec 13 16:48:23 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/treeEditor/DifferenceTreeEditor.java Tue Dec 13 18:23:49 2016 +0900 @@ -22,23 +22,32 @@ } @Override - public Either traverse(TreeNode root, NodePath path) { - Evaluator evalutor ; + public Either edit(TreeNode root, NodePath path, NodeEditor editor) { + Evaluator evalutor; if (path.get(0) == -2) { evalutor = new LastNodeEvaluator(); - } - else { + } else { evalutor = new DefaultEvaluator(path); } - return traverser.traverse(root, evalutor); + Either traverseEither = traverser.traverse(root, evalutor); + if (traverseEither.isA()) { + return DefaultEither.newA(traverseEither.a()); + } + + Traversal traversal = traverseEither.b(); + TreeNode target = traversal.destination(); + Either either = editor.edit(target); + if (!target.isDefine()) + return either; + if (either.isA()) { + return DefaultEither.newA(either.a()); + } + LoggingNode newWrap = either.b(); + + return clone(traversal, newWrap, editor); } - @Override - public Either edit(TreeNode root, Traversal traversal, NodeEditor transformer) { - return null; - } - - private Either clone(Traversal t, NodeEditor editor) { + private Either clone(Traversal t, LoggingNode newWrap, NodeEditor editor) { // copying nodes from bottom to root List> path = new List<>(); @@ -46,21 +55,11 @@ path = path.addLast(direction); } - // target + // top + Direction targetDirection = path.head(); - TreeNode target = targetDirection.getTarget(); - Either either = editor.edit(target); - if (either.isA()) { - return DefaultEither.newA(either.a()); - } - - LoggingNode newWrap = either.b(); - - // top int pos = targetDirection.getPosition(); TreeNode child = newWrap.getWrap(); - - for (Direction parentDirection : path.deleteHead()) { TreeNodeChildren chs = parentDirection.getTarget().getChildren(); diff -r c62462c28807 -r 80bdcdef0753 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/treeEditor/TreeEditor.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/treeEditor/TreeEditor.java Tue Dec 13 16:48:23 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/treeEditor/TreeEditor.java Tue Dec 13 18:23:49 2016 +0900 @@ -1,15 +1,13 @@ package jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.Traversal; +import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode; -import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; public interface TreeEditor { - public Either edit(TreeNode root, Traversal traversal, NodeEditor transformer); - public Either traverse(TreeNode root, NodePath path); + public Either edit(TreeNode root, NodePath path, NodeEditor editor) ; } diff -r c62462c28807 -r 80bdcdef0753 src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungleTreeEditor.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungleTreeEditor.java Tue Dec 13 16:48:23 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungleTreeEditor.java Tue Dec 13 18:23:49 2016 +0900 @@ -1,20 +1,19 @@ package jp.ac.u_ryukyu.ie.cr.jungleNetwork.persistent; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; -import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.DefaultTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.OperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.DefaultTreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.*; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.manager.TransactionManager; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.Traversal; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; @@ -42,13 +41,7 @@ } private Either _edit(final NodePath _path, NodeEditor _e) { - Either traverseEither = editor.traverse(root,_path); - if (traverseEither.isA()) { - return DefaultEither.newA(traverseEither.a()); - } - Traversal traversal = traverseEither.b(); - - Either editEither = editor.edit(root, traversal, _e); + Either editEither = editor.edit(root, _path, _e); if (editEither.isA()) { return DefaultEither.newA(editEither.a()); } diff -r c62462c28807 -r 80bdcdef0753 src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkDefaultJungleTreeEditor.java --- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkDefaultJungleTreeEditor.java Tue Dec 13 16:48:23 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkDefaultJungleTreeEditor.java Tue Dec 13 18:23:49 2016 +0900 @@ -2,20 +2,19 @@ import alice.codesegment.CodeSegment; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.DefaultTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.OperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.DefaultTreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.*; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.manager.TransactionManager; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.Traversal; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; @@ -64,13 +63,7 @@ private Either _edit(final NodePath _path,NodeEditor _e) { - Either traverseEither = editor.traverse(root,_path); - if (traverseEither.isA()) { - return DefaultEither.newA(traverseEither.a()); - } - Traversal traversal = traverseEither.b(); - - Either editEither = editor.edit(root, traversal, _e); + Either editEither = editor.edit(root, _path, _e); if(editEither.isA()){ return DefaultEither.newA(editEither.a()); } diff -r c62462c28807 -r 80bdcdef0753 src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/impl/treeeditor/DefaultTreeEditorTest.java --- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/impl/treeeditor/DefaultTreeEditorTest.java Tue Dec 13 16:48:23 2016 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/impl/treeeditor/DefaultTreeEditorTest.java Tue Dec 13 18:23:49 2016 +0900 @@ -40,11 +40,7 @@ String str = part.toString(); ByteBuffer value = ByteBuffer.wrap(str.getBytes()); PutAttribute putAttribute = new PutAttribute(key, value); - Either traversalEither = currentEditor.traverse(currentRoot,part); - if (traversalEither.isA()) - Assert.fail(); - Traversal traversal = traversalEither.b(); - Either editEither = currentEditor.edit(currentRoot, traversal, putAttribute); + Either editEither = currentEditor.edit(currentRoot, part, putAttribute); if (editEither.isA()) { Assert.fail(); } @@ -61,7 +57,7 @@ } TreeNode target = either.b().destination(); String expected = part.toString(); - String actual = new String(target.getAttributes().get(key).array()); + String actual = new String(target.getAttributes().get(key).array()); Assert.assertEquals(expected, actual); } @@ -82,12 +78,7 @@ DefaultTreeEditor instance = instance(); DefaultTreeNode node = new DefaultTreeNode(); DefaultNodePath path = new DefaultNodePath(); - - Either traversalEither = instance.traverse(node,path); - if (traversalEither.isA()) - Assert.fail(); - Traversal traversal = traversalEither.b(); - Either either = instance.edit(node, traversal, new AppendChildAt(0)); + Either either = instance.edit(node, path, new AppendChildAt(0)); if (either.isA()) { Assert.fail(); }