Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 267:80bdcdef0753 Implementation_of_communication
merge traverse and edit
line wrap: on
line diff
--- 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<Error,JungleTreeEditor> _edit(final NodePath _path,NodeEditor _e) { - Either<Error,Traversal> traverseEither = editor.traverse(root,_path); - if (traverseEither.isA()) { - return DefaultEither.newA(traverseEither.a()); - } - Traversal traversal = traverseEither.b(); - - Either<Error, LoggingNode> editEither = editor.edit(root, traversal, _e); + Either<Error, LoggingNode> editEither = editor.edit(root, _path, _e); if(editEither.isA()){ return DefaultEither.newA(editEither.a());
--- 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<Error, JungleTreeEditor> _edit(final NodePath _path, NodeEditor _e) { - Either<Error,Traversal> traverseEither = editor.traverse(root,_path); - if (traverseEither.isA()) { - return DefaultEither.newA(traverseEither.a()); - } - Traversal traversal = traverseEither.b(); - - Either<Error, LoggingNode> editEither = editor.edit(root, traversal, _e); + Either<Error, LoggingNode> editEither = editor.edit(root, _path, _e); if(editEither.isA()){ return DefaultEither.newA(editEither.a());
--- 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<Error, LoggingNode> edit(TreeNode root, Traversal traversal, NodeEditor editor) { - // target + public Either<Error, LoggingNode> edit(TreeNode root, NodePath path, NodeEditor editor) { + DefaultEvaluator e = new DefaultEvaluator(path); + Either<Error,Traversal> traverseEither = traverser.traverse(root,e); + if (traverseEither.isA()) { + return DefaultEither.newA(traverseEither.a()); + } + Traversal traversal = traverseEither.b(); TreeNode target = traversal.destination(); Either<Error, LoggingNode> either = editor.edit(target); if (either.isA()) { @@ -36,12 +41,6 @@ return clone(newWrap, traversal, editor); } - @Override - public Either<Error, Traversal> traverse(TreeNode root, NodePath path) { - DefaultEvaluator e = new DefaultEvaluator(path); - return traverser.traverse(root, e); - } - private Either<Error, LoggingNode> clone(LoggingNode newWrap, Traversal traversal, NodeEditor editor) { // copying nodes from bottom to root List<Direction<TreeNode>> path = new List<>();
--- 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<Error, Traversal> traverse(TreeNode root, NodePath path) { - Evaluator evalutor ; + public Either<Error, LoggingNode> 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<Error,Traversal> traverseEither = traverser.traverse(root, evalutor); + if (traverseEither.isA()) { + return DefaultEither.newA(traverseEither.a()); + } + + Traversal traversal = traverseEither.b(); + TreeNode target = traversal.destination(); + Either<Error, LoggingNode> 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<Error, LoggingNode> edit(TreeNode root, Traversal traversal, NodeEditor transformer) { - return null; - } - - private Either<Error, LoggingNode> clone(Traversal t, NodeEditor editor) { + private Either<Error, LoggingNode> clone(Traversal t, LoggingNode newWrap, NodeEditor editor) { // copying nodes from bottom to root List<Direction<TreeNode>> path = new List<>(); @@ -46,21 +55,11 @@ path = path.addLast(direction); } - // target + // top + Direction<TreeNode> targetDirection = path.head(); - TreeNode target = targetDirection.getTarget(); - Either<Error, LoggingNode> 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<TreeNode> parentDirection : path.deleteHead()) { TreeNodeChildren chs = parentDirection.getTarget().getChildren();
--- 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<Error,LoggingNode> edit(TreeNode root, Traversal traversal, NodeEditor transformer); - public Either<Error, Traversal> traverse(TreeNode root, NodePath path); + public Either<Error, LoggingNode> edit(TreeNode root, NodePath path, NodeEditor editor) ; }
--- 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<Error, JungleTreeEditor> _edit(final NodePath _path, NodeEditor _e) { - Either<Error,Traversal> traverseEither = editor.traverse(root,_path); - if (traverseEither.isA()) { - return DefaultEither.newA(traverseEither.a()); - } - Traversal traversal = traverseEither.b(); - - Either<Error, LoggingNode> editEither = editor.edit(root, traversal, _e); + Either<Error, LoggingNode> editEither = editor.edit(root, _path, _e); if (editEither.isA()) { return DefaultEither.newA(editEither.a()); }
--- 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<Error,JungleTreeEditor> _edit(final NodePath _path,NodeEditor _e) { - Either<Error,Traversal> traverseEither = editor.traverse(root,_path); - if (traverseEither.isA()) { - return DefaultEither.newA(traverseEither.a()); - } - Traversal traversal = traverseEither.b(); - - Either<Error, LoggingNode> editEither = editor.edit(root, traversal, _e); + Either<Error, LoggingNode> editEither = editor.edit(root, _path, _e); if(editEither.isA()){ return DefaultEither.newA(editEither.a()); }
--- 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<Error, Traversal> traversalEither = currentEditor.traverse(currentRoot,part); - if (traversalEither.isA()) - Assert.fail(); - Traversal traversal = traversalEither.b(); - Either<Error, LoggingNode> editEither = currentEditor.edit(currentRoot, traversal, putAttribute); + Either<Error, LoggingNode> 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<Error, Traversal> traversalEither = instance.traverse(node,path); - if (traversalEither.isA()) - Assert.fail(); - Traversal traversal = traversalEither.b(); - Either<Error, LoggingNode> either = instance.edit(node, traversal, new AppendChildAt(0)); + Either<Error, LoggingNode> either = instance.edit(node, path, new AppendChildAt(0)); if (either.isA()) { Assert.fail(); }