# HG changeset patch
# User tatsuki
# Date 1485441854 -32400
# Node ID 474728dcfdb8c20e9566fbe01f2fbc1366eff90b
# Parent f8e75ef7ac5d23e9ced02f8c8d75caf79eba6396
add PathType
diff -r f8e75ef7ac5d -r 474728dcfdb8 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/DefaultNodePath.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/DefaultNodePath.java Thu Jan 26 16:19:51 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/DefaultNodePath.java Thu Jan 26 23:44:14 2017 +0900
@@ -122,4 +122,10 @@
return PathType.Default;
}
+ @Override // Defultでは今の所使わない
+ public NodePath setType(PathType type) {
+ return null;
+ }
+
+
}
diff -r f8e75ef7ac5d -r 474728dcfdb8 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/NodePath.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/NodePath.java Thu Jan 26 16:19:51 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/NodePath.java Thu Jan 26 23:44:14 2017 +0900
@@ -16,4 +16,5 @@
public String getKey();
public ByteBuffer getValue();
public PathType getPathType();
+ public NodePath setType(PathType type);
}
diff -r f8e75ef7ac5d -r 474728dcfdb8 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/PathType.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/PathType.java Thu Jan 26 16:19:51 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/PathType.java Thu Jan 26 23:44:14 2017 +0900
@@ -1,5 +1,5 @@
package jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath;
public enum PathType {
- Default,RedBlack
+ Default,RedBlack,RedBlackNode,RedBlackAttribute
}
diff -r f8e75ef7ac5d -r 474728dcfdb8 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/RedBlackTreeNodePath.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/RedBlackTreeNodePath.java Thu Jan 26 16:19:51 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/nodepath/RedBlackTreeNodePath.java Thu Jan 26 23:44:14 2017 +0900
@@ -11,36 +11,24 @@
private final String key;
private final ByteBuffer value;
- /**
- * traverserを使うかどうかのフラグ
- * -2だった場合Traverserを使わない
- * 主にノードの追加、削除等回転処理が行われる処理の場合に使う
- *
- * それ以外の値だった場合Traverserを使う
- * Attribute関係とか
- * intの理由はgetで受け取れるから
- *
- * flagはaddでセットする
- * ココらへんは後でちゃんと直す
- */
- private int flags;
+ private final PathType type;
public RedBlackTreeNodePath() {
this.key = "default";
this.value = ByteBuffer.wrap("default".getBytes());
- this.flags = -2;
+ this.type = PathType.RedBlack;
}
public RedBlackTreeNodePath(String key, ByteBuffer value) {
this.key = key;
this.value = value;
- this.flags = -2;
+ this.type = PathType.RedBlack;
}
- private RedBlackTreeNodePath(String key, ByteBuffer value, int flags) {
+ private RedBlackTreeNodePath(String key, ByteBuffer value, PathType type) {
this.key = key;
this.value = value;
- this.flags = flags;
+ this.type = type;
}
@Override
@@ -55,7 +43,12 @@
@Override
public PathType getPathType() {
- return PathType.RedBlack;
+ return type;
+ }
+
+ @Override
+ public NodePath setType(PathType type) {
+ return new RedBlackTreeNodePath(this.getKey(), this.getValue(), type);
}
//以下使わない
@@ -66,12 +59,12 @@
@Override
public int get(int index) {
- return flags;
+ return -2;
}
@Override
public NodePath add(int pos) {
- return new RedBlackTreeNodePath(key, value, pos);
+ return null;
}
@Override
diff -r f8e75ef7ac5d -r 474728dcfdb8 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/RedBlackJungleTreeEditor.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/RedBlackJungleTreeEditor.java Thu Jan 26 16:19:51 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/RedBlackJungleTreeEditor.java Thu Jan 26 23:44:14 2017 +0900
@@ -23,6 +23,7 @@
import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.JungleTreeError.INVALID_ARGUMENT;
import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.JungleTreeError.NOT_USE_METHOD;
+import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.TreeEditorError.UNDEFINE_NODEPATH;
public class RedBlackJungleTreeEditor implements JungleTreeEditor {
@@ -81,43 +82,55 @@
*/
@Override
public Either addNewChildAndPutAttribute(NodePath path, int pos, String key, ByteBuffer value) {
+ if (path.getPathType() != PathType.RedBlack)
+ return DefaultEither.newA(UNDEFINE_NODEPATH);
AppendChildAndPutAttribute appendChildAndPutAttribute = new AppendChildAndPutAttribute(key, value, pos);
- return _edit(path, appendChildAndPutAttribute);
+ NodePath newParh = path.setType(PathType.RedBlackNode); //回転処理を行わないで木の複製を行う設定のPathに変えている… ダサい…
+ return _edit(newParh, appendChildAndPutAttribute);
}
@Override
public Either addNewChildAt(NodePath path, int _pos) {
+ if (path.getPathType() != PathType.RedBlack)
+ return DefaultEither.newA(UNDEFINE_NODEPATH);
ByteBuffer value = ByteBuffer.wrap("defaultValue".getBytes());
return addNewChildAndPutAttribute(path, 0, balanceKey, value);
}
@Override
public Either deleteChildAt(NodePath path, int pos) {
+ if (path.getPathType() != PathType.RedBlack)
+ return DefaultEither.newA(UNDEFINE_NODEPATH);
String key = path.getKey();
if (!key.equals(balanceKey))
return DefaultEither.newA(INVALID_ARGUMENT);
+ NodePath newParh = path.setType(PathType.RedBlackNode); //回転処理を行わないで木の複製を行う設定のPathに変えている… ダサい…
ByteBuffer value = path.getValue();
RedBlackTreeDeleteChildAt deleteChildAt = new RedBlackTreeDeleteChildAt(key, value);
- return _edit(path, deleteChildAt);
+ return _edit(newParh, deleteChildAt);
}
@Override
public Either putAttribute(NodePath path, String key, ByteBuffer value) {
+ if (path.getPathType() != PathType.RedBlack)
+ return DefaultEither.newA(UNDEFINE_NODEPATH);
if (key.equals(balanceKey))
return DefaultEither.newA(INVALID_ARGUMENT);
if (path.getPathType() != PathType.RedBlack)
return DefaultEither.newA(INVALID_ARGUMENT);
NodeEditor editor = new PutAttribute(key, value);
- NodePath newParh = path.add(-1); //回転処理を行わないで木の複製を行う設定のPathに変えている… ダサい…
+ NodePath newParh = path.setType(PathType.RedBlackAttribute); //回転処理を行わないで木の複製を行う設定のPathに変えている… ダサい…
return _edit(newParh, editor);
}
@Override
public Either deleteAttribute(NodePath path, String _key) {
+ if (path.getPathType() != PathType.RedBlack)
+ return DefaultEither.newA(UNDEFINE_NODEPATH);
if (_key.equals(balanceKey))
return DefaultEither.newA(INVALID_ARGUMENT);
DeleteAttribute deleteAttribute = new DeleteAttribute(_key);
- NodePath newParh = path.add(-1); //回転処理を行わないで木の複製を行う設定のPathに変えている… ダサい…
+ NodePath newParh = path.setType(PathType.RedBlackAttribute); //回転処理を行わないで木の複製を行う設定のPathに変えている… ダサい…
return _edit(newParh, deleteAttribute);
}
diff -r f8e75ef7ac5d -r 474728dcfdb8 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/treeEditor/RedBlackTreeEditor.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/treeEditor/RedBlackTreeEditor.java Thu Jan 26 16:19:51 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/treeEditor/RedBlackTreeEditor.java Thu Jan 26 23:44:14 2017 +0900
@@ -3,6 +3,7 @@
import jp.ac.u_ryukyu.ie.cr.jungle.data.list.List;
import jp.ac.u_ryukyu.ie.cr.jungle.store.logger.LoggingNode;
import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath;
+import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.PathType;
import jp.ac.u_ryukyu.ie.cr.jungle.store.trasnformer.NodeEditor;
import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode;
import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNodeChildren;
@@ -24,7 +25,7 @@
@Override
public Either edit(TreeNode root, NodePath path, NodeEditor editor) {
- if (path.get(0) == -2)
+ if (path.getPathType() == PathType.RedBlackNode)
return redBlackTreeNodeEdit(root, editor);
Evaluator e = new RedBlackTreeEvaluator(path);
Either traverseEither = traverser.traverse(root, e);
diff -r f8e75ef7ac5d -r 474728dcfdb8 src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/util/Error/TreeEditorError.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/util/Error/TreeEditorError.java Thu Jan 26 16:19:51 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/util/Error/TreeEditorError.java Thu Jan 26 23:44:14 2017 +0900
@@ -3,6 +3,7 @@
public class TreeEditorError
{
public static final Error NODEPATH_NOTFOUND = new DefaultError();
+ public static final Error UNDEFINE_NODEPATH = new DefaultError();
public static final Error NOT_USE_METHOD = new DefaultError();
public static final Error ADD_NEW_CHILD_ERROR = new DefaultError();
public static final Error UNDEFINENODE_PARENT_NOT_FOUND = new DefaultError();
@@ -11,3 +12,4 @@
public static final Error SET_APPENDEDNODE_ERROR= new DefaultError();
public static final Error DELETE_VALUE_NOT_FOUND = new DefaultError();
}
+
diff -r f8e75ef7ac5d -r 474728dcfdb8 src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/operations/NetworkNodePath.java
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/operations/NetworkNodePath.java Thu Jan 26 16:19:51 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungleNetwork/operations/NetworkNodePath.java Thu Jan 26 23:44:14 2017 +0900
@@ -13,10 +13,12 @@
@Message
public class NetworkNodePath implements NodePath {
LinkedList path;
+ PathType type;
public NetworkNodePath() {
path = new LinkedList();
path.add(-1);
+ type = PathType.Default;
}
public NetworkNodePath(NodePath _p) {
@@ -24,6 +26,15 @@
for (Integer pos : _p) {
path.add(pos);
}
+ type = _p.getPathType();
+ }
+
+ public NetworkNodePath(NodePath _p, PathType type) {
+ path = new LinkedList();
+ for (Integer pos : _p) {
+ path.add(pos);
+ }
+ this.type = type;
}
private NetworkNodePath(LinkedList _path) {
@@ -107,4 +118,9 @@
public PathType getPathType() {
return PathType.Default;
}
+
+ @Override //ネットワークでは今のところ使わない
+ public NodePath setType(PathType type) {
+ return null;
+ }
}
diff -r f8e75ef7ac5d -r 474728dcfdb8 src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/RedBlack/RedBlackTreeEditorAttributeTest.java
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/RedBlack/RedBlackTreeEditorAttributeTest.java Thu Jan 26 16:19:51 2017 +0900
+++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/RedBlack/RedBlackTreeEditorAttributeTest.java Thu Jan 26 23:44:14 2017 +0900
@@ -38,7 +38,6 @@
}
JungleTreeEditor editor = tree.getJungleTreeEditor();
- path = path.add(1);
NodePath rbtPath = new RedBlackTreeNodePath(balanceKey,ByteBuffer.wrap(("value6".getBytes())));
Either either = editor.putAttribute(rbtPath, key, testPutValue);
Assert.assertFalse(either.isA()); //AttributeのPutが成功したかどうか調べる
@@ -51,8 +50,7 @@
TreeNode attributePutedTreeRoot = tree.getRootNode();
Assert.assertNotEquals(attributePutedTreeRoot,oldRoot);//// とりあえずルートがちゃんと入れ替えられているかを調べる
-
- TreeNode editedNode = tree.getNodeOfPath(path).b();
+
InterfaceTraverser traverser = tree.getTraverser(true);
Iterator nodeIterator = traverser.find((TreeNode n) -> {
Attributes attributes = n.getAttributes();