Mercurial > hg > Members > shoshi > jungle > jungle-core
annotate src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/logger/LoggingChildren.java @ 308:201cc75a9984
change Red Black Tree Edit Path Extends
author | tatsuki |
---|---|
date | Thu, 26 Jan 2017 15:23:25 +0900 |
parents | 1a5f3d3f3437 |
children | 5b9a3bc593a7 |
rev | line source |
---|---|
263 | 1 package jp.ac.u_ryukyu.ie.cr.jungle.store.logger; |
21
848f73545c4d
add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff
changeset
|
2 |
92 | 3 |
209 | 4 import jp.ac.u_ryukyu.ie.cr.jungle.core.Children; |
292 | 5 import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.*; |
265 | 6 import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; |
209 | 7 import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; |
8 import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; | |
266 | 9 import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error; |
21
848f73545c4d
add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff
changeset
|
10 |
292 | 11 import java.nio.ByteBuffer; |
12 | |
295 | 13 public class LoggingChildren { |
14 private final TreeNode wrap; | |
15 private final OperationLog log; | |
16 | |
17 public LoggingChildren(TreeNode _wrap, OperationLog _log) { | |
18 wrap = _wrap; | |
19 log = _log; | |
20 } | |
21 | |
22 public int size() { | |
23 Children children = wrap.getChildren(); | |
24 return children.size(); | |
25 } | |
21
848f73545c4d
add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff
changeset
|
26 |
295 | 27 public Either<Error, LoggingNode> edit(NodeOperation _op) { |
28 Either<Error, TreeNode> either = _op.invoke(wrap); | |
29 if (either.isA()) { | |
30 return DefaultEither.newA(either.a()); | |
31 } | |
32 | |
33 TreeNode newWrap = either.b(); | |
34 OperationLog newLog = log.add(_op); | |
35 LoggingNode newLoggingNode = new LoggingNode(newWrap, newLog); | |
36 return DefaultEither.newB(newLoggingNode); | |
37 } | |
38 | |
39 public Either<Error, LoggingNode> addNewChildAt(final int _pos) { | |
40 NodeOperation addNewChildAt = new AppendChildAtOperation(_pos); | |
41 return edit(addNewChildAt); | |
42 } | |
21
848f73545c4d
add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff
changeset
|
43 |
292 | 44 |
295 | 45 public Either<Error, LoggingNode> addNewChildAndPutAttribute(int pos, String key, ByteBuffer value) { |
46 NodeOperation addnewChildAndPutAttribute = new AddNewChildAndPutAttribute(pos, key, value); | |
47 return edit(addnewChildAndPutAttribute); | |
48 } | |
292 | 49 |
295 | 50 public Either<Error, LoggingNode> deleteChildAt(final int pos) { |
51 NodeOperation deleteChildAt = new DeleteChildAtOperation(pos); | |
52 return edit(deleteChildAt); | |
53 } | |
41 | 54 |
249 | 55 |
295 | 56 public Either<Error, LoggingNode> redBlackTreeDeleteChildAt(String key, ByteBuffer value) { |
57 NodeOperation deleteChildAt = new RedBlackTreeDeleteChildAtOperation(key, value); | |
58 return edit(deleteChildAt); | |
59 | |
60 } | |
61 | |
62 public Either<Error, LoggingNode> moveChild(String move, int childNum) { | |
63 NodeOperation moveChild = new ChildMoveOperation(move, childNum); | |
64 return edit(moveChild); | |
65 } | |
249 | 66 |
295 | 67 public Either<Error, LoggingNode> at(int _pos) { |
68 Children children = wrap.getChildren(); | |
69 Either<Error, TreeNode> either = children.at(_pos); | |
70 if (either.isA()) { | |
71 return DefaultEither.newA(either.a()); | |
72 } | |
73 | |
74 TreeNode node = either.b(); | |
75 LoggingNode logNode = new LoggingNode(node); | |
76 return DefaultEither.newB(logNode); | |
77 } | |
308 | 78 |
21
848f73545c4d
add LoggingNode , LoggingAttributes , LoggingChildren , Logger
Shoshi TAMAKI
parents:
diff
changeset
|
79 } |