Mercurial > hg > Members > tatsuki > bench > jungle-core
view 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 |
line wrap: on
line source
package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.ReplaceRootNodeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; public class LoggingNode { private final TreeNode wrap; private final OperationLog log; public LoggingNode(TreeNode _wrap) { this(_wrap,new DefaultOperationLog()); } public LoggingNode(TreeNode _wrap,OperationLog _log) { wrap = _wrap; log = _log; } public LoggingAttributes getAttributes() { return new LoggingAttributes(wrap,log); } public LoggingChildren getChildren() { return new LoggingChildren(wrap,log); } public OperationLog getOperationLog() { return log; } public Either<Error, LoggingNode> replaceNewRootNode() { NodeOperation replaceRootNode = new ReplaceRootNodeOperation(); return edit(replaceRootNode); } public Either<Error, LoggingNode> edit(NodeOperation op){ Either<Error,TreeNode> either = op.invoke(wrap); if(either.isA()){ return DefaultEither.newA(either.a()); } TreeNode newWrap = either.b(); OperationLog newLog = log.add(op); LoggingNode newLoggingNode = new LoggingNode(newWrap,newLog); return DefaultEither.newB(newLoggingNode); } public TreeNode getWrap() { return wrap; } }