Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 146:371b6ddb78f2
repair putAttributeIndex and deleteAttributeIndex
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungle.java Fri Nov 21 12:46:06 2014 +0900 @@ -10,7 +10,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Journal; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.NullJournal; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; @@ -24,7 +23,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.Traverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.TreeMapOrd; public class DefaultJungle implements Jungle @@ -86,7 +84,7 @@ }; DefaultTreeNode root = new DefaultTreeNode(); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index = TreeMap.empty(Ord.stringOrd); + TreeMap<String, TreeMap<String, List<TreeNode>>> index = TreeMap.empty(Ord.stringOrd); TreeMap<TreeNode,TreeNode> parentIndex = TreeMap.empty(TreeMapOrd.treeNodeOrd); ChangeSet set = new DefaultChangeSet(root,null,list,uuid,name,0,index,parentIndex); DefaultTreeContext tc = new DefaultTreeContext(root,set);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungleTree.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/DefaultJungleTree.java Fri Nov 21 12:46:06 2014 +0900 @@ -4,7 +4,6 @@ import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.IndexTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; @@ -20,7 +19,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.GetOldTreeError; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.IndexManager; public class DefaultJungleTree implements JungleTree { @@ -43,7 +41,7 @@ TreeContext tc = repository.get(); DefaultTransactionManager txManager = new DefaultTransactionManager(writer, tc, repository, uuid); TreeNode root = tc.getTreeNode(); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index = getIndex(); + TreeMap<String, TreeMap<String, List<TreeNode>>>index = getIndex(); TreeMap<TreeNode, TreeNode> parentIndex = getParentIndex(); return new DefaultJungleTreeEditor(root, txManager, treeEditor, index,parentIndex); } @@ -53,7 +51,7 @@ TreeContext tc = repository.get(); DefaultTransactionManager txManager = new DefaultTransactionManager(writer, tc, repository, uuid); TreeNode root = tc.getTreeNode(); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index = getIndex(); + TreeMap<String, TreeMap<String, List<TreeNode>>> index = getIndex(); TreeMap<TreeNode, TreeNode> parentIndex = getParentIndex(); return new IndexJungleTreeEditor(root, txManager, indexTreeEditor, index, parentIndex); } @@ -81,14 +79,14 @@ public InterfaceTraverser getTraverser() { AtomicReservableReference<TreeContext>.Reservation reservation = repository.getReservation(); IndexManager indexManager = new IndexManager(reservation); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index = getIndex(); + TreeMap<String, TreeMap<String, List<TreeNode>>> index = getIndex(); if (index != null) return new InterfaceTraverser(getRootNode(), index, indexManager); return new InterfaceTraverser(getRootNode(), indexManager); } @Override - public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { + public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { TreeContext tc = repository.get(); ChangeSet cs = tc.getChangeSet(); return cs.getIndex();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTree.java Fri Nov 21 12:46:06 2014 +0900 @@ -3,14 +3,12 @@ import fj.data.List; import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public interface JungleTree { @@ -18,7 +16,7 @@ public InterfaceTraverser getTraverser(); public JungleTreeEditor getLocalTreeEditor(); public TreeNode getRootNode(); - public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex(); + public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex(); public TreeMap<TreeNode,TreeNode> getParentIndex(); public IndexJungleTreeEditor getIndexTreeEditor(); public Iterable<TreeOperation> getLog();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTreeEditor.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/JungleTreeEditor.java Fri Nov 21 12:46:06 2014 +0900 @@ -4,7 +4,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/App.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/App.java Fri Nov 21 12:46:06 2014 +0900 @@ -6,8 +6,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.IndexTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/ChangeSet.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/ChangeSet.java Fri Nov 21 12:46:06 2014 +0900 @@ -6,10 +6,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TreeContext; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public interface ChangeSet { @@ -21,7 +17,7 @@ public String getTreeName(); public long revision(); - public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex(); + public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex(); public Iterable<TreeOperation> getOperations(); public TreeMap<TreeNode, TreeNode> getParentIndex(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/IndexTreeEditor.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/IndexTreeEditor.java Fri Nov 21 12:46:06 2014 +0900 @@ -3,7 +3,11 @@ import java.util.Iterator; +import javax.swing.plaf.basic.BasicInternalFrameTitlePane.SystemMenuBar; + +import fj.P2; import fj.data.List; +import fj.data.Option; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; @@ -15,7 +19,8 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Triple; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.IndexEditor; public class IndexTreeEditor { @@ -28,7 +33,7 @@ } - public Either<Error,Pair<LoggingNode, TreeMap<TreeNode, TreeNode>>> edit(TreeNode root,NodePath path,NodeEditor editor,TreeMap<TreeNode, TreeNode> parentIndex) + public Either<Error,Triple<LoggingNode, TreeMap<TreeNode, TreeNode>,TreeMap<String,TreeMap<String,List<TreeNode>>>>> edit(TreeNode root,NodePath path,NodeEditor editor,TreeMap<TreeNode, TreeNode> parentIndex, IndexEditor indexEditor) { DefaultEvaluator e = new DefaultEvaluator(path); Either<Error, Traversal> either = traverser.traverse(root,e); @@ -38,12 +43,12 @@ } Traversal t = either.b(); - Either<Error,Pair<LoggingNode, TreeMap<TreeNode, TreeNode>>> ret = clone(t,editor,parentIndex); + Either<Error,Triple<LoggingNode, TreeMap<TreeNode, TreeNode>,TreeMap<String,TreeMap<String,List<TreeNode>>>>> ret = clone(t,editor,parentIndex, indexEditor); return ret; } - private Either<Error,Pair<LoggingNode, TreeMap<TreeNode, TreeNode>>> clone(Traversal t,NodeEditor editor , TreeMap<TreeNode, TreeNode> parentIndex) + private Either<Error,Triple<LoggingNode, TreeMap<TreeNode, TreeNode>,TreeMap<String,TreeMap<String,List<TreeNode>>>>> clone(Traversal t,NodeEditor editor , TreeMap<TreeNode, TreeNode> parentIndex, IndexEditor indexEditor) { // copying nodes from bottom to root TreeMap<TreeNode, TreeNode> newParentIndex = parentIndex; @@ -56,6 +61,7 @@ Direction<TreeNode> targetDirection = path.head(); TreeNode target = targetDirection.getTarget(); Iterator<TreeNode> targetDeleteChildren = target.getChildren().iterator(); + IndexEditor alreadyDeleteTargetIndexEditor = indexEditor.delete(target); for (;targetDeleteChildren.hasNext();) { TreeNode targetDeleteChild = targetDeleteChildren.next(); @@ -73,6 +79,9 @@ // top int pos = targetDirection.getPosition(); TreeNode child = newWrap.getWrap(); + + IndexEditor alreadyEditTargetIndexEditor = alreadyDeleteTargetIndexEditor.edit(child); + IndexEditor alreadyAddTargetIndexEditor = alreadyEditTargetIndexEditor.add(child); Iterator<TreeNode> targetPutChildren = child.getChildren().iterator(); for (; targetPutChildren.hasNext();) { @@ -81,9 +90,11 @@ } for (Direction<TreeNode> parentDirection : path.tail()) { - - TreeNodeChildren chs = parentDirection.getTarget().getChildren(); + TreeNode updateTargetNode = parentDirection.getTarget(); + TreeNodeChildren chs = updateTargetNode.getChildren(); + alreadyDeleteTargetIndexEditor = alreadyAddTargetIndexEditor.delete(updateTargetNode); + Iterator<TreeNode> deleteParentIndexChildren = chs.iterator(); for (;deleteParentIndexChildren.hasNext();) { TreeNode deleteParentIndexChild = deleteParentIndexChildren.next(); @@ -96,6 +107,7 @@ } TreeNode newParent = ret.b(); + alreadyAddTargetIndexEditor = alreadyDeleteTargetIndexEditor.add(newParent); Iterator<TreeNode> putParentIndexChildren = newParent.getChildren().iterator(); for (;putParentIndexChildren.hasNext();) { @@ -109,8 +121,11 @@ TreeNode newRoot = child; LoggingNode logNode = editor.wrap(newRoot, newWrap.getOperationLog()); - Pair<LoggingNode, TreeMap<TreeNode, TreeNode>> pair = new Pair<LoggingNode, TreeMap<TreeNode, TreeNode>>(logNode,newParentIndex); - return DefaultEither.newB(pair); + + + TreeMap<String,TreeMap<String,List<TreeNode>>> indexList = alreadyAddTargetIndexEditor.getIndex(); + Triple<LoggingNode, TreeMap<TreeNode, TreeNode>,TreeMap<String,TreeMap<String,List<TreeNode>>>> triple = new Triple<LoggingNode, TreeMap<TreeNode, TreeNode>,TreeMap<String,TreeMap<String,List<TreeNode>>>>(logNode,newParentIndex,indexList); + return DefaultEither.newB(triple); } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingChildren.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingChildren.java Fri Nov 21 12:46:06 2014 +0900 @@ -1,6 +1,5 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; -import java.util.Iterator; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingNode.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingNode.java Fri Nov 21 12:46:06 2014 +0900 @@ -1,10 +1,6 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; -import fj.data.List; -import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public class LoggingNode
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/operations/AppendChildAtOperation.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/operations/AppendChildAtOperation.java Fri Nov 21 12:46:06 2014 +0900 @@ -4,7 +4,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/operations/DeleteAttributeOperation.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/operations/DeleteAttributeOperation.java Fri Nov 21 12:46:06 2014 +0900 @@ -4,8 +4,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteAttribute; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/operations/DeleteChildAtOperation.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/operations/DeleteChildAtOperation.java Fri Nov 21 12:46:06 2014 +0900 @@ -4,8 +4,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.DeleteChildAt; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/operations/NodeOperation.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/operations/NodeOperation.java Fri Nov 21 12:46:06 2014 +0900 @@ -4,7 +4,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/operations/PutAttributeOperation.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/operations/PutAttributeOperation.java Fri Nov 21 12:46:06 2014 +0900 @@ -4,8 +4,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.PutAttribute; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/AppendChildAt.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/AppendChildAt.java Fri Nov 21 12:46:06 2014 +0900 @@ -1,18 +1,11 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; -import fj.data.List; -import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public class AppendChildAt implements NodeEditor {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/DeleteAttribute.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/DeleteAttribute.java Fri Nov 21 12:46:06 2014 +0900 @@ -1,15 +1,12 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; -import fj.data.List; -import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; + import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public class DeleteAttribute implements NodeEditor {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/DeleteChildAt.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/DeleteChildAt.java Fri Nov 21 12:46:06 2014 +0900 @@ -1,18 +1,12 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; -import fj.data.List; -import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; + import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public class DeleteChildAt implements NodeEditor {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/NodeEditor.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/NodeEditor.java Fri Nov 21 12:46:06 2014 +0900 @@ -1,15 +1,11 @@ package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer; -import fj.data.List; -import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; + import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public interface NodeEditor {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/PutAttribute.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/trasnformer/PutAttribute.java Fri Nov 21 12:46:06 2014 +0900 @@ -2,21 +2,12 @@ import java.nio.ByteBuffer; -import fj.data.List; -import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeAttributes; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public class PutAttribute implements NodeEditor {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/AtomicReservableReference.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/AtomicReservableReference.java Fri Nov 21 12:46:06 2014 +0900 @@ -3,7 +3,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import sun.security.action.GetBooleanAction; public class AtomicReservableReference<V> {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultChangeSet.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultChangeSet.java Fri Nov 21 12:46:06 2014 +0900 @@ -4,10 +4,8 @@ import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public class DefaultChangeSet implements ChangeSet { @@ -17,10 +15,10 @@ private final String uuid; private final String treeName; private final long revision; - private final TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index; + private final TreeMap<String, TreeMap<String, List<TreeNode>>> index; private final TreeMap<TreeNode,TreeNode> parentIndex; - public DefaultChangeSet(TreeNode _node,ChangeSet _prev,ChangeList _log,String _uuid, String _treeName, long _revision, TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index,TreeMap<TreeNode,TreeNode> parentIndex) + public DefaultChangeSet(TreeNode _node,ChangeSet _prev,ChangeList _log,String _uuid, String _treeName, long _revision, TreeMap<String, TreeMap<String, List<TreeNode>>> index,TreeMap<TreeNode,TreeNode> parentIndex) { this.root = _node; this.previous = _prev; @@ -76,7 +74,7 @@ } @Override - public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { + public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { return index; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultJungleTreeEditor.java Fri Nov 21 12:46:06 2014 +0900 @@ -24,7 +24,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public class DefaultJungleTreeEditor implements JungleTreeEditor { @@ -32,7 +31,7 @@ private final TreeNode root; private final TreeEditor editor; private final TreeOperationLog log; - private final TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index; + private final TreeMap<String, TreeMap<String, List<TreeNode>>> index; private final TreeMap<TreeNode,TreeNode> parentIndex; // public DefaultJungleTreeEditor(TreeNode root) @@ -40,14 +39,14 @@ // this(root,txManager,_editor,new DefaultTreeOperationLog()); // } - public DefaultJungleTreeEditor(TreeNode _root,TransactionManager _txManager,TreeEditor _editor, TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index,TreeMap<TreeNode,TreeNode> parentIndex) + public DefaultJungleTreeEditor(TreeNode _root,TransactionManager _txManager,TreeEditor _editor, TreeMap<String, TreeMap<String, List<TreeNode>>> index,TreeMap<TreeNode,TreeNode> parentIndex) { this(_root,_txManager,_editor,new DefaultTreeOperationLog(),index,parentIndex); } - public DefaultJungleTreeEditor(TreeNode newNode,TransactionManager _txManager,TreeEditor _editor,TreeOperationLog _log, TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index,TreeMap<TreeNode,TreeNode> parentIndex) + public DefaultJungleTreeEditor(TreeNode newNode,TransactionManager _txManager,TreeEditor _editor,TreeOperationLog _log, TreeMap<String, TreeMap<String, List<TreeNode>>> index,TreeMap<TreeNode,TreeNode> parentIndex) { this.root = newNode; this.txManager = _txManager;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTransactionManager.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTransactionManager.java Fri Nov 21 12:46:06 2014 +0900 @@ -8,7 +8,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Result; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; @@ -17,7 +16,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultError; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public class DefaultTransactionManager implements TransactionManager { @@ -36,7 +34,7 @@ } @Override - public Either<Error,TransactionManager> commit(TreeNode _newRoot,final TreeOperationLog _log, TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index,TreeMap<TreeNode,TreeNode> parentIndex) + public Either<Error,TransactionManager> commit(TreeNode _newRoot,final TreeOperationLog _log, TreeMap<String, TreeMap<String, List<TreeNode>>> index,TreeMap<TreeNode,TreeNode> parentIndex) { ChangeSet cs = tip.getChangeSet(); long currentRevision = cs.revision();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeAttribute.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeAttribute.java Fri Nov 21 12:46:06 2014 +0900 @@ -9,8 +9,6 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeAttributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteAttributeOperation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditorError; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeChildren.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/DefaultTreeNodeChildren.java Fri Nov 21 12:46:06 2014 +0900 @@ -8,11 +8,6 @@ import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeChildren; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultOperationLog; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditorError; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java Fri Nov 21 12:46:06 2014 +0900 @@ -24,35 +24,32 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.IterableConverter; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; -import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.AddNewChildrenIndexEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Triple; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.DefaultIndexEditor; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.DeleteChildIndexEditor; -import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.DeleteIndexEditor; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.IndexEditor; -import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.PutIndexEditor; public class IndexJungleTreeEditor implements JungleTreeEditor { private final TransactionManager txManager; private final TreeNode root; private final IndexTreeEditor editor; private final TreeOperationLog log; - private TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index; + private TreeMap<String, TreeMap<String, List<TreeNode>>> index; private TreeMap<TreeNode, TreeNode> parentIndex; - public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> getIndex() { + public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { return index; } public IndexJungleTreeEditor(TreeNode _root, TransactionManager _txManager, IndexTreeEditor treeEditor, - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index,TreeMap<TreeNode, TreeNode> parentIndex) { + TreeMap<String, TreeMap<String, List<TreeNode>>> index,TreeMap<TreeNode, TreeNode> parentIndex) { this(_root, _txManager, treeEditor, new DefaultTreeOperationLog(), index,parentIndex); } public IndexJungleTreeEditor(TreeNode newNode, TransactionManager _txManager, IndexTreeEditor _editor, - TreeOperationLog _log, TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index,TreeMap<TreeNode, TreeNode> parentIndex) { + TreeOperationLog _log, TreeMap<String, TreeMap<String, List<TreeNode>>> index,TreeMap<TreeNode, TreeNode> parentIndex) { this.root = newNode; this.txManager = _txManager; this.editor = _editor; @@ -63,13 +60,14 @@ public Either<Error, IndexJungleTreeEditor> _edit(final NodePath _path, NodeEditor _e, IndexEditor indexEditor) { - Either<Error,Pair<LoggingNode, TreeMap<TreeNode, TreeNode>>> either = editor.edit(root, _path, _e,parentIndex); + Either<Error,Triple<LoggingNode, TreeMap<TreeNode, TreeNode>,TreeMap<String,TreeMap<String,List<TreeNode>>>>> either = editor.edit(root, _path, _e, parentIndex, indexEditor); if (either.isA()) { return DefaultEither.newA(either.a()); } - LoggingNode newLogging = either.b().left(); - TreeMap<TreeNode,TreeNode> newParentIndex = either.b().right(); + LoggingNode newLogging = either.b().getA(); + TreeMap<TreeNode,TreeNode> newParentIndex = either.b().getB(); + TreeMap<String,TreeMap<String,List<TreeNode>>> newIndex = either.b().getC(); OperationLog newLog = newLogging.getOperationLog(); TreeNode newNode = newLogging.getWrap(); @@ -83,14 +81,14 @@ Iterable<TreeOperation> iterable = new IterableConverter<TreeOperation, NodeOperation>(newLog, converter); DefaultTreeOperationLog treeOperationLog = new DefaultTreeOperationLog(iterable, newLog.length()); TreeOperationLog newTreeOpLog = log.append(treeOperationLog); - Either<Error, IndexJungleTreeEditor> newEither = indexEditor.edit(newNode, txManager, editor, newTreeOpLog, index, newParentIndex); - return newEither; + IndexJungleTreeEditor newIndexTreeEditor = new IndexJungleTreeEditor(newNode, txManager, this.editor,newTreeOpLog, newIndex, newParentIndex); + return DefaultEither.newB(newIndexTreeEditor); } @Override public Either<Error, JungleTreeEditor> addNewChildAt(NodePath _path, int _pos) { AppendChildAt appendChildAt = new AppendChildAt(_pos); - AddNewChildrenIndexEditor indexEditor = new AddNewChildrenIndexEditor(_pos, _path); + IndexEditor indexEditor = new DefaultIndexEditor(index); Either<Error, IndexJungleTreeEditor> either = _edit(_path, appendChildAt, indexEditor); Either<Error, JungleTreeEditor> newEither = DefaultEither.newB(either.b()); return newEither; @@ -99,7 +97,7 @@ @Override public Either<Error, JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) { DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); - DeleteChildIndexEditor indexEditor = new DeleteChildIndexEditor(_pos, _path); + DeleteChildIndexEditor indexEditor = new DeleteChildIndexEditor(_pos, index); Either<Error, IndexJungleTreeEditor> either = _edit(_path, deleteChildAt, indexEditor); JungleTreeEditor editor = either.b(); Either<Error, JungleTreeEditor> newEither = DefaultEither.newB(editor); @@ -109,7 +107,7 @@ @Override public Either<Error, JungleTreeEditor> putAttribute(NodePath _path, String _key, ByteBuffer _value) { PutAttribute putAttribute = new PutAttribute(_key, _value); - PutIndexEditor indexEditor = new PutIndexEditor(_key, _value, _path); + IndexEditor indexEditor = new DefaultIndexEditor(index); Either<Error, IndexJungleTreeEditor> either = _edit(_path, putAttribute, indexEditor); JungleTreeEditor editor = either.b(); Either<Error, JungleTreeEditor> newEither = DefaultEither.newB(editor); @@ -119,7 +117,7 @@ @Override public Either<Error, JungleTreeEditor> deleteAttribute(NodePath _path, String _key) { DeleteAttribute deleteAttribute = new DeleteAttribute(_key); - DeleteIndexEditor indexEditor = new DeleteIndexEditor(_key, _path, root); + IndexEditor indexEditor = new DefaultIndexEditor(index); Either<Error, IndexJungleTreeEditor> either = _edit(_path, deleteAttribute, indexEditor); Either<Error, JungleTreeEditor> newEither = DefaultEither.newB(either.b()); return newEither; @@ -127,7 +125,7 @@ @Override public Either<Error, JungleTreeEditor> edit(NodePath _path, NodeEditor _editor) { - DefaultIndexEditor indexEditor = new DefaultIndexEditor(); + IndexEditor indexEditor = new DefaultIndexEditor(index); Either<Error, IndexJungleTreeEditor> either = _edit(_path, _editor, indexEditor); JungleTreeEditor editor = either.b(); Either<Error, JungleTreeEditor> newEither = DefaultEither.newB(editor);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/TransactionManager.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/TransactionManager.java Fri Nov 21 12:46:06 2014 +0900 @@ -2,16 +2,14 @@ import fj.data.List; import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public interface TransactionManager { - public Either<Error,TransactionManager> commit(TreeNode _newRoot,TreeOperationLog _log, TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index,TreeMap<TreeNode,TreeNode> parentIndex); + public Either<Error,TransactionManager> commit(TreeNode _newRoot,TreeOperationLog _log, TreeMap<String, TreeMap<String, List<TreeNode>>> index,TreeMap<TreeNode,TreeNode> parentIndex); public String getUUID(); public long getRevision(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/traverser/InterfaceTraverser.java Fri Nov 21 12:46:06 2014 +0900 @@ -20,7 +20,7 @@ // InterfaceTraverser traverser; TreeNode node; - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index; + TreeMap<String, TreeMap<String, List<TreeNode>>> index; IndexManager indexManager; public InterfaceTraverser(TreeNode _root, IndexManager indexManager) { @@ -29,7 +29,7 @@ this.indexManager = indexManager; } - public InterfaceTraverser(TreeNode _root, TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index, + public InterfaceTraverser(TreeNode _root, TreeMap<String, TreeMap<String, List<TreeNode>>> index, IndexManager indexManager) { this.node = _root; this.index = index;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/query/PathNodeIterator.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/query/PathNodeIterator.java Fri Nov 21 12:46:06 2014 +0900 @@ -4,7 +4,6 @@ import java.util.Stack; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/query/Query.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/query/Query.java Fri Nov 21 12:46:06 2014 +0900 @@ -1,8 +1,6 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query; -import fj.data.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public interface Query { boolean condition(TreeNode _node);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/AddNewChildrenIndexEditor.java Fri Nov 21 08:11:24 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; - -import fj.Ord; -import fj.data.List; -import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.IndexTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; - -public class AddNewChildrenIndexEditor implements IndexEditor { - - NodePath editNodePath; - - public AddNewChildrenIndexEditor(int pos, NodePath path) { - this.editNodePath = path.add(pos); - } - - @Override - public Either<Error, IndexJungleTreeEditor> edit(TreeNode root, TransactionManager txManager, IndexTreeEditor editor, - TreeOperationLog log, TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index, - TreeMap<TreeNode, TreeNode> parentIndex) { - - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = editIndex(index); - IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root, txManager, editor, newIndex,parentIndex); - return DefaultEither.newB(newEditor); - } - - public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> editIndex( - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) { - - if (!index.isEmpty()) { - List<String> keyList = index.keys(); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = TreeMap.empty(Ord.stringOrd); - TreeMap<String, List<Pair<TreeNode, NodePath>>> newInnerIndex = TreeMap.empty(Ord.stringOrd); - - for (String indexKey : keyList) { - TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = index.get(indexKey).some(); - List<String> innerIndexKeyList = innerIndex.keys(); - - for (String innerIndexKey : innerIndexKeyList) { - List<Pair<TreeNode, NodePath>> pairList = innerIndex.get(innerIndexKey).some(); - List<Pair<TreeNode, NodePath>> list = checkPath(pairList); - if (!list.isEmpty()) { - // System.out.println(new - // String(list.head().left().getAttributes().get("KEY").array())); - newInnerIndex = newInnerIndex.set(innerIndexKey, list); - } - } - newIndex = newIndex.set(indexKey, newInnerIndex); - } - return newIndex; - } else { - return index; - } - } - - public List<Pair<TreeNode, NodePath>> checkPath(List<Pair<TreeNode, NodePath>> pairList) { - - List<Pair<TreeNode, NodePath>> list = List.nil(); - for (Pair<TreeNode, NodePath> pair : pairList) { - - NodePath path = pair.right(); - // System.out.println("oldPath = " + path.toString()); - NodePath newPath = new DefaultNodePath(); - - if (editNodePath.size() > path.size()) { - list = list.cons(pair); - continue; - } - - Pair<Integer, NodePath> editNodePathCopy = editNodePath.pop(); - int loopCount = 0; - - for (Integer pathInt : path) { - loopCount++; - - if (pathInt == -1) - continue; - - if (editNodePathCopy.right().size() > 0) { - editNodePathCopy = editNodePathCopy.right().pop(); - - if (loopCount == editNodePath.size() && editNodePathCopy.left() <= pathInt) { - newPath = newPath.add(pathInt + 1); - continue; - } - - if (!(editNodePathCopy.left() == pathInt)) { - newPath = path; - break; - } - } - - newPath = newPath.add(pathInt); - - } - - // System.out.println("newPath = " + newPath.toString()); - Pair<TreeNode, NodePath> newPair = new Pair<TreeNode, NodePath>(pair.left(), newPath); - list = list.cons(newPair); - } - - return list; - } - -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/DefaultIndexEditor.java Fri Nov 21 08:11:24 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; - -import fj.data.List; -import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.IndexTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; - -public class DefaultIndexEditor implements IndexEditor { - - @Override - public Either<Error, IndexJungleTreeEditor> edit(TreeNode root,TransactionManager txManager, IndexTreeEditor editor,TreeOperationLog log,TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index, TreeMap<TreeNode,TreeNode> parentIndex){ - IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root,txManager,editor,log, index, parentIndex); - Either<Error, IndexJungleTreeEditor> either = DefaultEither.newB(newEditor); - return either; - } - - - -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/DeleteChildIndexEditor.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/DeleteChildIndexEditor.java Fri Nov 21 12:46:06 2014 +0900 @@ -1,116 +1,127 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; - import fj.Ord; import fj.data.List; +import fj.data.Option; import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.IndexTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNodeAttributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; +import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.query.PathNodeIterator; public class DeleteChildIndexEditor implements IndexEditor { - NodePath editNodePath; - - public DeleteChildIndexEditor(int pos, NodePath path) { - this.editNodePath = path.add(pos); - } - - @Override - public Either<Error, IndexJungleTreeEditor> edit(TreeNode root,TransactionManager txManager, IndexTreeEditor editor,TreeOperationLog log,TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index, TreeMap<TreeNode,TreeNode> parentIndex) { + TreeMap<String, TreeMap<String, List<TreeNode>>> indexTreeMap; + int pos; - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = editIndex(index); - IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root, txManager, editor, newIndex, parentIndex); - return DefaultEither.newB(newEditor); - } - - public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> editIndex( - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index) { - - if (!index.isEmpty()) { - List<String> keyList = index.keys(); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = TreeMap.empty(Ord.stringOrd); - TreeMap<String, List<Pair<TreeNode, NodePath>>> newInnerIndex = TreeMap.empty(Ord.stringOrd); + public DeleteChildIndexEditor(int pos, TreeMap<String, TreeMap<String, List<TreeNode>>> indexTreeMap) { + this.indexTreeMap = indexTreeMap; + this.pos = pos; + } - for (String indexKey : keyList) { - TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = index.get(indexKey).some(); - List<String> innerIndexKeyList = innerIndex.keys(); + @Override + public IndexEditor delete(TreeNode node) { + TreeNodeAttributes attribute = node.getAttributes(); + List<String> keys = attribute.getKeys(); + TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexTreeMap = indexTreeMap; + for (String key : keys) { + Option<TreeMap<String, List<TreeNode>>> indexOp = indexTreeMap.get(key); + if (indexOp.isSome()) { + TreeMap<String, List<TreeNode>> index = indexOp.some(); + String value = attribute.getString(key); + Option<List<TreeNode>> nodeListOp = index.get(value); + if (nodeListOp.isSome()) { + List<TreeNode> nodeList = nodeListOp.some(); + List<TreeNode> newNodeList = List.nil(); + for (TreeNode indexingNode : nodeList) { + if (indexingNode != node) + newNodeList = newNodeList.cons(indexingNode); + } + TreeMap<String, List<TreeNode>> newIndex; + newIndex = index.set(value, newNodeList); + newIndexTreeMap = newIndexTreeMap.set(key, newIndex); + } - for (String innerIndexKey : innerIndexKeyList) { - List<Pair<TreeNode, NodePath>> pairList = innerIndex.get(innerIndexKey).some(); - List<Pair<TreeNode, NodePath>> list = checkPath(pairList); - if (!list.isEmpty()){ - System.out.println(new String(list.head().left().getAttributes().get("KEY").array())); - newInnerIndex = newInnerIndex.set(innerIndexKey, list); - } - } - newIndex = newIndex.set(indexKey, newInnerIndex); - } - return newIndex; - } else { - return index; - } - } + } + } - public List<Pair<TreeNode, NodePath>> checkPath(List<Pair<TreeNode, NodePath>> pairList){ - - List<Pair<TreeNode, NodePath>> list = List.nil(); - for (Pair<TreeNode, NodePath> pair : pairList) { + return new DefaultIndexEditor(newIndexTreeMap); + } - NodePath path = pair.right(); - System.out.println("oldPath = " + path.toString()); - NodePath newPath = new DefaultNodePath(); - - if (path.toString().equals(editNodePath.toString())) { - continue; - } - - if (editNodePath.size() > path.size()) { - list = list.cons(pair); - continue; - } + @Override + public IndexEditor add(TreeNode node) { + TreeNodeAttributes attribute = node.getAttributes(); + List<String> keys = attribute.getKeys(); + TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexTreeMap = indexTreeMap; + for (String key : keys) { + Option<TreeMap<String, List<TreeNode>>> indexOp = indexTreeMap.get(key); + if (indexOp.isSome()) { + TreeMap<String, List<TreeNode>> index = indexOp.some(); + String value = attribute.getString(key); + Option<List<TreeNode>> nodeListOp = index.get(value); + if (nodeListOp.isSome()) { + List<TreeNode> nodeList = nodeListOp.some(); + List<TreeNode> newNodeList = nodeList.cons(node); + TreeMap<String, List<TreeNode>> newIndex = index.set(value, newNodeList); + newIndexTreeMap = newIndexTreeMap.set(key, newIndex); + } else { // test + List<TreeNode> nodeList = List.nil(); + value = attribute.getString(key); + List<TreeNode> newNodeList = nodeList.cons(node); + TreeMap<String, List<TreeNode>> newIndex = index.set(value, newNodeList); + newIndexTreeMap = newIndexTreeMap.set(key, newIndex); + } - Pair<Integer, NodePath> editNodePathCopy = editNodePath.pop(); - int loopCount = 0; + } else { // test + TreeMap<String, List<TreeNode>> index = TreeMap.empty(Ord.stringOrd); + List<TreeNode> nodeList = List.nil(); + String value = attribute.getString(key); + List<TreeNode> newNodeList = nodeList.cons(node); + TreeMap<String, List<TreeNode>> newIndex = index.set(value, newNodeList); + newIndexTreeMap = newIndexTreeMap.set(key, newIndex); + } + } - for (Integer pathInt : path) { - loopCount++; + return new DefaultIndexEditor(newIndexTreeMap); + } - if (pathInt == -1) - continue; - if (editNodePathCopy.right().size() > 0) { - - editNodePathCopy = editNodePathCopy.right().pop(); - if (loopCount == editNodePath.size() && editNodePathCopy.left() < pathInt) { - newPath = newPath.add(pathInt - 1); - continue; - } + @Override + public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex() { + return indexTreeMap; + } + + @Override + public IndexEditor edit(TreeNode node) { + PathNodeIterator nodeSearcher = new PathNodeIterator(new Pair<TreeNode, NodePath>(node, new DefaultNodePath())); + TreeMap<String, TreeMap<String, List<TreeNode>>> newIndexTreeMap = indexTreeMap; - if (!(editNodePathCopy.left() == pathInt)) { - newPath = path; - break; - } - } - - newPath = newPath.add(pathInt); + for (; nodeSearcher.hasNext();) { + TreeNode deleteNode = nodeSearcher.next().left(); + TreeNodeAttributes attribute = deleteNode.getAttributes(); + List<String> keys = attribute.getKeys(); + for (String key : keys) { + Option<TreeMap<String, List<TreeNode>>> indexOp = newIndexTreeMap.get(key); + if (indexOp.isSome()) { + TreeMap<String, List<TreeNode>> index = indexOp.some(); + String value = attribute.getString(key); + Option<List<TreeNode>> nodeListOp = index.get(value); + if (nodeListOp.isSome()) { + List<TreeNode> nodeList = nodeListOp.some(); + List<TreeNode> newNodeList = List.nil(); + for (TreeNode indexingNode : nodeList) { + if (indexingNode != deleteNode) + newNodeList = newNodeList.cons(indexingNode); + } + TreeMap<String, List<TreeNode>> newIndex = index.set(value, newNodeList); + newIndexTreeMap = newIndexTreeMap.set(key, newIndex); + } - } - - System.out.println("newPath = " + newPath.toString()); - Pair<TreeNode, NodePath> newPair = new Pair<TreeNode, NodePath>( - pair.left(), newPath); - list = list.cons(newPair); - } - - return list; - } + } + } + } + return null; + } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/DeleteIndexEditor.java Fri Nov 21 08:11:24 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; - -import java.nio.ByteBuffer; - -import fj.data.List; -import fj.data.Option; -import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.IndexTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; - -public class DeleteIndexEditor implements IndexEditor { - - String key; - String pathString; - NodePath path; - TreeNode node; - - public DeleteIndexEditor(String key, NodePath path, TreeNode node) { - this.key = key; - this.pathString = path.toString(); - this.path = path; - this.node = node; - } - - @Override - public Either<Error, IndexJungleTreeEditor> edit(TreeNode root,TransactionManager txManager, IndexTreeEditor editor,TreeOperationLog log,TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index, TreeMap<TreeNode,TreeNode> parentIndex) { - NodePath newPath = path.pop().right(); - TreeNode target = getTarget(node, newPath); - String attribute = target.getAttributes().getString(key); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = editIndex(attribute, index); - IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root,txManager,editor,log, newIndex, parentIndex); - Either<Error, IndexJungleTreeEditor> either = DefaultEither.newB(newEditor); - return either; - } - - public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> editIndex(String attribute, TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index){ - - Option<TreeMap<String, List<Pair<TreeNode, NodePath>>>> innerIndexOp = index.get(key); - - if (innerIndexOp.isSome()) { - TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = innerIndexOp.some(); - Option<List<Pair<TreeNode, NodePath>>> listOp = innerIndex.get(attribute); - - if (listOp.isSome()) { - List<Pair<TreeNode, NodePath>> list = listOp.some(); - List<Pair<TreeNode, NodePath>> newList = List.nil(); - - for (Pair<TreeNode, NodePath> pathNode : list){ - if (!pathNode.right().toString().equalsIgnoreCase(pathString)) { - newList = newList.cons(pathNode); - } - } - - if (newList.isEmpty()) { - TreeMap<String, List<Pair<TreeNode, NodePath>>> newInnerIndex = innerIndex.delete(attribute); - - if (newInnerIndex.isEmpty()) { - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = index.delete(key); - return newIndex; - } - - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = index.set(key, newInnerIndex); - return newIndex; - } - - TreeMap<String, List<Pair<TreeNode, NodePath>>> newInnerIndex = innerIndex.set(attribute,newList); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = index.set(key, newInnerIndex); - return newIndex; - - } else { - return index; - } - } else { - return index; - } - } - - public TreeNode getTarget(TreeNode node , NodePath path){ - Pair<Integer, NodePath> pathNode = path.pop(); - Either<Error, TreeNode> either = node.getChildren().at(pathNode.left()); - if (either.isA()) - return node; - - TreeNode child = either.b(); - if (pathNode.right().size() == 0) - return child; - - TreeNode target = getTarget(child,pathNode.right()); - return target; - } - - -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexEditor.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexEditor.java Fri Nov 21 12:46:06 2014 +0900 @@ -2,18 +2,12 @@ import fj.data.List; import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.IndexTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; + public interface IndexEditor { - Either<Error, IndexJungleTreeEditor> edit(TreeNode root,TransactionManager txManager, IndexTreeEditor editor,TreeOperationLog log,TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index, TreeMap<TreeNode,TreeNode> parentIndex); + public IndexEditor add(TreeNode node); + public IndexEditor delete(TreeNode node); + public IndexEditor edit(TreeNode node); + public TreeMap<String, TreeMap<String, List<TreeNode>>> getIndex(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexManager.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/IndexManager.java Fri Nov 21 12:46:06 2014 +0900 @@ -5,13 +5,11 @@ import fj.data.TreeMap; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.ChangeSet; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.AtomicReservableReference; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultChangeSet; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeContext; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TreeContext; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; public class IndexManager { @@ -21,7 +19,7 @@ this.reservation = reservation; } - public void commit(TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index){ + public void commit(TreeMap<String, TreeMap<String, List<TreeNode>>> index){ TreeContext tc = reservation.get(); ChangeSet cs = tc.getChangeSet(); TreeNode root = cs.getRoot();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/store/index/PutIndexEditor.java Fri Nov 21 08:11:24 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index; - - - -import fj.Ord; -import fj.data.List; -import fj.data.Option; -import fj.data.TreeMap; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.TreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.IndexTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.TransactionManager; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; - -import java.nio.ByteBuffer; - -public class PutIndexEditor implements IndexEditor { - - String key; - String attribute; - NodePath path; - TransactionManager txManager; - TreeNode root; - TreeEditor editor; - TreeOperationLog log; - - public PutIndexEditor(String key, ByteBuffer attribute,NodePath path) { - this.key = key; - this.attribute = new String(attribute.array()); - this.path = path; - } - - @Override - public Either<Error, IndexJungleTreeEditor>edit(TreeNode root,TransactionManager txManager, IndexTreeEditor editor,TreeOperationLog log,TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index, TreeMap<TreeNode,TreeNode> parentIndex) { - NodePath newPath = path.pop().right(); - TreeNode target = getTarget(root, newPath); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = editIndex(target, path, key, attribute,index); - IndexJungleTreeEditor newEditor = new IndexJungleTreeEditor(root,txManager,editor,log, newIndex, parentIndex); - Either<Error, IndexJungleTreeEditor> either = DefaultEither.newB(newEditor); - return either; - } - - public TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> editIndex(TreeNode target, NodePath path, String key, String attribute,TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index){ - - Option<TreeMap<String, List<Pair<TreeNode, NodePath>>>> innerIndexOp = index.get(key); - Pair<TreeNode, NodePath> pathNode = new Pair<TreeNode, NodePath>(target,path); - - if (attribute != null) { - if (innerIndexOp.isNone()) { - - TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = TreeMap.empty(Ord.stringOrd); - List<Pair<TreeNode, NodePath>> list = List.nil(); - list = list.cons(pathNode); - innerIndex = innerIndex.set(attribute, list); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = index.set(key, innerIndex); - return newIndex; - } else { - - TreeMap<String, List<Pair<TreeNode, NodePath>>> innerIndex = innerIndexOp.some(); - - Option<List<Pair<TreeNode, NodePath>>> opList = innerIndex.get(attribute); - - if (opList.isNone()) { - - List<Pair<TreeNode, NodePath>> list = List.nil(); - list = list.cons(pathNode); - innerIndex = innerIndex.set(attribute, list); - - } else { - - List<Pair<TreeNode, NodePath>> list = opList.some(); - list = list.cons(pathNode); - innerIndex = innerIndex.set(attribute, list); - - } - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> newIndex = index.set(key, innerIndex); - return newIndex; - } - } - return index; - } - - public TreeNode getTarget(TreeNode node , NodePath path){ - Pair<Integer, NodePath> pathNode = path.pop(); - Either<Error, TreeNode> either = node.getChildren().at(pathNode.left()); - if (either.isA()) - return node; - - TreeNode child = either.b(); - if (pathNode.right().size() == 0) - return child; - - TreeNode target = getTarget(child,pathNode.right()); - return target; - } - -}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/functionaljava/FjTreeMapTest.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/functionaljava/FjTreeMapTest.java Fri Nov 21 12:46:06 2014 +0900 @@ -37,6 +37,7 @@ TreeNode node1 = new DefaultTreeNode(); TreeNode node2 = new DefaultTreeNode(); treeMap = treeMap.set(node1,node2); + treeMap = treeMap.delete(node2); System.out.println(node1.toString()); System.out.println(node2.toString()); System.out.println(node1.toString());
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/AttributeIndexTest.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/AttributeIndexTest.java Fri Nov 21 12:46:06 2014 +0900 @@ -11,16 +11,14 @@ import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.IndexTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.IndexJungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Pair; import junit.framework.Assert; import fj.data.List; +import fj.data.Option; import fj.data.TreeMap; public class AttributeIndexTest { @@ -30,7 +28,7 @@ DefaultJungle jungle = new DefaultJungle(null,"hoge",new DefaultTraverser()); JungleTree tree = jungle.createNewTree("fuga"); IndexJungleTreeEditor editor = tree.getIndexTreeEditor(); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> emptyIndex = editor.getIndex(); + TreeMap<String, TreeMap<String, List<TreeNode>>> emptyIndex = editor.getIndex(); Assert.assertTrue(emptyIndex.isEmpty()); NodePath path = new DefaultNodePath(); Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path, 0); @@ -40,21 +38,28 @@ Either<Error, JungleTreeEditor> either2 = editor2.putAttribute(path.add(0),"key", ByteBuffer.wrap("test".toString().getBytes())); Assert.assertFalse(either2.isA()); JungleTreeEditor editor3 = either2.b(); - editor3.success(); - + editor3 = editor3.success().b(); + + editor3.putAttribute(path.add(0),"key", ByteBuffer.wrap("tatsuki".toString().getBytes())).b().success().b(); + TreeNode targetNode = tree.getRootNode().getChildren().at(0).b(); IndexJungleTreeEditor IndexEditor = tree.getIndexTreeEditor(); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> index = IndexEditor.getIndex(); - - Assert.assertEquals(index.get("key").some().get("test").some().head().left().getAttributes().getString("key"),"test"); + TreeMap<String, TreeMap<String, List<TreeNode>>> index = IndexEditor.getIndex(); + List<TreeNode> NodeList = index.get("key").some().get("tatsuki").some(); + String attributeIndex = NodeList.head().getAttributes().getString("key"); + Assert.assertEquals(attributeIndex,"tatsuki"); + Assert.assertEquals(NodeList.head(),targetNode); JungleTreeEditor editor4 = tree.getIndexTreeEditor(); - Either<Error, JungleTreeEditor> either3 = editor4.deleteAttribute(path.add(0), "key"); + Either<Error, JungleTreeEditor> either3 = editor4.deleteAttribute(path.add(0), "key").b().success(); Assert.assertFalse(either3.isA()); JungleTreeEditor editor5 = either3.b(); editor5.success(); IndexJungleTreeEditor IndexEditor2 = tree.getIndexTreeEditor(); - TreeMap<String, TreeMap<String, List<Pair<TreeNode, NodePath>>>> deleteIndex = IndexEditor2.getIndex(); - Assert.assertTrue(deleteIndex.isEmpty()); + TreeMap<String, TreeMap<String, List<TreeNode>>> deleteIndexList = IndexEditor2.getIndex(); + Option<TreeMap<String, List<TreeNode>>> deleteIndexOp = deleteIndexList.get("key"); + TreeMap<String, List<TreeNode>> deleteIndex = deleteIndexOp.some(); + Assert.assertTrue(deleteIndex.get("test").some().isEmpty()); + Assert.assertTrue(deleteIndex.get("tatsuki").some().isEmpty()); } }
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/ParentIndexTest.java Fri Nov 21 08:11:24 2014 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/index/ParentIndexTest.java Fri Nov 21 12:46:06 2014 +0900 @@ -1,5 +1,6 @@ package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.index; +import java.nio.ByteBuffer; import java.util.Iterator; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; @@ -13,6 +14,7 @@ import org.junit.Test; +import fj.data.List; import fj.data.Option; import fj.data.TreeMap; @@ -26,11 +28,14 @@ JungleTreeEditor editor = tree.getIndexTreeEditor(); DefaultNodePath path = new DefaultNodePath(); editor = editor.addNewChildAt(path, 0).b(); + + for (int num = 0; num < 5; num++) { editor = editor.addNewChildAt(path.add(0), num).b().success().b(); + editor = editor.putAttribute(path.add(0).add(num), "test",ByteBuffer.wrap("test".getBytes())).b().success().b(); } + TreeMap<TreeNode, TreeNode> parentIndex = tree.getParentIndex(); - TreeNode node = tree.getRootNode(); for (int num = 0; node.getChildren().size() != 0; num++) { Iterator<TreeNode> children = node.getChildren().iterator();