Mercurial > hg > Members > tatsuki > bench > jungle-core
changeset 138:b998fdc99bc0
add NodePathCompare and Test
author | one |
---|---|
date | Mon, 27 Oct 2014 19:04:59 +0900 |
parents | 7334f78a92c3 |
children | ec166c8ff079 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/NodePath.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultNodePath.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/clonable/NodePathCompareTest.java |
diffstat | 4 files changed, 46 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/NodePath.java Mon Oct 27 18:25:32 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/NodePath.java Mon Oct 27 19:04:59 2014 +0900 @@ -9,4 +9,5 @@ public NodePath tail(); public int size(); public Pair<Integer,NodePath> last(); + public boolean compare(NodePath path); }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultNodePath.java Mon Oct 27 18:25:32 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/DefaultNodePath.java Mon Oct 27 19:04:59 2014 +0900 @@ -94,4 +94,19 @@ tail = tail.tail().reverse(); return new DefaultNodePath(tail); } + + @Override + public boolean compare(NodePath targetPath) { + + if (targetPath.size() < path.length()) + return false; + + for (Integer currentNum : path) { + Pair<Integer, NodePath> currentTargetPathNumPair = targetPath.pop(); + targetPath = currentTargetPathNumPair.right(); + if (currentNum != currentTargetPathNumPair.left()) + return false; + } + return true; + } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java Mon Oct 27 18:25:32 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/transaction/IndexJungleTreeEditor.java Mon Oct 27 19:04:59 2014 +0900 @@ -25,7 +25,6 @@ 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.index.AddChildrenIndexTest; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.AddNewChildrenIndexEditor; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.DefaultIndexEditor; import jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.store.index.DeleteChildIndexEditor;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/clonable/NodePathCompareTest.java Mon Oct 27 19:04:59 2014 +0900 @@ -0,0 +1,30 @@ +package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.impl.clonable; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; +import junit.framework.Assert; + +import org.junit.Test; + +public class NodePathCompareTest { + + @Test + public void NodePathCompare(){ + NodePath path = new DefaultNodePath(); + path = path.add(0).add(1).add(2); + System.out.println(path.toString()); + + NodePath comparePath1 = new DefaultNodePath(); + comparePath1 = comparePath1.add(0).add(1).add(2).add(3); + + NodePath comparePath2 = new DefaultNodePath(); + comparePath2 = comparePath2.add(0).add(1); + + NodePath comparePath3 = new DefaultNodePath(); + comparePath3 = comparePath3.add(1).add(1).add(2).add(3); + + Assert.assertTrue(path.compare(comparePath1)); + Assert.assertFalse(path.compare(comparePath2)); + Assert.assertFalse(path.compare(comparePath3)); + } +}