Mercurial > hg > Members > shoshi > jungle > jungle-core
view src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/store/logger/LoggingNode.java @ 329:2a0cb1f0ba4e
rename Error package
author | kono |
---|---|
date | Sat, 08 Jul 2017 21:05:55 +0900 |
parents | 5da8a19dbe76 |
children |
line wrap: on
line source
package jp.ac.u_ryukyu.ie.cr.jungle.store.logger; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.util.jungleError.Error; import jp.ac.u_ryukyu.ie.cr.jungle.transaction.node.TreeNode; import jp.ac.u_ryukyu.ie.cr.jungle.store.operations.ReplaceRootNodeOperation; import jp.ac.u_ryukyu.ie.cr.jungle.util.DefaultEither; import jp.ac.u_ryukyu.ie.cr.jungle.util.Either; public class LoggingNode { private final TreeNode wrap; private final OperationLog log; private TreeNode editedNode; public LoggingNode(TreeNode _wrap) { this(_wrap, new DefaultOperationLog()); } public LoggingNode(TreeNode _wrap, OperationLog _log) { this.wrap = _wrap; this.log = _log; } public LoggingNode(TreeNode wrap,TreeNode editedNode, OperationLog log) { this.wrap = wrap; this.log = log; this.editedNode = editedNode; } 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; } public void setEditedNode(TreeNode editedNode) { this.editedNode = editedNode; } public TreeNode getEditedNode(){ return editedNode; } }