Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 302:0767620e6f5f
implements DifferentialInterfaceTraverser and this tests
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/JungleBenchMark.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/JungleBenchMark.java Sat Jan 07 18:02:53 2017 +0900 @@ -1,13 +1,13 @@ package jp.ac.u_ryukyu.ie.cr.benchMark; import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; +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.nodepath.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeAttributes; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; import java.nio.ByteBuffer;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/DefaultJungle.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/DefaultJungle.java Sat Jan 07 18:02:53 2017 +0900 @@ -5,6 +5,8 @@ import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.Journal; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.NullJournal; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.DifferentialInterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.DefaultTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; @@ -22,7 +24,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.redBlackTree.EmptyTreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.DefaultInterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.Traverser; import jp.ac.u_ryukyu.ie.cr.jungle.tree.DefaultJungleTree; import jp.ac.u_ryukyu.ie.cr.jungle.tree.DifferenceListJungleTree; @@ -103,7 +105,7 @@ } }; - InterfaceTraverser traverser = new InterfaceTraverser(rootNode, true); + InterfaceTraverser traverser = new DefaultInterfaceTraverser(rootNode, true); TreeContext tc = new DefaultTreeContext(rootNode, null, list, uuid, name, 0, traverser); JungleTree newTree = new DefaultJungleTree(tc, uuid, journal.getWriter(), treeEditor); if (trees.putIfAbsent(name, newTree) != null) { @@ -143,7 +145,7 @@ } }; - InterfaceTraverser traverser = new InterfaceTraverser(rootNode, true); + InterfaceTraverser traverser = new DifferentialInterfaceTraverser(rootNode,rootNode, true); TreeContext tc = new DifferenceTreeContext(rootNode, rootNode, null, list, uuid, name, 0, traverser); JungleTree newTree = new DifferenceListJungleTree(tc, uuid, journal.getWriter(), differenceEditor); if (trees.putIfAbsent(name, newTree) != null) { @@ -178,7 +180,7 @@ }; TreeNode rootNode = new EmptyTreeNode(); - InterfaceTraverser traverser = new InterfaceTraverser(rootNode, true); + InterfaceTraverser traverser = new DefaultInterfaceTraverser(rootNode, true); TreeContext tc = new DefaultTreeContext(rootNode, null, list, uuid, treeName, 0, traverser); JungleTree newTree = new RedBlackJungleTree(tc, uuid, journal.getWriter(), redBlackTreeEditor, balanceKey); if (trees.putIfAbsent(treeName, newTree) != null) {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/commandline/commandline.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/commandline/commandline.java Sat Jan 07 18:02:53 2017 +0900 @@ -2,13 +2,13 @@ import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; 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.omnigraffle.OmniGraffleCreater; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/query/JungleNodeIterator.java Thu Jan 05 22:44:35 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.jungle.query; - -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; - -import java.util.Iterator; -import java.util.Stack; - -public class JungleNodeIterator implements Iterator<TreeNode> { - - TreeNode root; - TreeNode node; - int childNumber; - private TreeNodeChildren children; - private Stack<TreeNode> nodeStack = new Stack<>(); - private Stack<Integer> searchStack = new Stack<>(); - - /* - * get queryIndexCondition from query - * if already index exists, use index - * otherwise traverse tree and create index - * - * */ - public JungleNodeIterator(TreeNode root) { - this.root = root; - this.node = root; - } - - @Override - public boolean hasNext() { - return node != null; - } - - @Override - public TreeNode next() { - TreeNode now = node; - if (node.getChildren().size() > 0) { - nodeStack.push(node); - children = node.getChildren(); - node = children.at(0).b(); - childNumber = 1; - searchStack.push(childNumber); - } else if (node == root) { - node = null; // no more node - children = null; - return now; - }else if (children != null && children.size() > childNumber) { - childNumber = searchStack.pop(); - node = children.at(childNumber).b(); - searchStack.push(++childNumber); - } else { - node = nodeStack.pop(); - children = node.getChildren(); - childNumber = searchStack.pop(); - for (; children.size() == childNumber;) { - if (node == root) { - node = null; // no more node - children = null; - return now; - } - node = nodeStack.pop(); - children = node.getChildren(); - childNumber = searchStack.pop(); - } - if (node != null && childNumber < children.size()) { - nodeStack.push(node); - node = children.at(childNumber).b(); - searchStack.push(++childNumber); - } - } - return now; - } - - @Override - public void remove() { - // TODO Auto-generated method stub - - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/query/traverser/DefaultInterfaceTraverser.java Sat Jan 07 18:02:53 2017 +0900 @@ -0,0 +1,141 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.query.traverser; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.nodeiterator.DefaultNodeIterator; +import jp.ac.u_ryukyu.ie.cr.jungle.query.Query; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.IndexCreater; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.IndexUpdater; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Pair; + +import java.util.Iterator; + +public class DefaultInterfaceTraverser implements InterfaceTraverser { + + private TreeNode root; + private Index index; + private ParentIndex parentIndex; + private boolean useIndex; + + public DefaultInterfaceTraverser(TreeNode root, boolean indexFlag) { + this(root, new Index(), new ParentIndex(), indexFlag); + } + + public DefaultInterfaceTraverser(TreeNode root, Index index, ParentIndex parentIndex, boolean useIndex) { + this.root = root; + this.index = index; + this.parentIndex = parentIndex; + this.useIndex = useIndex; + } + + @Override + public Index getIndex() { + return index; + } + + + @Override + public ParentIndex getParentIndex() { + return parentIndex; + } + + @Override + public void createIndex() { + IndexCreater creater = new IndexCreater(root); + index = creater.getIndex(); + parentIndex = creater.getParentIndex(); + } + + @Override + public void updateIndex(List<TreeNode> editedNodeList) { + IndexUpdater indexUpdater = new IndexUpdater(root, index, parentIndex); + Pair<Index, ParentIndex> p = indexUpdater.update(editedNodeList); + index = p.left(); + parentIndex = p.right(); + } + + /** + * 差分Treeで使う 差分Treeは一度作った木は変更しないのでIndexの中身を削除する必要はない + * なのでputだけで良い + */ + @Override + public void updateIndex(TreeNode subTreeRoot) { + IndexUpdater indexUpdater = new IndexUpdater(subTreeRoot, index, parentIndex); + Pair<Index, ParentIndex> p = indexUpdater.update(); + index = p.left(); + parentIndex = p.right(); + } + + /** + * public void updateIndex(List<TreeNode> editedNodeList,TreeNode subTreeNode) { + * IndexUpdater indexUpdater = new IndexUpdater(subTreeNode,index,parentIndex); + * Pair<Index,ParentIndex> p = indexUpdater.update(editedNodeList); + * index = p.left(); + * parentIndex = p.right(); + * } + **/ + + private TreeNode nextmatch(TreeNode node, Query query) { + if (query.condition(node)) + return node; + return null; + } + + @Override + public Iterator<TreeNode> find(final Query query) { + return find(query, null, null); + } + + @Override + public Iterator<TreeNode> find(final Query query, final String key, String searchValue) { + + Iterator<TreeNode> nodeIterator; + if (key != null && searchValue != null && useIndex) { + nodeIterator = index.get(key, searchValue); + ; + } else { + nodeIterator = new DefaultNodeIterator(root); + } + + TreeNode firstMatchNode = null; + for (; nodeIterator.hasNext(); ) { + firstMatchNode = nextmatch(nodeIterator.next(), query); + if (firstMatchNode != null) + break; + } + + final TreeNode finalFirstMatchNode = firstMatchNode; + + return new Iterator<TreeNode>() { + + TreeNode matchNode = finalFirstMatchNode; + + @Override + public boolean hasNext() { + if (matchNode == null) { + return false; + } + return true; + } + + @Override + public TreeNode next() { + TreeNode currentPair = matchNode; + for (; nodeIterator.hasNext(); ) { + matchNode = nextmatch(nodeIterator.next(), query); + if (matchNode != null) + return currentPair; + } + matchNode = null; + return currentPair; + } + + @Override + public void remove() { + } + + }; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/query/traverser/DifferentialInterfaceTraverser.java Sat Jan 07 18:02:53 2017 +0900 @@ -0,0 +1,142 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.query.traverser; + + +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import jp.ac.u_ryukyu.ie.cr.jungle.query.Query; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.nodeiterator.JungleDifferentialTreeNodeIterator; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.IndexCreater; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.IndexUpdater; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Pair; + +import java.util.Iterator; + +public class DifferentialInterfaceTraverser implements InterfaceTraverser { + private TreeNode root; + private Index index; + private ParentIndex parentIndex; + private boolean useIndex; + private TreeNode endNode; + + public DifferentialInterfaceTraverser(TreeNode root, TreeNode endNode, boolean indexFlag) { + this(root, endNode, new Index(), new ParentIndex(), indexFlag); + } + + public DifferentialInterfaceTraverser(TreeNode root, TreeNode endNode, Index index, ParentIndex parentIndex, boolean useIndex) { + this.root = root; + this.endNode = endNode; + this.index = index; + this.parentIndex = parentIndex; + this.useIndex = useIndex; + } + + + @Override + public Index getIndex() { + return index; + } + + + @Override + public ParentIndex getParentIndex() { + return parentIndex; + } + + @Override + public void createIndex() { + IndexCreater creater = new IndexCreater(root); + index = creater.getIndex(); + parentIndex = creater.getParentIndex(); + } + + + /** + * 一応書いたけど + * DifferentialTreeでは使わない + */ + @Override + public void updateIndex(List<TreeNode> editedNodeList) { + IndexUpdater indexUpdater = new IndexUpdater(root, index, parentIndex); + Pair<Index, ParentIndex> p = indexUpdater.update(editedNodeList); + index = p.left(); + parentIndex = p.right(); + } + + /** + * 差分Treeで使う 差分Treeは一度作った木は変更しないのでIndexの中身を削除する必要はない + * なのでputだけで良い + */ + @Override + public void updateIndex(TreeNode subTreeRoot) { + IndexUpdater indexUpdater = new IndexUpdater(subTreeRoot, index, parentIndex); + Pair<Index, ParentIndex> p = indexUpdater.update(); + index = p.left(); + parentIndex = p.right(); + } + + + private TreeNode nextmatch(TreeNode node, Query query) { + if (query.condition(node)) + return node; + return null; + } + + @Override + public Iterator<TreeNode> find(final Query query) { + return find(query, null, null); + } + + @Override + public Iterator<TreeNode> find(final Query query, final String key, String searchValue) { + + Iterator<TreeNode> nodeIterator; + if (key != null && searchValue != null && useIndex) { + nodeIterator = index.get(key, searchValue); + ; + } else { + nodeIterator = new JungleDifferentialTreeNodeIterator(root,endNode); + } + + TreeNode firstMatchNode = null; + for (; nodeIterator.hasNext(); ) { + firstMatchNode = nextmatch(nodeIterator.next(), query); + if (firstMatchNode != null) + break; + } + + final TreeNode finalFirstMatchNode = firstMatchNode; + + return new Iterator<TreeNode>() { + + TreeNode matchNode = finalFirstMatchNode; + + @Override + public boolean hasNext() { + if (matchNode == null) { + return false; + } + return true; + } + + @Override + public TreeNode next() { + TreeNode currentPair = matchNode; + for (; nodeIterator.hasNext(); ) { + matchNode = nextmatch(nodeIterator.next(), query); + if (matchNode != null) + return currentPair; + } + matchNode = null; + return currentPair; + } + + @Override + public void remove() { + } + + }; + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/query/traverser/InterfaceTraverser.java Sat Jan 07 18:02:53 2017 +0900 @@ -0,0 +1,28 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.query.traverser; + +import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; +import jp.ac.u_ryukyu.ie.cr.jungle.query.Query; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; +import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; + +import java.util.Iterator; + +/** + * Created by e115731 on 2017/01/07. + */ +public interface InterfaceTraverser { + Index getIndex(); + + public ParentIndex getParentIndex(); + + void createIndex(); + + void updateIndex(List<TreeNode> editedNodeList); + + void updateIndex(TreeNode subTreeRoot); + + Iterator<TreeNode> find(Query query); + + Iterator<TreeNode> find(Query query, String key, String searchValue); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/query/traverser/nodeiterator/DefaultNodeIterator.java Sat Jan 07 18:02:53 2017 +0900 @@ -0,0 +1,80 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.nodeiterator; + +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; + +import java.util.Iterator; +import java.util.Stack; + +public class DefaultNodeIterator implements Iterator<TreeNode> { + + TreeNode root; + TreeNode node; + int childNumber; + private TreeNodeChildren children; + private Stack<TreeNode> nodeStack = new Stack<>(); + private Stack<Integer> searchStack = new Stack<>(); + + /* + * get queryIndexCondition from query + * if already index exists, use index + * otherwise traverse tree and create index + * + * */ + public DefaultNodeIterator(TreeNode root) { + this.root = root; + this.node = root; + } + + @Override + public boolean hasNext() { + return node != null; + } + + @Override + public TreeNode next() { + TreeNode now = node; + if (node.getChildren().size() > 0) { + nodeStack.push(node); + children = node.getChildren(); + node = children.at(0).b(); + childNumber = 1; + searchStack.push(childNumber); + } else if (node == root) { + node = null; // no more node + children = null; + return now; + }else if (children != null && children.size() > childNumber) { + childNumber = searchStack.pop(); + node = children.at(childNumber).b(); + searchStack.push(++childNumber); + } else { + node = nodeStack.pop(); + children = node.getChildren(); + childNumber = searchStack.pop(); + for (; children.size() == childNumber;) { + if (node == root) { + node = null; // no more node + children = null; + return now; + } + node = nodeStack.pop(); + children = node.getChildren(); + childNumber = searchStack.pop(); + } + if (node != null && childNumber < children.size()) { + nodeStack.push(node); + node = children.at(childNumber).b(); + searchStack.push(++childNumber); + } + } + return now; + } + + @Override + public void remove() { + // TODO Auto-generated method stub + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/query/traverser/nodeiterator/JungleDifferentialTreeNodeIterator.java Sat Jan 07 18:02:53 2017 +0900 @@ -0,0 +1,79 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.nodeiterator; + +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; + +import java.util.Iterator; +import java.util.Stack; + +/** + * Created by e115731 on 2017/01/07. + */ +public class JungleDifferentialTreeNodeIterator implements Iterator<TreeNode> { + + private TreeNode root; + private TreeNode node; + private TreeNode endNode; + int childNumber; + private TreeNodeChildren children; + private Stack<TreeNode> nodeStack = new Stack<>(); + private Stack<Integer> searchStack = new Stack<>(); + + public JungleDifferentialTreeNodeIterator(TreeNode root, TreeNode endNode) { + this.root = root; + this.node = root; + this.endNode = endNode; + } + + @Override + public boolean hasNext() { + return node != null; + } + + @Override + public TreeNode next() { + TreeNode now = node; + if (node.getChildren().size() > 0 && node != endNode) { //ノードの下に子供がある + nodeStack.push(node); + children = node.getChildren(); + node = children.at(0).b(); + childNumber = 1; + searchStack.push(childNumber); + } else if (node == root) { //ノードとルートがここで同じなら全探索が終わったので探索は終了する + node = null; // no more node + children = null; + return now; + } else if (children != null && children.size() > childNumber) { // ノードの次の子供を見る + childNumber = searchStack.pop(); + node = children.at(childNumber).b(); + searchStack.push(++childNumber); + } else { // これ以下のノードが無いので上に戻る + node = nodeStack.pop(); + children = node.getChildren(); + childNumber = searchStack.pop(); + for (; children.size() == childNumber; ) { //ここで上に登る + if (node == root) { + node = null; // no more node + children = null; + return now; + } + node = nodeStack.pop(); + children = node.getChildren(); + childNumber = searchStack.pop(); + } + if (node != null && childNumber < children.size()) { //登っている途中で未探索の子ノードを見つけた場合 + nodeStack.push(node); + node = children.at(childNumber).b(); + searchStack.push(++childNumber); + } + } + return now; + } + + @Override + public void remove() { + // TODO Auto-generated method stub + + } + +} \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/TreeContext.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/TreeContext.java Sat Jan 07 18:02:53 2017 +0900 @@ -2,18 +2,16 @@ import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; public interface TreeContext { public TreeNode getRoot(); - public TreeNode getAppendedNode(); - - public boolean setAppendedNode(TreeNode AppendedNode); + public TreeNode getEndNode(); public TreeContext prev();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/InsertNodePositionData.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/omnigraffle/InsertNodePositionData.java Sat Jan 07 18:02:53 2017 +0900 @@ -1,7 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.jungle.store.omnigraffle; import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; -import jp.ac.u_ryukyu.ie.cr.jungle.query.JungleNodeIterator; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.nodeiterator.DefaultNodeIterator; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; @@ -42,7 +42,7 @@ public TreeMap<TreeNode, NodePoint> InsertPositionData() { ParentIndex parentIndex = tree.getParentIndex(); TreeNode rootNode = tree.getRootNode(); - JungleNodeIterator nodeIterator = new JungleNodeIterator(rootNode); + DefaultNodeIterator nodeIterator = new DefaultNodeIterator(rootNode); NodePoint rootPoint = new NodePoint(); //まずはrootのY座標を指定する、Y座標を指定する際は親Nodeを参照するため、rootだけは別に処理を書く必要がある rootPoint.setY(NODE_Y_GAP);
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/context/DefaultTreeContext.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/context/DefaultTreeContext.java Sat Jan 07 18:02:53 2017 +0900 @@ -2,12 +2,12 @@ import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; public class DefaultTreeContext implements TreeContext { private final TreeNode root; @@ -35,16 +35,11 @@ } @Override - public TreeNode getAppendedNode(){ + public TreeNode getEndNode(){ return null; // not use } @Override - public boolean setAppendedNode(TreeNode AppendedNode) { - return false; // 使わない - } - - @Override public TreeContext prev() { return previous; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/context/DifferenceTreeContext.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/context/DifferenceTreeContext.java Sat Jan 07 18:02:53 2017 +0900 @@ -1,12 +1,12 @@ package jp.ac.u_ryukyu.ie.cr.jungle.transaction.context; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; public class DifferenceTreeContext implements TreeContext { @@ -38,19 +38,11 @@ } @Override - public TreeNode getAppendedNode(){ + public TreeNode getEndNode(){ return appendedNode; } @Override - public boolean setAppendedNode(TreeNode appendedNode) { - if (this.appendedNode != null) - return false; - this.appendedNode = appendedNode; - return true; - } - - @Override public TreeContext prev() { return previous; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DifferenceJungleTreeEditor.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/DifferenceJungleTreeEditor.java Sat Jan 07 18:02:53 2017 +0900 @@ -24,7 +24,6 @@ import static jp.ac.u_ryukyu.ie.cr.jungle.store.Command.APPEND_CHILD; import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.TreeEditorError.ADD_NEW_CHILD_ERROR; -import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.TreeEditorError.SET_APPENDEDNODE_ERROR; public class DifferenceJungleTreeEditor implements JungleTreeEditor { @@ -34,7 +33,6 @@ private final TreeOperationLog log; private final TreeNode subTreeRoot; private TreeNode appendedNode; - private final List<TreeNode> editedNodeList = new List<>(); public DifferenceJungleTreeEditor(TreeNode subTreeRoot, TransactionManager txManager, TreeEditor editor) { this(subTreeRoot, subTreeRoot, txManager, editor, new DefaultTreeOperationLog()); @@ -75,7 +73,7 @@ if (op.getCommand() == APPEND_CHILD) { TreeNode newNode = newLogging.getWrap(); int position = op.getPosition(); - Either<Error,TreeNode> either = newNode.getChildren().at(position); + Either<Error, TreeNode> either = newNode.getChildren().at(position); if (either.isA()) return DefaultEither.newA(ADD_NEW_CHILD_ERROR); TreeNode newChild = either.b(); @@ -100,8 +98,8 @@ @Override public Either<Error, JungleTreeEditor> addNewChildAndPutAttribute(NodePath path, int pos, String key, ByteBuffer value) { - AppendChildAndPutAttribute appendChildAndPutAttribute = new AppendChildAndPutAttribute(key,value,pos); - return _edit(path,appendChildAndPutAttribute); + AppendChildAndPutAttribute appendChildAndPutAttribute = new AppendChildAndPutAttribute(key, value, pos); + return _edit(path, appendChildAndPutAttribute); } @Override @@ -141,13 +139,12 @@ @Override public Either<Error, JungleTreeEditor> success() { - Either<Error, TransactionManager> either = txManager.commit(subTreeRoot, log,editedNodeList); + List<TreeNode> endNodeList = new List<TreeNode>().add(0, appendedNode); + Either<Error, TransactionManager> either = txManager.commit(subTreeRoot, log, endNodeList); if (either.isA()) { return DefaultEither.newA(either.a()); } TransactionManager newTxManager = either.b(); - if (!newTxManager.setAppendedNode(appendedNode)) - return DefaultEither.newA(SET_APPENDEDNODE_ERROR); JungleTreeEditor newTreeEditor = new DifferenceJungleTreeEditor(new DifferencialTreeNode(), newTxManager, editor); return DefaultEither.newB(newTreeEditor); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java Sat Jan 07 18:02:53 2017 +0900 @@ -4,6 +4,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; @@ -11,7 +12,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.context.DefaultTreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.DefaultInterfaceTraverser; 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.DefaultError; @@ -65,7 +66,7 @@ Index index = tip.getIndex(); ParentIndex parentIndex = tip.getParentIndex(); - InterfaceTraverser traverser = new InterfaceTraverser(newRoot, index, parentIndex, true); + InterfaceTraverser traverser = new DefaultInterfaceTraverser(newRoot, index, parentIndex, true); traverser.updateIndex(editNodeList); //traverser.createIndex(); TreeContext newTreeContext = new DefaultTreeContext(newRoot, tip, list, uuid, _treeName, nextRevision, traverser); @@ -84,11 +85,6 @@ } @Override - public boolean setAppendedNode(TreeNode appendedNode) { - return false; //使わない - } - - @Override public String getUUID() { return uuid; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DifferenceTransactionManager.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DifferenceTransactionManager.java Sat Jan 07 18:02:53 2017 +0900 @@ -3,6 +3,8 @@ import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.DifferentialInterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; @@ -14,7 +16,6 @@ import jp.ac.u_ryukyu.ie.cr.jungle.transaction.context.DifferenceTreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; 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; @@ -23,7 +24,6 @@ import java.util.concurrent.atomic.AtomicReference; import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.TransactionError.APPEND_FAILD; -import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.TreeEditorError.APPENDED_NODE_NULL; import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.TreeEditorError.CAS_MISS; public class DifferenceTransactionManager implements TransactionManager { @@ -39,6 +39,17 @@ uuid = _uuid; } + /** + * DifferentialTreeではIndexの更新時 + * delete処理を行う必要が無いので + * editNodeListは使用しない + * commitの第三引数のeditNodeListは使用しない + * しかし、末尾のノード情報をrepositoryに入れる必要があるため + * editNodeListを使ってここに持って来ている + * 昔はJungleTreeEditorで後からsetしていたが、 + * DifferentialInterfaceTraverserに末尾ノードを入れる必要が出てきたので + * この実装になった + */ @Override public Either<Error, TransactionManager> commit(TreeNode subTreeRoot, TreeOperationLog log,List<TreeNode> editNodeList) { long currentRevision = tip.revision(); @@ -73,15 +84,14 @@ TreeNode root = tip.getRoot(); Index index = tip.getIndex(); ParentIndex parentIndex = tip.getParentIndex(); - InterfaceTraverser traverser = new InterfaceTraverser(root, index, parentIndex, true); - TreeContext newTreeContext = new DifferenceTreeContext(root, null, tip, list, uuid, _treeName, nextRevision, traverser); - if (tip.getAppendedNode() == null) - return DefaultEither.newA(APPENDED_NODE_NULL); + TreeNode endNode = editNodeList.get(0); + InterfaceTraverser traverser = new DifferentialInterfaceTraverser(root,endNode ,index, parentIndex, true); + TreeContext newTreeContext = new DifferenceTreeContext(root, endNode, tip, list, uuid, _treeName, nextRevision, traverser); if (repository.compareAndSet(newTreeContext.prev(), newTreeContext)) { Either<Error, TreeNode> either = appendSubTree(subTreeRoot); if (either.isA()) return DefaultEither.newA(either.a()); - traverser.updateIndex(tip.getAppendedNode()); + traverser.updateIndex(tip.getEndNode()); TransactionManager txManager = new DifferenceTransactionManager(writer, newTreeContext, repository, uuid); return DefaultEither.newB(txManager); } @@ -90,7 +100,7 @@ } private Either<Error, TreeNode> appendSubTree(TreeNode subTreeRoot) { - TreeNode appendedNode = tip.getAppendedNode(); + TreeNode appendedNode = tip.getEndNode(); TreeNodeChildren children = appendedNode.getChildren(); if (children.size() != 0) return DefaultEither.newA(APPEND_FAILD); //append Nodeが1つ以上子を持つ場合過去の木であるため、変更させない。そうすることで整合性を保証する @@ -104,11 +114,6 @@ } @Override - public boolean setAppendedNode(TreeNode appendedNode) { - return tip.setAppendedNode(appendedNode); - } - - @Override public String getUUID() { return uuid; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/RedBlackTreeTransactionManager.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/RedBlackTreeTransactionManager.java Sat Jan 07 18:02:53 2017 +0900 @@ -3,12 +3,13 @@ import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.context.DefaultTreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.DefaultInterfaceTraverser; 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.DefaultError; @@ -60,7 +61,7 @@ }; - InterfaceTraverser traverser = new InterfaceTraverser(newRoot, true); + InterfaceTraverser traverser = new DefaultInterfaceTraverser(newRoot, true); TreeContext newTreeContext = new DefaultTreeContext(newRoot, tip, list, uuid, _treeName, nextRevision, traverser); if (repository.compareAndSet(newTreeContext.prev(), newTreeContext)) { @@ -77,11 +78,6 @@ } @Override - public boolean setAppendedNode(TreeNode appendedNode) { - return false; //使わない - } - - @Override public String getUUID() { return uuid; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/TransactionManager.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/TransactionManager.java Sat Jan 07 18:02:53 2017 +0900 @@ -13,7 +13,6 @@ { public Either<Error,TransactionManager> commit(TreeNode _newRoot, TreeOperationLog _log,List<TreeNode> editNodeList); public Either<Error,TransactionManager> flashCommit(TreeNode _newRoot,TreeOperationLog _log); - public boolean setAppendedNode(TreeNode appendedNode); public String getUUID(); public long getRevision(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/RedBlackTreeNodeChildren.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/node/redBlackTree/RedBlackTreeNodeChildren.java Sat Jan 07 18:02:53 2017 +0900 @@ -34,22 +34,6 @@ } - /** - * 赤黒木ではノード単体の追加は行わない - * なので下2つのaddNewChildAtは使われない - * ここをなんとかしたかった - */ - @Override - public Either<Error, TreeNode> addNewChildAt(int pos) { - return null; - } //使わない - - @Override - public Either<Error, TreeNode> addNewChildAt(int pos, TreeNode newChild) { - return null; - } //使わない - - @Override public Either<Error, TreeNode> addNewChildAndPutAttribtue(int pos, String key, ByteBuffer value) { ColorlessTreeNode newNode = node.addNewChild(key, value); @@ -75,15 +59,7 @@ } - /** - * 赤黒木はPathを使ったノードの削除は行わない - * 本気出したら実装できるから - * 余裕ができたら実装しよう - */ - @Override - public Either<Error, TreeNode> deleteChildAt(int pos) { - return null; - } + @Override @@ -99,10 +75,6 @@ } return DefaultEither.newB(newNode); } - @Override - public Either<Error, TreeNode> moveChild(int pos, String move) { - return null; - } //使わない @Override public Either<Error, TreeNode> at(int pos) { @@ -157,4 +129,39 @@ }; } + + // ---------------- 以下 赤黒木では使わない関数 + @Override + public Either<Error, TreeNode> moveChild(int pos, String move) { + return null; + } //使わない + + + /** + * 赤黒木はPathを使ったノードの削除は行わない + * 本気出したら実装できるから + * 余裕ができたら実装しよう + */ + @Override + public Either<Error, TreeNode> deleteChildAt(int pos) { + return null; + } + + + + /** + * 赤黒木ではノード単体の追加は行わない + * なので下2つのaddNewChildAtは使われない + * ここをなんとかしたかった + */ + @Override + public Either<Error, TreeNode> addNewChildAt(int pos) { + return null; + } //使わない + + @Override + public Either<Error, TreeNode> addNewChildAt(int pos, TreeNode newChild) { + return null; + } //使わない + } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/traverser/InterfaceTraverser.java Thu Jan 05 22:44:35 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,132 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.jungle.traverser; - -import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; -import jp.ac.u_ryukyu.ie.cr.jungle.query.JungleNodeIterator; -import jp.ac.u_ryukyu.ie.cr.jungle.query.Query; -import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; -import jp.ac.u_ryukyu.ie.cr.jungle.store.index.IndexCreater; -import jp.ac.u_ryukyu.ie.cr.jungle.store.index.IndexUpdater; -import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.util.Pair; - -import java.util.Iterator; - -public class InterfaceTraverser { - - private TreeNode root; - private Index index; - private ParentIndex parentIndex; - private boolean useIndex; - - public InterfaceTraverser(TreeNode root, boolean indexFlag) { - this(root, new Index(), new ParentIndex(), indexFlag); - } - - public InterfaceTraverser(TreeNode root, Index index, ParentIndex parentIndex, boolean useIndex) { - this.root = root; - this.index = index; - this.parentIndex = parentIndex; - this.useIndex = useIndex; - } - - public Index getIndex() { - return index; - } - - - public ParentIndex getParentIndex() { - return parentIndex; - } - - public void createIndex() { - IndexCreater creater = new IndexCreater(root); - index = creater.getIndex(); - parentIndex = creater.getParentIndex(); - } - - public void updateIndex(List<TreeNode> editedNodeList) { - IndexUpdater indexUpdater = new IndexUpdater(root,index,parentIndex); - Pair<Index,ParentIndex> p = indexUpdater.update(editedNodeList); - index = p.left(); - parentIndex = p.right(); - } - - /** - * 差分Treeで使う 差分Treeは一度作った木は変更しないのでIndexの中身を削除する必要はない - * なのでputだけで良い - */ - public void updateIndex(TreeNode subTreeRoot) { - IndexUpdater indexUpdater = new IndexUpdater(subTreeRoot,index,parentIndex); - Pair<Index,ParentIndex> p = indexUpdater.update(); - index = p.left(); - parentIndex = p.right(); - } - - public void updateIndex(List<TreeNode> editedNodeList,TreeNode subTreeNode) { - IndexUpdater indexUpdater = new IndexUpdater(subTreeNode,index,parentIndex); - Pair<Index,ParentIndex> p = indexUpdater.update(editedNodeList); - index = p.left(); - parentIndex = p.right(); - } - - private TreeNode nextmatch(TreeNode node, Query query) { - if (query.condition(node)) - return node; - return null; - } - - public Iterator<TreeNode> find(final Query query) { - return find(query, null, null); - } - - public Iterator<TreeNode> find(final Query query, final String key, String searchValue) { - - Iterator<TreeNode> nodeIterator; - if (key != null && searchValue != null && useIndex) { - nodeIterator = index.get(key, searchValue); - ; - } else { - nodeIterator = new JungleNodeIterator(root); - } - - TreeNode firstMatchNode = null; - for (; nodeIterator.hasNext(); ) { - firstMatchNode = nextmatch(nodeIterator.next(), query); - if (firstMatchNode != null) - break; - } - - final TreeNode finalFirstMatchNode = firstMatchNode; - - return new Iterator<TreeNode>() { - - TreeNode matchNode = finalFirstMatchNode; - - @Override - public boolean hasNext() { - if (matchNode == null) { - return false; - } - return true; - } - - @Override - public TreeNode next() { - TreeNode currentPair = matchNode; - for (; nodeIterator.hasNext(); ) { - matchNode = nextmatch(nodeIterator.next(), query); - if (matchNode != null) - return currentPair; - } - matchNode = null; - return currentPair; - } - - @Override - public void remove() { - } - - }; - } -}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/tree/DefaultJungleTree.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/tree/DefaultJungleTree.java Sat Jan 07 18:02:53 2017 +0900 @@ -1,6 +1,7 @@ package jp.ac.u_ryukyu.ie.cr.jungle.tree; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; @@ -12,7 +13,6 @@ import jp.ac.u_ryukyu.ie.cr.jungle.transaction.manager.DefaultTransactionManager; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; 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; @@ -23,10 +23,10 @@ public class DefaultJungleTree implements JungleTree { - private final AtomicReference<TreeContext> repository; - private final String uuid; - private final ChangeListWriter writer; - private final TreeEditor treeEditor; + protected final AtomicReference<TreeContext> repository; + protected final String uuid; + protected final ChangeListWriter writer; + protected final TreeEditor treeEditor; public DefaultJungleTree(TreeContext tc, String uuid, ChangeListWriter writer, TreeEditor editor) { this.repository = new AtomicReference<TreeContext>(tc); @@ -90,6 +90,7 @@ TreeEditor getTreeEditor(){ return treeEditor; } + @Override public InterfaceTraverser getTraverser(boolean useIndex) { TreeContext tc = repository.get();
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/tree/DifferenceListJungleTree.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/tree/DifferenceListJungleTree.java Sat Jan 07 18:02:53 2017 +0900 @@ -10,6 +10,10 @@ import jp.ac.u_ryukyu.ie.cr.jungle.transaction.manager.TransactionManager; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Differencial.DifferencialTreeNode; 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; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.GetOldTreeError; import java.util.concurrent.atomic.AtomicReference; @@ -30,5 +34,25 @@ return new DifferenceJungleTreeEditor(subTreeRoot, txManager, treeEditor); } + @Override + public Either<Error, JungleTree> getOldTree(long revision) { + TreeContext tc = repository.get(); + for (; tc.revision() != revision; ) { + tc = tc.prev(); + if (tc == null) + return DefaultEither.newA(GetOldTreeError.OLD_TREE_NOT_FOUND); + } + + String oldTreeUuid = uuid + revision; + JungleTree oldTree = new DifferenceListJungleTree(tc, oldTreeUuid, writer, treeEditor); + return DefaultEither.newB(oldTree); + } + + //test用 method キャストして使ってね + public TreeNode getEndNode(){ + AtomicReference<TreeContext> repository = super.getRepository(); + TreeContext tc = repository.get(); + return tc.getEndNode(); + } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/tree/JungleTree.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/tree/JungleTree.java Sat Jan 07 18:02:53 2017 +0900 @@ -1,12 +1,12 @@ package jp.ac.u_ryukyu.ie.cr.jungle.tree; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/core/NetworkDefaultJungle.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/core/NetworkDefaultJungle.java Sat Jan 07 18:02:53 2017 +0900 @@ -5,6 +5,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.Journal; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.DefaultTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; @@ -13,7 +14,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Default.DefaultTreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.DefaultInterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; import jp.ac.u_ryukyu.ie.cr.jungleNetwork.transaction.NetworkDefaultJungleTree; @@ -69,7 +70,7 @@ } }; TreeNode root = new DefaultTreeNode(); - InterfaceTraverser traverser = new InterfaceTraverser(root, true); + InterfaceTraverser traverser = new DefaultInterfaceTraverser(root, true); TreeContext tc = new DefaultTreeContext(root, null, list, uuid, name, 0, traverser); JungleTree newTree = new NetworkDefaultJungleTree(name, tc, uuid, journal.getWriter(), editor); if (trees.putIfAbsent(name, newTree) != null) {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungle.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungle.java Sat Jan 07 18:02:53 2017 +0900 @@ -4,6 +4,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.DefaultTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; @@ -11,7 +12,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.treeEditor.TreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Default.DefaultTreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.DefaultInterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; import java.util.Enumeration; @@ -67,7 +68,7 @@ } }; TreeNode root = new DefaultTreeNode(); - InterfaceTraverser traverser = new InterfaceTraverser(root, true); + InterfaceTraverser traverser = new DefaultInterfaceTraverser(root, true); TreeContext tc = new PersistentTreeContext(root, null, list, uuid, name, 0, traverser); JungleTree newTree = new PersistentJungleTree(name, tc, uuid, journal.getWriter(), editor, 0); if (trees.putIfAbsent(name, newTree) != null) {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungleTree.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentJungleTree.java Sat Jan 07 18:02:53 2017 +0900 @@ -3,6 +3,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; @@ -12,7 +13,7 @@ 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.transaction.node.TreeNodeChildren; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.DefaultInterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.tree.DefaultJungleTree; import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; @@ -98,7 +99,7 @@ public InterfaceTraverser getTraverser(boolean useIndex) { Index index = getIndex(); ParentIndex parentIndex = getParentIndex(); - return new InterfaceTraverser(getRootNode(), index, parentIndex, useIndex); + return new DefaultInterfaceTraverser(getRootNode(), index, parentIndex, useIndex); } @Override
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentTransactionManager.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentTransactionManager.java Sat Jan 07 18:02:53 2017 +0900 @@ -3,12 +3,13 @@ import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.DefaultTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; 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.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.DefaultInterfaceTraverser; 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.DefaultError; @@ -44,7 +45,7 @@ else list = new PersistentChangeList(uuid, treeName, _log); - InterfaceTraverser traverser = new InterfaceTraverser(_newRoot, false); + InterfaceTraverser traverser = new DefaultInterfaceTraverser(_newRoot, false); traverser.createIndex(); PersistentTreeContext newContext = new PersistentTreeContext(_newRoot, tip, list, uuid, treeName, nextRevision, traverser); @@ -68,7 +69,7 @@ PersistentChangeList list; list = new PersistentChangeList(uuid, treeName, new DefaultTreeOperationLog()); - InterfaceTraverser traverser = new InterfaceTraverser(_newRoot, false); + InterfaceTraverser traverser = new DefaultInterfaceTraverser(_newRoot, false); traverser.createIndex(); PersistentTreeContext newContext = new PersistentTreeContext(_newRoot, tip, list, uuid, treeName, nextRevision, traverser); if (repository.compareAndSet(newContext.prev(), newContext)) { @@ -83,11 +84,6 @@ } @Override - public boolean setAppendedNode(TreeNode appendedNode) { - return false; // 使わない - } - - @Override public long getRevision() { return tip.revision(); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentTreeContext.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/persistent/PersistentTreeContext.java Sat Jan 07 18:02:53 2017 +0900 @@ -2,12 +2,12 @@ import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; public class PersistentTreeContext implements TreeContext { private final TreeNode root; @@ -35,16 +35,11 @@ } @Override - public TreeNode getAppendedNode() { + public TreeNode getEndNode() { return null; // not use } @Override - public boolean setAppendedNode(TreeNode AppendedNode) { - return false; //使わない - } - - @Override public TreeContext prev() { return previous; }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkDefaultJungleTree.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkDefaultJungleTree.java Sat Jan 07 18:02:53 2017 +0900 @@ -2,6 +2,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; @@ -11,7 +12,7 @@ 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.transaction.node.TreeNodeChildren; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.DefaultInterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.tree.DefaultJungleTree; import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; @@ -102,7 +103,7 @@ public InterfaceTraverser getTraverser(boolean useIndex) { Index index = getIndex(); ParentIndex parentIndex = getParentIndex(); - return new InterfaceTraverser(getRootNode(), index, parentIndex, useIndex); + return new DefaultInterfaceTraverser(getRootNode(), index, parentIndex, useIndex); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkTransactionManager.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/transaction/NetworkTransactionManager.java Sat Jan 07 18:02:53 2017 +0900 @@ -4,13 +4,14 @@ import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeList; import jp.ac.u_ryukyu.ie.cr.jungle.persistent.ChangeListWriter; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.store.TreeContext; import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.TreeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.context.DefaultTreeContext; 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.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.DefaultInterfaceTraverser; 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.DefaultError; @@ -61,7 +62,7 @@ } }; - InterfaceTraverser traverser = new InterfaceTraverser(newRoot, true); + InterfaceTraverser traverser = new DefaultInterfaceTraverser(newRoot, true); traverser.createIndex(); TreeContext newTreeContext = new DefaultTreeContext(newRoot, tip, list, uuid, treeName, nextRevision, traverser); @@ -81,11 +82,6 @@ } @Override - public boolean setAppendedNode(TreeNode appendedNode) { - return false; //使わない - } - - @Override public long getRevision() { return tip.revision(); }
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/CreateTreeMethod.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/CreateTreeMethod.java Sat Jan 07 18:02:53 2017 +0900 @@ -13,6 +13,11 @@ */ public class CreateTreeMethod { + /** + * Jungleの木を構築する関数 + * maxHeightで指定した深さまで木を構築する + * ノードは3つの子を持つ + */ public static JungleTreeEditor createTree(JungleTreeEditor editor, String key, String indexKey, int _maxHeight, NodePath path) { JungleTreeEditor newEditor = createTree(editor, key, indexKey, 0, _maxHeight, path); Either<Error,JungleTreeEditor> either = newEditor.success();
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/GetNodeOfPathTest.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/GetNodeOfPathTest.java Sat Jan 07 18:02:53 2017 +0900 @@ -2,11 +2,11 @@ import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; 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.transaction.editor.jungleTreeEditor.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; import junit.framework.Assert; import org.junit.Test;
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/RedBlack/RedBlackTreeEditorNodeTest.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/RedBlack/RedBlackTreeEditorNodeTest.java Sat Jan 07 18:02:53 2017 +0900 @@ -3,7 +3,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; import jp.ac.u_ryukyu.ie.cr.jungle.core.Attributes; -import jp.ac.u_ryukyu.ie.cr.jungle.query.JungleNodeIterator; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.nodeiterator.DefaultNodeIterator; 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.transaction.editor.jungleTreeEditor.JungleTreeEditor; @@ -42,7 +42,7 @@ Assert.assertFalse(either.isA()); TreeNode rootNode = tree.getRootNode(); - JungleNodeIterator iterator = new JungleNodeIterator(rootNode); + DefaultNodeIterator iterator = new DefaultNodeIterator(rootNode); int nodeCount = 0; List<String> list = new LinkedList<>(); for (int i = 1; i <= count; i++) { @@ -78,7 +78,7 @@ Assert.assertFalse(either.isA()); ColorlessTreeNode rootNode = (ColorlessTreeNode) tree.getRootNode(); - Iterator<TreeNode> iterator = new JungleNodeIterator(rootNode); + Iterator<TreeNode> iterator = new DefaultNodeIterator(rootNode); int nodeCount = 0; while (iterator.hasNext() && rootNode.getAttributes().get(key) != null) { //削除時間違えて他のノードを消してないかを調べる
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/impl/defaultnode/GetNodePath.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/impl/defaultnode/GetNodePath.java Sat Jan 07 18:02:53 2017 +0900 @@ -3,13 +3,13 @@ import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; -import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; 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.nodepath.NodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.Default.DefaultTreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error;
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/index/defaultTree/IndexTest.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/index/defaultTree/IndexTest.java Sat Jan 07 18:02:53 2017 +0900 @@ -4,7 +4,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; import jp.ac.u_ryukyu.ie.cr.jungle.core.Children; import jp.ac.u_ryukyu.ie.cr.jungle.data.treemap.TreeMap; -import jp.ac.u_ryukyu.ie.cr.jungle.query.JungleNodeIterator; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.nodeiterator.DefaultNodeIterator; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.Index; import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; @@ -42,7 +42,7 @@ createTree(editor, key, indexKey, 4, path); TreeNode oldTreeRoot = tree.getRootNode(); Index index = tree.getIndex(); - JungleNodeIterator iterator = new JungleNodeIterator(oldTreeRoot); + DefaultNodeIterator iterator = new DefaultNodeIterator(oldTreeRoot); while (iterator.hasNext()) { TreeNode node = iterator.next(); TreeNodeAttributes attribute = node.getAttributes(); @@ -71,7 +71,7 @@ TreeNode newTreeRoot = tree.getRootNode(); Index newIndex = tree.getIndex(); - iterator = new JungleNodeIterator(newTreeRoot); + iterator = new DefaultNodeIterator(newTreeRoot); while (iterator.hasNext()) { //木を編集した際に差分でIndexがアップデートされているかを調べる TreeNode node = iterator.next(); TreeNodeAttributes attribute = node.getAttributes();
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/index/defaultTree/ParentIndexPutTest.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/index/defaultTree/ParentIndexPutTest.java Sat Jan 07 18:02:53 2017 +0900 @@ -3,7 +3,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; import jp.ac.u_ryukyu.ie.cr.jungle.core.Children; -import jp.ac.u_ryukyu.ie.cr.jungle.query.JungleNodeIterator; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.nodeiterator.DefaultNodeIterator; import jp.ac.u_ryukyu.ie.cr.jungle.store.index.ParentIndex; import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; @@ -41,7 +41,7 @@ createTree(editor,key,indexKey,3,path); TreeNode oldTreeRoot = tree.getRootNode(); ParentIndex parentIndex = tree.getParentIndex(); - JungleNodeIterator iterator = new JungleNodeIterator(oldTreeRoot); + DefaultNodeIterator iterator = new DefaultNodeIterator(oldTreeRoot); while(iterator.hasNext()){ TreeNode parent = iterator.next(); Children children = parent.getChildren(); @@ -68,7 +68,7 @@ TreeNode newTreeRoot = tree.getRootNode(); ParentIndex newTreeParentIndex = tree.getParentIndex(); - iterator = new JungleNodeIterator(newTreeRoot); + iterator = new DefaultNodeIterator(newTreeRoot); while(iterator.hasNext()){ TreeNode parent = iterator.next(); Children children = parent.getChildren();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/traverse/DefaultInterfaceTraverserTest.java Sat Jan 07 18:02:53 2017 +0900 @@ -0,0 +1,81 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.traverse; + +import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.NullJournal; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; +import junit.framework.Assert; +import org.junit.Test; + +import java.util.Iterator; + +import static jp.ac.u_ryukyu.ie.cr.jungle.CreateTreeMethod.createTree; + + +public class DefaultInterfaceTraverserTest { + public static String key = "KEY"; + public static String indexKey = "INDEXKEY"; + @Test + public void InterfaseTraverserTest() { + Jungle jungle = new DefaultJungle(new NullJournal(), "hoge", new DefaultTraverser()); + jungle.createNewTree("TestTree"); + JungleTree tree = jungle.getTreeByName("TestTree"); + JungleTreeEditor editor = tree.getJungleTreeEditor(); + editor = createTree(editor,key,indexKey, 3, new DefaultNodePath()); + InterfaceTraverser traverser = tree.getTraverser(true); + + { + Iterator<TreeNode> iterator = traverser.find((TreeNode node) -> { // no index find + String value = node.getAttributes().getString(key); + if (value == null) + return false; + if (value.equals("<-1,1,1>")) + return true; + return false; + }, null, null); + + Assert.assertTrue(iterator.hasNext()); + TreeNode node = iterator.next(); + String value = node.getAttributes().getString("KEY"); + Assert.assertEquals("<-1,1,1>", value); + } + + + { + Iterator<TreeNode> iterator = traverser.find((TreeNode node) -> { // no index find + String value = node.getAttributes().getString(key); + if (value == null) + return false; + if (value.equals("no exist value")) + return true; + return false; + }, null, null); + + Assert.assertFalse(iterator.hasNext()); + } + + { + Iterator<TreeNode> iterator = traverser.find((TreeNode node) -> { // use index find + return true; + }, indexKey, "<-1,1,1>"); + + Assert.assertTrue(iterator.hasNext()); + TreeNode node = iterator.next(); + String value = node.getAttributes().getString("KEY"); + Assert.assertEquals("<-1,1,1>", value); + } + + { + Iterator<TreeNode> iterator = traverser.find((TreeNode node) -> { // use index find + return true; + }, indexKey, "no exist index value"); + + Assert.assertFalse(iterator.hasNext()); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/traverse/DifferentialInterfaceTraverserTest.java Sat Jan 07 18:02:53 2017 +0900 @@ -0,0 +1,166 @@ +package jp.ac.u_ryukyu.ie.cr.jungle.traverse; + +import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.jungle.persistent.NullJournal; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.InterfaceTraverser; +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.transaction.editor.jungleTreeEditor.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.jungle.tree.DifferenceListJungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; +import org.junit.Assert; +import org.junit.Test; + +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +/** + * Created by e115731 on 2017/01/07. + */ +public class DifferentialInterfaceTraverserTest { + + //3種類の木のTraverseについて調べる + @Test + public void DifferentialInterfaceTraverserTests1() { + String key = "key"; + String indexKey = "indexKey"; + Jungle jungle = new DefaultJungle(new NullJournal(), "hoge", new DefaultTraverser()); + + List<Integer> list = Arrays.asList(0,1,2); + test(key,indexKey,jungle,list,2); + + /* + + root + | + ○ + | + ------- + | | | + ○ ○ ● + | + ○ + | + ------- + | | | + ○ ○ ○ + 上記の形の木ができる + ●はrevision1の木のEndNode + revision1の木の探索において、ここでInterfaceTraverserの探索が止まるかを調べる + */ + + list = Arrays.asList(0,1,0); + test(key,indexKey,jungle,list,0); + + /* + + root + | + ○ + | + ------- + | | | + ● ○ ○ + | + ○ + | + ------- + | | | + ○ ○ ○ + 上記の形の木ができる + ●はrevision1の木のEndNode + revision1の木の探索において、ここでInterfaceTraverserの探索が止まるかを調べる + */ + + list = Arrays.asList(0,0,1); + test(key,indexKey,jungle,list,1); + + /* + + root + | + ○ + | + ------- + | | | + ○ ● ○ + | + ○ + | + ------- + | | | + ○ ○ ○ + 上記の形の木ができる + ●はrevision1の木のEndNode + revision1の木の探索において、ここでInterfaceTraverserの探索が止まるかを調べる + */ + // test2Left(key, indexKey, jungle); + } + + private void test(String key, String indexKey, Jungle jungle,List<Integer> nodeInsertOrder, int endNodePosition) { + jungle.createNewDifferenceTree("TestTree" + endNodePosition); + JungleTree tree = jungle.getTreeByName("TestTree" + endNodePosition); + JungleTreeEditor editor = tree.getJungleTreeEditor(); + NodePath path = new DefaultNodePath(); + for (int position : nodeInsertOrder) { + editor = addNode(key, indexKey, editor, path, position); + } + Either<Error, JungleTreeEditor> either = editor.success(); + if (either.isA()) + junit.framework.Assert.fail(); + + editor = tree.getJungleTreeEditor(); + for (int position : nodeInsertOrder) { + editor = addNode(key, indexKey, editor, path, position); + } + either = editor.success(); + if (either.isA()) + junit.framework.Assert.fail(); + + + + DifferenceListJungleTree oldTree = (DifferenceListJungleTree)tree.getOldTree(1).b(); //1つ前の木を取得する + TreeNode endNode = oldTree.getEndNode(); + TreeNode oldRoot = oldTree.getRootNode(); + TreeNode child = oldRoot.getChildren().at(0).b().getChildren().at(endNodePosition).b(); //黒丸の位置のノードを取得している + Assert.assertEquals(endNode,child); //指定した場所がちゃんとendノードになっているかを調べている + InterfaceTraverser traverser = oldTree.getTraverser(false); //Indexを使ってはいけない。Indexには過去の木が入っているためである + Iterator<TreeNode> iterator = traverser.find((TreeNode node) -> { + return true; //返ってくるノードの数を調べたいのでここはreturn trueで良い; + }); + + int nodeCount = 0; + while (iterator.hasNext()) { + iterator.next(); + nodeCount++; + } + int expectCount = 5; //前の木のノード数 + Assert.assertEquals(expectCount, nodeCount); + } + + + private JungleTreeEditor addNode(String key, String indexKey, JungleTreeEditor editor, NodePath path, int i) { + Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path, i); + if (either.isA()) + junit.framework.Assert.fail(); + editor = either.b(); + String value = path.add(i).toString(); + either = editor.putAttribute(path.add(i), key, ByteBuffer.wrap(value.getBytes())); + if (either.isA()) + junit.framework.Assert.fail(); + editor = either.b(); + either = editor.putAttribute(path.add(i), indexKey, ByteBuffer.wrap(value.getBytes())); + if (either.isA()) + junit.framework.Assert.fail(); + editor = either.b(); + return editor; + } + +}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/traverse/InterfaceTraverserTest.java Thu Jan 05 22:44:35 2017 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -package jp.ac.u_ryukyu.ie.cr.jungle.traverse; - -import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; -import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; -import jp.ac.u_ryukyu.ie.cr.jungle.persistent.NullJournal; -import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.jungle.traverser.InterfaceTraverser; -import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree; -import junit.framework.Assert; -import org.junit.Test; - -import java.util.Iterator; - -import static jp.ac.u_ryukyu.ie.cr.jungle.CreateTreeMethod.createTree; - -/** - * Created by e115731 on 15/08/11. - */ -public class InterfaceTraverserTest { - public static String key = "KEY"; - public static String indexKey = "INDEXKEY"; - @Test - public void InterfaseTraverserTest() { - Jungle jungle = new DefaultJungle(new NullJournal(), "hoge", new DefaultTraverser()); - jungle.createNewTree("TestTree"); - JungleTree tree = jungle.getTreeByName("TestTree"); - JungleTreeEditor editor = tree.getJungleTreeEditor(); - editor = createTree(editor,key,indexKey, 3, new DefaultNodePath()); - InterfaceTraverser traverser = tree.getTraverser(true); - - { - Iterator<TreeNode> iterator = traverser.find((TreeNode node) -> { // no index find - String value = node.getAttributes().getString(key); - if (value == null) - return false; - if (value.equals("<-1,1,1>")) - return true; - return false; - }, null, null); - - Assert.assertTrue(iterator.hasNext()); - TreeNode node = iterator.next(); - String value = node.getAttributes().getString("KEY"); - Assert.assertEquals("<-1,1,1>", value); - } - - { - Iterator<TreeNode> iterator = traverser.find((TreeNode node) -> { // no index find - String value = node.getAttributes().getString(key); - if (value == null) - return false; - if (value.equals("no exist value")) - return true; - return false; - }, null, null); - - Assert.assertFalse(iterator.hasNext()); - } - - { - Iterator<TreeNode> iterator = traverser.find((TreeNode node) -> { // use index find - return true; - }, indexKey, "<-1,1,1>"); - - Assert.assertTrue(iterator.hasNext()); - TreeNode node = iterator.next(); - String value = node.getAttributes().getString("KEY"); - Assert.assertEquals("<-1,1,1>", value); - } - - { - Iterator<TreeNode> iterator = traverser.find((TreeNode node) -> { // use index find - return true; - }, indexKey, "no exist index value"); - - Assert.assertFalse(iterator.hasNext()); - } - } -}
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/tree/JungleTreeCreaterTest.java Thu Jan 05 22:44:35 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/tree/JungleTreeCreaterTest.java Sat Jan 07 18:02:53 2017 +0900 @@ -3,7 +3,7 @@ import jp.ac.u_ryukyu.ie.cr.benchMark.JungleTreeCreater; import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle; import jp.ac.u_ryukyu.ie.cr.jungle.Jungle; -import jp.ac.u_ryukyu.ie.cr.jungle.query.JungleNodeIterator; +import jp.ac.u_ryukyu.ie.cr.jungle.query.traverser.nodeiterator.DefaultNodeIterator; 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.transaction.editor.jungleTreeEditor.JungleTreeEditor; @@ -27,7 +27,7 @@ JungleTreeCreater creater = new JungleTreeCreater(maxNodeCount); editor = creater.createTree(editor, key, indexKey, path); TreeNode root = tree.getRootNode(); - JungleNodeIterator iterator = new JungleNodeIterator(root); + DefaultNodeIterator iterator = new DefaultNodeIterator(root); int nodeCount = 0; while (iterator.hasNext()) { iterator.next();