Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 324:a0bcbc9a1a46
null attribute case in RedBlackJungleTree
author | suruga |
---|---|
date | Thu, 13 Apr 2017 20:55:21 +0900 |
parents | c788d2c2881f |
children | abd8e3cf9bfc |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/EmptyNode.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/TreeMap.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/PathType.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/traverser/RedBlackTreeEvaluator.java src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/impl/redblacktreenode/GetKeysTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/impl/redblacktreenode/GetfilteringKeyTest.java src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/traverse/RedBlackInterfaceTraverserTest.java |
diffstat | 7 files changed, 25 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/EmptyNode.java Thu Apr 13 19:16:59 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/EmptyNode.java Thu Apr 13 20:55:21 2017 +0900 @@ -73,7 +73,7 @@ protected int checkDepth(int count, int minCount) { // test method if (count < minCount | minCount == 0) minCount = count; - System.out.println("depth = " + count); + //System.out.println("depth = " + count); Assert.assertTrue(count <= 2 * minCount); return minCount;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/TreeMap.java Thu Apr 13 19:16:59 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/data/treemap/TreeMap.java Thu Apr 13 20:55:21 2017 +0900 @@ -110,6 +110,6 @@ @Test public void checkDepth() { root.checkDepth(0, 0); - System.out.println("-----------------------------------"); + //System.out.println("-----------------------------------"); } }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/PathType.java Thu Apr 13 19:16:59 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/PathType.java Thu Apr 13 20:55:21 2017 +0900 @@ -1,5 +1,9 @@ package jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath; + +import org.msgpack.annotation.OrdinalEnum; + +@OrdinalEnum public enum PathType { Default,RedBlack,RedBlackNode,RedBlackAttribute }
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/traverser/RedBlackTreeEvaluator.java Thu Apr 13 19:16:59 2017 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/traverser/RedBlackTreeEvaluator.java Thu Apr 13 20:55:21 2017 +0900 @@ -4,6 +4,8 @@ import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; +import java.nio.ByteBuffer; + /** * Created by e115731 on 2017/01/26. */ @@ -24,7 +26,11 @@ @Override public Evaluation evaluate(TreeNode current, int pos) { Attributes attribute = current.getAttributes(); - long value = attribute.get(key).hashCode(); + ByteBuffer k = attribute.get(key); + if (k == null) { + return new DefaultEvaluation(Result.GOAL, null); + } + long value = k.hashCode(); Result result = null; Evaluator nextEvaluator = null;
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/impl/redblacktreenode/GetKeysTest.java Thu Apr 13 19:16:59 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/impl/redblacktreenode/GetKeysTest.java Thu Apr 13 20:55:21 2017 +0900 @@ -5,6 +5,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.core.Attributes; 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.RedBlackTreeNodePath; 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.tree.JungleTree; @@ -32,7 +33,7 @@ } Jungle jungle = new DefaultJungle(null, "hogehoge"); JungleTree tree = jungle.createNewRedBlackTree("TreeName", "balanceKey"); - NodePath path = new DefaultNodePath(); + NodePath path = new RedBlackTreeNodePath(balanceKey, ByteBuffer.wrap(("value").getBytes())); JungleTreeEditor editor = tree.getJungleTreeEditor(); ByteBuffer value = ByteBuffer.wrap(("value").getBytes());
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/impl/redblacktreenode/GetfilteringKeyTest.java Thu Apr 13 19:16:59 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/impl/redblacktreenode/GetfilteringKeyTest.java Thu Apr 13 20:55:21 2017 +0900 @@ -5,6 +5,7 @@ import jp.ac.u_ryukyu.ie.cr.jungle.core.Attributes; 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.RedBlackTreeNodePath; 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.tree.JungleTree; @@ -39,7 +40,7 @@ Jungle jungle = new DefaultJungle(null, "hogehoge"); JungleTree tree = jungle.createNewRedBlackTree("TreeName", "balanceKey"); - NodePath path = new DefaultNodePath(); + NodePath path = new RedBlackTreeNodePath(balanceKey, ByteBuffer.wrap(("value").getBytes())); JungleTreeEditor editor = tree.getJungleTreeEditor(); ByteBuffer value = ByteBuffer.wrap(("value").getBytes());
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/traverse/RedBlackInterfaceTraverserTest.java Thu Apr 13 19:16:59 2017 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/traverse/RedBlackInterfaceTraverserTest.java Thu Apr 13 20:55:21 2017 +0900 @@ -6,6 +6,7 @@ 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.RedBlackTreeNodePath; 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.tree.JungleTree; @@ -17,6 +18,9 @@ import java.nio.ByteBuffer; import java.util.Iterator; +import static junit.framework.TestCase.assertFalse; +import static org.junit.Assert.assertTrue; + public class RedBlackInterfaceTraverserTest { private String balanceKey = "key"; @@ -26,19 +30,19 @@ jungle.createNewRedBlackTree("RedBlackTree", balanceKey); JungleTree tree = jungle.getTreeByName("RedBlackTree"); JungleTreeEditor editor = tree.getJungleTreeEditor(); - NodePath path = new DefaultNodePath(); for (int nodeCount = 0; nodeCount < 100; nodeCount++) { ByteBuffer value = ByteBuffer.wrap(("value" + nodeCount).getBytes()); + NodePath path = new RedBlackTreeNodePath(balanceKey, value); Either<Error,JungleTreeEditor> either = editor.addNewChildAndPutAttribute(path, 0, balanceKey, value); - Assert.assertFalse(either.isA()); + assertFalse(either.isA()); editor = either.b(); } Either<Error,JungleTreeEditor> either = editor.success(); - Assert.assertFalse(either.isA()); + assertFalse(either.isA()); InterfaceTraverser traverser = tree.getTraverser(true); Iterator<TreeNode> iterator = traverser.find((TreeNode node) -> { return true; },balanceKey,"value5"); - Assert.assertTrue(iterator.hasNext()); + assertTrue(iterator.hasNext()); } }