Mercurial > hg > Members > tatsuki > bench > jungle-core
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/store/impl/logger/LoggingNode.java @ 175:e26462a38ce0
add push pop
author | tatsuki |
---|---|
date | Fri, 06 Mar 2015 10:44:50 +0900 |
parents | 371b6ddb78f2 |
children |
comparison
equal
deleted
inserted
replaced
173:f26535302c96 | 175:e26462a38ce0 |
---|---|
1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; | 1 package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; |
2 | 2 |
3 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; | 3 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; |
4 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; | |
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.ReplaceRootNodeOperation; | |
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; | |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; | |
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; | |
4 | 9 |
5 | 10 |
6 public class LoggingNode | 11 public class LoggingNode |
7 { | 12 { |
13 | |
14 private final TreeNode wrap; | |
15 private final OperationLog log; | |
16 | |
8 public LoggingNode(TreeNode _wrap) | 17 public LoggingNode(TreeNode _wrap) |
9 { | 18 { |
10 this(_wrap,new DefaultOperationLog()); | 19 this(_wrap,new DefaultOperationLog()); |
11 } | 20 } |
12 | 21 |
13 public LoggingNode(TreeNode _wrap,OperationLog _log) | 22 public LoggingNode(TreeNode _wrap,OperationLog _log) |
14 { | 23 { |
15 wrap = _wrap; | 24 wrap = _wrap; |
16 log = _log; | 25 log = _log; |
17 } | 26 } |
18 | |
19 private final TreeNode wrap; | |
20 private final OperationLog log; | |
21 | 27 |
22 public LoggingAttributes getAttributes() | 28 public LoggingAttributes getAttributes() |
23 { | 29 { |
24 return new LoggingAttributes(wrap,log); | 30 return new LoggingAttributes(wrap,log); |
25 } | 31 } |
33 public OperationLog getOperationLog() | 39 public OperationLog getOperationLog() |
34 { | 40 { |
35 return log; | 41 return log; |
36 } | 42 } |
37 | 43 |
38 public TreeNode getWrap() | |
39 { | |
40 return wrap; | |
41 } | |
42 | 44 |
45 public Either<Error, LoggingNode> replaceNewRootNode() { | |
46 NodeOperation replaceRootNode = new ReplaceRootNodeOperation(); | |
47 return edit(replaceRootNode); | |
48 } | |
49 | |
50 public Either<Error, LoggingNode> edit(NodeOperation op){ | |
51 Either<Error,TreeNode> either = op.invoke(wrap); | |
52 if(either.isA()){ | |
53 return DefaultEither.newA(either.a()); | |
54 } | |
55 | |
56 TreeNode newWrap = either.b(); | |
57 OperationLog newLog = log.add(op); | |
58 LoggingNode newLoggingNode = new LoggingNode(newWrap,newLog); | |
59 return DefaultEither.newB(newLoggingNode); | |
60 } | |
61 | |
62 public TreeNode getWrap() | |
63 { | |
64 return wrap; | |
65 } | |
43 } | 66 } |