Mercurial > hg > Members > shoshi > jungle > jungle-core
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/editor/jungleTreeEditor/RedBlackJungleTreeEditor.java @ 310:474728dcfdb8
add PathType
author | tatsuki |
---|---|
date | Thu, 26 Jan 2017 23:44:14 +0900 |
parents | f8e75ef7ac5d |
children | 5b9a3bc593a7 |
comparison
equal
deleted
inserted
replaced
309:f8e75ef7ac5d | 310:474728dcfdb8 |
---|---|
21 | 21 |
22 import java.nio.ByteBuffer; | 22 import java.nio.ByteBuffer; |
23 | 23 |
24 import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.JungleTreeError.INVALID_ARGUMENT; | 24 import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.JungleTreeError.INVALID_ARGUMENT; |
25 import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.JungleTreeError.NOT_USE_METHOD; | 25 import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.JungleTreeError.NOT_USE_METHOD; |
26 import static jp.ac.u_ryukyu.ie.cr.jungle.util.Error.TreeEditorError.UNDEFINE_NODEPATH; | |
26 | 27 |
27 | 28 |
28 public class RedBlackJungleTreeEditor implements JungleTreeEditor { | 29 public class RedBlackJungleTreeEditor implements JungleTreeEditor { |
29 private final TransactionManager txManager; | 30 private final TransactionManager txManager; |
30 private final TreeNode root; | 31 private final TreeNode root; |
79 * Pathは無視する | 80 * Pathは無視する |
80 * Pathがあるのはインターフェスで定義されているmethodに合わせるため | 81 * Pathがあるのはインターフェスで定義されているmethodに合わせるため |
81 */ | 82 */ |
82 @Override | 83 @Override |
83 public Either<Error, JungleTreeEditor> addNewChildAndPutAttribute(NodePath path, int pos, String key, ByteBuffer value) { | 84 public Either<Error, JungleTreeEditor> addNewChildAndPutAttribute(NodePath path, int pos, String key, ByteBuffer value) { |
85 if (path.getPathType() != PathType.RedBlack) | |
86 return DefaultEither.newA(UNDEFINE_NODEPATH); | |
84 AppendChildAndPutAttribute appendChildAndPutAttribute = new AppendChildAndPutAttribute(key, value, pos); | 87 AppendChildAndPutAttribute appendChildAndPutAttribute = new AppendChildAndPutAttribute(key, value, pos); |
85 return _edit(path, appendChildAndPutAttribute); | 88 NodePath newParh = path.setType(PathType.RedBlackNode); //回転処理を行わないで木の複製を行う設定のPathに変えている… ダサい… |
89 return _edit(newParh, appendChildAndPutAttribute); | |
86 } | 90 } |
87 | 91 |
88 @Override | 92 @Override |
89 public Either<Error, JungleTreeEditor> addNewChildAt(NodePath path, int _pos) { | 93 public Either<Error, JungleTreeEditor> addNewChildAt(NodePath path, int _pos) { |
94 if (path.getPathType() != PathType.RedBlack) | |
95 return DefaultEither.newA(UNDEFINE_NODEPATH); | |
90 ByteBuffer value = ByteBuffer.wrap("defaultValue".getBytes()); | 96 ByteBuffer value = ByteBuffer.wrap("defaultValue".getBytes()); |
91 return addNewChildAndPutAttribute(path, 0, balanceKey, value); | 97 return addNewChildAndPutAttribute(path, 0, balanceKey, value); |
92 } | 98 } |
93 | 99 |
94 @Override | 100 @Override |
95 public Either<Error, JungleTreeEditor> deleteChildAt(NodePath path, int pos) { | 101 public Either<Error, JungleTreeEditor> deleteChildAt(NodePath path, int pos) { |
102 if (path.getPathType() != PathType.RedBlack) | |
103 return DefaultEither.newA(UNDEFINE_NODEPATH); | |
96 String key = path.getKey(); | 104 String key = path.getKey(); |
97 if (!key.equals(balanceKey)) | 105 if (!key.equals(balanceKey)) |
98 return DefaultEither.newA(INVALID_ARGUMENT); | 106 return DefaultEither.newA(INVALID_ARGUMENT); |
107 NodePath newParh = path.setType(PathType.RedBlackNode); //回転処理を行わないで木の複製を行う設定のPathに変えている… ダサい… | |
99 ByteBuffer value = path.getValue(); | 108 ByteBuffer value = path.getValue(); |
100 RedBlackTreeDeleteChildAt deleteChildAt = new RedBlackTreeDeleteChildAt(key, value); | 109 RedBlackTreeDeleteChildAt deleteChildAt = new RedBlackTreeDeleteChildAt(key, value); |
101 return _edit(path, deleteChildAt); | 110 return _edit(newParh, deleteChildAt); |
102 } | 111 } |
103 | 112 |
104 @Override | 113 @Override |
105 public Either<Error, JungleTreeEditor> putAttribute(NodePath path, String key, ByteBuffer value) { | 114 public Either<Error, JungleTreeEditor> putAttribute(NodePath path, String key, ByteBuffer value) { |
115 if (path.getPathType() != PathType.RedBlack) | |
116 return DefaultEither.newA(UNDEFINE_NODEPATH); | |
106 if (key.equals(balanceKey)) | 117 if (key.equals(balanceKey)) |
107 return DefaultEither.newA(INVALID_ARGUMENT); | 118 return DefaultEither.newA(INVALID_ARGUMENT); |
108 if (path.getPathType() != PathType.RedBlack) | 119 if (path.getPathType() != PathType.RedBlack) |
109 return DefaultEither.newA(INVALID_ARGUMENT); | 120 return DefaultEither.newA(INVALID_ARGUMENT); |
110 NodeEditor editor = new PutAttribute(key, value); | 121 NodeEditor editor = new PutAttribute(key, value); |
111 NodePath newParh = path.add(-1); //回転処理を行わないで木の複製を行う設定のPathに変えている… ダサい… | 122 NodePath newParh = path.setType(PathType.RedBlackAttribute); //回転処理を行わないで木の複製を行う設定のPathに変えている… ダサい… |
112 return _edit(newParh, editor); | 123 return _edit(newParh, editor); |
113 } | 124 } |
114 | 125 |
115 @Override | 126 @Override |
116 public Either<Error, JungleTreeEditor> deleteAttribute(NodePath path, String _key) { | 127 public Either<Error, JungleTreeEditor> deleteAttribute(NodePath path, String _key) { |
128 if (path.getPathType() != PathType.RedBlack) | |
129 return DefaultEither.newA(UNDEFINE_NODEPATH); | |
117 if (_key.equals(balanceKey)) | 130 if (_key.equals(balanceKey)) |
118 return DefaultEither.newA(INVALID_ARGUMENT); | 131 return DefaultEither.newA(INVALID_ARGUMENT); |
119 DeleteAttribute deleteAttribute = new DeleteAttribute(_key); | 132 DeleteAttribute deleteAttribute = new DeleteAttribute(_key); |
120 NodePath newParh = path.add(-1); //回転処理を行わないで木の複製を行う設定のPathに変えている… ダサい… | 133 NodePath newParh = path.setType(PathType.RedBlackAttribute); //回転処理を行わないで木の複製を行う設定のPathに変えている… ダサい… |
121 return _edit(newParh, deleteAttribute); | 134 return _edit(newParh, deleteAttribute); |
122 } | 135 } |
123 | 136 |
124 | 137 |
125 @Override | 138 @Override |